Grid.cpp 2.27 KB
Newer Older
Noah Olsen's avatar
commit  
Noah Olsen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

#include <cstdlib>
#include <iostream>
using namespace std;

#include "Grid.h"

// randomly generate grid and start score at 0
// Ensure player and enemies start at different places

// define the functions for grid
char Grid::getDirection() {
  cout << "Where do you want to go?" << endl;
  cout << "Please enter u for up, r for right, d for down, l for left, or m "
          "for a random direction."
       << endl;
  cin >> direction;
  return direction;
}
//2D array using subtraction in direction
/*
int Grid::move(int room, char direction) {
    
} */
// 2D array using subtraction in direction
int Grid::move(int room, char direction) {
  if (direction == 'u') {
    if ((room == 3) || (room == 2) || (room == 1)) {
    } else {
      room = room - 3;
    }
  } else if (direction == 'r') {
    if ((room == 3) || (room == 6) || (room == 9)) {
    } else {
      room = room + 1;
    }
  } else if (direction == 'd') {
    if ((room == 7) || (room == 8) || (room == 9)) {
    } else {
      room = room + 3;
    }
  } else if (direction == 'l') {
    if ((room == 1) || (room == 4) || (room == 7)) {
    } else {
      room = room - 1;
    }
  } else if (direction == 'm') {
    room = move(room, getRandDirection());
  } else {
    cout << "Invalid entry. Please input valid entry. ";
    room = move(room, getDirection());
  }
  return room;
}

char Grid::getRandDirection() {
  otherDirection = rand() % 4 + 1;
  if (otherDirection == 4) {
    return 'u';
  } else if (otherDirection == 2) {
    return 'r';
  } else if (otherDirection == 3) {
    return 'd';
  } else {
    return 'l';
  }
}

/*void Grid::printGrid(int player, int bosses) {
  char grid[10];
  for (int i = 0; i < 10; i++) {
    grid[i] = '.';
  }
  grid[player] = 'P';
  grid[bosses] = 'B';
  cout << grid[1] << grid[2] << grid[3] << endl;
  cout << grid[4] << grid[5] << grid[6] << endl;
  cout << grid[7] << grid[8] << grid[9] << endl;
}*/
// 2D array print inside a nested loop

void Grid::printGrid(int GridRows, int GridColumns) {//are these the appropriate parameters?
    char grid[GridRows][GridColumns];//sets max spaces in grid; 16 spaces max
    for(int i = 0; i < GridRows; i++) {
        for (int j = 0; j < GridColumns; j++) {
            grid[i][j] = '.';
            cout << grid[i][j];
        }
        cout << endl;
    }
}