Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Game The game begins with the player in possession of 0 total daisies. The p

ID: 3688600 • Letter: T

Question

The Game The game begins with the player in possession of 0 total daisies. The player is placed in a random spot [ row, col ] in a grid with 10 rows and 10 columns, each spot has a random number of daisies from 0-999. To make displaying the grid easier, think of row 0 column 0 [ 0, 0 ] being in the upper left corner and row 9 column 9 [ 9, 9 ] in the lower right corner: The player has seven choices: Gather daisies, Jump to another spot, go North, go South, go East, go West, or Quit.

Gathering Daises - when the player chooses to gather daisies they can't get them all, only 80% can be gathered at once - so 80% of the daisies are removed from the spot and added to their total daisies. After gathering daisies the player remains in the spot.

Jump - when the player chooses to Jump, they are placed in a random spot, any one of the spots in the 10x10 grid.

North – When the player selects north, they move up (row is one less) – make sure the player doesn’t fall off the board!

South– When the player selects south, they move down (row is one more) – make sure the player doesn’t fall off the board!

East– When the player selects east, they move to the right (column is one more) – make sure the player doesn’t fall off the board!

West– When the player selects west, they move to the left (column is one less) – make sure the player doesn’t fall off the board!

Map – displays to the user the grid

Quit - when the player quits, they are told of the total number of daisies they gathered, the total number of jumps they took, and the total number of gatherings they made.

Technical Items for this Lab

Since this is a lab on Arrays, there are some specifics that need to be addressed like needing an array, so I will give some constraints to ruin your day...

To simulate the spots with daisies, use a two dimensional array (10x10) of integers.

Populate each element in the array with a random number from 0..999.

For interacting with the user, allow the user to enter J for jump, G for gather, N for North, S for South, E for East, W for West, and Q to quit.

The spots displayed are in the format [row, col]

Sample Run

You are in spot [1, 9]

There are 203 daisies located here

You currently have a total of 0 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): m

Map of Grid:

568 218 321 863 141 342 304 624 49 126

250 127 98 57 911 713 265 885 426 203

184 912 829 703 124 667 667 735 943 822

282 893 749 734 916 77 336 515 144 466

362 495 90 549 502 577 259 173 556 335

310 544 471 50 585 783 293 387 700 743

578 12 809 588 185 193 504 688 505 972

701 273 319 736 160 633 326 878 281 255

352 563 902 707 735 179 219 462 84 878

965 79 795 248 387 906 377 479 401 804

You are in spot [1, 9]

There are 203 daisies located here

You currently have a total of 0 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): s

You are in spot [2, 9]

There are 822 daisies located here

You currently have a total of 0 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): g

You just gathered 657 daisies from this spot!

You are in spot [2, 9]

There are 165 daisies located here

You currently have a total of 657 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): e

You are in spot [2, 9]

There are 165 daisies located here

You currently have a total of 657 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): e

You are in spot [2, 9]

There are 165 daisies located here

You currently have a total of 657 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): w

You are in spot [2, 8]

There are 943 daisies located here

You currently have a total of 657 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): g

You just gathered 754 daisies from this spot!

You are in spot [2, 8]

There are 189 daisies located here

You currently have a total of 1,411 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): m

Map of Grid:

568 218 321 863 141 342 304 624 49 126

250 127 98 57 911 713 265 885 426 203

184 912 829 703 124 667 667 735 189 165

282 893 749 734 916 77 336 515 144 466

362 495 90 549 502 577 259 173 556 335

310 544 471 50 585 783 293 387 700 743

578 12 809 588 185 193 504 688 505 972

701 273 319 736 160 633 326 878 281 255

352 563 902 707 735 179 219 462 84 878

965 79 795 248 387 906 377 479 401 804

You are in spot [2, 8]

There are 189 daisies located here

You currently have a total of 1,411 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): j

You are in spot [2, 3]

There are 703 daisies located here

You currently have a total of 1,411 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): g

You just gathered 562 daisies from this spot!

You are in spot [2, 3]

There are 141 daisies located here

You currently have a total of 1,973 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): m

Map of Grid:

568 218 321 863 141 342 304 624 49 126

250 127 98 57 911 713 265 885 426 203

184 912 829 141 124 667 667 735 189 165

282 893 749 734 916 77 336 515 144 466

362 495 90 549 502 577 259 173 556 335

310 544 471 50 585 783 293 387 700 743

578 12 809 588 185 193 504 688 505 972

701 273 319 736 160 633 326 878 281 255

352 563 902 707 735 179 219 462 84 878

965 79 795 248 387 906 377 479 401 804

You are in spot [2, 3]

There are 141 daisies located here

You currently have a total of 1,973 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): g

You just gathered 112 daisies from this spot!

You are in spot [2, 3]

There are 29 daisies located here

You currently have a total of 2,085 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): g

You just gathered 23 daisies from this spot!

You are in spot [2, 3]

There are 6 daisies located here

You currently have a total of 2,108 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): g

You just gathered 4 daisies from this spot!

You are in spot [2, 3]

There are 2 daisies located here

You currently have a total of 2,112 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): g

You just gathered 1 daisies from this spot!

You are in spot [2, 3]

There are 1 daisies located here

You currently have a total of 2,113 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): m

Map of Grid:

568 218 321 863 141 342 304 624 49 126

250 127 98 57 911 713 265 885 426 203

184 912 829   1 124 667 667 735 189 165

282 893 749 734 916 77 336 515 144 466

362 495 90 549 502 577 259 173 556 335

310 544 471 50 585 783 293 387 700 743

578 12 809 588 185 193 504 688 505 972

701 273 319 736 160 633 326 878 281 255

352 563 902 707 735 179 219 462 84 878

965 79 795 248 387 906 377 479 401 804

You are in spot [2, 3]

There are 1 daisies located here

You currently have a total of 2,113 daisies

What would you like to do? (G, J, N, S, E, W, M, Q): q

You gathered a total of 2,113 daisies!

You did it in 1 jumps and 7 number of gatherings

Press any key to continue . . .

Explanation / Answer

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

void display(int arr[][10], int row, int col){
   cout << " Map of Grid: ";
   for(int i = 0; i < row; i++){
       for(int j = 0; j < col; j++){
           cout << arr[i][j] << " ";
           if(arr[i][j] < 100) cout << " ";
           if(arr[i][j] < 10) cout << " ";
       }
       cout << " ";
   }
}

int main(){
   srand(time(0));
   int arr[10][10];
   for(int i = 0; i < 10; i++){
       for(int j = 0; j < 10; j++){
           arr[i][j] = rand() % 1000;
       }
   }
   int count = 0, jump = 0, gather = 0;
   int row = rand() % 10, col = rand() % 10;

   while(true){
       cout << " You are in spot [" << row << ", " << col << "] ";
       cout << "There are " << arr[row][col] << " daisies located here ";
       cout << "You currently have a total of " << count << " daisies ";
       cout << "What would you like to do? (G, J, N, S, E, W, M, Q): ";
       char input;
       cin >> input;
       switch(input){
           case 'g':
           case 'G':
               count += (0.8 * arr[row][col]);
               cout << " You just gathered " << 0.8 * arr[row][col] << " daisies from this spot! ";
               arr[row][col] -= (0.8 * arr[row][col]);
               gather++;
               break;
           case 'j':
           case 'J':
               row = rand() % 10;
               col = rand() % 10;
               jump++;
               break;
           case 'n':
           case 'N':
               if(row == 0) cout << " Cannot go further north ";
               else{
                   row--;
               }
               break;
           case 's':
           case 'S':
               if(row == 9) cout << " Cannot go further south ";
               else{
                   row++;
               }
               break;
           case 'e':
           case 'E':
               if(col == 9) cout << " Cannot go further east ";
               else{
                   col++;
               }
               break;
           case 'w':
           case 'W':
               if(col == 0) cout << " Cannot go further west ";
               else{
                   col--;
               }
               break;
               break;
           case 'm':
           case 'M':
               display(arr, 10, 10);
               break;
           case 'q':
           case 'Q':
               cout << " You gathered a total of " << count << " daisies! ";
               cout << "You did it in " << jump << " jumps and " << gather << " number of gatherings ";
               return 0;
       }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote