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
|
#include <stdio.h>
#include <vector>
#include<iostream>
#include <windows.h>
using namespace std;
void sleep(unsigned milliseconds);
bool filter(int player_i,int player_j,int size,int round,char* m_vec);
void print_map(char **map, int size);
int robots_finder(char **map,int size,int *r_location_i,int *r_location_j);
int robots_number(char **map,int size);
void player_finder(char **map,int size,int &player_i,int &player_j);
void p_motion(char **map,int size,int round,char* m_vec);
void r_motions(char **map,int size)
{
int parameter_i,parameter_j,player_i,player_j;
int *r_location_i = new int[1],*r_location_j = new int[1];
|
player_finder(map,size,player_i,player_j);
int r_num = robots_finder(map,size,r_location_i,r_location_j);
for(int i=1;i<=r_num;i++)
{
parameter_i =0;
parameter_j =0;
if(r_location_i[i]>player_i) parameter_i = -1;
if(r_location_i[i]<player_i) parameter_i = 1;
if(r_location_j[i]>player_j) parameter_j = -1;
if(r_location_j[i]<player_j) parameter_j = 1;
map[r_location_i[i]][r_location_j[i]] = '.';
r_location_i[i] = r_location_i[i]+parameter_i;
r_location_j[i] = r_location_j[i]+parameter_j;
}
for(int i=1;i<=r_num;i++)
{
switch (map[r_location_i[i]][r_location_j[i]])
{
case '.':
map[r_location_i[i]][r_location_j[i]] = '+';
break;
case '@':
map[r_location_i[i]][r_location_j[i]] = '+';
print_map(map,size);
cout << "Robots win ." << endl;
sleep(1000);
exit(1);
break;
case '+':
map[r_location_i[i]][r_location_j[i]] = '*';
break;
case '*':
map[r_location_i[i]][r_location_j[i]] = '*';
break;
default: cout << "what r u doin' ??";
break;
}
}
}
int main()
{
////////////////////////////////////////////////////////////////////////////////
int size,har,round = 1;
cin >> size;
char **map = new char*[size+1];
char *motions = new char[3];
for (int i = 1; i <= size; i++) map[i] = new char[size+1];
map[1][0] = getchar();
for(int i = 1; i <= size; i++){ for(int j = 1; j <= size+1; j++) map[i][j] = getchar(); }
for(har = 1 ;; har++){motions[har] = getchar(); if (motions[har] == 10 && har !=0) break; }
do{
p_motion(map,size,round,motions);
r_motions(map,size);
print_map(map,size);
//________________________________________________________________
if(robots_number(map,size) == 0){cout << "Player wins ." << endl;
sleep(1000);
exit(1);}
//________________________________________________________________
round++;
sleep(2000);
}while(1);
////////////////////////////////////////////////////////////////////////////////
return 0;
} |