![]() ** The entry main method (the program starts here) */ Public static Scanner in = new Scanner(System.in) // the input Scanner Define named constants to represent the various states of the game Public static int currentPlayer // CROSS, NOUGHT Public static int board = new int // EMPTY, CROSS, NOUGHT Public static final int ROWS = 3, COLS = 3 // number of rows/columns Cell contents: using CROSS, NOUGHT and NO_SEED * All variables/methods are declared as static (i.e., class) * Tic-Tac-Toe: Two-player, console-based, non-graphics, non-OO version. Player 'O' won! TTTConsoleNonOO.java import Player 'O', enter your move (row column): 2 1 Player 'X', enter your move (row column): 2 3 Player 'X', enter your move (row column): 2 2 This move at (2,2) is not valid. Player 'O', enter your move (row column): 3 1 Player 'X', enter your move (row column): 1 3 Player 'O', enter your move (row column): 1 1 Player 'X', enter your move (row column): 2 2 Let us start with a 2-player console (non-graphics) version of Tic-Tac-Toe, where player 'X' and player 'O' enter their moves successively, as shown below: ![]() Let's Start with a 2-Player Console Non-OO Tic-Tac-Toe game can be programmed as a finite state machine, with clearly defined states and state transistion functions, as follows:įor this Tic-tac-toe, I shall try to closely follow this state diagram. Scanner enterCol = new Scanner(System.in) ("Enter a column (0,1,2) for player X: ") Scanner enterRow = new Scanner(System.in) Public static final int SIZE = 3 //size of each row and each column I am unsure about how to go from getting the row/column numbers and putting them into my board I assume I would need to call the getMove method in my if/else statements after the row and column are pressed? What I am having trouble with right now is making a getMove method. I have spelled out in comments in my code what I need.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |