I'm nearing the end of my program and I've hit a snag that I don't know how to fix.
I'm trying to compare the rank value of two cards, so I use a method to get the rank of the card that was just removed from the queue. However, I can't convert the card to int values. I'm a little confused by this because the Card is simply two int values, rank and suit which are then converted to strings via the cRank/cSuit arrays.
This is the specific code that is causing the error
x = Card.getRank(PlayerOne.remove()); //Incompatible types: Card cannot be converted to int
Here is the code, and if you see anything that makes you want to cry just point it out.
Card class
package randomdeck;
import java.util.ArrayList;
import java.util.Stack;
public class Card
{
int suit;
int rank;
public String[] cRank = new String[] { "Ace", "2",
"3", "4", "5", "6", "7", "8", "9", "10", "Jack",
"Queen", "King" };
public String[] cSuit = new String[] { "Hearts",
"Spades", "Diamonds", "Clubs" };
public Card(int rank, int suit)
{
this.suit=suit;
this.rank=rank;
}
int getRank(int rank)
{
return rank;
}
int getSuit(int suit)
{
return suit;
}
void setSuit()
{
suit=Card.this.suit;
}
void setRank()
{
rank=Card.this.rank;
}
public String toString()
{
return cRank[rank] + " of " + cSuit[suit];
}
}
Deck Class
public class Deck
{
Stack<Card> Deck = new Stack<Card>();
public Deck()
{
for(int rank=0; rank<13; rank++)
{
for(int suit=0; suit<4; suit++)
{
Deck.push(new Card(rank,suit));
}
}
}
public void peekDeck()
{
System.out.println(Deck);
}
public void printDeckSize()
{
System.out.println("DECK " + Deck.size());
}
public int getDeckSize()
{
Deck.size();
return Deck.size();
}
public Stack popDeck()
{
Deck.pop();
return Deck;
}
public Stack getDeck()
{
return Deck;
}
public void shuffleDeck()
{
long seed = System.nanoTime();
//Collections.shuffle(Deck, new Random(seed)); //MichealScot.no/gif
ArrayList<Card> temp = new ArrayList<Card>();
while(Deck.size()!=0)
{
temp.add(Deck.pop());
}
Collections.shuffle(temp, new Random(seed));
System.out.println(temp);
Deck.addAll(temp);
temp.clear();
System.out.println(temp);
}
Wargame Class (CLASS WITH ERROR)
public class Wargame extends Deck
{
Queue<Card> PlayerOne = new LinkedList<Card>();
Queue<Card> PlayerTwo = new LinkedList<Card>(); //Stacks that will be used to hold players winnings/starting deck
public Wargame()
{
}
void splitDeck()
{
while(PlayerOne.size()<getDeckSize())
{
PlayerOne.add(Deck.pop());
}
//System.out.println(PlayerOne);
int x = Deck.size();
for(int i=0; i<x; i++)
{
PlayerTwo.add(Deck.pop());
}
//System.out.println(PlayerTwo);
}
public void Game()
{
shuffleDeck();
splitDeck();
ArrayList Temp = new ArrayList();
while(PlayerOne.size()!=0 || PlayerTwo.size()!=0)
{
int x=0;
int y=0;
//Temp.add(PlayerOne.remove());
//Temp.get(0);
x = Card.getRank(PlayerOne.remove());
y = Card.getRank(PlayerTwo.remove()); //Incompatable types, Card cannont be converted to int
}
}