![](/media/cache/group/13920082_1104334289609725_7513665353164031743_o.jpg.50x50_q85.jpg)
P9: A7,A13 battle ship 2016 J
Dependencies: mbed
main.cpp
- Committer:
- dragondrunk
- Date:
- 2016-12-06
- Revision:
- 0:b6fa066730db
File content as of revision 0:b6fa066730db:
/******************************************************************************/ /* This Nicleo is state 0 */ /******************************************************************************/ #include "mbed.h" #include "ColorMbed.h" // Setting int ifUrJirat = 1; // Initail I/O. AnalogIn VRx(A0); AnalogIn VRy(A1); DigitalIn Button(PA_4); Serial bt(PA_15, PB_7); Serial com(D1,D0); ColorMbed dotmatrix; Timer t; // Initial function. char posit2char(int posit); char check_joys(int jx,int jy); int IamWin(); int TellUrEnemy_uWin(); int char2posit(char cha); int check_joys_int(int jx,int jy); int check_correctPosition(int X,int Y); int protect_ship(int head_position,int ship_type); int get_ship_platform(int input_position,int ship_type); void atk_enemy(); void enemy_atk(); void check_end(); void check_ready(); void mark_ship_destroyed(); void Select_Position(char M,int SetOrPlay); void get_atk_platform(int atkpos); void get_ship_UShipsRdestroyed(); //inessential void print_ship_destroyed(); void print_enemy_platform(); void print_ship_platform(); void print_atk_platform(); // Nasarun's function. int _power(int number , int power); void hex_to_array(int* ar); void place_ship3(char dir); void array_to_hex(int ar1[8][8]); void place_ship2_4(int ship,char dir); void ch_same_position(int ar1[8][8],int ar2[8][8]); void discard_same_position(int ar1[8][8],int ar2[8][8]); void hex_to_array_ship(int *hex_array); // convert hex_array to complete picture array[8][8][3] // Nasrun : Fuction place bomb void plant_bomb(char dir); void set_zero(); // plot color void change_orange_myship(int row,int col); void change_orange_hisship(int row,int col); void change_red_myship(int row,int col); void change_red_hisship(int row,int col); void change_green_hisship(int row,int col); void change_red_deadship(int* array_coordinate,int mode); void change_green_myship(int row,int col); void change_green_hisship(int row,int col); void display_bomb_enemy(int row,int col); // Initial variable. int check_ship_underATK = 0; int select_Position = 0; int ATKposition = 0; int enemy_ready = 0; int check_ship1 = 0; int check_ship2 = 0; int check_win = 0; int state = 0; //Index. int iShipType = 0; int iWaitATK = 0; int iGSU=0; int iSUSPD = 0; //Array int ship_SelectType[8] = {4,3,2,2,1,1,1,1}; int enemy_platform[8][8] = {{0}}; int ship_platform[8][8] = {{0}}; //______________________________________________This is ship area. int atk_platform[8][8] = {{0}}; int ship_underATK[15] = {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9}; int ship_myShipsRdestroyed[15] = {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9}; int ship_UShipsRdestroyed[15] = {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9}; int ship_destroyed[8] = {0}; int ship4[4] = {0}; int ship3[3] = {0}; int ship2[2][2] = {{0}}; int ship1[4] = {0}; //fuction nasrun int return_position[8][8] ; int for_hex = 0; int ch_post[8][8] = {{1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1}}; int return_hex[8]; int display_battle[8][8][3] = {0}; int _temppic[8] = {0x01,0x01,0x01,0x01,0,0,0,0}; int temppic2[8] = {0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; int temppic3[7][8] = {{0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00},{0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00},{0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00},{0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00},{0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00},{0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00},{0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; int temppic4[8] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; int forshift[8] = {0}; int pic[8] = {0}; int i,j; int check_boat3=0; int check_hex=0; int ship[8][8][3] = {0}; // gen hex to ship int plot_bombed_usage[8][8][3] = {{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}}; int bomb[8][8][3] = {{{100,100,90},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}}; int main_frame1[8][8][3] = {{{0}}}; // for show im placed bomb phase int main_frame2[8][8][3] = {{{0}}}; int bomb_enemy[8][8][3] = {{{0}}}; int zero[8][8][3] = {{{0}}}; // psrameter for function plant_bomb int col = 0; int row = 0; int iCheck = 0; int temp_array[3] = {0}; // function Test! int main(){ //-------------------------------------------------------------------Main Function. bt.baud(9600); float Vx; float Vy; int SW,iVxVy,iSW,n = 0; int uli = 0; char m; int rgb[3] = {60,0,0}; int state_place_ship = 0; dotmatrix.init(); int winlose[2][8] = {{0x3c,0x42,0xa5,0x81,0xa5,0x99,0x42,0x3c},{0x3c,0x42,0xa5,0x81,0x99,0xa5,0x42,0x3c}}; int rgbwin[3] = {0,255,0}; int rgblose[3] = {0,0,255}; int threetwoone[4][8] = {{0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},{0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},{0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},{0x00,0xef,0xa1,0xad,0xa9,0xef,0x00,0x00}}; int rgbtto[3] = {0}; int picwait[9][8] = { {0xff,0xff,0x42,0x24,0x24,0x42,0x81,0xff}, {0xff,0xff,0x7e,0x24,0x24,0x42,0x81,0xff}, {0xff,0xff,0x7e,0x3c,0x24,0x42,0x81,0xff}, {0xff,0x81,0x7e,0x3c,0x3c,0x42,0x81,0xff}, {0xff,0x81,0x42,0x3c,0x3c,0x7e,0x81,0xff}, {0xff,0x81,0x42,0x24,0x3c,0x7e,0xff,0xff}, {0xff,0x81,0x42,0x24,0x24,0x7e,0xff,0xff}, {0xff,0x81,0x42,0x24,0x24,0x42,0xff,0xff}, {0xff,0x81,0x42,0x24,0x24,0x42,0x81,0xff}}; int rgbwait[3] = {0}; int shiprun[19][8][8][3] = { {{{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{200,0,0}, {200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}}, {{200,0,0}, {200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}}}, {{{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{200,0,0}, {200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}}, {{200,0,0}, {200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}}}, {{{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{200,0,0}, {200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}}, {{200,0,0}, {200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}}}, {{{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{200,0,0}, {200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}}, {{200,0,0}, {200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}}}, {{{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{200,0,0}, {200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}}, {{200,0,0}, {200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}}}, {{{10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{200,0,0}, {200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}}, {{200,0,0}, {200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}}}, {{{10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}}, {{10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}}, {{200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}}}, {{{0,0,0}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {0,0,0}}, {{10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}}, {{10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}}, {{200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}}, {{200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}}}, {{{0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}}, {{10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}}, {{10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}}, {{10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {0,0,0}}, {{10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}}, {{200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}}, {{200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}}}, {{{0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}}, {{0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}}, {{10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}}, {{10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}}, {{0,0,0}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {0,0,0}}, {{200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}, {200,30,0}}, {{200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}, {200,30,0}}}, {{{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}}, {{0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}}, {{10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}}, {{0,0,0}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}}, {{0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}}, {{200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}, {200,30,0}, {200,20,0}}, {{200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}, {200,30,0}, {200,20,0}}}, {{{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}}, {{0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}}, {{200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}, {200,30,0}, {200,20,0}, {200,10,0}}, {{200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}, {200,30,0}, {200,20,0}, {200,10,0}}}, {{{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}}, {{200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}, {200,30,0}, {200,20,0}, {200,10,0}, {200,0,0}}, {{200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}, {200,30,0}, {200,20,0}, {200,10,0}, {200,0,0}}}, {{{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {10,20,20}}, {{200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}, {200,30,0}, {200,20,0}, {200,10,0}}, {{200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}, {200,30,0}, {200,20,0}, {200,10,0}}}, {{{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {10,20,20}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}}, {{200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}, {200,30,0}, {200,20,0}}, {{200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}, {200,30,0}, {200,20,0}}}, {{{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}}, {{200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}, {200,30,0}}, {{200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}, {200,30,0}}}, {{{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}}, {{200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}, {200,40,0}}}, {{{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {10,20,20}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}}, {{200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}, {200,50,0}}}, {{{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}}, {{200,10,0}, {200,20,0}, {200,30,0}, {200,40,0}, {200,50,0}, {200,60,0}, {200,80,0}, {200,60,0}}}, }; int circle[65][8] = { {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00}, {0xff,0x80,0x80,0x00,0x00,0x00,0x00,0x00}, {0xff,0x80,0x80,0x80,0x00,0x00,0x00,0x00}, {0xff,0x80,0x80,0x80,0x80,0x00,0x00,0x00}, {0xff,0x80,0x80,0x80,0x80,0x80,0x00,0x00}, {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0x00}, {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0x80}, {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0xc0}, {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0xe0}, {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0xf0}, {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0xf8}, {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0xfc}, {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0xfe}, {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0xff}, {0xff,0x80,0x80,0x80,0x80,0x80,0x81,0xff}, {0xff,0x80,0x80,0x80,0x80,0x81,0x81,0xff}, {0xff,0x80,0x80,0x80,0x81,0x81,0x81,0xff}, {0xff,0x80,0x80,0x81,0x81,0x81,0x81,0xff}, {0xff,0x80,0x81,0x81,0x81,0x81,0x81,0xff}, {0xff,0x81,0x81,0x81,0x81,0x81,0x81,0xff}, {0xff,0x83,0x81,0x81,0x81,0x81,0x81,0xff}, {0xff,0x87,0x81,0x81,0x81,0x81,0x81,0xff}, {0xff,0x8f,0x81,0x81,0x81,0x81,0x81,0xff}, {0xff,0x9f,0x81,0x81,0x81,0x81,0x81,0xff}, {0xff,0xbf,0x81,0x81,0x81,0x81,0x81,0xff}, {0xff,0xff,0x81,0x81,0x81,0x81,0x81,0xff}, {0xff,0xff,0xc1,0x81,0x81,0x81,0x81,0xff}, {0xff,0xff,0xc1,0xc1,0x81,0x81,0x81,0xff}, {0xff,0xff,0xc1,0xc1,0xc1,0x81,0x81,0xff}, {0xff,0xff,0xc1,0xc1,0xc1,0xc1,0x81,0xff}, {0xff,0xff,0xc1,0xc1,0xc1,0xc1,0xc1,0xff}, {0xff,0xff,0xc1,0xc1,0xc1,0xc1,0xe1,0xff}, {0xff,0xff,0xc1,0xc1,0xc1,0xc1,0xf1,0xff}, {0xff,0xff,0xc1,0xc1,0xc1,0xc1,0xf9,0xff}, {0xff,0xff,0xc1,0xc1,0xc1,0xc1,0xfd,0xff}, {0xff,0xff,0xc1,0xc1,0xc1,0xc1,0xff,0xff}, {0xff,0xff,0xc1,0xc1,0xc1,0xc3,0xff,0xff}, {0xff,0xff,0xc1,0xc1,0xc3,0xc3,0xff,0xff}, {0xff,0xff,0xc1,0xc3,0xc3,0xc3,0xff,0xff}, {0xff,0xff,0xc3,0xc3,0xc3,0xc3,0xff,0xff}, {0xff,0xff,0xc7,0xc3,0xc3,0xc3,0xff,0xff}, {0xff,0xff,0xcf,0xc3,0xc3,0xc3,0xff,0xff}, {0xff,0xff,0xdf,0xc3,0xc3,0xc3,0xff,0xff}, {0xff,0xff,0xff,0xc3,0xc3,0xc3,0xff,0xff}, {0xff,0xff,0xff,0xe3,0xc3,0xc3,0xff,0xff}, {0xff,0xff,0xff,0xe3,0xe3,0xc3,0xff,0xff}, {0xff,0xff,0xff,0xe3,0xe3,0xe3,0xff,0xff}, {0xff,0xff,0xff,0xe3,0xe3,0xf3,0xff,0xff}, {0xff,0xff,0xff,0xe3,0xe3,0xfb,0xff,0xff}, {0xff,0xff,0xff,0xe3,0xe3,0xff,0xff,0xff}, {0xff,0xff,0xff,0xe3,0xe7,0xff,0xff,0xff}, {0xff,0xff,0xff,0xe7,0xe7,0xff,0xff,0xff}, {0xff,0xff,0xff,0xef,0xe7,0xff,0xff,0xff}, {0xff,0xff,0xff,0xff,0xe7,0xff,0xff,0xff}, {0xff,0xff,0xff,0xff,0xf7,0xff,0xff,0xff}, {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff} }; int rgbcircle[3] = {0}; int counter = 0; int click = 0; int extwhile = 0; t.start(); while(1){ for( int a=0 ; a<=64 ;a++){ extwhile = extwhile+1; counter = counter+10; if( counter == 60 ){ click = click+1; counter=0; } if(click == 0){ rgbcircle[0] = 0; rgbcircle[1] = 0; rgbcircle[2] = counter; } else if(click == 1){ rgbcircle[0] = 0; rgbcircle[1] = counter; rgbcircle[2] = 60; } else if(click == 2){ rgbcircle[0] = 0; rgbcircle[1] = 60; rgbcircle[2] = 60 - counter; } else if(click == 3){ rgbcircle[0] = counter; rgbcircle[1] = 60; rgbcircle[2] = 0; } else if(click == 4){ rgbcircle[0] = 60; rgbcircle[1] = 60 - counter; rgbcircle[2] = 0; } else if(click == 5){ rgbcircle[0] = 60; rgbcircle[1] = 0; rgbcircle[2] = counter; } else if(click == 6){ rgbcircle[0] = 60 - counter; rgbcircle[1] = 0; rgbcircle[2] = 60; } else if(click == 7){ rgbcircle[0] = 0; rgbcircle[1] = 0; rgbcircle[2] = 60; click = 1; } wait(0.0025); if(t.read() <= 0.8){dotmatrix.display_pic(circle[a],rgbcircle);} } break; } t.stop(); t.reset(); t.start(); while(1){ if( t.read()<=0.2){dotmatrix.display_big_array(shiprun[0]);} else if( t.read()>0.2 && t.read()<=0.4){dotmatrix.display_big_array(shiprun[1]);} else if( t.read()>0.4 && t.read()<=0.6){dotmatrix.display_big_array(shiprun[2]);} else if( t.read()>0.6 && t.read()<=0.8){dotmatrix.display_big_array(shiprun[3]);} else if( t.read()>0.8 && t.read()<=1){dotmatrix.display_big_array(shiprun[4]);} else if( t.read()>1 && t.read()<=1.2){dotmatrix.display_big_array(shiprun[5]);} else if( t.read()>1.2 && t.read()<=1.4){dotmatrix.display_big_array(shiprun[6]);} else if( t.read()>1.2 && t.read()<=1.6){dotmatrix.display_big_array(shiprun[7]);} else if( t.read()>1.6 && t.read()<=1.8){dotmatrix.display_big_array(shiprun[8]);} else if( t.read()>1.8 && t.read()<=2){dotmatrix.display_big_array(shiprun[9]);} else if( t.read()>2 && t.read()<=2.2){dotmatrix.display_big_array(shiprun[10]);} else if( t.read()>2.2 && t.read()<=2.4){dotmatrix.display_big_array(shiprun[11]);} else if( t.read()>2.4 && t.read()<=2.6){dotmatrix.display_big_array(shiprun[12]);} else if( t.read()>2.6 && t.read()<=2.8){dotmatrix.display_big_array(shiprun[13]);} else if( t.read()>2.8 && t.read()<=3){dotmatrix.display_big_array(shiprun[14]);} else if( t.read()>3 && t.read()<=3.2){dotmatrix.display_big_array(shiprun[15]);} else if( t.read()>3.2 && t.read()<=3.4){dotmatrix.display_big_array(shiprun[16]);} else if( t.read()>3.4 && t.read()<=3.6){dotmatrix.display_big_array(shiprun[17]);} else if( t.read()>3.6 && t.read()<=3.8){dotmatrix.display_big_array(shiprun[18]);} else{break;} } t.stop(); t.reset(); t.start(); while(1) { if(t.read()<0.4){ dotmatrix.display_pic(_temppic,rgb); } else if(t.read() > 0.4 && t.read() < 0.8){ dotmatrix.display_pic(pic,rgb); } else{ t.reset(); } if(iShipType<8){ Vx = VRx.read() * 1024; Vy = VRy.read() * 1024; SW = Button.read(); m = check_joys(Vx,Vy); n = check_joys_int(Vx,Vy); if(n == 1){ //_______________________________________________________ For make sure coordinate is press 1 time. iVxVy = 0; check_ready(); } if(SW == 1){ //______________________________________________________ For make sure switch is press 1 time. iSW = 0; check_ready(); } if(m!=NULL && iVxVy==0){ //__________________________________________ Get position that wait for press switch. check_ready(); Select_Position(m,0); if(state_place_ship == 0){ place_ship2_4(0,m); // 4 } else if(state_place_ship == 1){ place_ship3(m); // 3 } else if(state_place_ship == 2){ place_ship2_4(1,m); // 2 } else if(state_place_ship == 3){ place_ship2_4(2,m); //2 } else if(state_place_ship == 4){ place_ship2_4(3,m); // 1 } else if(state_place_ship == 5){ place_ship2_4(4,m); // 1 } else if(state_place_ship == 6){ place_ship2_4(5,m); // 1 } else if(state_place_ship == 7){ place_ship2_4(6,m); // 1 } printf("select_Position = %d\n",select_Position); check_ready(); iVxVy = 1; check_ready(); } if(SW==0 && iSW==0){ //______________________________________________If switch pressing by human. printf("Wait!\n"); check_ready(); if(get_ship_platform(select_Position,ship_SelectType[iShipType])==0){ //__Please read explanation in function get_ship_platform. printf("Please input correct position\n"); }else{ iShipType++; if(state_place_ship == 0){ for(j=0;j<8;j++){ pic[j] = temppic3[0][j]+pic[j]; } for(j=0;j<8;j++){ _temppic[j] = temppic2[j]; } } else if(state_place_ship == 1){ for(j=0;j<8;j++){ pic[j] = temppic2[j]+pic[j]; } for(j=0;j<8;j++){ _temppic[j] = temppic3[1][j]; } } else if(state_place_ship == 2){ for(j=0;j<8;j++){ pic[j] = temppic3[1][j]+pic[j]; } for(j=0;j<8;j++){ _temppic[j] = temppic3[2][j]; } } else if(state_place_ship == 3){ for(j=0;j<8;j++){ pic[j] = temppic3[2][j]+pic[j]; } for(j=0;j<8;j++){ _temppic[j] = temppic3[3][j]; } } else if(state_place_ship == 4){ for(j=0;j<8;j++){ pic[j] = temppic3[3][j]+pic[j]; } for(j=0;j<8;j++){ _temppic[j] = temppic3[4][j]; } } else if(state_place_ship == 5){ for(j=0;j<8;j++){ pic[j] = temppic3[4][j]+pic[j]; } for(j=0;j<8;j++){ _temppic[j] = temppic3[5][j]; } } else if(state_place_ship == 6){ for(j=0;j<8;j++){ pic[j] = temppic3[5][j]+pic[j]; } for(j=0;j<8;j++){ _temppic[j] = temppic3[6][j]; } } else if(state_place_ship == 7){ for(j=0;j<8;j++){ pic[j] = temppic3[6][j]+pic[j]; } } state_place_ship = state_place_ship + 1; select_Position = 0; } check_ready(); iSW = 1; print_ship_platform(); check_ready(); } }else{ counter = 0; if(enemy_ready!=1){ printf("sent E\n"); while(uli<50){ bt.printf("E"); uli++; } }else{ bt.putc('l'); printf("sent l\n"); } printf("\n"); break; } } if(enemy_ready == 0){ printf("Wait for enemy ready\n"); t.stop(); t.reset(); t.start(); while(1){ counter = counter+1; if( counter == 60 ){ click = click+1; counter=0; } if(click == 0){ rgbwait[0] = 0; rgbwait[1] = 0; rgbwait[2] = counter; } else if(click == 1){ rgbwait[0] = 0; rgbwait[1] = counter; rgbwait[2] = 60; } else if(click == 2){ rgb[0] = 0; rgb[1] = 60; rgb[2] = 60 - counter; } else if(click == 3){ rgbwait[0] = counter; rgbwait[1] = 60; rgbwait[2] = 0; } else if(click == 4){ rgbwait[0] = 60; rgbwait[1] = 60 - counter; rgbwait[2] = 0; } else if(click == 5){ rgbwait[0] = 60; rgbwait[1] = 0; rgbwait[2] = counter; } else if(click == 6){ rgbwait[0] = 60 - counter; rgbwait[1] = 0; rgbwait[2] = 60; } else if(click == 7){ rgbwait[0] = 0; rgbwait[1] = 0; rgbwait[2] = 60; click = 1; } if(t.read()<0.2){dotmatrix.display_pic(picwait[0],rgbwait);} else if(t.read()>0.2 && t.read()<=0.4){dotmatrix.display_pic(picwait[1],rgbwait);} else if(t.read()>0.4 && t.read()<=0.6){dotmatrix.display_pic(picwait[2],rgbwait);} else if(t.read()>0.6 && t.read()<=0.8){dotmatrix.display_pic(picwait[3],rgbwait);} else if(t.read()>0.8 && t.read()<=1){dotmatrix.display_pic(picwait[4],rgbwait);} else if(t.read()>1 && t.read()<=1.2){dotmatrix.display_pic(picwait[5],rgbwait);} else if(t.read()>1.2 && t.read()<=1.4){dotmatrix.display_pic(picwait[6],rgbwait);} else if(t.read()>1.4 && t.read()<=1.6){dotmatrix.display_pic(picwait[7],rgbwait);} else if(t.read()>1.6 && t.read()<=1.8){dotmatrix.display_pic(picwait[8],rgbwait);} else if(t.read()>1.8 ){t.reset();} if(bt.readable()){ if(bt.getc()=='l'){ break; } } } state = 0; }else{state = 1;} hex_to_array_ship(pic); t.stop(); t.reset(); t.start(); while(1){ counter = counter+1; if( counter == 60 ){ click = click+1; counter=0; } if(click == 0){ rgbtto[0] = 0; rgbtto[1] = 0; rgbtto[2] = counter; } else if(click == 1){ rgbtto[0] = 0; rgbtto[1] = counter; rgbtto[2] = 60; } else if(click == 2){ rgbtto[0] = 0; rgbtto[1] = 60; rgbtto[2] = 60 - counter; } else if(click == 3){ rgbtto[0] = counter; rgbtto[1] = 60; rgbtto[2] = 0; } else if(click == 4){ rgbtto[0] = 60; rgbtto[1] = 60 - counter; rgbtto[2] = 0; } else if(click == 5){ rgbtto[0] = 60; rgbtto[1] = 0; rgbtto[2] = counter; } else if(click == 6){ rgbtto[0] = 60 - counter; rgbtto[1] = 0; rgbtto[2] = 60; } else if(click == 7){ rgbtto[0] = 0; rgbtto[1] = 0; rgbtto[2] = 60; click = 1; } if(t.read()<1.5){dotmatrix.display_pic(threetwoone[0],rgbtto);} else if(t.read()>1.5 && t.read()<3){dotmatrix.display_pic(threetwoone[1],rgbtto);} else if(t.read()>3 && t.read()<4.5){dotmatrix.display_pic(threetwoone[2],rgbtto);} else if(t.read()>4.5 && t.read()<6){dotmatrix.display_pic(threetwoone[3],rgb);} else{break;} } t.stop(); t.reset(); while(1) { //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Play if(state == 0){ printf("Your turn.\n"); atk_enemy(); printf("This is enemy_platform.\n"); print_enemy_platform(); state = 1; }else{ printf("Wait for enemy attack.\n"); enemy_atk(); if(check_win==1){ dotmatrix.display_pic(winlose[0],rgbwin); printf("BOO!! You Win!\n"); break; } printf("This is atk_platform.\n"); print_atk_platform(); printf("This is ship_destroyed. : "); print_ship_destroyed(); if(TellUrEnemy_uWin()==1){ while(uli<100){ bt.putc('u'); uli++; } dotmatrix.display_pic(winlose[1],rgblose); printf("BOO!! You lost!\n"); break; }else{state = 0;} } } while(1){ printf("END\n"); if(check_win == 1){dotmatrix.display_pic(winlose[0],rgbwin);} else{dotmatrix.display_pic(winlose[1],rgblose);} } } /******************************************************************************/ /* */ /* */ /* Another function */ /* */ /* */ /******************************************************************************/ char check_joys(int jx,int jy){ //-----------------------------------------------Check joystick that it up,down,left or right. 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(jx < 14.0){ return 'd';} else if(jx > 1010.0){return 'a';} else if(jy < 14.0){ return 's';} else if(jy > 1010.0){return 'w';} else{return NULL;} } } int check_joys_int(int jx,int jy){ //--------------------------------------------Check joystick that it is centre. if(jx>=450.0&&jx<=600.0){ if(jy>=450.0&&jy<=600.0){ return 1; }else{ return 0; } }else{ return 0; } } void Select_Position(char M,int SetOrPlay){ //-------------------------------------------------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; } break; case 'd': if(select_Position%10!=7){ if(SetOrPlay==1){ select_Position = select_Position + 1; }else{ if(protect_ships==1 or protect_ships==0){ select_Position = select_Position + 1; } } } break; case 'w': if(select_Position/10!=0){ select_Position = select_Position - 10; } break; case 's': if(select_Position/10!=7){ if(SetOrPlay==1){ select_Position = select_Position + 10; }else{ if(protect_ships==1 or protect_ships==2){ select_Position = select_Position + 10; } } } 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+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; int error = 0; y = input_position/10; x = input_position%10; for(i=0;i<ship_type;i++){ 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;} if(ship_type%2 == 0){y++;}else{x++;} } if(ship_type==2){check_ship2++;} if(error == 1){return 0;}else{ y = input_position/10; x = input_position%10; for(i=0;i<ship_type;i++){ if(ship_type == 2 and check_ship2==1){ ship_platform[y][x] = ship_type + 3; }else{ship_platform[y][x] = ship_type;} if(ship_type%2 == 0){y++;}else{x++;} } return 1; } } int check_correctPosition(int X,int Y){ if(X<=7){ if(Y<=7){ if(ship_platform[X][Y] == 0){return 1;}else{return 0;} }else{return 0;} }else{return 0;} } void print_ship_platform(){ for(int i=0;i<8;i++){ for(int j=0;j<8;j++){ printf("| %d |",ship_platform[i][j]); } printf("\n"); } } void print_enemy_platform(){ for(int i=0;i<8;i++){ for(int j=0;j<8;j++){ printf("| %d |",enemy_platform[i][j]); } printf("\n"); } } void print_atk_platform(){ for(int i=0;i<8;i++){ for(int j=0;j<8;j++){ printf("| %d |",atk_platform[i][j]); } printf("\n"); } } void print_ship_destroyed(){ printf("{"); 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;} } char posit2char(int posit){ int as = posit+48; char ch = as; return ch ; } int char2posit(char cha){ int as = cha; as = as-48; return as; } void get_atk_platform(int atkpos){ int i,j,k,x,y,error = 0; x = atkpos/10; y = atkpos%10; if(ship_platform[x][y]!=0){ change_orange_myship(x,y); if(atk_platform[x][y]==0){ atk_platform[x][y] = ship_platform[x][y]; printf("posit2char : %c\n",posit2char(atk_platform[x][y])); bt.putc(posit2char(atk_platform[x][y])); for(k=0;k<15;k++){ if(ship_underATK[k]==atkpos){error=1;break;} } if (error!=1) { ship_underATK[check_ship_underATK] = atkpos; 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]==5){ for(i=0;i<2;i++){ for(j=0;j<15;j++){ if(ship2[0][i]==ship_underATK[j]){ship_destroyed[2]++;} } } }else if(atk_platform[x][y]==2){ for(i=0;i<2;i++){ for(j=0;j<15;j++){ if(ship2[1][i]==ship_underATK[j]){ship_destroyed[3]++;} } } }else if(atk_platform[x][y]==1){ atk_platform[x][y] = 11; ship_myShipsRdestroyed[iGSU] = atkpos; for(i=0;i<4;i++){ for(j=0;j<15;j++){ if(ship3[i]==ship_underATK[j]){ ship_destroyed[4+i]++; iGSU++; } } } } } }else{ printf("You repeatedly attacked.\n"); } }else{ change_green_myship(x,y); atk_platform[x][y] = 8; bt.putc(posit2char(atk_platform[x][y])); } } void get_ship_UShipsRdestroyed(){ int error=0; int ship[8] = {0}; for(int k=0;k<2;k++){ for(int i=0;i<8;i++){ for(int j=0;j<8;j++){ if(enemy_platform[i][j]==4){ error=0; if(k==0){ship[0]++;} if(ship[4]==1){ for(int l=0;l<15;l++){ if(ship_UShipsRdestroyed[l]==(i*10)+j){error=1;break;} } if(error!=1){ ship_UShipsRdestroyed[iSUSPD] = (i*10)+j; iSUSPD++; } } } else if(enemy_platform[i][j]==3){ error=0; if(k==0){ ship[1]++; } if(ship[5]==1){ for(int l=0;l<15;l++){ if(ship_UShipsRdestroyed[l]==(i*10)+j){error=1;break;} } if(error!=1){ ship_UShipsRdestroyed[iSUSPD] = (i*10)+j; iSUSPD++; } } } else if(enemy_platform[i][j]==2){ error=0; if(k==0){ ship[2]++; } if(ship[6]==1){ for(int l=0;l<15;l++){ if(ship_UShipsRdestroyed[l]==(i*10)+j){error=1;break;} } if(error!=1){ ship_UShipsRdestroyed[iSUSPD] = (i*10)+j; iSUSPD++; } } } else if(enemy_platform[i][j]==5){ error=0; if(k==0){ ship[3]++; } if(ship[7]==1){ for(int l=0;l<15;l++){ if(ship_UShipsRdestroyed[l]==(i*10)+j){error=1;break;} } if(error!=1){ ship_UShipsRdestroyed[iSUSPD] = (i*10)+j; iSUSPD++; } } } else if(enemy_platform[i][j]==1){ for(int l=0;l<15;l++){ if(ship_UShipsRdestroyed[l]==(i*10)+j){error=1;break;} } if(error!=1){ ship_UShipsRdestroyed[iSUSPD] = (i*10)+j; iSUSPD++; } } } } if(ship[0]==4){ship[4]=1;} if(ship[1]==3){ship[5]=1;} if(ship[2]==2){ship[6]=1;} if(ship[3]==2){ship[7]=1;} }/* printf("ship[] : "); for (int i=0;i<8;i++) { printf("| %d |", ship[i]); } printf("\n"); for(int i=0;i<15;i++){ printf("| %d ",ship_UShipsRdestroyed[i] ); } printf("\n");*/ } void mark_ship_destroyed(){ int i,j,k = 0; if(ship_destroyed[0]==10){ for(i=0;i<8;i++){ for(j=0;j<8;j++){ if(atk_platform[i][j]==4){ atk_platform[i][j] = 11; ship_myShipsRdestroyed[iGSU] = (i*10)+j; iGSU++; } } } } if(ship_destroyed[1]==6){ for(i=0;i<8;i++){ for(j=0;j<8;j++){ if(atk_platform[i][j]==3){ atk_platform[i][j] = 11; ship_myShipsRdestroyed[iGSU] = (i*10)+j; iGSU++; } } } } if(ship_destroyed[2]==3){ for(k=0;k<2;k++){ i = ship2[0][k]/10; j = ship2[0][k]%10; atk_platform[i][j] = 11; ship_myShipsRdestroyed[iGSU] = (i*10)+j; iGSU++; } } if(ship_destroyed[3]==3){ for(k=0;k<2;k++){ i = ship2[1][k]/10; j = ship2[1][k]%10; atk_platform[i][j] = 11; ship_myShipsRdestroyed[iGSU] = (i*10)+j; iGSU++; } } } void atk_enemy(){ // comment for display : see only bomb and history of planting float Vx; float Vy; int SW,iVxVy,iSW,n = 0; char m; select_Position = 0; t.start(); while(1){ for(int i = 0;i<8;i++){ for (int j = 0 ;j < 8; j++) { main_frame1[i][j][0] = plot_bombed_usage[i][j][0] + bomb[i][j][0]; main_frame1[i][j][1] = plot_bombed_usage[i][j][1] + bomb[i][j][1]; main_frame1[i][j][2] = plot_bombed_usage[i][j][2] + bomb[i][j][2]; } } if(t.read()<0.4){ dotmatrix.display_big_array(main_frame1); } else if(t.read() > 0.4 && t.read() < 0.8){ dotmatrix.display_big_array(plot_bombed_usage); } else{ t.reset(); } Vx = VRx.read() * 1024; Vy = VRy.read() * 1024; SW = Button.read(); m = check_joys(Vx,Vy); n = check_joys_int(Vx,Vy); if(n == 1){ iVxVy = 0;} if(SW == 1){ iSW = 0; } if(iSW == 1){ if(bt.readable()){ enemy_platform[select_Position/10][select_Position%10] = char2posit(bt.getc()); if(enemy_platform[select_Position/10][select_Position%10] == 8){ change_green_hisship(select_Position/10,select_Position%10); } else{ change_orange_hisship(select_Position/10,select_Position%10); } get_ship_UShipsRdestroyed(); change_red_deadship(ship_UShipsRdestroyed,1); t.stop(); t.reset(); t.start(); while (1) { if(t.read()<1){dotmatrix.display_big_array(plot_bombed_usage);} else{break;} // try++++++++++++++++++++++++++++++++++ } set_zero(); break; } } if(m!=NULL and iVxVy==0){ Select_Position(m,1); plant_bomb(m); printf("select_Position = %d\n",select_Position); bt.putc(posit2char(select_Position)); iVxVy = 1; } if(SW==0 && iSW==0){ bt.putc('B'); printf("You attacking at position %d\n",select_Position); iSW = 1; } } } void enemy_atk(){ int data_fromEnemy; char replica_data_fromEnemy; select_Position = 0; t.start(); while(1){ for(int i = 0;i<8;i++){ for (int j = 0 ;j < 8; j++) { main_frame2[i][j][0] = ship[i][j][0] + bomb_enemy[i][j][0]; main_frame2[i][j][1] = ship[i][j][1] + bomb_enemy[i][j][1]; main_frame2[i][j][2] = ship[i][j][2] + bomb_enemy[i][j][2]; } } if(t.read()<0.4){ dotmatrix.display_big_array(main_frame2); } else if(t.read() > 0.4 && t.read() < 0.8){ dotmatrix.display_big_array(ship); } else{ t.reset(); } if(bt.readable()){ replica_data_fromEnemy = bt.getc(); if(replica_data_fromEnemy!='u' and replica_data_fromEnemy!=8){ data_fromEnemy = char2posit(replica_data_fromEnemy); if(data_fromEnemy != 18){ select_Position = data_fromEnemy; display_bomb_enemy(select_Position/10,select_Position%10); printf("enemy select_Position = %d\n",select_Position); }else{ ATKposition = select_Position; break; } } if(replica_data_fromEnemy=='u'){ check_win = 1; break; } } } if(check_win!=1){ printf("Enemy attack at your area %d\n",ATKposition); get_atk_platform(ATKposition); t.stop(); t.reset(); t.start(); while (1) { if(t.read()<1){dotmatrix.display_big_array(ship);} else{break;} // try++++++++++++++++++++++++++++++++++ } mark_ship_destroyed(); change_red_deadship(ship_myShipsRdestroyed,0); } for (int i = 0; i < 15; i++) { printf("! %d !", ship_underATK[i]); } } int TellUrEnemy_uWin(){ int sub_end = 0; for(int i=0;i<15;i++){ if(ship_underATK[i]!=9){sub_end++;} } if(sub_end==15){return 1;}else{return 0;} } int IamWin(){ char chare; if(bt.readable()){ chare = bt.getc(); if(chare=='u'){return 1;}else{return 0;} }else{return 0;} } // ____________________________________________________________________________________________________________________________________Nasarun's function. void hex_to_array(int* ar){ int i; int j; int temp; for(i = 0;i<8;i++){ temp = ar[i]; for(j = 0;j<8;j++){ if(0x80 & temp){ return_position[i][j] = 1; } else{ return_position[i][j] = 0; } temp = temp << 1; } } } void ch_same_position(int ar1[8][8],int ar2[8][8]){ int i; int j; for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ if(ar1[i][j] == 1 && ar2[i][j] == 1){ ch_post[i][j] = 1; } else{ ch_post[i][j] = 0; } } } } void discard_same_position(int ar1[8][8],int ar2[8][8]){ int i; int j; for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ if(ar1[i][j] == ch_post[i][j] && ar2[i][j] == ch_post[i][j] ){ ar1[i][j] = 0; ar2[i][j] = 0; } } } } int _power(int number , int power){ int i = 0; int number1 = number; if(power == 0){return 1;} for(i = 1 ; i <= power ; i++ ){ if(power == 1){return number;} if(i == 1){number = number * 1;} else{number1 = number1 * number;} } return number1; } void array_to_hex(int ar1[8][8]){ int prompt; int i; int j; for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ prompt = _power(2,7-j); if(ar1[i][j] == 1){ for_hex = for_hex + prompt; } else{ for_hex = for_hex + 0; } } return_hex[i] = for_hex; prompt = 0; for_hex = 0; } } void place_ship3(char dir){ int post1[8][8] = {0}; int post2[8][8] = {0}; int hex_post1[8] = {0}; int hex_post2[8] = {0}; int hex_post_cut[8] = {0}; int get_same_position[8][8]; int wow=0; if(dir == 'w'&& temppic2[0] == 0){ for(j=0;j<8;j++){ if(j == 7){ forshift[7] = 0; } else{ forshift[j] = temppic2[j+1]; } } for(j=0;j<8;j++){ temppic2[j] = forshift[j]; _temppic[j] = temppic2[j]; } // begin to compare and combine two frame hex_to_array(_temppic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post1[i][j] = return_position[i][j]; } } hex_to_array(pic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post2[i][j] = return_position[i][j]; } } // begin to check boypeacemaker ch_same_position(post1,post2); for(i=0;i<8;i++){ for(j=0;j<8;j++){ get_same_position[i][j] = ch_post[i][j]; if(get_same_position[i][j] == 1){ wow = 1; } } } if(wow == 0){ for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];} } else{ discard_same_position(post1,post2); array_to_hex(post1); for(i = 0;i<8;i++){ hex_post1[i] = return_hex[i]; } array_to_hex(post2); for(i = 0;i<8;i++){ hex_post2[i] = return_hex[i]; } array_to_hex(get_same_position); for(i = 0;i<8;i++){ hex_post_cut[i] = return_hex[i]; } for(i = 0;i<8;i++){ _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; } } } if(dir == 'd'){ for(i=0;i<8;i++){ if(temppic2[i] == 0xe0){ check_boat3 = 1; } } if(check_boat3 == 0){ for(j=0;j<8;j++){ if(temppic2[j] != 0){ temppic2[j] = temppic2[j]*2; } else{ temppic2[j] = 0; } _temppic[j] = temppic2[j]; } // begin to compare and combine two frame hex_to_array(_temppic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post1[i][j] = return_position[i][j]; } } hex_to_array(pic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post2[i][j] = return_position[i][j]; } } // begin to check boypeacemaker ch_same_position(post1,post2); for(i=0;i<8;i++){ for(j=0;j<8;j++){ get_same_position[i][j] = ch_post[i][j]; if(get_same_position[i][j] == 1){ wow = 1; } } } if(wow == 0){ for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];} } else{ discard_same_position(post1,post2); array_to_hex(post1); for(i = 0;i<8;i++){ hex_post1[i] = return_hex[i]; } array_to_hex(post2); for(i = 0;i<8;i++){ hex_post2[i] = return_hex[i]; } array_to_hex(get_same_position); for(i = 0;i<8;i++){ hex_post_cut[i] = return_hex[i]; } for(i = 0;i<8;i++){ _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; } } } check_boat3 = 0; } if(dir == 'a'){ for(i=0;i<8;i++){ if(temppic2[i] == 0x07){ check_boat3 = 1; } } if(check_boat3 == 0){ for(j=0;j<8;j++){ if(temppic2[j] != 0){ temppic2[j] = temppic2[j]/2; } else{ temppic2[j] = 0; } _temppic[j] = temppic2[j]; } // begin to compare and combine two frame hex_to_array(_temppic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post1[i][j] = return_position[i][j]; } } hex_to_array(pic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post2[i][j] = return_position[i][j]; } } // begin to check boypeacemaker ch_same_position(post1,post2); for(i=0;i<8;i++){ for(j=0;j<8;j++){ get_same_position[i][j] = ch_post[i][j]; if(get_same_position[i][j] == 1){ wow = 1; } } } if(wow == 0){ for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];} } else{ discard_same_position(post1,post2); array_to_hex(post1); for(i = 0;i<8;i++){ hex_post1[i] = return_hex[i]; } array_to_hex(post2); for(i = 0;i<8;i++){ hex_post2[i] = return_hex[i]; } array_to_hex(get_same_position); for(i = 0;i<8;i++){ hex_post_cut[i] = return_hex[i]; } for(i = 0;i<8;i++){ _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; } } } check_boat3 = 0; } if(dir == 's' && temppic2[7] == 0){ for(j=0;j<8;j++){ if(j == 0){ forshift[0] = 0; } else{ forshift[j] = temppic2[j-1]; } } for(j=0;j<8;j++){ temppic2[j] = forshift[j]; _temppic[j] = temppic2[j]; } // begin to compare and combine two frame hex_to_array(_temppic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post1[i][j] = return_position[i][j]; } } hex_to_array(pic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post2[i][j] = return_position[i][j]; } } // begin to check boypeacemaker ch_same_position(post1,post2); for(i=0;i<8;i++){ for(j=0;j<8;j++){ get_same_position[i][j] = ch_post[i][j]; if(get_same_position[i][j] == 1){ wow = 1; } } } if(wow == 0){ for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];} } else{ discard_same_position(post1,post2); array_to_hex(post1); for(i = 0;i<8;i++){ hex_post1[i] = return_hex[i]; } array_to_hex(post2); for(i = 0;i<8;i++){ hex_post2[i] = return_hex[i]; } array_to_hex(get_same_position); for(i = 0;i<8;i++){ hex_post_cut[i] = return_hex[i]; } for(i = 0;i<8;i++){ _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; } } } } // ******************************************************************** ship 2 channal ****************************************************************** void place_ship2_4(int ship,char dir){ int post1[8][8] = {0}; int post2[8][8] = {0}; int hex_post1[8] = {0}; int hex_post2[8] = {0}; int hex_post_cut[8] = {0}; int get_same_position[8][8]; int wow=0; if(dir == 'w'&& temppic3[ship][0] == 0 ){ for(j=0;j<8;j++){ if(j == 7){ forshift[7] = 0; } else{ forshift[j] = temppic3[ship][j+1]; } } for(j=0;j<8;j++){ temppic3[ship][j] = forshift[j]; _temppic[j] = temppic3[ship][j]; } // begin to compare and combine two frame hex_to_array(_temppic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post1[i][j] = return_position[i][j]; } } hex_to_array(pic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post2[i][j] = return_position[i][j]; } } // begin to check boypeacemaker ch_same_position(post1,post2); for(i=0;i<8;i++){ for(j=0;j<8;j++){ get_same_position[i][j] = ch_post[i][j]; if(get_same_position[i][j] == 1){ wow = 1; } } } if(wow == 0){ for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];} } else{ discard_same_position(post1,post2); array_to_hex(post1); for(i = 0;i<8;i++){ hex_post1[i] = return_hex[i]; } array_to_hex(post2); for(i = 0;i<8;i++){ hex_post2[i] = return_hex[i]; } array_to_hex(get_same_position); for(i = 0;i<8;i++){ hex_post_cut[i] = return_hex[i]; } for(i = 0;i<8;i++){ _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; } } } if(dir == 'd' && temppic3[ship][0] != 0x80 && temppic3[ship][1] != 0x80 && temppic3[ship][2] != 0x80 && temppic3[ship][3] != 0x80 && temppic3[ship][4] != 0x80 && temppic3[ship][5] != 0x80 && temppic3[ship][6] != 0x80 && temppic3[ship][7] != 0x80 ){ for(j=0;j<8;j++){ if(temppic3[j] != 0){ temppic3[ship][j] = temppic3[ship][j]*2; } else{ temppic3[ship][j] = 0; } _temppic[j] = temppic3[ship][j]; } // begin to compare and combine two frame hex_to_array(_temppic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post1[i][j] = return_position[i][j]; } } hex_to_array(pic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post2[i][j] = return_position[i][j]; } } // begin to check boypeacemaker ch_same_position(post1,post2); for(i=0;i<8;i++){ for(j=0;j<8;j++){ get_same_position[i][j] = ch_post[i][j]; if(get_same_position[i][j] == 1){ wow = 1; } } } if(wow == 0){ for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];} } else{ discard_same_position(post1,post2); array_to_hex(post1); for(i = 0;i<8;i++){ hex_post1[i] = return_hex[i]; } array_to_hex(post2); for(i = 0;i<8;i++){ hex_post2[i] = return_hex[i]; } array_to_hex(get_same_position); for(i = 0;i<8;i++){ hex_post_cut[i] = return_hex[i]; } for(i = 0;i<8;i++){ _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; } } } if(dir == 'a' && temppic3[ship][0] != 0x01 && temppic3[ship][1] != 0x01 && temppic3[ship][2] != 0x01 && temppic3[ship][3] != 0x01 && temppic3[ship][4] != 0x01 && temppic3[ship][5] != 0x01 && temppic3[ship][6] != 0x01 && temppic3[ship][7] != 0x01){ for(j=0;j<8;j++){ if(temppic3[ship][j] != 0){ temppic3[ship][j] = temppic3[ship][j]/2; } else{ temppic3[ship][j] = 0; } _temppic[j] = temppic3[ship][j]; } // begin to compare and combine two frame hex_to_array(_temppic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post1[i][j] = return_position[i][j]; } } hex_to_array(pic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post2[i][j] = return_position[i][j]; } } // begin to check boypeacemaker ch_same_position(post1,post2); for(i=0;i<8;i++){ for(j=0;j<8;j++){ get_same_position[i][j] = ch_post[i][j]; if(get_same_position[i][j] == 1){ wow = 1; } } } if(wow == 0){ for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];} } else{ discard_same_position(post1,post2); array_to_hex(post1); for(i = 0;i<8;i++){ hex_post1[i] = return_hex[i]; } array_to_hex(post2); for(i = 0;i<8;i++){ hex_post2[i] = return_hex[i]; } array_to_hex(get_same_position); for(i = 0;i<8;i++){ hex_post_cut[i] = return_hex[i]; } for(i = 0;i<8;i++){ _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; } } } if(dir == 's' && temppic3[ship][7] == 0){ for(j=0;j<8;j++){ if(j == 0){ forshift[0] = 0; } else{ forshift[j] = temppic3[ship][j-1]; } } for(j=0;j<8;j++){ temppic3[ship][j] = forshift[j]; _temppic[j] = temppic3[ship][j]; } // begin to compare and combine two frame hex_to_array(_temppic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post1[i][j] = return_position[i][j]; } } hex_to_array(pic); for(i = 0;i<8;i++){ for(j = 0;j<8;j++){ post2[i][j] = return_position[i][j]; } } // begin to check boypeacemaker ch_same_position(post1,post2); for(i=0;i<8;i++){ for(j=0;j<8;j++){ get_same_position[i][j] = ch_post[i][j]; if(get_same_position[i][j] == 1){ wow = 1; } } } if(wow == 0){ for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];} } else{ discard_same_position(post1,post2); array_to_hex(post1); for(i = 0;i<8;i++){ hex_post1[i] = return_hex[i]; } array_to_hex(post2); for(i = 0;i<8;i++){ hex_post2[i] = return_hex[i]; } array_to_hex(get_same_position); for(i = 0;i<8;i++){ hex_post_cut[i] = return_hex[i]; } for(i = 0;i<8;i++){ _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; } } } } void hex_to_array_ship(int *hex_array){ int i,j; int temp; for(i = 0; i<8;i++){ temp = hex_array[i]; for(j = 0;j<8;j++){ if(temp & 0x80){ ship[i][7-j][0] = 80; ship[i][7-j][1] = 20; } else{ ship[i][7-j][0] = 0; ship[i][7-j][1] = 0; ship[i][7-j][2] = 0; } temp = temp << 1; } } } void plant_bomb(char dir){ //scanf("%c",&dir); if(dir == 'w' && row>0){ row = row - 1; for(i=0;i<3;i++){ temp_array[i] = bomb[row][col][i]; } for(i=0;i<3;i++){ bomb[row][col][i] = bomb[row+1][col][i]; bomb[row+1][col][i] = temp_array[i]; } iCheck = 0; }else if(dir == 'a' && col>0){ col = col - 1; for(i=0;i<3;i++){ temp_array[i] = bomb[row][col][i]; } for(i=0;i<3;i++){ bomb[row][col][i] = bomb[row][col+1][i]; bomb[row][col+1][i] = temp_array[i]; } iCheck = 0; }else if(dir == 's' && row<7){ row = row + 1; for(i=0;i<3;i++){ temp_array[i] = bomb[row][col][i]; } for(i=0;i<3;i++){ bomb[row][col][i] = bomb[row-1][col][i]; bomb[row-1][col][i] = temp_array[i]; } iCheck = 0; }else if(dir == 'd' && col<7){ col = col + 1; for(i=0;i<3;i++){ temp_array[i] = bomb[row][col][i]; } for(i=0;i<3;i++){ bomb[row][col][i] = bomb[row][col-1][i]; bomb[row][col-1][i] = temp_array[i]; } iCheck = 0; } // if change state pls use set_zero } void set_zero(){ memcpy(bomb,zero,sizeof bomb); bomb[0][0][0] = 20; bomb[0][0][1] = 20; bomb[0][0][2] = 10; row = 0; col = 0; } void change_orange_myship(int row,int col){ // change to orange //printf("plot orange (myship) at |%d,%d| \n",row,col); for(int i = 0; i<8;i++){ for(int j = 0;j<8;j++){ if(i == row && j == col){ ship[i][j][0] = 0; //b ship[i][j][1] = 150; //g ship[i][j][2] = 250; //r } } } } void change_orange_hisship(int row,int col){ // change to orange //printf("plot orange (enemy ship) at |%d,%d| \n",row,col); for(int i = 0; i<8;i++){ for(int j = 0;j<8;j++){ if(i == row && j == col){ plot_bombed_usage[i][j][0] = 0; //b plot_bombed_usage[i][j][1] = 150; //g plot_bombed_usage[i][j][2] = 250; //r } } } } void change_red_hisship(int row,int col){ // change to red //printf("plot red (enemy ship) at |%d,%d| \n",row,col); for(int i = 0; i<8;i++){ for(int j = 0;j<8;j++){ if(i == row && j == col){ plot_bombed_usage[i][j][0] = 0; plot_bombed_usage[i][j][1] = 0; plot_bombed_usage[i][j][2] = 200; } } } } void change_red_myship(int row,int col){ // change to red //printf("plot red (my ship) at |%d,%d| \n",row,col); for(int i = 0; i<8;i++){ for(int j = 0;j<8;j++){ if(i == row && j == col){ ship[i][j][0] = 0; ship[i][j][1] = 0; ship[i][j][2] = 200; } } } } void change_red_deadship(int* array_coordinate,int mode){ // change to red int row = 0; int col = 0; for(int i = 0;i<15;i++){ if(array_coordinate[i] != 9){ row = array_coordinate[i] / 10; col = array_coordinate[i] % 10; if(mode == 0){ change_red_myship(row,col); } else if(mode == 1){ change_red_hisship(row,col); } } } } void change_green_myship(int row,int col){ for(int i = 0; i<8;i++){ for(int j = 0;j<8;j++){ if(i == row && j == col){ ship[i][j][0] = 0; ship[i][j][1] = 200; ship[i][j][2] = 0; } } } } void change_green_hisship(int row,int col){ for(int i = 0; i<8;i++){ for(int j = 0;j<8;j++){ if(i == row && j == col){ plot_bombed_usage[i][j][0] = 0; plot_bombed_usage[i][j][1] = 200; plot_bombed_usage[i][j][2] = 0; } } } } void display_bomb_enemy(int row,int col){ int zero_array[8][8][3] = {{{0}}}; memcpy(bomb_enemy,zero_array,sizeof bomb_enemy); for(int i = 0; i<8;i++){ for(int j = 0;j<8;j++){ if(i == row && j == col){ bomb_enemy[i][j][0] = 20; bomb_enemy[i][j][1] = 20; bomb_enemy[i][j][2] = 10; } } } }