import OthelloBoard; import OthelloPlayer; import OthelloComputerPlayer; import OthelloRules; import SimpleOutput; import SimpleInput; /** This "faux" class represents a textual user interface and is designed to work with the above classes. * * @author Amber McNett * @author Hisako Watanabe * @author Katt Thorne (in abstentia) * version 1.0 of February 2000 */ public class OthelloTUI // +--------+-------------------------------------------------- // | Fields | // +--------+ // player 1's name String name; // player 2's name String name2; // +------------+-------0--------------------------------------- // | Methods | // +-------------+ /** This is the main method which will begin the program and let it know how many human players will be * playing. */ public static void main(String[] args) { SimpleOutput out = new SimpleOutput(); SimpleInput in = new SimpleInput(); OthelloTUI othtui = new OthelloTUI(); int playnum; out.println("Welcome to CS152 Othello, version 1.0! How many human players will be playing today?"); this.playnum = in.readint(playnum); while (playnum > 2 || playnum < 0) { out.println("Invalid number. Please enter again.") this.playnum = in.readint(playnum); } if (playnum == 0) { this.name = String("Computer 1"); this.name 2 = String("Computer 2"); return othtui.run(); } else if (playnum == 1) { out.println("Please enter your name: "); this.name = in.readString(); this.name2 = String("Computer"); return othtui.run; } else { return othtui.run; out.println("Please enter your name, player one: "); this.name = in.readString(); out.println("Please enter your name, player two: "); this.name2 = in.readString(); } } // main /** this method asks a human player for its next move, moves for the computer, * updates the board, and checks the rules to see if moves are legal. * It also ends the game if the board is full. */ public void run() { OthelloBoard newboard = new OthelloBoard(); OthelloRules rules = new OthelloRules(); ComputerPlayer complay = new CompPlay(); Player player = new player(); int row=0; int col=0; piece.setBoard(); while (!board.askendgame()){ while (rules.whoseturn == human) { while (!rules.legal()) { out.println("Enter the column on the board where you would like to move:"); this.col = in.readint(); out.println("Enter the row on the board where you would like to move:"); this.row = in.readint(); } // while (!rules.legal) board.place(this.col, this.row); board.update(); player.endturn; player.nextturn; board.askendgame(); } // rules (whose turn == human) complay.move(); board.update(); complay.endturn; complay.nextturn; board.askendgame(); } // while (!endgame) board.endgame(); outln.print("The winner is: " + rules.winner + "! Congratulations," + rules.winner + "!"); } // run } // OthelloTUI