{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Project 5 - Maze game engine - Robert J England II COS 221...

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

View Full Document Right Arrow Icon
Robert J. England II COS 221 Projects 5 & 6 Maze Program Project done for Prof. Larry Latour Monday, December 08, 2006
Background image of page 1

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

View Full Document Right Arrow Icon
The following is the actual code used in the program. This time, the test is done with a special debug command during standard program running. // Maze.cpp :  // Maze game engine created by Robert J. England // containing Room, RoomLink, RoomList, and Player classes // for COS 221 with Larry Latour // at the University of Maine in Orono // Friday, December 08, 2006 // #include   "stdafx.h" #include   <iostream> #include   <fstream> #include   <string> using   namespace  std; class  Room;   // declaration before use in RoomLink class class  RoomLink { public : // Constructor RoomLink(Room * v) : value(v), nextLink(0), prevLink(0) {}; // POST: Creates a room link for use in a list, with a // room value v // Data fields Room * value; RoomLink * nextLink; RoomLink * prevLink; }; class  RoomList { public : // Constructor RoomList() : firstLink(0), lastLink(0) {}; // POST: Creates an empty list of rooms // Accessor methods Room * back()  if  (lastLink)  return  lastLink->value;  else   return  0;}; // POST: Returns the last room in the list, if it exists; // otherwise null is returned Room * front() if  (firstLink)  return  firstLink->value;  else   return  0;}; // POST: Returns the first room in the list, if it exists; // otherwise null is returned Room * findRoom(string name); // POST: Finds a room in the list by its name; if the room // is not in this list, null is returned
Background image of page 2
Room * nextRoom(Room * thisRoom); // POST: Finds this room in the list and returns the next // room, if it exists; null is returned if either this or // the next room does not exist void  printRooms(); // POST: Prints a sequence of room names to the screen // Modifier methods void  addRoom(Room * newRoom); // POST: newRoom is added to the room list, if it is not // already in the list void  readBuilding(); // PRE:  The room list must be the building list // (i.e. the list of all rooms used in the game) // POST: The entire list of rooms is read from MazeCfg.txt // and the building is created from the input private : // Data fields RoomLink * firstLink; RoomLink * lastLink; }; class  Room { public : // Constructor Room(string str)  : name(str), doors( new  RoomList) {}; // POST: A new room is created, with str as its name, and // zero rooms connected to it // Data fields string name; RoomList * doors; }; class  Player { public : // Constructor Player() { building =  new  RoomList; myRoom =  new  Room( "Room1" ); loadGame( "Room1" );}; // POST: A new player is created, and a game is loaded // Modifier methods void  loadGame(string roomname); // PRE:  roomname is the name of a room in the building // POST: A building is read from MazeCfg.txt, and the // player is placed in the room roomname void
Background image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}