Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 12 Weeks Ago, 1 Day Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
In my homework we have to take an existing code and implement functions in it to make it more readable and condense it.
Â
// GSP115 TREASURE CAVE// Week 4#pragma once#include "GSP115_Course_Project.h"// Global Constantsconst int MAX_ROWS = 7;const int MIN_ROWS = 0;const int MAX_COLS = 7;const int MIN_COLS = 0;const int TOTAL_ROWS = MAX_ROWS + 1;const int TOTAL_COLS = MAX_COLS + 1;//Display Constantsconst char ULC = 201;//Upper left cornerconst char HB = 205;//Horizontal borderconst char URC = 187;//Upper right cornerconst char VB = 186;//Vertical borderconst char LRC = 188;//Lower right cornerconst char LLC = 200;//Lower left cornerconst char MT = ' ';//Empty locationconst char PSymbol = 'P';//Player symbolconst char TOSymbol = 'T';//Torch symbolconst char WSymbol = 'W';//Weapon symbolconst char TRSymbol = '$';//Treasure symbolconst char MSymbol = 'M';//Monster symbolconst char NSymbol = 'N';//Noisemaker symbolconst char XSymbol = 'X';//Cave exit symbolusing namespace std;// function prototypesgameObject placeInCave( gameObjectType array[TOTAL_ROWS][TOTAL_COLS]);// <WK4 status=permanent>bool checkVisible(gameObject x, gameObject y, int dist );// </WK4>bool showOnBoard(gameObject x);int main(){//**Initialize Variables**srand(time(NULL));// Seed the random number functiongameObjectType cave[TOTAL_ROWS][TOTAL_COLS];// the cave--a twodimensional arraychar board[TOTAL_ROWS+3][TOTAL_COLS+3]=// the game board--a twodimensional array{{MT,MT,'0','1','2','3','4','5','6','7',MT},{MT,ULC,HB,HB,HB,HB,HB,HB,HB,HB,URC},{'A',VB,MT,MT,MT,MT,MT,MT,MT,MT,VB},{'B',VB,MT,MT,MT,MT,MT,MT,MT,MT,VB},{'C',VB,MT,MT,MT,MT,MT,MT,MT,MT,VB},{'D',VB,MT,MT,MT,MT,MT,MT,MT,MT,VB},{'E',VB,MT,MT,MT,MT,MT,MT,MT,MT,VB},{'F',VB,MT,MT,MT,MT,MT,MT,MT,MT,VB},{'G',VB,MT,MT,MT,MT,MT,MT,MT,MT,VB},{'H',VB,MT,MT,MT,MT,MT,MT,MT,MT,VB},{MT,LLC,HB,HB,HB,HB,HB,HB,HB,HB,LRC}};playerObject player ={true, false, false, false, false,{-1, -1, false,true}};// the player
#pragma once#include <iostream>#include <conio.h>#include <stdio.h>#include <time.h>#include <stdlib.h>#include <windows.h>enum gameObjectType{EMPTY, PLAYER, TREASURE, MONSTER, WEAPON, TORCH, NOISEMAKER//, CAVE_EXIT-add in week 6};struct gameObject{int row;// row position of the objectint column;// column position of the objectbool isFound;// flag to indicate if the object has been found(or is dead, in the case of the monster)bool isVisible;// flag to indicate if the object can be seen onthe board -add in week 4};struct playerObject{bool alive;// flag to indicate if the player is alive or deadbool hasWeapon;// flag to indicate if the player has the weaponbool hasTreasure;// flag to indicate if the player has the treasurebool hasTorch;// flag to indicate if the player has the torch-add in week 4bool hasNoisemaker;// flag to indicate if the player has thenoisemaker -add in week 4gameObject position;// variables for row, column and visibility};