Game Design Lab 1
Introduction to C++ and Classes
Game Design will be taught in C++, which is taught in CS312. However, that course is not required as a pre-requisite. C is used in a number of courses include (sometimes) CS250, CS430, CS435, CS475, and occasionally others. As such, you may have familiarity with a C family language. Java is closely related to C++, and so this also may prove useful. The goal of this lab is to write a simple program making use of the class facilities of C++, as well as the bool and string data types which are not in C.
The file lab1main.cpp is given, and contains a test routine expecting a class called "astronaught". The astronaught class must have 4 properties and 2 methods. The properties are:
Methods are as follows:
- name : The name of the astronaught. Data type is string.
- age : The age of the astronaught, which must default to 26. Data type is int, or unsigned int if you prefer.
- alive : Whether or not the astronaught is alive. This must start as true. Data type is bool.
- flights : Number of space flights the astronaught has experienced. This should start at 0.
Note from looking at lab1main.cpp that all properties are expected to be public. This stakes a position in an unresolved CS debate, which contradicts the standard practice given in many tutorials. It will simplify your code in this case. Do keep in mind that in many cases it is preferred to add extra methods soley to access properties (accessor methods). Take CS312 for a more detailed discussion of the nature of object-oriented programming. At some point, you will likely form a strong opinion on this topic, and this point may have been in the past.
- A constructor : This takes one string argument, which is the astronaugt's name. It is used to initialize the name property.
- void fly() : This is called when the astronaught is flown. It must increment flights. It should also give a 10% chance the astronaught dies, in which case the alive property will be changed to false.