Nasrun Hayeeyama
/
project_ShipDot
Nasrun
Fork of project_ShipDot by
Diff: main.cpp
- Revision:
- 7:e35ba3ddb9af
- Parent:
- 6:7f99124272d9
- Child:
- 8:a8d39b5d17ab
--- a/main.cpp Sat Dec 03 05:14:38 2016 +0000 +++ b/main.cpp Sat Dec 03 07:32:47 2016 +0000 @@ -13,25 +13,30 @@ char posit2char(int posit); char check_joys(int jx,int jy); int char2posit(char cha); +int IamWin(); +int TellUrEnemy_uWin(); int check_joys_int(int jx,int jy); int check_correctPosition(int X,int Y); int getShip_position(int input_position,int ship_type); void atk_enemy(); void enemy_atk(); void check_ready(); +void print_ship_destroyed(); void print_enemy_platform(); void print_ship_platform(); void print_atk_platform(); void mark_ship_destroyed(); void Select_Position(char M); void getATK_platform(int atkpos); +void check_end(); +// Setting +int ifUrJirat = 1; // 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; @@ -103,18 +108,25 @@ } select_Position = 0; printf("%d",enemy_ready); - if(enemy_ready == 1){state = 1;}else{state = 0;} //__________________________Set state + if(enemy_ready == 1){state = 1;}else{state = 0;} while(1) { //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Play if(state == 0){ atk_enemy(); printf("This is enemy_platform.\n"); print_enemy_platform(); + if(IamWin()){printf("You win!\n");}else{state = 1;} }else{ enemy_atk(); printf("This is atk_platform.\n"); print_atk_platform(); + printf("This is ship_destroyed. : "); + print_ship_destroyed(); + if(TellUrEnemy_uWin()){ + bt.putc('q'); + printf("BOO!! You lost!"); + break; + }else{state = 0;} } - // wait for check that who is winner. } } @@ -127,19 +139,18 @@ /******************************************************************************/ char check_joys(int jx,int jy){ //-----------------------------------------------Check joystick that it up,down,left or right. - if(jx < 24.0){ - return 'a'; - } - else if(jx > 1000.0){ - return 'd'; - } - else if(jy < 24.0){ - return 'w'; - } - else if(jy > 1000.0){ - return 's'; - }else{ - return NULL; + if(ifUrJirat==1){ + if(jx < 14.0){ return 'a';} + else if(jx > 1010.0){return 'd';} + else if(jy < 14.0){ return 'w';} + else if(jy > 1010.0){return 's';} + else{return NULL;} + }else if(ifUrJirat==0){ + if(jx < 14.0){ return 'a';} + else if(jx > 1010.0){return 'd';} + else if(jy < 14.0){ return 'w';} + else if(jy > 1010.0){return 's';} + else{return NULL;} } } int check_joys_int(int jx,int jy){ //--------------------------------------------Check joystick that it is centre. @@ -250,6 +261,14 @@ printf("\n"); } } +void print_ship_destroyed(){ + ptintf("{"); + for(int i=0;i<8;i++){ + printf("%d",ship_destroyed[i]); + if(i!=14){printf(",");} + } + printf("}\n"); +} void check_ready(){ if(bt.readable()){ enemy_ready = 1; @@ -269,8 +288,8 @@ void getATK_platform(int atkpos){ int i,j,x,y = 0; - y = atkpos/10; - x = atkpos%10; + x = atkpos/10; + y = atkpos%10; if(ship_platform[x][y]!=0 and atk_platform[x][y]==0){ atk_platform[x][y] = ship_platform[x][y]; @@ -355,7 +374,8 @@ void atk_enemy(){ float Vx; float Vy; - int SW,iVxVy,iSW,n; + int SW,iVxVy,iSW,n = 0; + int iPrintUturn = 0; char m; while(1){ @@ -399,6 +419,7 @@ data_fromEnemy = char2posit(bt.getc()); if(data_fromEnemy!=18){ select_Position = data_fromEnemy; + printf("enemy select_Position = %d\n",select_Position); }else{ ATKposition = select_Position; break; @@ -408,4 +429,15 @@ printf("Enemy attack at your area %d\n",ATKposition); getATK_platform(ATKposition); mark_ship_destroyed(); +} +int TellUrEnemy_uWin(){ + int sub_end = 0; + + for(int i=0;i<15;i++){ + if(ship_underATK[i]!=0){sub_end++;} + if(sub_end==15){return 1;}else{return 0;} + } +} +int IamWin(){ + if(bt.readable()){if(bt.getc()=='q'){return 1;}else{return 0;}} } \ No newline at end of file