Nasrun Hayeeyama
/
project_ShipDot
Nasrun
Fork of project_ShipDot by
Diff: main.cpp
- Revision:
- 17:aeb7cbfb8640
- Parent:
- 16:3fac68a7fd7c
- Child:
- 18:ecef8382d41e
--- a/main.cpp Sat Dec 03 12:04:22 2016 +0000 +++ b/main.cpp Sat Dec 03 15:26:17 2016 +0000 @@ -41,6 +41,7 @@ int enemy_ready = 0; int check_ship1 = 0; int check_ship2 = 0; +int iShipType = 0; int iWaitATK = 0; int state = 0; int ship_SelectType[8] = {4,3,2,2,1,1,1,1}; @@ -59,7 +60,6 @@ float Vx; float Vy; int SW,iVxVy,iSW,n; - int iShipType = 0; unsigned long int uli = 0; char m; @@ -79,10 +79,8 @@ check_ready(); } if(m!=NULL && iVxVy==0){ //__________________________________________ Get position that wait for press switch. - if(protect_ship(select_Position,ship_SelectType[iShipType]!=0)){ Select_Position(m); printf("select_Position = %d\n",select_Position); - }else{printf("Not allow position.\n");} check_ready(); iVxVy = 1; check_ready(); @@ -180,32 +178,47 @@ } } void Select_Position(char M){ //-------------------------------------------------Change position of cursor (Joystick). + int protect_ships; + protect_ships = protect_ship(select_Position,ship_SelectType[iShipType]); switch(M){ case 'a': - if(select_Position%10!=0){select_Position = select_Position - 1;} + if(select_Position%10!=0){ + select_Position = select_Position - 1; + } break; case 'd': - if(select_Position%10!=7){select_Position = select_Position + 1;} + if(select_Position%10!=7){ + if(protect_ships==1 or protect_ships==0){ + select_Position = select_Position + 1; + }//else{ + //printf("Not allow position.\n"); + //} + } break; case 'w': - if(select_Position/10!=0){select_Position = select_Position - 10;} + if(select_Position/10!=0){ + select_Position = select_Position - 10; + } break; case 's': - if(select_Position/10!=7){select_Position = select_Position + 10;} + if(select_Position/10!=7){ + if(protect_ships==1 or protect_ships==2){ + select_Position = select_Position + 10; + }//else{ + //printf("Not allow position.\n"); + //} + } break; } } int protect_ship(int head_position,int ship_type){ int x,y = 0; - y = head_position/10; x = head_position%10; - - if(ship_type==4){if((y+3)>7){return 0;}else{return 1;}} - else if(ship_type==3){if((x+2)>7){return 0;}else{return 1;}} - else if(ship_type==2){if((y+1)>7){return 0;}else{return 1;}} + if(ship_type==4){if((y+4)>7){return 0;}else{return 1;}} + else if(ship_type==3){if((x+3)>7){return 2;}else{return 1;}} + else if(ship_type==2){if((y+2)>7){return 0;}else{return 1;}} else{return 1;} - } int get_ship_platform(int input_position,int ship_type){ //-----------------------Plot ship in ship area. int i,x,y = 0; @@ -432,5 +445,9 @@ if(sub_end==15){return 1;}else{return 0;} } int IamWin(){ - if(bt.readable()){if(bt.getc()=='q'){return 1;}else{return 0;}}else{return 0;} + char chare; + if(bt.readable()){ + chare = bt.getc() + if(chare=='q'){return 1;}else{return 0;} + }else{return 0;} } \ No newline at end of file