- Joined
- Jan 21, 2007
- Sythe Gold
- 1,234
- Messages
- 14,211
Now Swan, call of your damned armies. I am using object orientation!
This is not done, nor are all the parts working... shuffle is though... that took awhile since i kept finding very small errors in coding... i am making a blackjack game... i decided to make a nice deck class first...
Now, somebody go make a 1v1 poker game.
This is not done, nor are all the parts working... shuffle is though... that took awhile since i kept finding very small errors in coding... i am making a blackjack game... i decided to make a nice deck class first...
Now, somebody go make a 1v1 poker game.
Code:
import java.util.*;
public class Deck
{
String[] a = new String[52];
String[] suits = new String[]
{ "Hearts", "Clubs", "Spades", "Diamonds" };
String[] faces = new String[]
{ "Ace", "Jack", "Queen", "King" };
int topCard = -1;
public Deck()
{
int count = 0;
for (int c = 1; c < 5; c++)
{
for (int b = 0; b < 13; b++)
{
a[count] = b + 1 + "" + c;
count++;
}
}
}
public String shuffle()
{
int[] used = new int[52];
int random;
int count = 0;
boolean cont = true;
boolean first = true;
topCard = -1;
for (int c = 1; c < 5; c++)
{
for (int b = 1; b < 14; b++)
{
if (count > 0)
{
first = true;
cont = true;
random = random(0, 51);
while (cont)
{
cont = false;
if (!first)
{
random = random(0, 51);
}
else
{
first = false;
}
for (int a = 0; a <= count - 1; a++)
{
if (used[a] == random)
{
cont = true;
break;
}
else
{
}
}
}
a[random] = b + "" + c;
used[count] = random;
count++;
}
else if (count == 0)
{
random = random(0, 51);
a[random] = b + "" + c;
used[count] = random;
count++;
}
}
}
return toString();
}
public String toString()
{
return Arrays.toString(a);
}
public String getCard(int location)
{
return a[location - 1];
}
public String getCard(int location, boolean suit)
{
if (!suit)
{
return getCard(location);
}
else
{
String y = getCard(location);
if(y.length() == 3)
return y.charAt(0) + y.charAt(1) + " of " + suits[1];
else
return y.charAt(0) + " of " + suits[1];
}
}
public String getTopCard()
{
topCard++;
return a[topCard];
}
private static int random(int min, int max)
{
return (int) (Math.random() * (max - min + 1)) + min;
}
}












