Objectives

After this project, students should be able to:
● Implement user-defined classes using given specifications, including
○ Member variables
○ Member functions
○ Constructors
● Implement a multi-file C++ program using coordination between multiple classes

● Use file input to read a game board file

Background

A game uses a 2D grid to represent the terrain of the surface of the moon on which a lunar rover may land and traverse through. Each region in the surface is represented by a character, and so the entire grid can be represented by a text file.

The example below is a smaller version of the grid (10 x 10) than for the project (15 x 40); refer to the sample output for more info.

Read-friendly representation
Text file (e.g. grid.txt)
| 0 1 2 3 4 5 6 7 8 9
--+--------------------
0 | X X - - X -
1 | X X - - X F - -
2 | X F X X -
3 | - F X - X
4 | $ - X X - - X X -
5 | X - X - - X X X
6 | - - X - - X F
7 | X - X X F - -
8 | X X - - X X - X -
9 | F - - X X
XX --X
XX- -X F--
X FXX -
-F X-X
$-XX--X X
X -X --XXX
- -X--X F
X-XXF- -
XX- -XX-X
F- - X X











Different parts of the surface have different types, as indicated by the characters shown in each region:

Surface Type
Description
' ' (space character)
Safe
'-'
Rough
'X'
Impassible
'F'
Fuel
'$'
Target
The goal of the game is to land the rover, then traverse through the surface to reach the target without running out  of fuel (each move requires fuel) and/or taking too much damage (traversing through rough regions causes damage to the rover).

The game starts with the landing phase. The player can land the rover anywhere on the map, provided it is not an impassible region.

Once the rover has landed, the game moves onto the rover phase. The rover can move in one of four directions: up, down, left, and right. The result of the move depends on the surface type to which the rover is moving:

Surface Type
Description
Result
' ' (space character)
Safe
-2 to fuel
'-'
Rough
-2 to fuel, +8 damage
'X'
Impassible
Game loss
'F'
Fuel
Replenish fuel +25 (max 100)
'$'
Target
Game win
The game ends when the rover moves onto an impassible region, takes 100+ damage, or runs out of fuel (game loss), or reaches the target region (game win).

Instructions

Header files, LunarRover.h and LunarSurface.h, are provided for the classes LunarRover and LunarSurface. Use the provided member variables and function prototypes to implement the implementation files, LunarRover.cpp and LunarSurface.cpp. You may NOT modify the given headers; Your program and classes contained within it must function according to the flow chart given in the Game Play section of this document.

Write a program named main.cpp that plays the game.

Setup

● Prompt the user for the name of the text file that contains surface type information

● Create an instance of the LunarSurface class

○ Use the input file to populate the surface types

■ If the file cannot be opened, display an error message and keep asking for a valid file

■ If the file contains an invalid number of characters and/or surface types, display an error message and keep asking for a valid file

Landing Phase

● Display a well-formatted visualization of the surface

● Create an instance of the LunarRover class

● Prompt the user to select a region to land using row and column numbers

○ Validate the row and column numbers

○ Do not allow the user to land the rover on an impassible region

Roving Phase

● (Occurs in a loop until the game ends)

● Display a well-formatted visualization of the surface, including the location of the rover

● Display the current status of the rover (fuel and damage)

● Prompt the user to move the rover in one of four directions

'W' for up

'A' for left

'S' for down

'D' for right

● Update the location and status of the rover

● If the game has ended, display an appropriate message and ask the user if they'd like to play again

Game Play

In this section, the functionality of the Lunar Lander game is described, along with basic interactions between all classes. First, the top-level program flow for the Lunar Lander game is shown in Figure 1 below.

From Figure 1, the initialization phase is easy to implement and requires no further description. The Main Game Play phase is broken up into several stages: Initialize Game Play, Landing Phase, and Roving Phase. The flow diagram given below (Figure 2) gives more detail on each stage and also describes how main() coordinates with the LunarRover and LunarSurface classes, as well as how both classes communicate with each other.

Finally, the Roving Phase requires a loop that continually gets the user's next move and determines the result of that move. If the move results in finding the target, moving into impassable terrain, wandering off the game board, running out of fuel, or taking too much damage, then the game ends and the user is asked if they want to play again. Otherwise, the game continues with the user's next move. A final flow diagram is given below for the Roving Phase (Figure 3).

Optional Bonus (up to +50 points)

Extend the LunarRover and LunarSurface classes with additional features that may improve visuals or gameplay. For the bonus, you may modify the LunarRover.h and LunarSurface.h header files. Use your creativity to earn as many points as possible. Additional features may include, but are not limited to:

● During the landing phase, the player cannot see the fuel and target regions

● The size (number of rows and columns) of the surface may vary

● Implement functionality to allow for saving / loading your game

● Generate a random board:

○ The surface types must be randomly generated based on the following parameters:

■ ~40% of the regions are safe

■ ~30% of the regions are rough

■ ~20% of the regions are impassible

■ ~10% of the regions provide fuel

○ Guarantee that >50% of the passible regions (safe, rough, and fuel) have a path to the target

● Fog of war

○ The user cannot see the surface types of region more than 3 units away from the rover location

■ Distance from the rover location is calculated using Manhattan distance

● Gameplay elements:

○ Additional surface types (and different outcomes)

■ Repair surface

■ Aliens

○ Scrolling surface

○ Dynamic surfaces

○ Multiple rovers

● ASCII art, including color coded and/or stylized text output

● Actual pixel-based graphics using MFC or QT – if your game is fully playable in one of these environments, you will receive the maximum bonus toward your grade

● Algorithm design for automatically solving the game

○ Basic path finding to connect the start and end locations of the game through passable terrain
○ Advanced path finding to connect the start and end locations of the game through passable / rough terrain without causing maximum damage to the rover or running out of fuel

Make sure to list and describe all additional features that you implement in a text file named README.txt. Additionally, if your project requires any special compilation instructions, then also include them in README.txt.

Sample Output

A sample game-play video has been posted on Canvas to show you a working example of the Lunar Rover game. When you play the video, you will notice that each column has been repeated 3 times to make the game board appear bigger on the console. You may design your program in a similar fashion or take a different approach for drawing your game board. Make sure to discuss this approach with your teacher to make sure it is appropriate for submission.

Submission

Submit the following file(s) to Canvas before the deadline – the README.txt file should contain any special instructions for compiling your project, gameplay instructions, and a description of any bonus items you included:
1. LunarRover.h AND LunarRover.cpp
2. LunarSurface.h AND LunarSurface.cpp
3. main.cpp
4. README.txt