Nasrun Hayeeyama
/
project_ShipDot
Nasrun
Fork of project_ShipDot by
Diff: main.cpp
- Revision:
- 2:d93832fe8deb
- Parent:
- 1:6157c77da3d5
- Child:
- 3:baff75bbb78e
--- a/main.cpp Fri Dec 02 08:16:18 2016 +0000 +++ b/main.cpp Fri Dec 02 09:04:29 2016 +0000 @@ -22,18 +22,20 @@ int char2posit(char cha); // Initial variable. +int check_ship_underATK = 0; int select_Position = 0; int ATKposition = 0; int enemy_ready = 0; int iPrintUturn = 0; +int check_ship1 = 0; +int check_ship2 = 0; int iWaitATK = 0; int state = 0; -int ship_notdestroy[8] = {4,3,2,2,1,1,1,1}; +int ship_SelectType[8] = {4,3,2,2,1,1,1,1}; int ship_platform[8][8] = {{0}}; //__________________________________________________This is ship area. int atk_platform[8][8] = {{0}}; -int ship_destroyed[15] = {0}; -int check_ship1 = 0; -int check_ship2 = 0; +int ship_underATK[15] = {0}; +int ship_destroyed[8] = {0}; int ship4[4] = {0}; int ship3[3] = {0}; int ship2[2][2] = {{0}}; @@ -69,7 +71,7 @@ if(SW==0 && iSW==0){ //______________________________________________If switch pressing by human. printf("Wait!\n"); check_ready(); - if(get_position(select_Position,ship_notdestroy[iShipType])==0){ //__Please read explanation in function get_position. + if(get_position(select_Position,ship_SelectType[iShipType])==0){ //__Please read explanation in function get_position. printf("Please input correct position\n"); }else{ iShipType++; @@ -273,14 +275,51 @@ return as; } void getATK_position(int atkpos){ - int i,x,y = 0; + int i,j,k,x,y = 0; y = atkpos/10; x = atkpos%10; - if(ship_platform[x][y]!=0){ + if(ship_platform[x][y]!=0 and atk_platform[x][y]==0){ atk_platform[x][y] = ship_platform[x][y]; - ship_destroyed[] = (y*10)+x; + ship_underATK[check_ship_underATK] = (y*10)+x; + check_ship_underATK++; + if(atk_platform[x][y]==4){ + for(i=0;i<4;i++){ + for(j=0;j<15;j++){ + if(ship4[i]==ship_underATK[j]){ + ship_destroyed[0]++; + } + } + } + }else if(atk_platform[x][y]==3){ + for(i=0;i<3;i++){ + for(j=0;j<15;j++){ + if(ship3[i]==ship_underATK[j]){ + ship_destroyed[1]++; + } + } + } + }else if(atk_platform[x][y]==2){ + for(i=0;i<4;i++){ + for(j=0;j<15;j++){ + if(ship2[0][i]==ship_underATK[j]){ + ship_destroyed[2]++; + } + if(ship2[1][i]==ship_underATK[j]){ + ship_destroyed[3]++; + } + } + } + }else if(atk_platform[x][y]==1){ + for(i=0;i<4;i++){ + for(j=0;j<15;j++){ + if(ship3[i]==ship_underATK[j]){ + ship_destroyed[4+i]++; + } + } + } + } }else{ atk_platform[x][y] = 8; }