## Introduction

代写一个Python的游戏作业，做一个带UI的叫Mario的游戏。这次作业只是整个游戏的第一部分。

## Problam Statement

Over our next two assignments, we shall build our own version of the game Mario. Well, a simple TUI version. TUI means Text-based User Interface or Textual User Interface as opposed to GUI, which stands for Graphical User Interface.

The goal of our Assignment 4 is to set up our game, i.e., set up the maze Mario is meant to travel through. This maze will contain obstacles, Mario himself and an exit gate. The goal of our Assignment 5 will be to allow the user to play our game by moving Mario around the maze.

Let’s start with Assignment 4, shall we. In order to develop our Assignment 4 in an incremental fashion, I propose the following scheme: considering the algorithm below, let’s develop, test and debug each of its steps, one at a time, and move on to the next step only when the step we have been working on is completed. Here is our algorithm:

- Welcome the user.
- Create a maze with a width of mazeWidth and a height of mazeHeight.

a. Assign the value 15 to the variable mazeWidth and the value 12 to the variable mazeHeight. Note that the values of these two variables will change, so let’s make sure we develop our program such that modifying the values of these variables can be done easily.

b. Originally, each cell must contain this string “ . “. Note that the content of our cells will change, so let’s make sure we develop our program such that we can easily change the content of our cells. - Display a boundary around our maze.

a. Originally, we must use the “-“ symbol to create the top and the bottom parts of the boundary around our maze. Note that this symbol will change, so let’s make sure we develop our program such that we can easily change this symbol.

b. Originally, we must use the “|” symbol to create the side sections of the boundary around our maze. Note that this symbol will change, so let’s make sure we develop our program such that we can easily change this symbol. The side sections of the boundary may be tricky to construct! Suggestion: One way to build them is to create a string for each of the row of our maze. This string will contain blank spaces, a number (see 4. b. below), 2 symbols indicating a side section of the boundary and the actual row of our maze.

c. This boundary is not part of our maze, it is outside our maze. - At the top and left of the boundary, display numbers. These numbers will help the user to select a cell in our maze.

a. To produce the top row of numbers, we can build and print a string that will be made of blank spaces and numbers.

b. To produce the left-side column of numbers may be tricky! See the suggestion described in 3. b. above. - Add aNumOfRewardingObstacles of rewarding obstacles to our maze.

a. Assign the value 20 to aNumOfRewardingObstacles. Note that this number will change, so let’s make sure we develop our program such that we can easily change this number.

b. Originally, we must use the symbol “R” to indicate that a cell of our maze contains a rewarding obstacle. Note that this symbol will change, so let’s make sure we develop our program such that we can easily change this symbol.

c. All these obstacles must be randomly located in our maze.

d. We cannot position more than 1 obstacle (of any types) in a cell. - Add aNumOfExplodingObstacles of exploding obstacles to our maze.

a. Assign the value 20 to aNumOfExplodingObstacles. Note that this number will change, so let’s make sure we develop our program such that we can easily change this number.

b. Originally, we must use the symbol “E” to indicate that a cell of our maze contains an exploding obstacle. Note that this symbol will change, so let’s make sure we develop our program such that we can easily change this symbol.

c. All these obstacles must be randomly located in our maze.

d. We cannot position more than 1 obstacle (of any types) in a cell. - Ask the user for Mario’s initial location in the maze.

a. Let’s make sure that the user has entered a location that makes sense:

i. The user has entered 2 integers separated by a blank space. The user has

1) not simply pressed the Enter key, or

2) entered a string, or

3) entered 1 integer or 1 float, or

4) entered 2 numbers of which one or both are floats, or

5) entered more than 2 integers or floats.

ii. The row number entered by the user does not exceed the maximum number of rows of our maze.

iii. The column number entered by the user does not exceed the maximum number of columns of our maze.

iv. Finally, the user has entered the row number and column number of an empty cell.

b. Add Mario at that location. Originally, we must use the symbol “M” to indicate the location of Mario in our maze. Note that this symbol will change, so let’s make sure we develop our program such that we can easily change this symbol.

The Sample Run 1, posted on our course web site below the description of this assignment, illustrates how the program responds to the user when s/he has entered invalid data described in the step (7.) above. - Based on Mario’s location, our program is to place the exit gate on the top or bottom part of our boundary according to the following rule:

a. Imagine we divide our maze into 4 quadrants: top right, top left, bottom right, bottom left.

i. If the user has placed Mario in the top right quadrant, then our program positions the exit gate on the bottom section of the boundary to the left of the median (imaginary vertical line dividing our maze in two).

ii. If the user has placed Mario in the top left quadrant, then our program positions the exit gate on the bottom section of the boundary to the right of the median.

iii. If the user has placed Mario in the bottom right quadrant, then our program positions the exit gate on the top section of the boundary to the left of the median.

iv. If the user has placed Mario in the bottom left quadrant, then our program positions the exit gate on the top section of the boundary to the right of the median.

b. Originally, we must use the symbol “=” to indicate the exit gate on the top or bottom part of the boundary of our maze. Note that this symbol will change, so let’s make sure we develop our program such that we can easily change this symbol.

The code we create for Assignment 4 must produce exactly the same output as the one shown in the images included above and the Sample Runs. Of course, the position of our obstacles (both types), of Mario and of the exit gate will be different but everything else must be the same.

## Caution

Remember that indices of list elements start at 0, while the numbers displayed above and to the left of our maze start at 1. Therefore, when the user selects the cell in which Mario is to be placed on our maze, once we read these two numbers (the row and column numbers), we may have to decrement them by 1 in order to use these numbers as indices.

## Marking

When marking Assignment 4, we will look at how well our solution satisfies the description and requirements of this assignment as described in the problem Statement section above as well as the criteria listed here:

- How well are we abiding to the Good Programming Style items described on the GPS web page of our course web site?
- Have we created functions?
- Have we developed our solution using the following guidelines:
- Decomposition
- Encapsulation
- Function interface design:
- Is each of our functions performing one main (well-defined) action, i.e., it has one purpose?
- Does the name of each of our functions describe the main action or purpose performed by this function?
- Generalization
- Are our functions called from the “# Main” section of our program or from our user-defined functions? Bottom line: all our functions must be called at least once.
- Have we use docstring when implementing our functions (have a look at our textbook for an explanation and an example).
- Whether or not the program executes: are there any syntax and/or runtime errors?
- Whether or not the program solves the problem: are there any semantic errors?