Hey, ran into a little trouble with this, keep getting this error. I went over it many times, but can seem to find where the curly bracket is missing or if I have too many or so.

import java.lang.*;
/**
 * Carries out the instructions from all the objects.
 * Enter your names, and be prepared for an all out
 * BRAWL!!!
 * 
 * @author Eric Foertsch
 * @version 2.02
 */
public class Game{
    private GameBoard gameB;
    private Spinner spinn;
    private Player player1, player2, player3, player4;
    private int whoseTurn;

/**
 * Instantiate's both the Gameboard and Spinner,
 * Takes user defined names, and assigns them to a player number,
 * and sets up player 1 to take the first turn.
 */
public Game(String pPlayerName1,String pPlayerName2,String pPlayerName3,String pPlayerName4){
    gameB = new GameBoard();
    spinn = new Spinner(6);
    player1 = new Player(pPlayerName1, 1);
    player2 = new Player(pPlayerName2, 2);
    player3 = new Player(pPlayerName3, 3);
    player4 = new Player(pPlayerName4, 4);
    whoseTurn = 1;
    }
    
/**
 * Creates a visual representation of the gameboard, and pieces,
 * and prints it out.
 */
public void printGameStatus(){
    System.out.println(gameB.toString());
    System.out.println(gameB.getPlayerLine(player1));
    System.out.println(gameB.getPlayerLine(player2));
    System.out.println(gameB.getPlayerLine(player3));
    System.out.println(gameB.getPlayerLine(player4));
    }

/**
* this is a helper method to generate spaces.
* * the call replicate(" ",13) will return a 13 character String of spaces
*/
private String replicate(String input, int nbr){
    String retVal="";
    for(int i=0; i<nbr; i++)
            retVal+=input;
        return retVal;
    }

/**
 * Sets up the turn order, and rules for this game.
 * It contains, a rollback if whoseTurn = 5,
 * it also contains instructions for losing and taking
 * another turn, as well as winning and losing.
 */
public boolean nextTurn(){
    String returnValue ="";

/**
 * Player 1
 */        
if(whoseTurn == 1){
    returnValue = player1.takeTurn(spinn, gameB);
    System.out.println("Player 1 " + returnValue);
if(returnValue.contains("Spin again") || (player1.getPosition() == 5) || (player1.getPosition() == 10) || (player1.getPosition() == 15)){
    player1.takeTurn(spinn, gameB);
    whoseTurn = whoseTurn + 1;
        return true;
            }
if(returnValue.contains("won")){
        return false;
            }
whoseTurn = whoseTurn + 1;
        return true;
}

/**
 * Player 2
 */
if(whoseTurn == 2){
    returnValue = player2.takeTurn(spinn, gameB);
    System.out.println("Player 2 " + returnValue);
if(returnValue.contains("Spin again") || (player2.getPosition() == 5) || (player2.getPosition() == 10) || (player2.getPosition() == 15)){
    player2.takeTurn(spinn, gameB);
    whoseTurn = whoseTurn + 1;
        return true;
            }
if(returnValue.contains("won")){
        return false;
            }
whoseTurn = whoseTurn + 1;
        return true;
}

/**
 * Player 3
 */           
if(whoseTurn == 3){
    returnValue = player3.takeTurn(spinn, gameB);
    System.out.println("Player 3 " + returnValue);
if(returnValue.contains("Spin again") || (player3.getPosition() == 5) || (player3.getPosition() == 10) || (player3.getPosition() == 15)){
    player3.takeTurn(spinn, gameB);
    whoseTurn = whoseTurn + 1;
        return true;
            }
if(returnValue.contains("won"))
        return false;
            }
whoseTurn = whoseTurn + 1;
        return true;
}

/**
 * Player 4
 */        
if(whoseTurn == 4){ <----Errors here 
    returnValue = player4.takeTurn(spinn, gameB);
    System.out.println("Player 4 " + returnValue);
if(returnValue.contains("Spin again") || (player4.getPosition() == 5) || (player4.getPosition() == 10) || (player4.getPosition() == 15)){
    player4.takeTurn(spinn, gameB);
    whoseTurn = 1;
        return true;
            }
if(returnValue.contains("won")){
        return false;
            }
whoseTurn = 1;
        return true;
}
        return true;
}

/**
 * Plays the whole game, untill there is a winner.
 */
public void playWholeGame(){
    boolean done = true;
        while(done == true){
        done = nextTurn();
        printGameStatus();
}
}
}

It works fine with 3 players, but the fourth errors.

Recommended Answers

All 3 Replies

if (returnValue.contains("won")) {
                return false;
            }
            // } <--------------------------------------------<

            whoseTurn = whoseTurn + 1;
            return true;
        }
        /**
         * Player 4
         */
        if (whoseTurn == 4) { //<----        Errors here

I tried to add that curly bracket there, no luck.

It gave me an <identifier> error on the

whoseTurn = whoseTurn + 1;

below it

if (returnValue.contains("won")) { // added bracket
                    return false;
                }
                whoseTurn = whoseTurn + 1;
                return true;
            }

            /**
             * Player 4
             */
            if (whoseTurn == 4) { //<----Errors here
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.