-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.cpp
260 lines (131 loc) · 3.32 KB
/
backup.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#include<stdio.h>
#include<stdlib.h>
#define length_1 10
#define width_1 10
#define tedad_kashti 10
struct information{
char tol[10], arz[10];
char kind[10], jahat[10];
};
struct information player[2];
void locate_info(void);
void gameplay(int array1[][width_1], int array2[][width_1]);
void show(int array[][width_1]);
void anjame_bazi(char *str3, int array[][width_1]);
int check(int array[][width_1]);
int main(){
int tester = 0;
int array1[length_1][width_1];
int array2[length_1][width_1];
locate_info();
gameplay(array1, array2);
while(((check(array1)) && (check(array2)))){
char str_1[10];
printf("Enter a point\n");
scanf("%s" , str_1);
if((tester % 2) == 0){
anjame_bazi( str_1, array2);
show(array2);
}
else{
anjame_bazi( str_1, array1);
show(array1);
}
++tester;
}
}
void locate_info(void){
int i, j;
for(j = 0; j < 2; ++j){
printf("Enter your ships location:\n");
for(i = 0; i < tedad_kashti; ++i){
char str[50];
gets(str);
if((str[5] < 48) || (str[5] > (length_1 + 48)) || (str[7] < 48) || (str[7] > (width_1 + 48))){
printf("This location is not defined!\n");
--i;
continue;
}
player[j].kind[i] = str[0];
player[j].tol[i] = str[5];
player[j].arz[i] = str[7];
player[j].jahat[i] = str[15];
printf("\n");
}
printf("\n");
}
}
void gameplay(int array1[][width_1], int array2[][width_1]){
int m, n, l, pot;
int tol1, arz1, tol2, arz2;
for(m = 0; m < length_1; ++m){
for(n = 0; n < width_1; ++n){
array1[m][n] = 0;
array2[m][n] = 0;
}
}
for(l = 0; l < tedad_kashti; ++l){
tol1 = (player[0].tol[l] - 48);
arz1 = (player[0].arz[l] - 48);
array1[tol1][arz1] = 1;
}
for(pot = 0; pot < tedad_kashti; ++pot){
tol2 = (player[1].tol[pot] - 48);
arz2 = (player[1].arz[pot] - 48);
array2[tol2][arz2] = 1;
}
}
//show the plan
void show(int array[][width_1]){
int array_new[length_1][width_1];
int r, s;
for(r = 0; r < length_1; ++r){
for(s = 0; s < width_1; ++s){
if((array[r][s]) == 0){
array_new[r][s] = 63;
}
if((array[r][s]) == 1){
array_new[r][s] = 63;
}
if((array[r][s]) == 7){
array_new[r][s] = 42;
}
if((array[r][s]) == 6){
array_new[r][s] = 32;
}
}
}
for(r = 0; r < length_1; ++r){
for(s = 0; s < width_1; ++s){
printf("%c" , array_new[r][s]);
}
printf("\n");
}
}
//check end of game
int check(int array[][width_1]){
int a, b, counter = 0;
for(a = 0; a < length_1; ++a){
for(b = 0; b < width_1; ++b){
if((array[a][b]) == 7){
++counter;
}
}
}
if(counter == 10){
return 0;
}
return 1;
}
void anjame_bazi(char *str3, int array[][width_1]){
int q;
q = (str3[1] - 48);
int e;
e = (str3[3] - 48);
if(array[q][e] == 0){
array[q][e] = 6;
}
if(array[q][e] == 1){
array[q][e] = 7;
}
}