Battleship留学生辅导、讲解Python程序设计、辅导programming、Python语言辅导 讲解留学生Processing|

- 首页 >> 其他
Battleship +

1.OBJECTIVES

The purpose of this assignment is to improve your problem solving and programming skill with Python. You can practise and acquire hands-on knowledge with Python programming, in particular on data processing, branching, and looping.

Here you are asked to write a Python program that allows the user to play an extended version of Battleship with the computer. The user is asked to place his ships on the board according 3D coordinates (row, column, depth) and orientation (vertical or horizontal), followed by the computer. The user is then asked a set of 3D coordinates, which represents an attack with an area of impact, on the computer’s ships, and the program will report if it is a hit, a miss, and if any ships are sunk. After the player’s turn, the computer will then select a set of coordinates and the computer reports the results. The game will end when either the player or computer’s ships are all sunk.

You should consider the following in your code:

1.Algorithm design (major steps):

a.Create user’s account or login using existing account
b.User inputs ship and target coordinates

c.Reporting if the attack was a hit or a miss

d.Updating user and computer boards to determine results of the game.
2.Programming style with proper comments

3.Correctness of your solution.
2.DETAILED FLOW OF THE PROGRAM

If the GUI version is too challenging for your team, console version is sufficient to fulfil the basic requirements. Please discuss among team members to decide the interface.

2.1 Create account

The sample interfaces of Console version and GUI version are as follows:
Figure 1. Console version

Figure 2. GUI version

Requirement:

File handling:
A file is used to store user information to simulate register and login function.

Once the program starts
?New user registration: enter user name (make sure it is unique), date of birth, password to store in the file

String operation
The password must meet the following common criteria:
The length of the password is more than 8 characters
At least one upper case letter
At least one lower case letter
At least one digit
At least one special symbol (punctuation)
Cannot contain user name

Exception handling for file operation
If the file cannot be found, need handle the exception. E.g., New text file will be created if there is no pre-existing file.

2.2 Login

Figure 3. GUI version

Existing user needs enter user name and password to login. User name and password must match the one stored in the file to login. The users can try three times before the account is locked. Once the account is locked, the user has to answer question to activate the account, in our system, the question is date of birth.

2.3 Position the battleships

The battleship board will be 10 rows, 10 columns, 2 depth layers (10 x 10 x 2). Among the depth layers, one represents the sea surface while the other represents the subsea. The length of the ships are as follows.
1 x Carrier: 4 units
1 x Submarine: 3 units

A ship takes up continuous boxes and can only oriented in a horizontal or vertical manner. A Carrier cannot be placed in the subsea layer, while a submarine can be placed on either of these two layers. Within the same layer, ships cannot be placed on one another, i.e. no overlapping coordinates.

Figure 4. Console version

Figure 5. GUI version

You can make use of up to 4 boards to track the progress of the game, each containing information of both the surface and the subsea layer. For example,

1.User’s ship placement board

2.User’s targeting board

3.Computer’s ship placement board

4.Computer’s targeting board

2.4 Start the battle

Note: You are not required to implement any form of “intelligence” in the computer’s selection of targets. Random targets will suffice for this assignment.

After the user and computer has placed all the ships, the user will be prompted to enter a target coordinate. The program then reports if it is a hit or miss and records it accordingly in the board. The computer then makes its move (selects a coordinate) and its results are also recorded respectively. In this version of Battleship, an attack does not only have impact on a grid, but also all the grids surrounding it. For example, for a target coordinate of (3,3,1), the affected targets are: (3,3,1), (4,3,1), (2,3,1), (3,4,1), (3,2,1), (2,2,1), (2,4,1), (4,2,1) and (4,4,1). This continues until either the player or computer’s ship are all sunk. Announce the winner and end the program.

Figure 6. GUI version