Reference no: EM133011260
CSE5APG Advanced Python Programming - La Trobe University
Build a Naughts and Crosses game
Assignment description
The Assignment 2 will test your understanding and ability to apply what you have learnt throughout the lectures.
- Python basics
- Data structures
- Function
- OOP
- Exception Handling
Naughts and Crosses game (aka Tic-Tac-Toe) is a well-known and very sim- ple two-player game. The game consists of a playing grid (3x3 or higher) and two players. The playing grid has a set of squares. The squares will be filled by the players. The two players are known as the Naughts player which will be detonated as "O" and the Crosses player which will be denoted as "X". The playing rules are :
ˆ The Naughts player plays with "O".
ˆ The Crosses player plays with "X".
ˆ Players take turns by placing "O" or "X" on the playing grid square.
ˆ Only one player can play at a time- either "O" or "X".
ˆ The player makes their selection by entering the location of grid square they want to go (the square they want to fill).
ˆ If any of the two players have filled a grid square, then the other player and the same player cannot filled that square.
ˆ If any player gets three of their marks ("O" or "X".) on the board in a row, column or one of the two diagonals, this player will be the winner.
ˆ When the playing grid square fills up with neither player winning, the game terminates with no winner.
Steps you must complete
Please see and run attached code: test.py. You need to convert test.py into a new code using: function, OOP and exception handling. The code should ask the user to key-in the size of playing grid (e.g., 3x3, 6x6, ..etc). For example, current grid and final should be printed using function. In addition, invalid input should be handled. You need to develop three main classes: Board, Player, GameState. Each class must be implemented and tested. It is ex- pected that your program can accept various grid sizes, so all input should be set automatically based on the gird size. You must use the same names for classes (Board, Player, GameState) and functions.
The main steps are:
1. Once you run the program, the user will be prompted with a menu.
2.The user will need to enter their choice.
3. The choice will be to either begin the game, or quit.
4. If the user enters an invalid choice, the user should be prompted appro- priately letting them choose once more.
5. The program should not end unless the user chooses otherwise.
6. If the user begins the game, the game will be terminated if one player win the game or all playing grid square have been filled up with neither player winning.
3.1 Main Menu
In the main menu, the user will be prompt with a menu consisting two choices.
ˆ Begin the game
ˆ Quit the game
This will menu will be printed out to the screen.
3.2 User enter choice
The user will enter their choice. Which will result in the following.
ˆ Begin game should prompt with The game has begun then return to the main menu.
ˆ The quit game, should break out of the loop and stop the program.
3.3 Check User Input
The users choice should be checked to see if it is valid. If not then throws a custom error.
3.4 Throw custom error if user input is invalid
Please implement a custom error. This custom error should be caught be a try catch error.
4 Overview of flow of code
5 Classes Information
The Assignment 2 will consist of developing three main classes: Board, Player, GameState.
6 The Main
Below is a detailed UML diagrams explaining how the classes are related to each other. They are for explanation purpose. You can add any parameters or functions.
6.1 Overview of class relationship
7 Board
7.1 Relationship
Board
- display board(board: list)
+ check board(board: list, gameover: bool)
7.2 Board Class
8 Player
8.1 Relationship
Player
- interaction(board: list)
+ update board(board: list, gameover: bool)
8.2 Player Class
9 GameState
9.1 Relationship
GameState
- interaction(board: list)
+ update board(board: list, gameover: bool)
9.2 GameState Class
Attachment:- Advanced Python Programming.rar