Hi. I am a bigginer in java and I really need help. When I run the program my while loop does not executes....what am I doing wrong. Can somebody help me( the GameBord class and its methods validMove, printBoard, and updateBoard are corect; the program should ask the user to enter 2 interger; the moves of the peg board game; until no more legal moves are left). Thank You.
below is my program:
import java.io.*;
class P4
{
public static GameBoard pegBoard;
public static int move;
public static int piece;
public static void main(String args[])
{
System.out.println(" xxxxxxxx"
System.out.println(" xxxxxxxxxxx\n"
System.out.println(" ______"
System.out.println(" / 0 \\"
System.out.println(" / 1 2 \\"
System.out.println(" / 3 4 5 \\"
System.out.println(" / 6 7 8 9 \\"
System.out.println(" /10 11 12 13 14\\"
System.out.println(" ----------------\n"
init();
pegBoard.printBoard();
while(endOfGame() )
{
getInput();
if (pegBoard.validMove(move, piece))
{
pegBoard.updateBoard(move, piece);
pegBoard.printBoard();
}
else
{
System.out.println(" Invalid Move"
getInput();
}
}
System.out.println("GoodBye"
}
public static void init()
{
int i;
pegBoard= new GameBoard(15);
for(i=0; i< 15; i++)
{
pegBoard.board='*';
}
pegBoard.board[12]=' ';
}
public static void getInput()
{
System.out.print(" Which piece would you like to move? "
piece = UserInput.readInt();
System.out.print(" Where would you like to move the piece? "
move = UserInput.readInt();
}
public static boolean endOfGame()
{
int i,j;
boolean r = true;
for(i=0; i< pegBoard.board.length; i++)
{
for(j=0; j<pegBoard.board.length; j++)
{
if(pegBoard.validMove(i,j) )
{
r =true;
continue;
}
else
r = false;
}
}
return r;
}
}
below is my program:
import java.io.*;
class P4
{
public static GameBoard pegBoard;
public static int move;
public static int piece;
public static void main(String args[])
{
System.out.println(" xxxxxxxx"
System.out.println(" xxxxxxxxxxx\n"
System.out.println(" ______"
System.out.println(" / 0 \\"
System.out.println(" / 1 2 \\"
System.out.println(" / 3 4 5 \\"
System.out.println(" / 6 7 8 9 \\"
System.out.println(" /10 11 12 13 14\\"
System.out.println(" ----------------\n"
init();
pegBoard.printBoard();
while(endOfGame() )
{
getInput();
if (pegBoard.validMove(move, piece))
{
pegBoard.updateBoard(move, piece);
pegBoard.printBoard();
}
else
{
System.out.println(" Invalid Move"
getInput();
}
}
System.out.println("GoodBye"
}
public static void init()
{
int i;
pegBoard= new GameBoard(15);
for(i=0; i< 15; i++)
{
pegBoard.board='*';
}
pegBoard.board[12]=' ';
}
public static void getInput()
{
System.out.print(" Which piece would you like to move? "
piece = UserInput.readInt();
System.out.print(" Where would you like to move the piece? "
move = UserInput.readInt();
}
public static boolean endOfGame()
{
int i,j;
boolean r = true;
for(i=0; i< pegBoard.board.length; i++)
{
for(j=0; j<pegBoard.board.length; j++)
{
if(pegBoard.validMove(i,j) )
{
r =true;
continue;
}
else
r = false;
}
}
return r;
}
}