-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab4COP.cpp
185 lines (180 loc) · 4.54 KB
/
lab4COP.cpp
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <iostream>
#include <cstdlib>
#include <ctime>
using std::cout;
using std::cin;
using std::endl;
int***newArray();
void deletePunteros(int***,int);
void randomLlenar1(int***, int, int);
void randomLlenar2(int***, int, int);
void imprimirMatriz(int***, int);
int menu(int, int);
int main(int argc, char const *argv[]){
srand(time(NULL));
int size=12, bandera=1;
int cantCoor = 15, wave1=3, expansive1=3, wave2=3, expansive2=3, cantJUG1 = 14, cantJUG2 = 14;
bool win=false;
int***arregloJug1=newArray();
int***arregloJug2=newArray();
randomLlenar1(arregloJug1, size, cantCoor);
randomLlenar2(arregloJug2, size, cantCoor);
do{
if (bandera==1){
cout<<"---------------MAPA DE SUBMARINOS DEL JUGADOR 1-----------------"<<endl;
imprimirMatriz(arregloJug1, size);
cout<<"-----------MAPA DE ATAQUES-------------"<<endl;
cout << "NUMERO DE SUBMARINOS ENEMIGOS" << cantJUG2 << endl;
int opcion1=menu(wave1, expansive1);
if (opcion1 == 1){
cout << "Ataque1" << endl;
}else if (opcion1 == 2){
cout << "Wave Attack XY" << endl;
}else if (opcion1 == 3){
cout << "wave Attack ZY" << endl;
}else if(opcion1 == 4){
cout << "wave Attack ZX" << endl;
}else if (opcion1 == 5){
cout << "expansive Attack" << endl;
}else{
cout <<"No es una opcion -_-!!!" << endl;
}
if (cantJUG2==0){
cout << "Ganastes!!!" << endl;
win = true;
break;
}
bandera=2;
}else if(bandera==2){
cout<<"---------------MAPA DE SUBMARINOS DEL JUGADOR 2-----------------"<<endl;
imprimirMatriz(arregloJug2, size);
cout<<"-----------MAPA DE ATAQUES-------------"<<endl;
cout << "NUMERO DE SUBMARINOS ENEMIGOS" << cantJUG2 << endl;
int opcion2=menu(wave2, expansive2);
if (opcion2 == 1){
cout << "Ataque1" << endl;
}else if (opcion2 == 2){
cout << "Wave Attack XY" << endl;
}else if (opcion2 == 3){
cout << "wave Attack ZY" << endl;
}else if(opcion2 == 4){
cout << "wave Attack ZX" << endl;
}else if (opcion2 == 5){
cout << "expansive Attack" << endl;
}else{
cout <<"No es una opcion -_-!!!" << endl;
}
if (cantJUG1==0){
cout << "Ganastes!!!" << endl;
win = true;
break;
}
bandera=1;
}
}while(win==false);
imprimirMatriz(arregloJug1, size);
cout<<"--------------------------------"<<endl;
imprimirMatriz(arregloJug2, size);
deletePunteros(arregloJug1, size);
deletePunteros(arregloJug2 ,size);
return 0;
}
int***newArray(){
int size=12;
int***arreglo= new int**[size];
for (int i = 0; i < size; ++i){
arreglo[i]=new int*[12];
}
for (int i = 0; i < size; ++i){
for (int j = 0; j < size; ++j){
arreglo[i][j]= new int[12];
}
}//fin new
return arreglo;
}
void deletePunteros(int*** arreglo, int size){
for (int i = 0; i < size; ++i)
{
for (int j = 0; j < size; ++j)
{
delete[] arreglo[i][j];
}
}
for (int i = 0; i < size; ++i)
{
delete[] arreglo[i];
}
delete[] arreglo;//fin delete
}
void randomLlenar1(int*** array, int size, int cantCoor){
bool validCoor;
for (int i = 0; i < size; ++i){
for (int j = 0; j < size; ++j){
for (int k = 0; k < size; ++k){
array[i][j][k]=0;
}
}
}
for (int i = 0; i < cantCoor; ++i){
while(validCoor){
int coordX=rand()%12;
int coordY=rand()%12;
int coordZ=rand()%12;
if (array[coordX][coordY][coordZ] == 1){
validCoor = true;
}else{
array[coordX][coordY][coordZ] = 1;
validCoor = false;
}
}
validCoor= true;
}
}
void randomLlenar2(int*** array, int size, int cantCoor){
bool validCoor;
for (int i = 0; i < size; ++i){
for (int j = 0; j < size; ++j){
for (int k = 0; k < size; ++k){
array[i][j][k]=0;
}
}
}
for (int i = 0; i < cantCoor; ++i){
while(validCoor){
int coordX=rand()%12;
int coordY=rand()%12;
int coordZ=rand()%12;
if (array[coordX][coordY][coordZ] == 1){
validCoor = true;
}else{
array[coordX][coordY][coordZ] = 1;
validCoor = false;
}
}
validCoor= true;
}
}
void imprimirMatriz(int*** array, int size){
for (int i = 0; i < size; ++i){
for (int j = 0; j < size; ++j){
for (int k = 0; k < size; ++k){
if (array[i][j][k]==1){
cout<<"("<<i<<", "<<j<<", "<<k<<")"<<endl;
}
}
}
}
}
int menu(int wave, int expansive){
int opcion;
cout<<"1. Ataque Normal"<<endl;
cout<<"2. Ataque wave en XY"<<endl;
cout<<"3. Ataque wave en XZ"<<endl;
cout<<"4. Ataque wave en YZ"<<endl;
cout<<"5. Ataque expansivo"<<endl;
cout<<"WAVES DISPONIBLES: "<<wave<<endl;
cout<<"EXPANSIVAS DISPONIBLES: "<<expansive<<endl;
cout<<"Ingrese su opcion: ";
cin>>opcion;
return opcion;
}