Jirat Nakarit
/
project_ShipDot
Jirat
Fork of project by
main.cpp@3:baff75bbb78e, 2016-12-02 (annotated)
- Committer:
- gunpuen2
- Date:
- Fri Dec 02 09:36:06 2016 +0000
- Revision:
- 3:baff75bbb78e
- Parent:
- 2:d93832fe8deb
- Child:
- 4:8a86bacddcac
Test with Joe (16:35 || 2/12/2559)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gunpuen2 | 0:a8e057156263 | 1 | /******************************************************************************/ |
gunpuen2 | 1:6157c77da3d5 | 2 | /* This Nicleo is state 0 */ |
gunpuen2 | 0:a8e057156263 | 3 | /******************************************************************************/ |
gunpuen2 | 0:a8e057156263 | 4 | #include "mbed.h" |
gunpuen2 | 0:a8e057156263 | 5 | |
gunpuen2 | 0:a8e057156263 | 6 | // Initail I/O. |
gunpuen2 | 0:a8e057156263 | 7 | AnalogIn VRx(A2); |
gunpuen2 | 0:a8e057156263 | 8 | AnalogIn VRy(A3); |
gunpuen2 | 0:a8e057156263 | 9 | DigitalIn Button(D13); |
gunpuen2 | 0:a8e057156263 | 10 | Serial bt(PA_15, PB_7); |
gunpuen2 | 0:a8e057156263 | 11 | |
gunpuen2 | 0:a8e057156263 | 12 | // Initial function. |
gunpuen2 | 0:a8e057156263 | 13 | char check_joys(int jx,int jy); |
gunpuen2 | 0:a8e057156263 | 14 | int check_joys_int(int jx,int jy); |
gunpuen2 | 0:a8e057156263 | 15 | int check_correctPosition(int X,int Y); |
gunpuen2 | 0:a8e057156263 | 16 | int get_position(int input_position,int ship_type); |
gunpuen2 | 0:a8e057156263 | 17 | void check_ready(); |
gunpuen2 | 0:a8e057156263 | 18 | void print_metrix(); |
gunpuen2 | 0:a8e057156263 | 19 | void Select_Position(char M); |
gunpuen2 | 1:6157c77da3d5 | 20 | void getATK_position(int atkpos); |
gunpuen2 | 1:6157c77da3d5 | 21 | char posit2char(int posit); |
gunpuen2 | 1:6157c77da3d5 | 22 | int char2posit(char cha); |
gunpuen2 | 0:a8e057156263 | 23 | |
gunpuen2 | 0:a8e057156263 | 24 | // Initial variable. |
gunpuen2 | 2:d93832fe8deb | 25 | int check_ship_underATK = 0; |
gunpuen2 | 0:a8e057156263 | 26 | int select_Position = 0; |
gunpuen2 | 0:a8e057156263 | 27 | int ATKposition = 0; |
gunpuen2 | 1:6157c77da3d5 | 28 | int enemy_ready = 0; |
gunpuen2 | 1:6157c77da3d5 | 29 | int iPrintUturn = 0; |
gunpuen2 | 2:d93832fe8deb | 30 | int check_ship1 = 0; |
gunpuen2 | 2:d93832fe8deb | 31 | int check_ship2 = 0; |
gunpuen2 | 0:a8e057156263 | 32 | int iWaitATK = 0; |
gunpuen2 | 0:a8e057156263 | 33 | int state = 0; |
gunpuen2 | 2:d93832fe8deb | 34 | int ship_SelectType[8] = {4,3,2,2,1,1,1,1}; |
gunpuen2 | 1:6157c77da3d5 | 35 | int ship_platform[8][8] = {{0}}; //__________________________________________________This is ship area. |
gunpuen2 | 1:6157c77da3d5 | 36 | int atk_platform[8][8] = {{0}}; |
gunpuen2 | 2:d93832fe8deb | 37 | int ship_underATK[15] = {0}; |
gunpuen2 | 2:d93832fe8deb | 38 | int ship_destroyed[8] = {0}; |
gunpuen2 | 0:a8e057156263 | 39 | int ship4[4] = {0}; |
gunpuen2 | 0:a8e057156263 | 40 | int ship3[3] = {0}; |
gunpuen2 | 0:a8e057156263 | 41 | int ship2[2][2] = {{0}}; |
gunpuen2 | 0:a8e057156263 | 42 | int ship1[4] = {0}; |
gunpuen2 | 0:a8e057156263 | 43 | |
gunpuen2 | 0:a8e057156263 | 44 | int main(){ //-------------------------------------------------------------------Main Function. |
gunpuen2 | 0:a8e057156263 | 45 | float Vx; |
gunpuen2 | 0:a8e057156263 | 46 | float Vy; |
gunpuen2 | 0:a8e057156263 | 47 | int SW,iVxVy,iSW,n; |
gunpuen2 | 0:a8e057156263 | 48 | int iShipType = 0; |
gunpuen2 | 3:baff75bbb78e | 49 | unsigned long int uli = 0; |
gunpuen2 | 0:a8e057156263 | 50 | char m; |
gunpuen2 | 0:a8e057156263 | 51 | while(1) { |
gunpuen2 | 0:a8e057156263 | 52 | if(iShipType<8){ |
gunpuen2 | 0:a8e057156263 | 53 | Vx = VRx.read() * 1024; |
gunpuen2 | 0:a8e057156263 | 54 | Vy = VRy.read() * 1024; |
gunpuen2 | 0:a8e057156263 | 55 | SW = Button.read(); |
gunpuen2 | 0:a8e057156263 | 56 | m = check_joys(Vx,Vy); |
gunpuen2 | 0:a8e057156263 | 57 | n = check_joys_int(Vx,Vy); |
gunpuen2 | 0:a8e057156263 | 58 | if(n == 1){ //_______________________________________________________ For make sure coordinate is press 1 time. |
gunpuen2 | 0:a8e057156263 | 59 | iVxVy = 0; |
gunpuen2 | 0:a8e057156263 | 60 | check_ready(); |
gunpuen2 | 0:a8e057156263 | 61 | } |
gunpuen2 | 0:a8e057156263 | 62 | if(SW == 1){ //______________________________________________________ For make sure switch is press 1 time. |
gunpuen2 | 0:a8e057156263 | 63 | iSW = 0; |
gunpuen2 | 0:a8e057156263 | 64 | check_ready(); |
gunpuen2 | 0:a8e057156263 | 65 | } |
gunpuen2 | 0:a8e057156263 | 66 | if(m!=NULL && iVxVy==0){ //__________________________________________ Get position that wait for press switch. |
gunpuen2 | 0:a8e057156263 | 67 | Select_Position(m); |
gunpuen2 | 0:a8e057156263 | 68 | check_ready(); |
gunpuen2 | 0:a8e057156263 | 69 | printf("select_Position = %d\n",select_Position); |
gunpuen2 | 0:a8e057156263 | 70 | iVxVy = 1; |
gunpuen2 | 3:baff75bbb78e | 71 | check_ready(); |
gunpuen2 | 0:a8e057156263 | 72 | } |
gunpuen2 | 0:a8e057156263 | 73 | if(SW==0 && iSW==0){ //______________________________________________If switch pressing by human. |
gunpuen2 | 0:a8e057156263 | 74 | printf("Wait!\n"); |
gunpuen2 | 0:a8e057156263 | 75 | check_ready(); |
gunpuen2 | 2:d93832fe8deb | 76 | if(get_position(select_Position,ship_SelectType[iShipType])==0){ //__Please read explanation in function get_position. |
gunpuen2 | 0:a8e057156263 | 77 | printf("Please input correct position\n"); |
gunpuen2 | 0:a8e057156263 | 78 | }else{ |
gunpuen2 | 0:a8e057156263 | 79 | iShipType++; |
gunpuen2 | 0:a8e057156263 | 80 | } |
gunpuen2 | 0:a8e057156263 | 81 | check_ready(); |
gunpuen2 | 0:a8e057156263 | 82 | iSW = 1; |
gunpuen2 | 0:a8e057156263 | 83 | print_metrix(); |
gunpuen2 | 3:baff75bbb78e | 84 | check_ready(); |
gunpuen2 | 0:a8e057156263 | 85 | } |
gunpuen2 | 0:a8e057156263 | 86 | }else{ |
gunpuen2 | 3:baff75bbb78e | 87 | if(enemy_ready!=1){ |
gunpuen2 | 3:baff75bbb78e | 88 | printf("sent E\n"); |
gunpuen2 | 3:baff75bbb78e | 89 | while(uli<5000){ |
gunpuen2 | 3:baff75bbb78e | 90 | bt.putc('E'); |
gunpuen2 | 3:baff75bbb78e | 91 | uli++; |
gunpuen2 | 3:baff75bbb78e | 92 | } |
gunpuen2 | 3:baff75bbb78e | 93 | } |
gunpuen2 | 0:a8e057156263 | 94 | printf("\n"); |
gunpuen2 | 0:a8e057156263 | 95 | break; |
gunpuen2 | 0:a8e057156263 | 96 | } |
gunpuen2 | 0:a8e057156263 | 97 | } |
gunpuen2 | 0:a8e057156263 | 98 | select_Position = 0; |
gunpuen2 | 1:6157c77da3d5 | 99 | if(enemy_ready == 1){state = 1;}else{state = 0;} //__________________________Set state |
gunpuen2 | 0:a8e057156263 | 100 | while(1) { //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Play |
gunpuen2 | 1:6157c77da3d5 | 101 | if(state == 0){ |
gunpuen2 | 1:6157c77da3d5 | 102 | if(iPrintUturn==0){ |
gunpuen2 | 1:6157c77da3d5 | 103 | printf("Your turn.\n"); |
gunpuen2 | 1:6157c77da3d5 | 104 | iPrintUturn = 1; |
gunpuen2 | 1:6157c77da3d5 | 105 | } |
gunpuen2 | 0:a8e057156263 | 106 | Vx = VRx.read() * 1024; |
gunpuen2 | 0:a8e057156263 | 107 | Vy = VRy.read() * 1024; |
gunpuen2 | 0:a8e057156263 | 108 | SW = Button.read(); |
gunpuen2 | 0:a8e057156263 | 109 | m = check_joys(Vx,Vy); |
gunpuen2 | 0:a8e057156263 | 110 | n = check_joys_int(Vx,Vy); |
gunpuen2 | 0:a8e057156263 | 111 | if(n == 1){ |
gunpuen2 | 0:a8e057156263 | 112 | iVxVy = 0; |
gunpuen2 | 0:a8e057156263 | 113 | } |
gunpuen2 | 0:a8e057156263 | 114 | if(SW == 1){ |
gunpuen2 | 0:a8e057156263 | 115 | iSW = 0; |
gunpuen2 | 0:a8e057156263 | 116 | } |
gunpuen2 | 0:a8e057156263 | 117 | if(m!=NULL && iVxVy==0){ |
gunpuen2 | 0:a8e057156263 | 118 | Select_Position(m); |
gunpuen2 | 0:a8e057156263 | 119 | printf("select_Position = %d\n",select_Position); |
gunpuen2 | 0:a8e057156263 | 120 | iVxVy = 1; |
gunpuen2 | 0:a8e057156263 | 121 | } |
gunpuen2 | 0:a8e057156263 | 122 | if(SW==0 && iSW==0){ |
gunpuen2 | 1:6157c77da3d5 | 123 | bt.putc(posit2char(select_Position)); |
gunpuen2 | 1:6157c77da3d5 | 124 | printf("You attacking at position %d\n",select_Position); |
gunpuen2 | 1:6157c77da3d5 | 125 | state = 1; |
gunpuen2 | 0:a8e057156263 | 126 | iSW = 1; |
gunpuen2 | 0:a8e057156263 | 127 | } |
gunpuen2 | 0:a8e057156263 | 128 | }else{ |
gunpuen2 | 1:6157c77da3d5 | 129 | iPrintUturn = 0; |
gunpuen2 | 0:a8e057156263 | 130 | while(1){ |
gunpuen2 | 0:a8e057156263 | 131 | if(bt.readable()){ |
gunpuen2 | 0:a8e057156263 | 132 | // Wait for resive position of enemy that atk you. |
gunpuen2 | 1:6157c77da3d5 | 133 | ATKposition = char2posit(bt.getc()); |
gunpuen2 | 0:a8e057156263 | 134 | iWaitATK = 1; |
gunpuen2 | 1:6157c77da3d5 | 135 | }else{ |
gunpuen2 | 1:6157c77da3d5 | 136 | printf("Wait for enemy attack\n"); |
gunpuen2 | 0:a8e057156263 | 137 | } |
gunpuen2 | 0:a8e057156263 | 138 | if(iWaitATK==1){ |
gunpuen2 | 1:6157c77da3d5 | 139 | printf("Enemy attack at your area %d\n",ATKposition); |
gunpuen2 | 1:6157c77da3d5 | 140 | state = 0; |
gunpuen2 | 0:a8e057156263 | 141 | break; |
gunpuen2 | 0:a8e057156263 | 142 | } |
gunpuen2 | 0:a8e057156263 | 143 | } |
gunpuen2 | 0:a8e057156263 | 144 | } |
gunpuen2 | 0:a8e057156263 | 145 | } |
gunpuen2 | 0:a8e057156263 | 146 | } |
gunpuen2 | 0:a8e057156263 | 147 | |
gunpuen2 | 0:a8e057156263 | 148 | |
gunpuen2 | 0:a8e057156263 | 149 | |
gunpuen2 | 0:a8e057156263 | 150 | |
gunpuen2 | 0:a8e057156263 | 151 | |
gunpuen2 | 0:a8e057156263 | 152 | |
gunpuen2 | 0:a8e057156263 | 153 | |
gunpuen2 | 0:a8e057156263 | 154 | |
gunpuen2 | 0:a8e057156263 | 155 | |
gunpuen2 | 0:a8e057156263 | 156 | |
gunpuen2 | 0:a8e057156263 | 157 | |
gunpuen2 | 0:a8e057156263 | 158 | |
gunpuen2 | 0:a8e057156263 | 159 | |
gunpuen2 | 0:a8e057156263 | 160 | |
gunpuen2 | 0:a8e057156263 | 161 | char check_joys(int jx,int jy){ //-----------------------------------------------Check joystick that it up,down,left or right. |
gunpuen2 | 0:a8e057156263 | 162 | if(jx < 24.0){ |
gunpuen2 | 0:a8e057156263 | 163 | return 'a'; |
gunpuen2 | 0:a8e057156263 | 164 | } |
gunpuen2 | 0:a8e057156263 | 165 | else if(jx > 1000.0){ |
gunpuen2 | 0:a8e057156263 | 166 | return 'd'; |
gunpuen2 | 0:a8e057156263 | 167 | } |
gunpuen2 | 0:a8e057156263 | 168 | else if(jy < 24.0){ |
gunpuen2 | 0:a8e057156263 | 169 | return 'w'; |
gunpuen2 | 0:a8e057156263 | 170 | } |
gunpuen2 | 0:a8e057156263 | 171 | else if(jy > 1000.0){ |
gunpuen2 | 0:a8e057156263 | 172 | return 's'; |
gunpuen2 | 0:a8e057156263 | 173 | }else{ |
gunpuen2 | 0:a8e057156263 | 174 | return NULL; |
gunpuen2 | 0:a8e057156263 | 175 | } |
gunpuen2 | 0:a8e057156263 | 176 | } |
gunpuen2 | 0:a8e057156263 | 177 | int check_joys_int(int jx,int jy){ //--------------------------------------------Check joystick that it is centre. |
gunpuen2 | 0:a8e057156263 | 178 | if(jx>=450.0&&jx<=600.0){ |
gunpuen2 | 0:a8e057156263 | 179 | if(jy>=450.0&&jy<=600.0){ |
gunpuen2 | 0:a8e057156263 | 180 | return 1; |
gunpuen2 | 0:a8e057156263 | 181 | }else{ |
gunpuen2 | 0:a8e057156263 | 182 | return 0; |
gunpuen2 | 0:a8e057156263 | 183 | } |
gunpuen2 | 0:a8e057156263 | 184 | }else{ |
gunpuen2 | 0:a8e057156263 | 185 | return 0; |
gunpuen2 | 0:a8e057156263 | 186 | } |
gunpuen2 | 0:a8e057156263 | 187 | } |
gunpuen2 | 0:a8e057156263 | 188 | void Select_Position(char M){ //-------------------------------------------------Change position of cursor (Joystick). |
gunpuen2 | 0:a8e057156263 | 189 | switch(M){ |
gunpuen2 | 0:a8e057156263 | 190 | case 'a': |
gunpuen2 | 0:a8e057156263 | 191 | if(select_Position%10!=0){select_Position = select_Position - 1;} |
gunpuen2 | 0:a8e057156263 | 192 | break; |
gunpuen2 | 0:a8e057156263 | 193 | case 'd': |
gunpuen2 | 0:a8e057156263 | 194 | if(select_Position%10!=7){select_Position = select_Position + 1;} |
gunpuen2 | 0:a8e057156263 | 195 | break; |
gunpuen2 | 0:a8e057156263 | 196 | case 'w': |
gunpuen2 | 0:a8e057156263 | 197 | if(select_Position/10!=0){select_Position = select_Position - 10;} |
gunpuen2 | 0:a8e057156263 | 198 | break; |
gunpuen2 | 0:a8e057156263 | 199 | case 's': |
gunpuen2 | 0:a8e057156263 | 200 | if(select_Position/10!=7){select_Position = select_Position + 10;} |
gunpuen2 | 0:a8e057156263 | 201 | break; |
gunpuen2 | 0:a8e057156263 | 202 | } |
gunpuen2 | 0:a8e057156263 | 203 | } |
gunpuen2 | 0:a8e057156263 | 204 | int get_position(int input_position,int ship_type){ //---------------------------Plot ship in ship area. |
gunpuen2 | 0:a8e057156263 | 205 | int i,x,y = 0; |
gunpuen2 | 0:a8e057156263 | 206 | int error = 0; |
gunpuen2 | 0:a8e057156263 | 207 | |
gunpuen2 | 0:a8e057156263 | 208 | y = input_position/10; |
gunpuen2 | 0:a8e057156263 | 209 | x = input_position%10; |
gunpuen2 | 0:a8e057156263 | 210 | |
gunpuen2 | 0:a8e057156263 | 211 | for(i=0;i<ship_type;i++){ |
gunpuen2 | 0:a8e057156263 | 212 | if(check_correctPosition(y,x) == 1){ |
gunpuen2 | 0:a8e057156263 | 213 | if(ship_type == 4){ship4[i] = (y*10)+x;} |
gunpuen2 | 0:a8e057156263 | 214 | else if(ship_type == 3){ship3[i] = (y*10)+x;} |
gunpuen2 | 0:a8e057156263 | 215 | else if(ship_type == 2){ship2[check_ship2][i] = (y*10)+x;} |
gunpuen2 | 0:a8e057156263 | 216 | else if(ship_type == 1){ship1[check_ship1] = (y*10)+x;check_ship1++;} |
gunpuen2 | 0:a8e057156263 | 217 | }else{ |
gunpuen2 | 0:a8e057156263 | 218 | error = 1; |
gunpuen2 | 0:a8e057156263 | 219 | break; |
gunpuen2 | 0:a8e057156263 | 220 | } |
gunpuen2 | 0:a8e057156263 | 221 | if(ship_type%2 == 0){ |
gunpuen2 | 0:a8e057156263 | 222 | y++; |
gunpuen2 | 0:a8e057156263 | 223 | }else{ |
gunpuen2 | 0:a8e057156263 | 224 | x++; |
gunpuen2 | 0:a8e057156263 | 225 | } |
gunpuen2 | 0:a8e057156263 | 226 | } |
gunpuen2 | 0:a8e057156263 | 227 | if(ship_type==2){ |
gunpuen2 | 0:a8e057156263 | 228 | check_ship2++; |
gunpuen2 | 0:a8e057156263 | 229 | } |
gunpuen2 | 0:a8e057156263 | 230 | if(error == 1){ |
gunpuen2 | 0:a8e057156263 | 231 | return 0; |
gunpuen2 | 0:a8e057156263 | 232 | }else{ |
gunpuen2 | 0:a8e057156263 | 233 | y = input_position/10; |
gunpuen2 | 0:a8e057156263 | 234 | x = input_position%10; |
gunpuen2 | 0:a8e057156263 | 235 | for(i=0;i<ship_type;i++){ |
gunpuen2 | 1:6157c77da3d5 | 236 | ship_platform[y][x] = ship_type; |
gunpuen2 | 0:a8e057156263 | 237 | if(ship_type%2 == 0){ |
gunpuen2 | 0:a8e057156263 | 238 | y++; |
gunpuen2 | 0:a8e057156263 | 239 | }else{ |
gunpuen2 | 0:a8e057156263 | 240 | x++; |
gunpuen2 | 0:a8e057156263 | 241 | } |
gunpuen2 | 0:a8e057156263 | 242 | } |
gunpuen2 | 0:a8e057156263 | 243 | return 1; |
gunpuen2 | 0:a8e057156263 | 244 | } |
gunpuen2 | 0:a8e057156263 | 245 | } |
gunpuen2 | 0:a8e057156263 | 246 | int check_correctPosition(int X,int Y){ |
gunpuen2 | 0:a8e057156263 | 247 | if(X<=7){ |
gunpuen2 | 0:a8e057156263 | 248 | if(Y<=7){ |
gunpuen2 | 1:6157c77da3d5 | 249 | if(ship_platform[X][Y] == 0){ |
gunpuen2 | 0:a8e057156263 | 250 | return 1; |
gunpuen2 | 0:a8e057156263 | 251 | }else{ |
gunpuen2 | 0:a8e057156263 | 252 | return 0; |
gunpuen2 | 0:a8e057156263 | 253 | } |
gunpuen2 | 1:6157c77da3d5 | 254 | }else{ |
gunpuen2 | 1:6157c77da3d5 | 255 | return 0; |
gunpuen2 | 0:a8e057156263 | 256 | } |
gunpuen2 | 0:a8e057156263 | 257 | }else{ |
gunpuen2 | 0:a8e057156263 | 258 | return 0; |
gunpuen2 | 0:a8e057156263 | 259 | } |
gunpuen2 | 0:a8e057156263 | 260 | } |
gunpuen2 | 0:a8e057156263 | 261 | void print_metrix(){ |
gunpuen2 | 0:a8e057156263 | 262 | for(int i=0;i<8;i++){ |
gunpuen2 | 0:a8e057156263 | 263 | for(int j=0;j<8;j++){ |
gunpuen2 | 1:6157c77da3d5 | 264 | printf("| %d |",ship_platform[i][j]); |
gunpuen2 | 0:a8e057156263 | 265 | } |
gunpuen2 | 0:a8e057156263 | 266 | printf("\n"); |
gunpuen2 | 0:a8e057156263 | 267 | } |
gunpuen2 | 0:a8e057156263 | 268 | } |
gunpuen2 | 0:a8e057156263 | 269 | void check_ready(){ |
gunpuen2 | 0:a8e057156263 | 270 | if(bt.readable()){ |
gunpuen2 | 1:6157c77da3d5 | 271 | enemy_ready = 1; |
gunpuen2 | 1:6157c77da3d5 | 272 | } |
gunpuen2 | 1:6157c77da3d5 | 273 | } |
gunpuen2 | 1:6157c77da3d5 | 274 | char posit2char(int posit){ |
gunpuen2 | 1:6157c77da3d5 | 275 | int as = posit+48; |
gunpuen2 | 1:6157c77da3d5 | 276 | char ch = as; |
gunpuen2 | 1:6157c77da3d5 | 277 | return ch ; |
gunpuen2 | 1:6157c77da3d5 | 278 | } |
gunpuen2 | 1:6157c77da3d5 | 279 | |
gunpuen2 | 1:6157c77da3d5 | 280 | int char2posit(char cha){ |
gunpuen2 | 1:6157c77da3d5 | 281 | int as = cha; |
gunpuen2 | 1:6157c77da3d5 | 282 | as = as-48; |
gunpuen2 | 1:6157c77da3d5 | 283 | return as; |
gunpuen2 | 1:6157c77da3d5 | 284 | } |
gunpuen2 | 1:6157c77da3d5 | 285 | void getATK_position(int atkpos){ |
gunpuen2 | 2:d93832fe8deb | 286 | int i,j,k,x,y = 0; |
gunpuen2 | 1:6157c77da3d5 | 287 | |
gunpuen2 | 1:6157c77da3d5 | 288 | y = atkpos/10; |
gunpuen2 | 1:6157c77da3d5 | 289 | x = atkpos%10; |
gunpuen2 | 1:6157c77da3d5 | 290 | |
gunpuen2 | 2:d93832fe8deb | 291 | if(ship_platform[x][y]!=0 and atk_platform[x][y]==0){ |
gunpuen2 | 1:6157c77da3d5 | 292 | atk_platform[x][y] = ship_platform[x][y]; |
gunpuen2 | 2:d93832fe8deb | 293 | ship_underATK[check_ship_underATK] = (y*10)+x; |
gunpuen2 | 2:d93832fe8deb | 294 | check_ship_underATK++; |
gunpuen2 | 2:d93832fe8deb | 295 | if(atk_platform[x][y]==4){ |
gunpuen2 | 2:d93832fe8deb | 296 | for(i=0;i<4;i++){ |
gunpuen2 | 2:d93832fe8deb | 297 | for(j=0;j<15;j++){ |
gunpuen2 | 2:d93832fe8deb | 298 | if(ship4[i]==ship_underATK[j]){ |
gunpuen2 | 2:d93832fe8deb | 299 | ship_destroyed[0]++; |
gunpuen2 | 2:d93832fe8deb | 300 | } |
gunpuen2 | 2:d93832fe8deb | 301 | } |
gunpuen2 | 2:d93832fe8deb | 302 | } |
gunpuen2 | 2:d93832fe8deb | 303 | }else if(atk_platform[x][y]==3){ |
gunpuen2 | 2:d93832fe8deb | 304 | for(i=0;i<3;i++){ |
gunpuen2 | 2:d93832fe8deb | 305 | for(j=0;j<15;j++){ |
gunpuen2 | 2:d93832fe8deb | 306 | if(ship3[i]==ship_underATK[j]){ |
gunpuen2 | 2:d93832fe8deb | 307 | ship_destroyed[1]++; |
gunpuen2 | 2:d93832fe8deb | 308 | } |
gunpuen2 | 2:d93832fe8deb | 309 | } |
gunpuen2 | 2:d93832fe8deb | 310 | } |
gunpuen2 | 2:d93832fe8deb | 311 | }else if(atk_platform[x][y]==2){ |
gunpuen2 | 2:d93832fe8deb | 312 | for(i=0;i<4;i++){ |
gunpuen2 | 2:d93832fe8deb | 313 | for(j=0;j<15;j++){ |
gunpuen2 | 2:d93832fe8deb | 314 | if(ship2[0][i]==ship_underATK[j]){ |
gunpuen2 | 2:d93832fe8deb | 315 | ship_destroyed[2]++; |
gunpuen2 | 2:d93832fe8deb | 316 | } |
gunpuen2 | 2:d93832fe8deb | 317 | if(ship2[1][i]==ship_underATK[j]){ |
gunpuen2 | 2:d93832fe8deb | 318 | ship_destroyed[3]++; |
gunpuen2 | 2:d93832fe8deb | 319 | } |
gunpuen2 | 2:d93832fe8deb | 320 | } |
gunpuen2 | 2:d93832fe8deb | 321 | } |
gunpuen2 | 2:d93832fe8deb | 322 | }else if(atk_platform[x][y]==1){ |
gunpuen2 | 2:d93832fe8deb | 323 | for(i=0;i<4;i++){ |
gunpuen2 | 2:d93832fe8deb | 324 | for(j=0;j<15;j++){ |
gunpuen2 | 2:d93832fe8deb | 325 | if(ship3[i]==ship_underATK[j]){ |
gunpuen2 | 2:d93832fe8deb | 326 | ship_destroyed[4+i]++; |
gunpuen2 | 2:d93832fe8deb | 327 | } |
gunpuen2 | 2:d93832fe8deb | 328 | } |
gunpuen2 | 2:d93832fe8deb | 329 | } |
gunpuen2 | 2:d93832fe8deb | 330 | } |
gunpuen2 | 1:6157c77da3d5 | 331 | }else{ |
gunpuen2 | 1:6157c77da3d5 | 332 | atk_platform[x][y] = 8; |
gunpuen2 | 0:a8e057156263 | 333 | } |
gunpuen2 | 0:a8e057156263 | 334 | } |
gunpuen2 | 0:a8e057156263 | 335 | /* |
gunpuen2 | 0:a8e057156263 | 336 | int check_when_enemyATK(int position){ |
gunpuen2 | 0:a8e057156263 | 337 | |
gunpuen2 | 0:a8e057156263 | 338 | } |
gunpuen2 | 0:a8e057156263 | 339 | */ |