ProjectBattleShip_FRA221 / Mbed 2 deprecated project_ShipDot_2

Dependencies:   mbed

Fork of project_ShipDot by Nasrun Hayeeyama

Files at this revision

API Documentation at this revision

Comitter:
gunpuen2
Date:
Mon Dec 05 10:48:47 2016 +0000
Parent:
28:163296348881
Commit message:
Fix red point (17:48 || 5/12/2559)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Dec 05 09:01:58 2016 +0000
+++ b/main.cpp	Mon Dec 05 10:48:47 2016 +0000
@@ -33,6 +33,7 @@
 void mark_ship_destroyed();
 void Select_Position(char M,int SetOrPlay);
 void get_atk_platform(int atkpos);
+void get_ship_UShipsRdestroyed();
 
 //inessential
 void print_ship_destroyed();
@@ -56,15 +57,21 @@
 int enemy_ready = 0;
 int check_ship1 = 0;
 int check_ship2 = 0;
+int check_win = 0;
+int state = 0;
+//Index.
 int iShipType = 0;
 int iWaitATK = 0;
-int check_win = 0;
-int state = 0;
+int iGSU=0;
+int iSUSPD = 0;
+//Array
 int ship_SelectType[8] = {4,3,2,2,1,1,1,1};
 int enemy_platform[8][8] = {{0}};
 int ship_platform[8][8] = {{0}}; //______________________________________________This is ship area.
 int atk_platform[8][8] = {{0}};
 int ship_underATK[15] = {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9};
+int ship_myShipsRdestroyed[15] = {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9};
+int ship_UShipsRdestroyed[15] = {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9};
 int ship_destroyed[8] = {0};
 int ship4[4] = {0};
 int ship3[3] = {0};
@@ -483,10 +490,15 @@
                         if(ship3[i]==ship_underATK[j]){ship_destroyed[1]++;}
                     }
                 }
-            }else if(atk_platform[x][y]==2){
-                for(i=0;i<4;i++){
+            }else if(atk_platform[x][y]==5){
+                for(i=0;i<2;i++){
                     for(j=0;j<15;j++){
                         if(ship2[0][i]==ship_underATK[j]){ship_destroyed[2]++;}
+                    }
+                }
+            }else if(atk_platform[x][y]==2){
+                for(i=0;i<2;i++){
+                    for(j=0;j<15;j++){
                         if(ship2[1][i]==ship_underATK[j]){ship_destroyed[3]++;}
                     }
                 }
@@ -496,6 +508,8 @@
                         if(ship3[i]==ship_underATK[j]){
                             ship_destroyed[4+i]++;
                             atk_platform[x][y] = 11;
+                            ship_myShipsRdestroyed[iGSU] = atkpos;
+                            iGSU++;
                         }
                     }
                 }
@@ -551,20 +565,49 @@
     }
     */
 }
+void get_ship_UShipsRdestroyed(){
+    int ship[8] = {0};
+    for(int k=0;k<2;k++){
+        for(int i=0;i<8;i++){
+            for(int j=0;j<8;j++){
+                if(enemy_platform[i][j]==4){
+                    if(k==0){ship[0]++;}
+                    if(ship[4]==1){ship_UShipsRdestroyed[iSUSPD] = enemy_platform[i][j];}
+                }
+                else if(enemy_platform[i][j]==3){
+                    if(k==0){ship[1]++;}
+                    if(ship[5]==1){ship_UShipsRdestroyed[iSUSPD] = enemy_platform[i][j];}
+                }
+                else if(enemy_platform[i][j]==2){
+                    if(k==0){ship[2]++;}
+                    if(ship[6]==1){ship_UShipsRdestroyed[iSUSPD] = enemy_platform[i][j];}
+                }
+                else if(enemy_platform[i][j]==5){
+                    if(k==0){ship[3]++;}
+                    if(ship[7]==1){ship_UShipsRdestroyed[iSUSPD] = enemy_platform[i][j];}
+                }
+            }
+        }
+        if(ship[0]==4){ship[4]=1;}
+        if(ship[1]==3){ship[5]=1;}
+        if(ship[2]==2){ship[6]=1;}
+        if(ship[3]==2){ship[7]=1;}
+    }
+}
 void mark_ship_destroyed(){
     int i,j,k = 0;
     
     if(ship_destroyed[0]==10){
         for(i=0;i<8;i++){
             for(j=0;j<8;j++){
-                if(atk_platform[i][j]==4){atk_platform[i][j] = 11;}
+                if(atk_platform[i][j]==4){atk_platform[i][j] = 11;ship_myShipsRdestroyed[iGSU] = (i*10)+j;iGSU++;}
             }
         }
     }
     if(ship_destroyed[1]==6){
         for(i=0;i<8;i++){
             for(j=0;j<8;j++){
-                if(atk_platform[i][j]==3){atk_platform[i][j] = 11;}
+                if(atk_platform[i][j]==3){atk_platform[i][j] = 11;ship_myShipsRdestroyed[iGSU] = (i*10)+j;iGSU++;}
             }
         }
     }
@@ -573,6 +616,8 @@
             i = ship2[0][k]/10;
             j = ship2[0][k]%10;
             atk_platform[i][j] = 11;
+            ship_myShipsRdestroyed[iGSU] = (i*10)+j;
+            iGSU++;
         }
     }
     if(ship_destroyed[3]==3){
@@ -580,6 +625,8 @@
             i = ship2[1][k]/10;
             j = ship2[1][k]%10;
             atk_platform[i][j] = 11;
+            ship_myShipsRdestroyed[iGSU] = (i*10)+j;
+            iGSU++;
         }
     }
 }