Thread: Making a Game Assignment

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    63

    Question Making a Game Assignment

    The assignment is to create three different raceways and populate them with obstacles, N = waves in Seaway, M = oil in Raceway, and O = fog in Airway. Three different vehicles on three different raceways, a boat, a car, and a plane are racing each others. They move at different speeds and the obstacles slow move them back by different amounts. The exact instructions are posted here: CS320 Programming Languages: Program Three

    We've managed to create the three raceways and populate them with the obstacles at random. The question is how do we access the Raceway class in our Vehicle class to let the sub-classes know there is an obstacle that it's about to hit and therefor will be moved back by a certain amount of units.


    Code:
    //Great Vehicle Race
    //Written by Douglas Oonk & Jack Trocinski
    
    #include <iostream>
    #include <cstdlib>
    
    using namespace std;
    	
    class Raceway {
    	public:
    		char seaway[3][100];
    		char roadway[3][100];
    		char airway[3][100];
            	void race() {
                		
    			srand(time(0));
    		
                		for(int i=0; i < 3; i++){	
                    		for(int j = 0; j < 100; j++){
                        			seaway[i][j] = '-';
    					roadway[i][j] = '-';
    					airway[i][j] = '-';
                    		}
                		}
                		for(int i=0; i < 3; i++){
    				for(int n = 0; n< 4; n++) {
                    			int j = rand()%100;
                    			roadway[i][j] = 'M';	//oil spills		
    				}
                		}
    			for(int i=0; i < 3; i++){
    				for(int n = 0; n< 4; n++) {
                    			int j = rand()%100;
                    			seaway[i][j] = 'N';	//large waves		
    				}
                		}
    			for(int i=0; i < 3; i++){
    				for(int n = 0; n< 4; n++) {
                    			int j = rand()%100;
                    			airway[i][j] = 'O';	//fog
    				}
                		}
                	}
    		
    ////////////////////////////////////////////print arrays//////////////////////////////////////			
            		
    		void printSeaway() {
    			cout << "The Seaway race" << endl;
    			for(int i=0; i < 3; i++){
                    		for(int j = 0; j < 100; j++){
                        			cout << seaway[i][j];
                    			}
                    		cout << endl;
                		}
    		}
    			
    		void printRoadway() {		
    			cout << "The Roadway race" <<endl;
    			for(int i=0; i < 3; i++){
                    		for(int j = 0; j < 100; j++){
                        			cout << roadway[i][j];
                    			}
                    		cout << endl;
                		}
    		}
    		
    		void printAirway() {
    			cout << "The Airway race" << endl;
    			for(int i=0; i < 3; i++){
                    		for(int j = 0; j < 100; j++){
                        			cout << airway[i][j];
                    			}
                    		cout << endl;
                		}	
    		}
    				
    };
    	
    //end class race
    
    class Vehicle {
    	public:
    		virtual int move() = 0;
    };
    	
    class Wheeled: public Vehicle {
    	public:
    		int move() {
    			return 3;
    		}
    };
    
    class Propellored: public Vehicle {
    	public:
    		int move() {
    			return 4;
    		}
    };
    	
    class FourWD: public Wheeled {
    	public:
    		int move() {
    			return 2;		//if hits oil spills
    		}
    };
    	
    class Cycle: public Wheeled {
    	public:
    		int move() {
    			return 0;		//if hits oil spills
    		}
    };
    
    class Boat: public Propellored {
    	public:
    		
    		int move() {
    			return 2;		//if hits large waves
    		}
    };
    	
    class Plane: public Propellored {
    	public:
    		int move() {
    			return 2;		//if hits fog
    		}
    };
    
    int main() {
    	cout << "Welcome to the  Great Raceway!" << endl;
    	cout << "Written by Doug Oonk and Jack Trocinski" << endl;
    	
    	Raceway raceObject;
        	raceObject.race();
    	
    	raceObject.printSeaway();
    	raceObject.printRoadway();
    	raceObject.printAirway();
    	
        	return 0;
    }

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    This is an ugly, overly-contrived assignment. However...

    Your question is how do the vehicles access the raceways. Note that the interfaces for the member functions are completely unspecified. So, for instance, the move function could take a raceway reference.

    Other points:

    You're not following these directions:
    * The values of N, M and O should be between 10 and 50.
    * At least two blank columns should follow any column with an obstacle.

    Note that it is not actually telling you to put the characters N, M, and O onto the raceways. You could presumably use asterisks, since each raceway type has it's own unique obstacle type. N, M, and O are variables that you randomly set between 10 and 50.

    Your Vehicle class has no member variables, and yet the assignment says it should "know the index of the cell it is in in its raceway track and it should have a direction."

    I'm not sure what this sentence (for lack of a better word) in the assignment means: "Create a loop that iterates of each over four instances of the object types and moves them according to these rules." Presumably it means one instance of the 4 vehicle types.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    63
    Quote Originally Posted by oogabooga View Post
    This is an ugly, overly-contrived assignment. However...
    I agree, and thanks for the help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c++ Assignment: Game of Life
    By Dylan Metz in forum C++ Programming
    Replies: 22
    Last Post: 02-29-2012, 04:00 AM
  2. Help making a game
    By colbygil in forum Game Programming
    Replies: 11
    Last Post: 04-09-2010, 02:39 PM
  3. Should I use a game engine in making a RPG game?
    By m3rk in forum Game Programming
    Replies: 6
    Last Post: 01-26-2009, 04:58 AM
  4. Making a game
    By KneeGrow in forum Game Programming
    Replies: 1
    Last Post: 04-16-2004, 12:40 PM
  5. help with making a game
    By thatdude in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2003, 06:10 AM