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.
Dependencies: mbed
Fork of project_ShipDot by
Diff: main.cpp
- Revision:
- 4:8a86bacddcac
- Parent:
- 3:baff75bbb78e
- Child:
- 5:41b42d8e0af1
diff -r baff75bbb78e -r 8a86bacddcac main.cpp
--- a/main.cpp Fri Dec 02 09:36:06 2016 +0000
+++ b/main.cpp Fri Dec 02 14:34:53 2016 +0000
@@ -10,16 +10,17 @@
Serial bt(PA_15, PB_7);
// Initial function.
+char posit2char(int posit);
char check_joys(int jx,int jy);
+int char2posit(char cha);
int check_joys_int(int jx,int jy);
int check_correctPosition(int X,int Y);
-int get_position(int input_position,int ship_type);
+int getShip_position(int input_position,int ship_type);
void check_ready();
void print_metrix();
+void mark_ship_destroyed();
void Select_Position(char M);
-void getATK_position(int atkpos);
-char posit2char(int posit);
-int char2posit(char cha);
+void getATK_platform(int atkpos);
// Initial variable.
int check_ship_underATK = 0;
@@ -32,9 +33,9 @@
int iWaitATK = 0;
int state = 0;
int ship_SelectType[8] = {4,3,2,2,1,1,1,1};
-int ship_platform[8][8] = {{0}}; //__________________________________________________This is ship area.
+int ship_platform[8][8] = {{0}}; //______________________________________________This is ship area.
int atk_platform[8][8] = {{0}};
-int ship_underATK[15] = {0};
+int ship_underATK[15] = {9};
int ship_destroyed[8] = {0};
int ship4[4] = {0};
int ship3[3] = {0};
@@ -73,7 +74,7 @@
if(SW==0 && iSW==0){ //______________________________________________If switch pressing by human.
printf("Wait!\n");
check_ready();
- if(get_position(select_Position,ship_SelectType[iShipType])==0){ //__Please read explanation in function get_position.
+ if(getShip_position(select_Position,ship_SelectType[iShipType])==0){ //__Please read explanation in function getShip_position.
printf("Please input correct position\n");
}else{
iShipType++;
@@ -86,8 +87,8 @@
}else{
if(enemy_ready!=1){
printf("sent E\n");
- while(uli<5000){
- bt.putc('E');
+ while(uli<1000){
+ bt.printf("E");
uli++;
}
}
@@ -96,6 +97,7 @@
}
}
select_Position = 0;
+ printf("%d",enemy_ready);
if(enemy_ready == 1){state = 1;}else{state = 0;} //__________________________Set state
while(1) { //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Play
if(state == 0){
@@ -137,26 +139,24 @@
}
if(iWaitATK==1){
printf("Enemy attack at your area %d\n",ATKposition);
+ getATK_platform(ATKposition);
+ mark_ship_destroyed();
state = 0;
break;
}
}
}
+ // wait for check that who is winner.
}
}
-
-
-
-
-
-
-
-
-
-
-
-
+/******************************************************************************/
+/* */
+/* */
+/* Another function */
+/* */
+/* */
+/******************************************************************************/
char check_joys(int jx,int jy){ //-----------------------------------------------Check joystick that it up,down,left or right.
if(jx < 24.0){
@@ -201,7 +201,7 @@
break;
}
}
-int get_position(int input_position,int ship_type){ //---------------------------Plot ship in ship area.
+int getShip_position(int input_position,int ship_type){ //-----------------------Plot ship in ship area.
int i,x,y = 0;
int error = 0;
@@ -282,8 +282,8 @@
as = as-48;
return as;
}
-void getATK_position(int atkpos){
- int i,j,k,x,y = 0;
+void getATK_platform(int atkpos){
+ int i,j,x,y = 0;
y = atkpos/10;
x = atkpos%10;
@@ -324,6 +324,7 @@
for(j=0;j<15;j++){
if(ship3[i]==ship_underATK[j]){
ship_destroyed[4+i]++;
+ atk_platform[x][y] = 11;
}
}
}
@@ -332,8 +333,36 @@
atk_platform[x][y] = 8;
}
}
-/*
-int check_when_enemyATK(int position){
+void mark_ship_destroyed(){
+ int i,j,k = 0;
-}
-*/
\ No newline at end of file
+ if(ship_destroyed[0]==4){
+ for(i=0;i<8;i++){
+ for(j=0;j<8;j++){
+ if(atk_platform[i][j]==4){
+ atk_platform[i][j] = 11;
+ }
+ }
+ }
+ }else if(ship_destroyed[1]==3){
+ for(i=0;i<8;i++){
+ for(j=0;j<8;j++){
+ if(atk_platform[i][j]==3){
+ atk_platform[i][j] = 11;
+ }
+ }
+ }
+ }else if(ship_destroyed[2]==2){
+ for(k=0;k<2;k++){
+ i = ship2[0][k]/10;
+ j = ship2[0][k]%10;
+ atk_platform[i][j] = 11;
+ }
+ }else if(ship_destroyed[3]==2){
+ for(k=0;k<2;k++){
+ i = ship2[1][k]/10;
+ j = ship2[1][k]%10;
+ atk_platform[i][j] = 11;
+ }
+ }
+}
\ No newline at end of file
