Nasrun Hayeeyama
/
project_ShipDot
Nasrun
Fork of project_ShipDot by
main.cpp@4:8a86bacddcac, 2016-12-02 (annotated)
- Committer:
- gunpuen2
- Date:
- Fri Dec 02 14:34:53 2016 +0000
- Revision:
- 4:8a86bacddcac
- Parent:
- 3:baff75bbb78e
- Child:
- 5:41b42d8e0af1
In my opinion I think that my code is ready to use.
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 | 4:8a86bacddcac | 13 | char posit2char(int posit); |
gunpuen2 | 0:a8e057156263 | 14 | char check_joys(int jx,int jy); |
gunpuen2 | 4:8a86bacddcac | 15 | int char2posit(char cha); |
gunpuen2 | 0:a8e057156263 | 16 | int check_joys_int(int jx,int jy); |
gunpuen2 | 0:a8e057156263 | 17 | int check_correctPosition(int X,int Y); |
gunpuen2 | 4:8a86bacddcac | 18 | int getShip_position(int input_position,int ship_type); |
gunpuen2 | 0:a8e057156263 | 19 | void check_ready(); |
gunpuen2 | 0:a8e057156263 | 20 | void print_metrix(); |
gunpuen2 | 4:8a86bacddcac | 21 | void mark_ship_destroyed(); |
gunpuen2 | 0:a8e057156263 | 22 | void Select_Position(char M); |
gunpuen2 | 4:8a86bacddcac | 23 | void getATK_platform(int atkpos); |
gunpuen2 | 0:a8e057156263 | 24 | |
gunpuen2 | 0:a8e057156263 | 25 | // Initial variable. |
gunpuen2 | 2:d93832fe8deb | 26 | int check_ship_underATK = 0; |
gunpuen2 | 0:a8e057156263 | 27 | int select_Position = 0; |
gunpuen2 | 0:a8e057156263 | 28 | int ATKposition = 0; |
gunpuen2 | 1:6157c77da3d5 | 29 | int enemy_ready = 0; |
gunpuen2 | 1:6157c77da3d5 | 30 | int iPrintUturn = 0; |
gunpuen2 | 2:d93832fe8deb | 31 | int check_ship1 = 0; |
gunpuen2 | 2:d93832fe8deb | 32 | int check_ship2 = 0; |
gunpuen2 | 0:a8e057156263 | 33 | int iWaitATK = 0; |
gunpuen2 | 0:a8e057156263 | 34 | int state = 0; |
gunpuen2 | 2:d93832fe8deb | 35 | int ship_SelectType[8] = {4,3,2,2,1,1,1,1}; |
gunpuen2 | 4:8a86bacddcac | 36 | int ship_platform[8][8] = {{0}}; //______________________________________________This is ship area. |
gunpuen2 | 1:6157c77da3d5 | 37 | int atk_platform[8][8] = {{0}}; |
gunpuen2 | 4:8a86bacddcac | 38 | int ship_underATK[15] = {9}; |
gunpuen2 | 2:d93832fe8deb | 39 | int ship_destroyed[8] = {0}; |
gunpuen2 | 0:a8e057156263 | 40 | int ship4[4] = {0}; |
gunpuen2 | 0:a8e057156263 | 41 | int ship3[3] = {0}; |
gunpuen2 | 0:a8e057156263 | 42 | int ship2[2][2] = {{0}}; |
gunpuen2 | 0:a8e057156263 | 43 | int ship1[4] = {0}; |
gunpuen2 | 0:a8e057156263 | 44 | |
gunpuen2 | 0:a8e057156263 | 45 | int main(){ //-------------------------------------------------------------------Main Function. |
gunpuen2 | 0:a8e057156263 | 46 | float Vx; |
gunpuen2 | 0:a8e057156263 | 47 | float Vy; |
gunpuen2 | 0:a8e057156263 | 48 | int SW,iVxVy,iSW,n; |
gunpuen2 | 0:a8e057156263 | 49 | int iShipType = 0; |
gunpuen2 | 3:baff75bbb78e | 50 | unsigned long int uli = 0; |
gunpuen2 | 0:a8e057156263 | 51 | char m; |
gunpuen2 | 0:a8e057156263 | 52 | while(1) { |
gunpuen2 | 0:a8e057156263 | 53 | if(iShipType<8){ |
gunpuen2 | 0:a8e057156263 | 54 | Vx = VRx.read() * 1024; |
gunpuen2 | 0:a8e057156263 | 55 | Vy = VRy.read() * 1024; |
gunpuen2 | 0:a8e057156263 | 56 | SW = Button.read(); |
gunpuen2 | 0:a8e057156263 | 57 | m = check_joys(Vx,Vy); |
gunpuen2 | 0:a8e057156263 | 58 | n = check_joys_int(Vx,Vy); |
gunpuen2 | 0:a8e057156263 | 59 | if(n == 1){ //_______________________________________________________ For make sure coordinate is press 1 time. |
gunpuen2 | 0:a8e057156263 | 60 | iVxVy = 0; |
gunpuen2 | 0:a8e057156263 | 61 | check_ready(); |
gunpuen2 | 0:a8e057156263 | 62 | } |
gunpuen2 | 0:a8e057156263 | 63 | if(SW == 1){ //______________________________________________________ For make sure switch is press 1 time. |
gunpuen2 | 0:a8e057156263 | 64 | iSW = 0; |
gunpuen2 | 0:a8e057156263 | 65 | check_ready(); |
gunpuen2 | 0:a8e057156263 | 66 | } |
gunpuen2 | 0:a8e057156263 | 67 | if(m!=NULL && iVxVy==0){ //__________________________________________ Get position that wait for press switch. |
gunpuen2 | 0:a8e057156263 | 68 | Select_Position(m); |
gunpuen2 | 0:a8e057156263 | 69 | check_ready(); |
gunpuen2 | 0:a8e057156263 | 70 | printf("select_Position = %d\n",select_Position); |
gunpuen2 | 0:a8e057156263 | 71 | iVxVy = 1; |
gunpuen2 | 3:baff75bbb78e | 72 | check_ready(); |
gunpuen2 | 0:a8e057156263 | 73 | } |
gunpuen2 | 0:a8e057156263 | 74 | if(SW==0 && iSW==0){ //______________________________________________If switch pressing by human. |
gunpuen2 | 0:a8e057156263 | 75 | printf("Wait!\n"); |
gunpuen2 | 0:a8e057156263 | 76 | check_ready(); |
gunpuen2 | 4:8a86bacddcac | 77 | if(getShip_position(select_Position,ship_SelectType[iShipType])==0){ //__Please read explanation in function getShip_position. |
gunpuen2 | 0:a8e057156263 | 78 | printf("Please input correct position\n"); |
gunpuen2 | 0:a8e057156263 | 79 | }else{ |
gunpuen2 | 0:a8e057156263 | 80 | iShipType++; |
gunpuen2 | 0:a8e057156263 | 81 | } |
gunpuen2 | 0:a8e057156263 | 82 | check_ready(); |
gunpuen2 | 0:a8e057156263 | 83 | iSW = 1; |
gunpuen2 | 0:a8e057156263 | 84 | print_metrix(); |
gunpuen2 | 3:baff75bbb78e | 85 | check_ready(); |
gunpuen2 | 0:a8e057156263 | 86 | } |
gunpuen2 | 0:a8e057156263 | 87 | }else{ |
gunpuen2 | 3:baff75bbb78e | 88 | if(enemy_ready!=1){ |
gunpuen2 | 3:baff75bbb78e | 89 | printf("sent E\n"); |
gunpuen2 | 4:8a86bacddcac | 90 | while(uli<1000){ |
gunpuen2 | 4:8a86bacddcac | 91 | bt.printf("E"); |
gunpuen2 | 3:baff75bbb78e | 92 | uli++; |
gunpuen2 | 3:baff75bbb78e | 93 | } |
gunpuen2 | 3:baff75bbb78e | 94 | } |
gunpuen2 | 0:a8e057156263 | 95 | printf("\n"); |
gunpuen2 | 0:a8e057156263 | 96 | break; |
gunpuen2 | 0:a8e057156263 | 97 | } |
gunpuen2 | 0:a8e057156263 | 98 | } |
gunpuen2 | 0:a8e057156263 | 99 | select_Position = 0; |
gunpuen2 | 4:8a86bacddcac | 100 | printf("%d",enemy_ready); |
gunpuen2 | 1:6157c77da3d5 | 101 | if(enemy_ready == 1){state = 1;}else{state = 0;} //__________________________Set state |
gunpuen2 | 0:a8e057156263 | 102 | while(1) { //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Play |
gunpuen2 | 1:6157c77da3d5 | 103 | if(state == 0){ |
gunpuen2 | 1:6157c77da3d5 | 104 | if(iPrintUturn==0){ |
gunpuen2 | 1:6157c77da3d5 | 105 | printf("Your turn.\n"); |
gunpuen2 | 1:6157c77da3d5 | 106 | iPrintUturn = 1; |
gunpuen2 | 1:6157c77da3d5 | 107 | } |
gunpuen2 | 0:a8e057156263 | 108 | Vx = VRx.read() * 1024; |
gunpuen2 | 0:a8e057156263 | 109 | Vy = VRy.read() * 1024; |
gunpuen2 | 0:a8e057156263 | 110 | SW = Button.read(); |
gunpuen2 | 0:a8e057156263 | 111 | m = check_joys(Vx,Vy); |
gunpuen2 | 0:a8e057156263 | 112 | n = check_joys_int(Vx,Vy); |
gunpuen2 | 0:a8e057156263 | 113 | if(n == 1){ |
gunpuen2 | 0:a8e057156263 | 114 | iVxVy = 0; |
gunpuen2 | 0:a8e057156263 | 115 | } |
gunpuen2 | 0:a8e057156263 | 116 | if(SW == 1){ |
gunpuen2 | 0:a8e057156263 | 117 | iSW = 0; |
gunpuen2 | 0:a8e057156263 | 118 | } |
gunpuen2 | 0:a8e057156263 | 119 | if(m!=NULL && iVxVy==0){ |
gunpuen2 | 0:a8e057156263 | 120 | Select_Position(m); |
gunpuen2 | 0:a8e057156263 | 121 | printf("select_Position = %d\n",select_Position); |
gunpuen2 | 0:a8e057156263 | 122 | iVxVy = 1; |
gunpuen2 | 0:a8e057156263 | 123 | } |
gunpuen2 | 0:a8e057156263 | 124 | if(SW==0 && iSW==0){ |
gunpuen2 | 1:6157c77da3d5 | 125 | bt.putc(posit2char(select_Position)); |
gunpuen2 | 1:6157c77da3d5 | 126 | printf("You attacking at position %d\n",select_Position); |
gunpuen2 | 1:6157c77da3d5 | 127 | state = 1; |
gunpuen2 | 0:a8e057156263 | 128 | iSW = 1; |
gunpuen2 | 0:a8e057156263 | 129 | } |
gunpuen2 | 0:a8e057156263 | 130 | }else{ |
gunpuen2 | 1:6157c77da3d5 | 131 | iPrintUturn = 0; |
gunpuen2 | 0:a8e057156263 | 132 | while(1){ |
gunpuen2 | 0:a8e057156263 | 133 | if(bt.readable()){ |
gunpuen2 | 0:a8e057156263 | 134 | // Wait for resive position of enemy that atk you. |
gunpuen2 | 1:6157c77da3d5 | 135 | ATKposition = char2posit(bt.getc()); |
gunpuen2 | 0:a8e057156263 | 136 | iWaitATK = 1; |
gunpuen2 | 1:6157c77da3d5 | 137 | }else{ |
gunpuen2 | 1:6157c77da3d5 | 138 | printf("Wait for enemy attack\n"); |
gunpuen2 | 0:a8e057156263 | 139 | } |
gunpuen2 | 0:a8e057156263 | 140 | if(iWaitATK==1){ |
gunpuen2 | 1:6157c77da3d5 | 141 | printf("Enemy attack at your area %d\n",ATKposition); |
gunpuen2 | 4:8a86bacddcac | 142 | getATK_platform(ATKposition); |
gunpuen2 | 4:8a86bacddcac | 143 | mark_ship_destroyed(); |
gunpuen2 | 1:6157c77da3d5 | 144 | state = 0; |
gunpuen2 | 0:a8e057156263 | 145 | break; |
gunpuen2 | 0:a8e057156263 | 146 | } |
gunpuen2 | 0:a8e057156263 | 147 | } |
gunpuen2 | 0:a8e057156263 | 148 | } |
gunpuen2 | 4:8a86bacddcac | 149 | // wait for check that who is winner. |
gunpuen2 | 0:a8e057156263 | 150 | } |
gunpuen2 | 0:a8e057156263 | 151 | } |
gunpuen2 | 0:a8e057156263 | 152 | |
gunpuen2 | 4:8a86bacddcac | 153 | /******************************************************************************/ |
gunpuen2 | 4:8a86bacddcac | 154 | /* */ |
gunpuen2 | 4:8a86bacddcac | 155 | /* */ |
gunpuen2 | 4:8a86bacddcac | 156 | /* Another function */ |
gunpuen2 | 4:8a86bacddcac | 157 | /* */ |
gunpuen2 | 4:8a86bacddcac | 158 | /* */ |
gunpuen2 | 4:8a86bacddcac | 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 | 4:8a86bacddcac | 204 | int getShip_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 | 4:8a86bacddcac | 285 | void getATK_platform(int atkpos){ |
gunpuen2 | 4:8a86bacddcac | 286 | int i,j,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 | 4:8a86bacddcac | 327 | atk_platform[x][y] = 11; |
gunpuen2 | 2:d93832fe8deb | 328 | } |
gunpuen2 | 2:d93832fe8deb | 329 | } |
gunpuen2 | 2:d93832fe8deb | 330 | } |
gunpuen2 | 2:d93832fe8deb | 331 | } |
gunpuen2 | 1:6157c77da3d5 | 332 | }else{ |
gunpuen2 | 1:6157c77da3d5 | 333 | atk_platform[x][y] = 8; |
gunpuen2 | 0:a8e057156263 | 334 | } |
gunpuen2 | 0:a8e057156263 | 335 | } |
gunpuen2 | 4:8a86bacddcac | 336 | void mark_ship_destroyed(){ |
gunpuen2 | 4:8a86bacddcac | 337 | int i,j,k = 0; |
gunpuen2 | 0:a8e057156263 | 338 | |
gunpuen2 | 4:8a86bacddcac | 339 | if(ship_destroyed[0]==4){ |
gunpuen2 | 4:8a86bacddcac | 340 | for(i=0;i<8;i++){ |
gunpuen2 | 4:8a86bacddcac | 341 | for(j=0;j<8;j++){ |
gunpuen2 | 4:8a86bacddcac | 342 | if(atk_platform[i][j]==4){ |
gunpuen2 | 4:8a86bacddcac | 343 | atk_platform[i][j] = 11; |
gunpuen2 | 4:8a86bacddcac | 344 | } |
gunpuen2 | 4:8a86bacddcac | 345 | } |
gunpuen2 | 4:8a86bacddcac | 346 | } |
gunpuen2 | 4:8a86bacddcac | 347 | }else if(ship_destroyed[1]==3){ |
gunpuen2 | 4:8a86bacddcac | 348 | for(i=0;i<8;i++){ |
gunpuen2 | 4:8a86bacddcac | 349 | for(j=0;j<8;j++){ |
gunpuen2 | 4:8a86bacddcac | 350 | if(atk_platform[i][j]==3){ |
gunpuen2 | 4:8a86bacddcac | 351 | atk_platform[i][j] = 11; |
gunpuen2 | 4:8a86bacddcac | 352 | } |
gunpuen2 | 4:8a86bacddcac | 353 | } |
gunpuen2 | 4:8a86bacddcac | 354 | } |
gunpuen2 | 4:8a86bacddcac | 355 | }else if(ship_destroyed[2]==2){ |
gunpuen2 | 4:8a86bacddcac | 356 | for(k=0;k<2;k++){ |
gunpuen2 | 4:8a86bacddcac | 357 | i = ship2[0][k]/10; |
gunpuen2 | 4:8a86bacddcac | 358 | j = ship2[0][k]%10; |
gunpuen2 | 4:8a86bacddcac | 359 | atk_platform[i][j] = 11; |
gunpuen2 | 4:8a86bacddcac | 360 | } |
gunpuen2 | 4:8a86bacddcac | 361 | }else if(ship_destroyed[3]==2){ |
gunpuen2 | 4:8a86bacddcac | 362 | for(k=0;k<2;k++){ |
gunpuen2 | 4:8a86bacddcac | 363 | i = ship2[1][k]/10; |
gunpuen2 | 4:8a86bacddcac | 364 | j = ship2[1][k]%10; |
gunpuen2 | 4:8a86bacddcac | 365 | atk_platform[i][j] = 11; |
gunpuen2 | 4:8a86bacddcac | 366 | } |
gunpuen2 | 4:8a86bacddcac | 367 | } |
gunpuen2 | 4:8a86bacddcac | 368 | } |