Need Java help

Status
Not open for further replies.

Yoyo

I love parentheticals
Joined
May 20, 2011
Messages
1,069
Reaction score
774
I'm doing a final project in AP CS and it's a black jack game. (It's C# which is close enough to java) I have most of it done, but for some reason I cannot get it to not draw the same card.

There is the skinny.

I have 2 arrays that have suit and type of card:

public static String[] suit = new String[] { "Clubs", "Diamonds", "Hearts", "Spades" };
public static String[] type = new String[] { "2", "3", "4", "5", "6", "7", "8", "9", "10", "ace", "jack", "king", "queen" };

Here is how I have the computer draw cards:

Random random = new Random();
Random random2 = new Random();

// generates two random numbers to pick an index from the array
int radnomSuitDrawDealer = random.Next(0, 4);
int randomTypeDrawDealer = random2.Next(0, 13);

// Assigns each randomly selected index into a string
String suitDrawDealer = theArrays.suit[radnomSuitDrawDealer];
String typeDrawDealer = theArrays.type[randomTypeDrawDealer];

// for purposes of selecting the image from the saved location, the end result is, for example, "8Hearts"
String draw1 = suitDrawDealer.ToString();
String draw2 = typeDrawDealer.ToString();
String whatHasBeenDrawn = draw2 + draw1;


Here is where I hit a road block. I decided to make another string array of 52 empty spaces, so I could assign each card that is played a spot in the array. To make sure no card is played twice in the same game, I figured I could run a for loop through the newly created array, and if whatHasBeenDrawn is the same as any spot in the array, it would generate new numbers, ect.

To assign each drawn card a spot in the array, I have an int counter that has a value of 0 (when initalized) and is incremented every time a value is set to it:

beenPlayed.hasBeenPlayed[count] = whatHasBeenDrawn;
count++;

Here is my for loop statment to run through the empty array, along with my if statement to check the hasBeenPlayed array agaisnt the whatHasBeenPlayed string:


for (int j = 0; j < beenPlayed.hasBeenPlayed.Length; j++)
{
if (whatHasBeenDrawn.Equals(beenPlayed.hasBeenPlayed[j]))
{

The problem is it's not working. I've made it print out the value of certain spots, for example:

label4.Text = beenPlayed.hasBeenPlayed[2].toString();

And it works fine, the value is getting set correctly. But my question is this: Why is it still drawing the same card twice despite this for and if statement?
 
I've tried making a temp string and changing my if statement:

String temp = beenPlayed.hasBeenPlayed.ToString();

if (whatHasBeenDrawn.Equals(temp))
{

I've tried the if statement every which possible way and I still have no luck.
 
a gentleman can't even get some help
 
Mind giving me the .cs file?
It'll be easier for me to get you an answer that way, and i'll (hopefully) see what is wrong easier.
 
Status
Not open for further replies.

Users who are viewing this thread