Project 7 Program Skeleton

Project 7 Program Skeleton - / robots.cpp / Portions you...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
// robots.cpp // Portions you are to complete are marked with a TODO: comment. // We've provided some incorrect return statements (so indicated) just // to allow this skeleton program to compile and run, albeit incorrectly. // The first thing you probably want to do is implement the trivial // functions (marked TRIVIAL). Then get Arena::display going. That gives // you more flexibility in the order you tackle the rest of the functionality. // As you finish implementing each TODO: item, remove its TODO: comment. #include <iostream> #include <string> #include <cstdlib> #include <ctime> using namespace std; /////////////////////////////////////////////////////////// //////////////// // Manifest constants /////////////////////////////////////////////////////////// //////////////// const int MAXROWS = 20; // max number of rows in the arena const int MAXCOLS = 40; // max number of columns in the arena const int MAXROBOTS = 200; // max number of robots allowed const int UP = 0; const int DOWN = 1; const int LEFT = 2; const int RIGHT = 3; /////////////////////////////////////////////////////////// ////////////////
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
// Auxiliary function declarations /////////////////////////////////////////////////////////// //////////////// int decodeDirection(char dir); void clearScreen(); /////////////////////////////////////////////////////////// //////////////// // Type definitions /////////////////////////////////////////////////////////// //////////////// class Arena; // This is needed to let the compiler know that Arena is a // type name, since it's mentioned in the Robot declaration. class Robot { public: // Constructor Robot(Arena* ap, int r, int c); // Accessors int row() const; int col() const; // Mutators void move(); private: Arena* m_arena; int m_row; int m_col; }; class Player { public: // Constructor Player(Arena *ap, int r, int c);
Background image of page 2
// Accessors int row() const; int col() const; int age() const; bool isDead() const; // Mutators string takeComputerChosenTurn(); void stand(); void move(int dir); bool shoot(int dir); void setDead(); private: Arena* m_arena; int m_row; int m_col; int m_age; bool m_dead; }; class Arena { public: // Constructor/destructor Arena(int nRows, int nCols); ~Arena(); // Accessors int rows() const; int cols() const; Player* player() const; int robotCount() const; int nRobotsAt(int r, int c) const; void display(string msg) const; // Mutators bool addRobot(int r, int c); bool addPlayer(int r, int c); bool destroyRobot(int r, int c); bool moveRobots(); private:
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
int m_rows; int m_cols; Player* m_player; Robot* m_robots[MAXROBOTS]; int m_nRobots; }; class Game { public: // Constructor/destructor Game(int rows, int cols, int nRobots); ~Game(); // Mutators void play(); private: Arena* m_arena; }; /////////////////////////////////////////////////////////// //////////////// // Robot implementation /////////////////////////////////////////////////////////// ////////////////
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/07/2009 for the course CS 31 taught by Professor Melkanoff during the Spring '00 term at UCLA.

Page1 / 15

Project 7 Program Skeleton - / robots.cpp / Portions you...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online