Untitled
unknown
plain_text
a year ago
3.9 kB
11
Indexable
#include <iostream>
#include <fstream>
#include <ctime>
#include "commands.cpp"
#include "gameMap.cpp"
#include "robots.cpp"
#include "gamePlay.cpp"
using namespace std;
int map_size_x = 0; // The width of the game map (number of columns).
int map_size_y = 0; // The height of the game map (number of rows).
int player_count = 0; // The number of players (robots) participating in the game.
int num_of_commands = 84; // The total number of commands available in the game.
int start_robot_x_id = 1; // Index for the starting x-coordinate of the robot in the robot conditions array.
int start_robot_y_id = 0; // Index for the starting y-coordinate of the robot in the robot conditions array.
int robot_x_id = 3; // Index for the current x-coordinate of the robot in the robot conditions array.
int robot_y_id = 2; // Index for the current y-coordinate of the robot in the robot conditions array.
int direction_id = 4; // Index for the direction the robot is facing in the robot conditions array.
int damage_id = 5; // Index for the amount of damage a robot has taken in the robot conditions array.
int reboot_id = 6; // Index indicating whether the robot is in reboot mode in the robot conditions array (1 for next turn).
int recent_flag_id = 7; // Index for the most recent flag number the robot has touched in the robot conditions array.
int** createRobotConditionsArray(int player_count) {
int** robot_conditions = new int*[player_count];
for (int i = 0; i < player_count; i++) {
robot_conditions[i] = new int[8];
robot_conditions[i][direction_id] = 0; //direction facing
robot_conditions[i][damage_id] = 0; //damage taken
robot_conditions[i][reboot_id] = 0; //1 if rebooting
robot_conditions[i][recent_flag_id] = 0; //most recent flag
}
return robot_conditions;
}
void setRobotPositions(char** game_map, int** robot_conditions, int player_index, int start_y, int start_x) {
robot_conditions[player_index][start_robot_y_id] = start_y;
robot_conditions[player_index][start_robot_x_id] = start_x;
robot_conditions[player_index][robot_y_id] = start_y;
robot_conditions[player_index][robot_x_id] = start_x;
}
int** getRobotPositions(char** game_map) {
int** robot_conditions = createRobotConditionsArray(player_count);
// Get Robot Positions and remove Robots from the game map
for (int i = 0; i < map_size_y; i++) {
for (int j = 0; j < map_size_x; j++) {
if (game_map[i][j] == 'D') {
if (player_count < 4) {
game_map[i][j] = '.';
} else {
game_map[i][j] = '.';
setRobotPositions(game_map, robot_conditions, 3, i, j);
}
} else if (game_map[i][j] == 'C') {
if (player_count == 2) {
game_map[i][j] = '.';
} else {
game_map[i][j] = '.';
setRobotPositions(game_map, robot_conditions, 2, i, j);
}
} else if (game_map[i][j] == 'B') {
game_map[i][j] = '.';
setRobotPositions(game_map, robot_conditions, 1, i, j);
} else if (game_map[i][j] == 'A') {
game_map[i][j] = '.';
setRobotPositions(game_map, robot_conditions, 0, i, j);
}
}
}
return robot_conditions;
}
int main() {
srand(time(NULL));
char** game_map = buildMap();
string* command_list = buildCommandList();
do {
cout << "Choose a number of players (2-4):" << endl;
cin >> player_count;
} while (player_count < 2 || player_count > 4);
int** robot_conditions = getRobotPositions(game_map);
playGame(game_map, command_list, robot_conditions);
}Editor is loading...
Leave a Comment