Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 3:e21ecfae42e4, committed 2015-12-07
- Comitter:
- AndyTran
- Date:
- Mon Dec 07 22:10:04 2015 +0000
- Parent:
- 2:1a54e4ed2669
- Commit message:
- duck
Changed in this revision
| game_board.cpp | Show annotated file Show diff for this revision Revisions of this file | 
| game_board.h | Show annotated file Show diff for this revision Revisions of this file | 
--- a/game_board.cpp	Sat Dec 05 10:23:50 2015 +0000
+++ b/game_board.cpp	Mon Dec 07 22:10:04 2015 +0000
@@ -5,7 +5,16 @@
 
 void game_board::new_game_board ()
 {
-   //int i,j;
+   ship_lose = 0; 
+   for (i = 0; i < 6; i++);
+    {
+        _my_ship[i][0] = 0;
+        _my_ship[i][1] = 0;
+        _my_ship[i][2] = 0;
+        _my_ship[i][3] = 0;
+        _my_ship[i][4] = 0;
+        _my_ship[i][5] = 0;
+    }
    F_row = "F _ _ _ _ _ _   F _ _ _ _ _ _\n\r";
    E_row = "E _ _ _ _ _ _   E _ _ _ _ _ _\n\r";
    D_row = "D _ _ _ _ _ _   D _ _ _ _ _ _\n\r";
@@ -19,6 +28,7 @@
 bool game_board::place_hit_miss_friendly  (int row, int colum){
     if (_my_ship[row-1][colum-1] >= 1){
         _my_ship[row-1][colum-1] = 2; //freindly got destroy
+        ship_lose = ship_lose + 1;
         switch (row - 1)
             {
                 case 0: F_row[(colum)*2] = '*'; 
@@ -104,21 +114,9 @@
     return (r_row);
 };
 bool game_board::looser(){
-    int i,j,ship_lost = 0;
-
-    for (i = 0; i < 6; i++) 
-    {
-        for (j = 0; j < 6; j++) 
-        {
-            if (_my_ship[i][j] == 2) 
-            {
-                ship_lost = ship_lost + 1;
-            }
-        }
-    }
     //check for the number of ship is destroy;
     //if 5 or more ship is destroy player lose the game
-    if (ship_lost > 5) 
+    while (ship_lose > 5) 
     {
         return true; //you lose
     } 
--- a/game_board.h	Sat Dec 05 10:23:50 2015 +0000
+++ b/game_board.h	Mon Dec 07 22:10:04 2015 +0000
@@ -7,9 +7,11 @@
         //unsigned char _gameboard [6][27];
         string A_row,B_row,C_row,D_row,E_row,F_row,N_row, label;
         int _my_ship [6][6];
+        int ship_lose;
     public:
         game_board(){
            int i;
+           ship_lose = 0;
            for (i = 0; i < 6; i++);
            {
                _my_ship[i][0] = 0;