Serial Communication
Dependencies: mbed
Fork of Nucleo_serial_menu by
Diff: main.cpp
- Revision:
- 7:a651b3c90958
- Parent:
- 6:cac4ed620e57
- Child:
- 8:d90b2dfb339d
--- a/main.cpp Thu Dec 01 08:45:38 2016 +0000 +++ b/main.cpp Thu Dec 01 09:35:33 2016 +0000 @@ -109,6 +109,7 @@ } }else{ while(1){ + printf(""); if(bt.readable()){ // Wait for resive position of enemy that atk you. iWaitATK = 1; @@ -191,23 +192,23 @@ int i,x,y = 0; int error = 0; - x = input_position/10; - y = input_position%10; + y = input_position/10; + x = input_position%10; for(i=0;i<ship_type;i++){ - if(check_correctPosition(x,y) == 0){ + if(check_correctPosition(y,x) == 1){ + if(ship_type == 4){ship4[i] = (y*10)+x;} + else if(ship_type == 3){ship3[i] = (y*10)+x;} + else if(ship_type == 2){ship2[check_ship2][i] = (y*10)+x;} + else if(ship_type == 1){ship1[check_ship1] = (y*10)+x;check_ship1++;} + }else{ error = 1; break; - }else{ - if(ship_type == 4){ship4[i] = (x*10)+y;} - else if(ship_type == 3){ship3[i] = (x*10)+y;} - else if(ship_type == 2){ship2[check_ship2][i] = (x*10)+y;} - else if(ship_type == 1){ship1[check_ship1] = (x*10)+y;check_ship1++;} } if(ship_type%2 == 0){ - x++; + y++; }else{ - y++; + x++; } } if(ship_type==2){ @@ -216,25 +217,28 @@ if(error == 1){ return 0; }else{ - x = input_position/10; - y = input_position%10; + y = input_position/10; + x = input_position%10; for(i=0;i<ship_type;i++){ - ship_flor[x][y] = ship_type; + ship_flor[y][x] = ship_type; if(ship_type%2 == 0){ + y++; + }else{ x++; - }else{ - y++; } } return 1; } } int check_correctPosition(int X,int Y){ - if(X<=7||Y<=7){ - if(ship_flor[X][Y] == 0){ - return 1; - }else{ - return 0; + printf("%d ++ %d\n",X,Y); + if(X<=7){ + if(Y<=7){ + if(ship_flor[X][Y] == 0){ + return 1; + }else{ + return 0; + } } }else{ return 0;