Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Jacks-MacBook-Pro:Cs124 Jack_XXX$
- public static void main(String[] args) {
- ConnectFour connectFour= new ConnectFour();
- BoardView view = connectFour.getView();
- JFrame worldFrame = new JFrame();
- JPanel buttonPanel = new JPanel();
- view.repaint();
- worldFrame.setContentPane(view);
- worldFrame.add(buttonPanel);
- worldFrame.validate();
- worldFrame.pack();
- worldFrame.setVisible(true);
- Scanner input = new Scanner(System.in);
- System.out.println("Welcome to Connect Four. The object of the game is to get four of the same colored pieces in a row.");
- System.out.println("Red will go first.");
- //sets up the gameboard and then draws it
- for (int i = 0; i < connectFour.getGameBoard().length; i++) {
- for (int j = 0; j < connectFour.getGameBoard()[0].length; j++) {
- connectFour.getGameBoard()[i][j] = 0;
- }
- }
- view.repaint();
- connectFour.printGameBoard();
- String pwon = "";
- boolean playgame=true;
- //actual gamecode
- while(playgame=true){
- boolean game=false;
- while (game == false) {
- System.out.println("Red, which column would you like to move into?");
- System.out.println("Note Column Numbers 1 to 7 are accepted.");
- int x = input.nextInt();
- connectFour.move1(x, connectFour.getGameBoard());
- if ((connectFour.getGameBoard()[0][x-1]==1)||(connectFour.getGameBoard()[0][x-1]==2)){
- System.out.println("Invalid move. You lost your turn");
- }
- view.repaint();
- connectFour.printGameBoard();
- if (connectFour.isFourInaRow()) {
- pwon = "Red";
- break;
- }
- System.out.println("Black, which column would you like to move into?");
- System.out.println("Note Column Numbers 1 to 7 are accepted.");
- x = input.nextInt();
- connectFour.move2(x, connectFour.getGameBoard());
- if ((connectFour.getGameBoard()[0][x-1]==1)||(connectFour.getGameBoard()[0][x-1]==2)){
- System.out.println("Invalid move. You lost your turn");
- }
- view.repaint();
- connectFour.printGameBoard();
- if (connectFour.isFourInaRow()) {
- pwon = "Black";
- break;
- }
- }
- if (connectFour.checkRow() == true) {
- System.out.println("row");
- } else if (connectFour.checkColumn() == true) {
- System.out.println("col");
- } else if (connectFour.checkDiag() == true) {
- System.out.println("diag");
- } else{
- System.out.println("draw");
- }
- System.out.println("Congrats " + pwon + " won the game.");
- System.out.println("Would you like to play again? Y/N");
- input.nextLine();
- String answer = input.nextLine();
- if((answer.equals("N"))||(answer.equals("n"))){
- break;
- }
- }
- System.out.println("Thanks for playing.");
- }
- input.nextLine();
- String answer = input.nextLine();
- String answer = input.nextLine();
- if ( answer . toUpperCase ( ) . equals ( "N" ) )
- {
- System . out . println ( "Thanks for playing!" ) ;
- System . exit ( 0 ) ;
- }
Add Comment
Please, Sign In to add comment