Java Programming Help

profilemsalkaht
lab5_shell.docx

import java.util.Scanner;

public class Lab5Shell

{

public static void main(String args[])

{

// variables

Scanner input = new Scanner(System.in);

char[][] board = new char[7][8];

boolean finished = false;

boolean gameOver = false;

char currentPlayer = 'X';

int numMoves = 0;

// loop until user wants to stop

do

{

// init game board

// initialize variables

// display the board

DisplayBoard(board);

// loop until this game is over

do

{

// get the next move for the current player

int columnChosen;

do

{

System.out.println("Enter the column you want to place your piece.");

columnChosen = input.nextInt();

} while ((columnChosen < 1) || (columnChosen > 7) || (board[1][columnChosen] != ' '));

// place piece

// increment number of moves

// display the board

DisplayBoard(board);

// check for win

if (CheckForWin(board))

{

// if winner, display congratulations and set gameOver true

}

else if (numMoves == 42)

{

// if tie, display result and set gameOver true

}

else

{

// switch current player

}

} while (!gameOver);

// ask if user wants to play again, set finished accordingly

} while (!finished);

}

// this method displays the board passed in

public static void DisplayBoard(char[][] board)

{

}

// this method determines if a game has been won

public static boolean CheckForWin(char[][] board)

{

// check for horizontal

for (int row = 1; row <= 6; row++)

{

for (int col = 1; col <= 4; col++)

{

if (board[row][col] == board[row][col+1] &&

board[row][col] == board[row][col+2] &&

board[row][col] == board[row][col+3] &&

board[row][col] != ' ')

{

return true;

}

}

}

// check for vertical

// check for diagonal up

// check for diagonal down

return false;

}

}