I'm writing a piece of code for a game which I am a creating: just a simple game where the player must guess higher or lower for the next card in the sequence.
I am just 1 step away from it working, however I am very confused as to how I can tackle the problem I am faced with.
Here is the code:
Code:
/**
* This class models a player.
*/
public class Player
{
private String name;
private Card[] card = new Card[5];
private int score = 0;
/**
* Contructor for objects of class Player.
* @param A String which initialises the name of the player.
*/
public Player(String name)
{
this.name = name;
}
/**
* Gets the score of the player.
* @return An integer value representing the score of the player.
*/
public int getScore()
{
return score;
}
/**
* Gets the name of the player.
* @return A String representing the name of the player.
*/
public String getName()
{
return name;
}
/**
* Gives the player 5 cards from the pack.
*/
private void fill()
{
PackOfCards deck = new PackOfCards();
int i = 0;
while(i < card.length) {
card[i] = deck.selectCard();
i++;
}
}
/**
* Calls the fill() method and creates the method to enable the player to play the game.
*/
public void play()
{
fill();
Reader reader = new Reader();
boolean stillPlaying = true;
System.out.println(card[0].toString());
int index = 1;
while(stillPlaying = true) {
if(reader.equals("higher") /*&& is correct*/) {
if(card[index] > card[index - 1]) {
score++;
index++;
System.out.println(card[index].toString());
}
}
if(reader.equals("higher") /*&& is wrong*/) {
score = 0;
index++;
System.out.println(card[index].toString());
stillPlaying = false;
}
if(reader.equals("lower") /*&& is correct*/) {
score++;
index++;
System.out.println(card[index].toString());
}
if(reader.equals("lower") /*&& is wrong*/) {
score = 0;
index++;
System.out.println(card[index].toString());
stillPlaying = false;
}
if(reader.equals("freeze")) {
stillPlaying = false;
}
}
Reader.close();
}
}
I coloured the text that is causing the error in
red. I want it to do:
if(the current card is greater than the previous card) {
}
However, I am unsure how to do so. I get an error which complains about the > operator.
Would anyone mind helping me?
Cheers