SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 1 Day Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 14 Nov 2017 My Price 10.00

code that is highlighted in purple, and then need to understand

I need help with some code. I need to understand what I need to add to the program and where it needs added. I have attached a document with more specifics.

Need help understanding what needs added to this piece of code that is highlighted in purple, and then need to understand where the code needs inserted into the program.

gameObjectplaceInCave( gameObjectType array[TOTAL_ROWS][TOTAL_COLS])

//function that takes in the total number of rows and cols in the array

{

int r, c;

gameObjectobj;

//Find a random row and column that is empty and place the object there.

do

{

r = rand()%8; //gets a random number between 0 and 7

c = rand()%8;//gets a random number between 0 and 7

} while (array[r][c] != EMPTY);

obj.row = r;

obj.column = c;

obj.isFound = false;

return obj;

}

// </WK2>

 

Program to insert code into.

------------------------------------------------------------------------------------------------------

 

#pragma once

#include "GSP115_Course_Project.h"

#include "stdafx.h"

#include "String.h"

#include <array>

#include <iostream>

#include <time.h>

 

 

 

// Global Constants

const 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;

 

using namespace std;

#include <string.h>

 

// <WK2 status=permanent>

// function prototypes

gameObjectplaceInCave(gameObjectType array[TOTAL_ROWS][TOTAL_COLS]);

// </WK2>

 

int _tmain(int argc, _TCHAR* argv[])

{

   //**Initialize Variables**

   srand(time(NULL));      // Seed the random number function

 

// <WK2 status=permanent>

   gameObjectType cave[TOTAL_ROWS][TOTAL_COLS];   // the cave--a two dimensional array

// </WK2>

// <WK2 status=permanent>

   playerObject player ={true, false, false, false, false,{-1, -1, false, true}};   // the player

   gameObject treasure = {-1, -1, false, true};      // the treasure

   gameObject monster = {-1, -1, false, true};      // the monster

// </WK2>

   int row, column;                        // temporarily hold the new player position

 

   string msg;                              // status message variable

   char command;                           // player input

 

   bool movePlayer = true;      // flag to indicate the player position can be updated

   bool gameOver = false;      // status flag

 

// <WK2 status=permanent>

   //**Prepare Cave***********

   //...Initialize an empty cave

   for (gameObjectType (&R)[TOTAL_COLS] : cave)

   {

      for (auto &C : R) C = EMPTY;

   }

// </WK2>

 

   //...Add player in rows 0-2, columns 0-2

// <WK2 status=permanent>

   player.position.row = rand() %3;

   player.position.column = rand()%3;

   cave[player.position.row][player.position.column] = PLAYER;

   //...Add Treasure in rows 4-6, column 1-6

   treasure.row = rand()%3 + 4;

   treasure.column = rand()%6 +1;

   cave[treasure.row][treasure.column] = TREASURE;

   //...Add Monster at treasure row +1 , column -1

   monster.row = treasure.row + 1;

   monster.column = treasure.column -1;

   cave[monster.row][monster.column] = MONSTER;

// </WK2>

// <WK1 status=2>

   cout << "Player will start at row " <<char('A' + player.position.row) << " and column " <<player.position.column + 1 << endl;//WK1&2 only

// </WK1>

 

   //**Play Game*************

   //...Begin Game Loop

   while (!gameOver)

   {

// <WK1 status=2>

      cout << "You have moved to position " <<char('A'+ player.position.row) <<player.position.column +1 << endl;//WK1&2 only

// </WK1>

      cout <<msg.c_str() << endl;

      //....Get command

      cout << "What is your command? ";

      cin >> command;

      //....Clear display and message

      msg.clear();

      system("cls");

      //....Process player command

// <WK2 status=permanent>

      row = player.position.row;

      column = player.position.column;

// </WK2>

      switch (command)

      {

      case 'a':

// <WK2 status=permanent>

         column = player.position.column - 1;

// </WK2>

         if (column < MIN_COLS)

         {

// <WK2 status=permanent>

            column = player.position.column;

// </WK2>

            msg = "You have hit the west wall!";

         }

         break;

      case 's':

// <WK2 status=permanent>

         row = player.position.row + 1;

// </WK2>

         if (row > MAX_ROWS)

         {

// <WK2 status=permanent>

            row = player.position.row;

// </WK2>

            msg = "You have hit the south wall!";

         }

         break;

      case 'w':

// <WK2 status=permanent>

         column = player.position.column;//Is this really needed?

         row = player.position.row - 1;

// </WK2>

         if (row < MIN_ROWS)

         {

// <WK2 status=permanent>

            row = player.position.row;

// </WK2>

            msg = "You have hit the north wall!";

         }

         break;      

      case 'd':

// <WK2 status=permanent>

         row = player.position.row;//Is this really needed?

         column = player.position.column + 1;

// </WK2>

         if (column > MAX_COLS)

         {

// <WK2 status=permanent>

            column = player.position.column;

// </WK2>

            msg = "You have hit the east wall!";

         }

         break;      

      case 'q':

         gameOver = true;

         msg = "Quitting?\n";

         break;

      default:

         movePlayer = false;

         break;

      }

      //....Check if the game is over

      if (!gameOver)

      {

// <WK2 status=permanent>

         //..... Check for events

         switch (cave[row][column])

         {

            //......If treasure found, set flag to show player has treasure

         case TREASURE:

            player.hasTreasure = true;

            treasure.isFound = true;

            msg = "You found the treasure!";//-add gameover in week2, remove in week 6

// <WK2 status=5>

            gameOver = true;

// </WK2>

            break;

            //......If monster found

         case MONSTER:

            if (!monster.isFound)

            {

               msg = "You have found the monster";

               //.......Resolve combat

               //gameOver = resolveCombat(player, monster, killedValue, killMonsterValue,msg, movePlayer, monsterPause);//-add in week 6

// <WK2 status=5>

               gameOver = true;

// </WK2>

// <WK2 status=3>

               player.alive = false;

// </WK2>

            }

            break;

         }

// </WK2>

 

         //.....Move Player

         if (movePlayer)

         {

// <WK2 status=permanent>

            cave[player.position.row][player.position.column] = EMPTY;      //updates position information

            cave[row][column] = PLAYER;

            player.position.row = row;

            player.position.column = column;

// </WK2>

         }

         movePlayer = true;

      }

   }

   //...End Game Loop

   //**End Game**************

 

// <WK2 status=permanent>

   //...Provide end win/loss message

   cout <<msg.c_str() << endl;

   if (player.alive)

   {

      if (player.hasTreasure) msg = "You are alive and rich!";

      else msg = "You didn't get the treasure, but you live to seek adventure another day.";

   }

   else

   {

      msg = "RIP Adventurer";

   }

   cout <<msg.c_str() << endl;

// </WK2>

 

   //...Do clean-up

   //...Quit

   return 0;

 

}

 

Attachments:

Answers

(5)
Status NEW Posted 14 Nov 2017 08:11 AM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)