By Your mission, should you decide to accept it, is to create a Java program that can play a game of Tic-Tac-Toe with the user. As you probably know, Tic-Tac-Toe is a simple game usually played with paper and pencil. First, you make a simple 3 x 3 grid on the paper.
Then two players alternate turns by marking Xs and Os in empty spaces on the grid. The first player who makes three of his or her marks in a horizontal, vertical, or diagonal row wins. Rules For Tic Tac ToeIf all of the spaces in the grid are filled before any player marks three in a row, the game is a draw. Here are the rules and instructions for this challenge: • The computer plays against the human. The human moves first and is X. Tic Tac Toe Java ProjectJava Swing Tutorials For Tic Tac Toe Program Computer MoveThe computer is O. • The program should begin by displaying a short welcome message, and then should prompt the player for his or her first move. For example: Welcome to Tic-Tac-Toe. Please enter your first move: • To designate the squares of the grid, use the letters A, B, and C for the columns and the numerals 1, 2, and 3 for the rows, like this: A1 B1 C1 A2 B2 C2 A3 B3 C3 Thus, to place an X in the top-left square, the human player would enter the text A1 when the program prompts the player for a move. After the human enters a move, the program should display the current status of the board on the console. • Use X to mark the human’s plays and O to mark the computer’s plays. Tic Tac Toe Program In CUse vertical bar characters (found on the keyboard with the backslash character, just above the Enter key) and hyphens to draw the board in a simple grid. For example, if the user has entered A1 as his or her first move, the program would display the following: X|| ---|---|---|| ---|---|---|| • After the human’s move, the program determines its move, announces it to the user, displays an updated board, and then prompts for the user’s move. For example, you might see this: I will play A2: X| O| ---|---|---|| ---|---|---|| Please enter your next move: • Play continues until one player has scored three in a row or all squares have been filled with no winner. Your program must be able to determine whether either player has scored three in a row and won the game. (This is the most difficult part of this programming challenge.) • When the game is over, the program displays a message indicating the result of the game: “You beat me!” if the human player wins, “I beat you!” if the computer player wins, or “It’s a draw!” if the game ends in a draw.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
November 2018
Categories |