P9: A7,A13 battle ship 2016 J

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /******************************************************************************/
00002 /*                           This Nicleo is state 0                           */
00003 /******************************************************************************/
00004 #include "mbed.h"
00005 #include "ColorMbed.h"
00006 
00007 // Setting
00008 int ifUrJirat = 1;
00009 
00010 // Initail I/O.
00011 AnalogIn VRx(A0);
00012 AnalogIn VRy(A1);
00013 DigitalIn Button(PA_4);
00014 Serial bt(PA_15, PB_7);
00015 Serial com(D1,D0);
00016 ColorMbed dotmatrix;
00017 Timer t;
00018 
00019 // Initial function.
00020 char posit2char(int posit);
00021 char check_joys(int jx,int jy);
00022 int IamWin();
00023 int TellUrEnemy_uWin();
00024 int char2posit(char cha);
00025 int check_joys_int(int jx,int jy);
00026 int check_correctPosition(int X,int Y);
00027 int protect_ship(int head_position,int ship_type);
00028 int get_ship_platform(int input_position,int ship_type);
00029 void atk_enemy();
00030 void enemy_atk();
00031 void check_end();
00032 void check_ready();
00033 void mark_ship_destroyed();
00034 void Select_Position(char M,int SetOrPlay);
00035 void get_atk_platform(int atkpos);
00036 void get_ship_UShipsRdestroyed();
00037 
00038 //inessential
00039 void print_ship_destroyed();
00040 void print_enemy_platform();
00041 void print_ship_platform();
00042 void print_atk_platform();
00043 
00044 // Nasarun's function.
00045 int _power(int number , int power);
00046 void hex_to_array(int* ar);
00047 void place_ship3(char dir);
00048 void array_to_hex(int ar1[8][8]);
00049 void place_ship2_4(int ship,char dir);
00050 void ch_same_position(int ar1[8][8],int ar2[8][8]);
00051 void discard_same_position(int ar1[8][8],int ar2[8][8]);
00052 void hex_to_array_ship(int *hex_array); // convert hex_array to complete picture array[8][8][3]
00053 
00054 // Nasrun : Fuction place bomb
00055 void plant_bomb(char dir);
00056 void set_zero();
00057 // plot color
00058 void change_orange_myship(int row,int col);
00059 void change_orange_hisship(int row,int col);
00060 void change_red_myship(int row,int col);
00061 void change_red_hisship(int row,int col);
00062 void change_green_hisship(int row,int col);
00063 void change_red_deadship(int* array_coordinate,int mode);
00064 void change_green_myship(int row,int col);
00065 void change_green_hisship(int row,int col);
00066 void display_bomb_enemy(int row,int col);
00067 
00068 
00069 // Initial variable.
00070 int check_ship_underATK = 0;
00071 int select_Position = 0;
00072 int ATKposition = 0;
00073 int enemy_ready = 0;
00074 int check_ship1 = 0;
00075 int check_ship2 = 0;
00076 int check_win = 0;
00077 int state = 0;
00078 //Index.
00079 int iShipType = 0;
00080 int iWaitATK = 0;
00081 int iGSU=0;
00082 int iSUSPD = 0;
00083 //Array
00084 int ship_SelectType[8] = {4,3,2,2,1,1,1,1};
00085 int enemy_platform[8][8] = {{0}};
00086 int ship_platform[8][8] = {{0}}; //______________________________________________This is ship area.
00087 int atk_platform[8][8] = {{0}};
00088 int ship_underATK[15] = {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9};
00089 int ship_myShipsRdestroyed[15] = {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9};
00090 int ship_UShipsRdestroyed[15] = {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9};
00091 int ship_destroyed[8] = {0};
00092 int ship4[4] = {0};
00093 int ship3[3] = {0};
00094 int ship2[2][2] = {{0}};
00095 int ship1[4] = {0};
00096 //fuction nasrun
00097 int return_position[8][8] ;
00098 int for_hex = 0;
00099 int ch_post[8][8] = {{1,1,1,1,1,1,1,1},
00100                     {1,1,1,1,1,1,1,1},
00101                     {1,1,1,1,1,1,1,1},
00102                     {1,1,1,1,1,1,1,1},
00103                     {1,1,1,1,1,1,1,1},
00104                     {1,1,1,1,1,1,1,1},
00105                     {1,1,1,1,1,1,1,1},
00106                     {1,1,1,1,1,1,1,1}};
00107 int return_hex[8];
00108 int display_battle[8][8][3] = {0};
00109 int _temppic[8] = {0x01,0x01,0x01,0x01,0,0,0,0};
00110 int temppic2[8] = {0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
00111 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}};
00112 int temppic4[8] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
00113 int forshift[8] = {0};
00114 int pic[8] = {0};
00115 int i,j;
00116 int check_boat3=0;
00117 int check_hex=0;
00118 
00119 
00120 
00121 int ship[8][8][3] = {0}; // gen hex to ship
00122 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}},
00123                                  {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
00124                                  {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
00125                                  {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
00126                                  {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
00127                                  {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
00128                                  {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
00129                                  {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}};
00130 
00131 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}},
00132                       {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
00133                       {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
00134                       {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
00135                       {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
00136                       {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
00137                       {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
00138                       {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}};
00139 
00140 int main_frame1[8][8][3] = {{{0}}}; // for show im placed bomb phase
00141 int main_frame2[8][8][3] = {{{0}}};
00142 
00143 int bomb_enemy[8][8][3] = {{{0}}};
00144 
00145 int zero[8][8][3] = {{{0}}};
00146 // psrameter for function plant_bomb
00147 int col = 0;
00148 int row = 0;
00149 int iCheck = 0;
00150 int temp_array[3] = {0};
00151 
00152 // function Test!
00153 int main(){ //-------------------------------------------------------------------Main Function.
00154     bt.baud(9600);
00155     float Vx;
00156     float Vy;
00157     int SW,iVxVy,iSW,n = 0;
00158     int uli = 0;
00159     char m;
00160     int rgb[3] = {60,0,0};
00161     int state_place_ship = 0;
00162     dotmatrix.init();
00163 
00164     int winlose[2][8] = {{0x3c,0x42,0xa5,0x81,0xa5,0x99,0x42,0x3c},{0x3c,0x42,0xa5,0x81,0x99,0xa5,0x42,0x3c}};
00165     int rgbwin[3] = {0,255,0};
00166     int rgblose[3] = {0,0,255};
00167 
00168     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}};
00169     int rgbtto[3] = {0};
00170 
00171     int picwait[9][8] = {
00172         {0xff,0xff,0x42,0x24,0x24,0x42,0x81,0xff},
00173         {0xff,0xff,0x7e,0x24,0x24,0x42,0x81,0xff},
00174         {0xff,0xff,0x7e,0x3c,0x24,0x42,0x81,0xff},
00175         {0xff,0x81,0x7e,0x3c,0x3c,0x42,0x81,0xff},
00176         {0xff,0x81,0x42,0x3c,0x3c,0x7e,0x81,0xff},
00177         {0xff,0x81,0x42,0x24,0x3c,0x7e,0xff,0xff},
00178         {0xff,0x81,0x42,0x24,0x24,0x7e,0xff,0xff},
00179         {0xff,0x81,0x42,0x24,0x24,0x42,0xff,0xff},
00180         {0xff,0x81,0x42,0x24,0x24,0x42,0x81,0xff}};
00181     int rgbwait[3] = {0};
00182     int shiprun[19][8][8][3] = {
00183 
00184                             {{{0,0,0},    {0,0,0},      {0,0,0},     {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},   {0,0,0}},
00185                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},     {0,0,0},     {0,0,0},  {0,0,0}},
00186                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},    {0,0,0},    {0,0,0}},
00187                             {{0,0,0},     {0,0,0},      {0,0,0},     {0,0,0},   {0,0,0},     {0,0,0},     {0,0,0},   {0,0,0}},
00188                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},    {0,0,0},    {0,0,0},   {0,0,0}},
00189                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},    {0,0,0}},
00190                             {{200,0,0},       {200,10,0},      {200,20,0},     {200,30,0},   {200,40,0},     {200,50,0},     {200,60,0},  {200,80,0}},
00191                             {{200,0,0},      {200,10,0},       {200,20,0},    {200,30,0},     {200,40,0},    {200,50,0},    {200,60,0},    {200,80,0}}},
00192 
00193                             {{{0,0,0},    {0,0,0},      {0,0,0},     {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},   {0,0,0}},
00194                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},     {0,0,0},     {0,0,0},  {0,0,0}},
00195                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},    {0,0,0},    {0,0,0}},
00196                             {{10,20,20},     {0,0,0},      {0,0,0},     {0,0,0},   {0,0,0},     {0,0,0},     {0,0,0},   {0,0,0}},
00197                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},    {0,0,0},    {0,0,0},   {0,0,0}},
00198                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},    {0,0,0}},
00199                             {{200,0,0},       {200,10,0},      {200,20,0},     {200,30,0},   {200,40,0},     {200,50,0},     {200,60,0},  {200,80,0}},
00200                             {{200,0,0},      {200,10,0},       {200,20,0},    {200,30,0},     {200,40,0},    {200,50,0},    {200,60,0},    {200,80,0}}},
00201 
00202 
00203                             {{{0,0,0},    {0,0,0},      {0,0,0},     {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},   {0,0,0}},
00204                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},     {0,0,0},     {0,0,0},  {0,0,0}},
00205                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},    {0,0,0},    {0,0,0}},
00206                             {{10,20,20},     {10,20,20},      {0,0,0},     {0,0,0},   {0,0,0},     {0,0,0},     {0,0,0},   {0,0,0}},
00207                             {{10,20,20},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},    {0,0,0},    {0,0,0},   {0,0,0}},
00208                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},    {0,0,0}},
00209                             {{200,0,0},       {200,10,0},      {200,20,0},     {200,30,0},   {200,40,0},     {200,50,0},     {200,60,0},  {200,80,0}},
00210                             {{200,0,0},      {200,10,0},       {200,20,0},    {200,30,0},     {200,40,0},    {200,50,0},    {200,60,0},    {200,80,0}}},
00211 
00212                             {{{0,0,0},    {0,0,0},      {0,0,0},     {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},   {0,0,0}},
00213                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},     {0,0,0},     {0,0,0},  {0,0,0}},
00214                             {{10,20,20},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},    {0,0,0},    {0,0,0}},
00215                             {{10,20,20},     {10,20,20},      {10,20,20},     {0,0,0},   {0,0,0},     {0,0,0},     {0,0,0},   {0,0,0}},
00216                             {{10,20,20},       {10,20,20},     {0,0,0},    {0,0,0},     {0,0,0},    {0,0,0},    {0,0,0},   {0,0,0}},
00217                             {{10,20,20},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},    {0,0,0}},
00218                             {{200,0,0},       {200,10,0},      {200,20,0},     {200,30,0},   {200,40,0},     {200,50,0},     {200,60,0},  {200,80,0}},
00219                             {{200,0,0},      {200,10,0},       {200,20,0},    {200,30,0},     {200,40,0},    {200,50,0},    {200,60,0},    {200,80,0}}},
00220 
00221 
00222                             {{{0,0,0},    {0,0,0},      {0,0,0},     {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},   {0,0,0}},
00223                             {{10,20,20},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},     {0,0,0},     {0,0,0},  {0,0,0}},
00224                             {{0,0,0},      {10,20,20},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},    {0,0,0},    {0,0,0}},
00225                             {{10,20,20},     {10,20,20},      {10,20,20},     {10,20,20},   {0,0,0},     {0,0,0},     {0,0,0},   {0,0,0}},
00226                             {{10,20,20},       {10,20,20},     {10,20,20},    {0,0,0},     {0,0,0},    {0,0,0},    {0,0,0},   {0,0,0}},
00227                             {{10,20,20},      {10,20,20},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},    {0,0,0}},
00228                             {{200,0,0},       {200,10,0},      {200,20,0},     {200,30,0},   {200,40,0},     {200,50,0},     {200,60,0},  {200,80,0}},
00229                             {{200,0,0},      {200,10,0},       {200,20,0},    {200,30,0},     {200,40,0},    {200,50,0},    {200,60,0},    {200,80,0}}},
00230 
00231 
00232                             {{{10,20,20},    {0,0,0},      {0,0,0},     {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},   {0,0,0}},
00233                             {{0,0,0},       {10,20,20},     {0,0,0},    {0,0,0},     {0,0,0},     {0,0,0},     {0,0,0},  {0,0,0}},
00234                             {{0,0,0},      {0,0,0},       {10,20,20},   {0,0,0},    {0,0,0},      {0,0,0},    {0,0,0},    {0,0,0}},
00235                             {{10,20,20},     {10,20,20},      {10,20,20},     {10,20,20},   {10,20,20},     {0,0,0},     {0,0,0},   {0,0,0}},
00236                             {{10,20,20},       {10,20,20},     {10,20,20},    {10,20,20},     {0,0,0},    {0,0,0},    {0,0,0},   {0,0,0}},
00237                             {{10,20,20},      {10,20,20},       {10,20,20},   {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},    {0,0,0}},
00238                             {{200,0,0},       {200,10,0},      {200,20,0},     {200,30,0},   {200,40,0},     {200,50,0},     {200,60,0},  {200,80,0}},
00239                             {{200,0,0},      {200,10,0},       {200,20,0},    {200,30,0},     {200,40,0},    {200,50,0},    {200,60,0},    {200,80,0}}},
00240 
00241 
00242                             {{{10,20,20},    {10,20,20},      {0,0,0},     {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},   {0,0,0}},
00243                             {{0,0,0},       {0,0,0},     {10,20,20},    {0,0,0},     {0,0,0},     {0,0,0},     {0,0,0},  {0,0,0}},
00244                             {{0,0,0},      {0,0,0},       {0,0,0},   {10,20,20},    {0,0,0},      {0,0,0},    {0,0,0},    {0,0,0}},
00245                             {{10,20,20},     {10,20,20},      {10,20,20},     {10,20,20},   {10,20,20},     {10,20,20},     {0,0,0},   {0,0,0}},
00246                             {{10,20,20},       {10,20,20},     {10,20,20},    {10,20,20},     {10,20,20},    {0,0,0},    {0,0,0},   {0,0,0}},
00247                             {{10,20,20},      {10,20,20},       {10,20,20},   {10,20,20},    {0,0,0},      {0,0,0},   {0,0,0},    {0,0,0}},
00248                             {{200,10,0},       {200,20,0},      {200,30,0},     {200,40,0},   {200,50,0},     {200,60,0},     {200,80,0},  {200,60,0}},
00249                             {{200,10,0},      {200,20,0},       {200,30,0},    {200,40,0},     {200,50,0},    {200,60,0},    {200,80,0},    {200,60,0}}},
00250 
00251                             {{{0,0,0},    {10,20,20},      {10,20,20},     {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},   {0,0,0}},
00252                             {{10,20,20},       {0,0,0},     {0,0,0},    {10,20,20},     {0,0,0},     {0,0,0},     {0,0,0},  {0,0,0}},
00253                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {10,20,20},      {0,0,0},    {0,0,0},    {0,0,0}},
00254                             {{10,20,20},     {10,20,20},      {10,20,20},     {10,20,20},   {10,20,20},     {10,20,20},     {10,20,20},   {0,0,0}},
00255                             {{10,20,20},       {10,20,20},     {10,20,20},    {10,20,20},     {10,20,20},    {10,20,20},    {0,0,0},   {0,0,0}},
00256                             {{10,20,20},      {10,20,20},       {10,20,20},   {10,20,20},    {10,20,20},      {0,0,0},   {0,0,0},    {0,0,0}},
00257                             {{200,20,0},       {200,30,0},      {200,40,0},     {200,50,0},   {200,60,0},     {200,80,0},     {200,60,0},  {200,50,0}},
00258                             {{200,20,0},      {200,30,0},       {200,40,0},    {200,50,0},     {200,60,0},    {200,80,0},    {200,60,0},    {200,50,0}}},
00259 
00260                             {{{0,0,0},    {0,0,0},      {10,20,20},     {10,20,20},    {0,0,0},      {0,0,0},   {0,0,0},   {0,0,0}},
00261                             {{0,0,0},       {10,20,20},     {0,0,0},    {0,0,0},     {10,20,20},     {0,0,0},     {0,0,0},  {0,0,0}},
00262                             {{10,20,20},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {10,20,20},    {0,0,0},    {0,0,0}},
00263                             {{10,20,20},     {10,20,20},      {10,20,20},     {10,20,20},   {10,20,20},     {10,20,20},     {10,20,20},   {10,20,20}},
00264                             {{10,20,20},       {10,20,20},     {10,20,20},    {10,20,20},     {10,20,20},    {10,20,20},    {10,20,20},   {0,0,0}},
00265                             {{10,20,20},      {10,20,20},       {10,20,20},   {10,20,20},    {10,20,20},      {10,20,20},   {0,0,0},    {0,0,0}},
00266                             {{200,30,0},       {200,40,0},      {200,50,0},     {200,60,0},   {200,80,0},     {200,60,0},     {200,50,0},  {200,40,0}},
00267                             {{200,30,0},      {200,40,0},       {200,50,0},    {200,60,0},     {200,80,0},    {200,60,0},    {200,50,0},    {200,40,0}}},
00268 
00269 
00270 
00271                             {{{0,0,0},    {0,0,0},      {0,0,0},     {10,20,20},    {10,20,20},      {0,0,0},   {0,0,0},   {0,0,0}},
00272                             {{0,0,0},       {0,0,0},     {10,20,20},    {0,0,0},     {0,0,0},     {10,20,20},     {0,0,0},  {0,0,0}},
00273                             {{0,0,0},      {10,20,20},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},    {10,20,20},    {0,0,0}},
00274                             {{10,20,20},     {10,20,20},      {10,20,20},     {10,20,20},   {10,20,20},     {10,20,20},     {10,20,20},   {10,20,20}},
00275                             {{10,20,20},       {10,20,20},     {10,20,20},    {10,20,20},     {10,20,20},    {10,20,20},    {10,20,20},   {10,20,20}},
00276                             {{0,0,0},      {10,20,20},       {10,20,20},   {10,20,20},    {10,20,20},      {10,20,20},   {10,20,20},    {0,0,0}},
00277                             {{200,40,0},       {200,50,0},      {200,60,0},     {200,80,0},   {200,60,0},     {200,50,0},     {200,40,0},  {200,30,0}},
00278                             {{200,40,0},      {200,50,0},       {200,60,0},    {200,80,0},     {200,60,0},    {200,50,0},    {200,40,0},    {200,30,0}}},
00279 
00280 
00281                             {{{0,0,0},    {0,0,0},      {0,0,0},     {0,0,0},    {10,20,20},      {10,20,20},   {0,0,0},   {0,0,0}},
00282                             {{0,0,0},       {0,0,0},     {0,0,0},    {10,20,20},     {0,0,0},     {0,0,0},     {10,20,20},  {0,0,0}},
00283                             {{0,0,0},      {0,0,0},       {10,20,20},   {0,0,0},    {0,0,0},      {0,0,0},    {0,0,0},    {10,20,20}},
00284                             {{10,20,20},     {10,20,20},      {10,20,20},     {10,20,20},   {10,20,20},     {10,20,20},     {10,20,20},   {10,20,20}},
00285                             {{0,0,0},       {10,20,20},     {10,20,20},    {10,20,20},     {10,20,20},    {10,20,20},    {10,20,20},   {10,20,20}},
00286                             {{0,0,0},      {0,0,0},       {10,20,20},   {10,20,20},    {10,20,20},      {10,20,20},   {10,20,20},    {10,20,20}},
00287                             {{200,50,0},       {200,60,0},      {200,80,0},     {200,60,0},   {200,50,0},     {200,40,0},     {200,30,0},  {200,20,0}},
00288                             {{200,50,0},      {200,60,0},       {200,80,0},    {200,60,0},     {200,50,0},    {200,40,0},    {200,30,0},    {200,20,0}}},
00289 
00290                             {{{0,0,0},    {0,0,0},      {0,0,0},     {0,0,0},    {0,0,0},      {10,20,20},   {10,20,20},   {0,0,0}},
00291                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {10,20,20},     {0,0,0},     {0,0,0},  {10,20,20}},
00292                             {{0,0,0},      {0,0,0},       {0,0,0},   {10,20,20},    {0,0,0},      {0,0,0},    {0,0,0},    {0,0,0}},
00293                             {{0,0,0},     {10,20,20},      {10,20,20},     {10,20,20},   {10,20,20},     {10,20,20},     {10,20,20},   {10,20,20}},
00294                             {{0,0,0},       {0,0,0},     {10,20,20},    {10,20,20},     {10,20,20},    {10,20,20},    {10,20,20},   {10,20,20}},
00295                             {{0,0,0},      {0,0,0},       {0,0,0},   {10,20,20},    {10,20,20},      {10,20,20},   {10,20,20},    {10,20,20}},
00296                             {{200,60,0},       {200,80,0},      {200,60,0},     {200,50,0},   {200,40,0},     {200,30,0},     {200,20,0},  {200,10,0}},
00297                             {{200,60,0},      {200,80,0},       {200,60,0},    {200,50,0},     {200,40,0},    {200,30,0},    {200,20,0},    {200,10,0}}},
00298 
00299                             {{{0,0,0},    {0,0,0},      {0,0,0},     {0,0,0},    {0,0,0},      {0,0,0},   {10,20,20},   {10,20,20}},
00300                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},     {10,20,20},     {0,0,0},  {0,0,0}},
00301                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {10,20,20},      {0,0,0},    {0,0,0},    {0,0,0}},
00302                             {{0,0,0},     {0,0,0},      {10,20,20},     {10,20,20},   {10,20,20},     {10,20,20},     {10,20,20},   {10,20,20}},
00303                             {{0,0,0},       {0,0,0},     {0,0,0},    {10,20,20},     {10,20,20},    {10,20,20},    {10,20,20},   {10,20,20}},
00304                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {10,20,20},      {10,20,20},   {10,20,20},    {10,20,20}},
00305                             {{200,80,0},       {200,60,0},      {200,50,0},     {200,40,0},   {200,30,0},     {200,20,0},     {200,10,0},     {200,0,0}},
00306                             {{200,80,0},      {200,60,0},       {200,50,0},    {200,40,0},     {200,30,0},    {200,20,0},     {200,10,0},    {200,0,0}}},
00307 
00308                             {{{0,0,0},    {0,0,0},      {0,0,0},     {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},   {10,20,20}},
00309                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},     {0,0,0},     {10,20,20},  {0,0,0}},
00310                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {10,20,20},    {0,0,0},    {0,0,0}},
00311                             {{0,0,0},     {0,0,0},      {0,0,0},     {10,20,20},   {10,20,20},     {10,20,20},     {10,20,20},   {10,20,20}},
00312                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {10,20,20},    {10,20,20},    {10,20,20},   {10,20,20}},
00313                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {10,20,20},   {10,20,20},    {10,20,20}},
00314                             {{200,60,0},       {200,80,0},      {200,60,0},     {200,50,0},   {200,40,0},     {200,30,0},     {200,20,0},  {200,10,0}},
00315                             {{200,60,0},      {200,80,0},       {200,60,0},    {200,50,0},     {200,40,0},    {200,30,0},    {200,20,0},    {200,10,0}}},
00316 
00317                             {{{0,0,0},    {0,0,0},      {0,0,0},     {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},   {0,0,0}},
00318                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},     {0,0,0},     {0,0,0},  {10,20,20}},
00319                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},    {10,20,20},    {0,0,0}},
00320                             {{0,0,0},     {0,0,0},      {0,0,0},     {0,0,0},   {10,20,20},     {10,20,20},     {10,20,20},   {10,20,20}},
00321                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},    {10,20,20},    {10,20,20},   {10,20,20}},
00322                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},   {10,20,20},    {10,20,20}},
00323                             {{200,50,0},       {200,60,0},      {200,80,0},     {200,60,0},   {200,50,0},     {200,40,0},     {200,30,0},  {200,20,0}},
00324                             {{200,50,0},      {200,60,0},       {200,80,0},    {200,60,0},     {200,50,0},    {200,40,0},    {200,30,0},    {200,20,0}}},
00325 
00326                             {{{0,0,0},    {0,0,0},      {0,0,0},     {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},   {0,0,0}},
00327                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},     {0,0,0},     {0,0,0},  {0,0,0}},
00328                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},    {0,0,0},    {10,20,20}},
00329                             {{0,0,0},     {0,0,0},      {0,0,0},     {0,0,0},   {0,0,0},     {10,20,20},     {10,20,20},   {10,20,20}},
00330                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},    {0,0,0},    {10,20,20},   {10,20,20}},
00331                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},    {10,20,20}},
00332                             {{200,40,0},       {200,50,0},      {200,60,0},     {200,80,0},   {200,60,0},     {200,50,0},     {200,40,0},  {200,30,0}},
00333                             {{200,40,0},      {200,50,0},       {200,60,0},    {200,80,0},     {200,60,0},    {200,50,0},    {200,40,0},    {200,30,0}}},
00334 
00335                             {{{0,0,0},    {0,0,0},      {0,0,0},     {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},   {0,0,0}},
00336                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},     {0,0,0},     {0,0,0},  {0,0,0}},
00337                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},    {0,0,0},    {0,0,0}},
00338                             {{0,0,0},     {0,0,0},      {0,0,0},     {0,0,0},   {0,0,0},     {0,0,0},     {10,20,20},   {10,20,20}},
00339                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},    {0,0,0},    {0,0,0},   {10,20,20}},
00340                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},    {0,0,0}},
00341                             {{200,30,0},       {200,40,0},      {200,50,0},     {200,60,0},   {200,80,0},     {200,60,0},     {200,50,0},  {200,40,0}},
00342                             {{200,30,0},      {200,40,0},       {200,50,0},    {200,60,0},     {200,80,0},    {200,60,0},    {200,50,0},    {200,40,0}}},
00343 
00344                             {{{0,0,0},    {0,0,0},      {0,0,0},     {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},   {0,0,0}},
00345                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},     {0,0,0},     {0,0,0},  {0,0,0}},
00346                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},    {0,0,0},    {0,0,0}},
00347                             {{0,0,0},     {0,0,0},      {0,0,0},     {0,0,0},   {0,0,0},     {0,0,0},     {0,0,0},   {10,20,20}},
00348                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},    {0,0,0},    {0,0,0},   {0,0,0}},
00349                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},    {0,0,0}},
00350                             {{200,20,0},       {200,30,0},      {200,40,0},     {200,50,0},   {200,60,0},     {200,80,0},     {200,60,0},  {200,50,0}},
00351                             {{200,20,0},      {200,30,0},       {200,40,0},    {200,50,0},     {200,60,0},    {200,80,0},    {200,60,0},    {200,50,0}}},
00352 
00353                             {{{0,0,0},    {0,0,0},      {0,0,0},     {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},   {0,0,0}},
00354                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},     {0,0,0},     {0,0,0},  {0,0,0}},
00355                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},    {0,0,0},    {0,0,0}},
00356                             {{0,0,0},     {0,0,0},      {0,0,0},     {0,0,0},   {0,0,0},     {0,0,0},     {0,0,0},   {0,0,0}},
00357                             {{0,0,0},       {0,0,0},     {0,0,0},    {0,0,0},     {0,0,0},    {0,0,0},    {0,0,0},   {0,0,0}},
00358                             {{0,0,0},      {0,0,0},       {0,0,0},   {0,0,0},    {0,0,0},      {0,0,0},   {0,0,0},    {0,0,0}},
00359                             {{200,10,0},       {200,20,0},      {200,30,0},     {200,40,0},   {200,50,0},     {200,60,0},     {200,80,0},  {200,60,0}},
00360                             {{200,10,0},      {200,20,0},       {200,30,0},    {200,40,0},     {200,50,0},    {200,60,0},    {200,80,0},    {200,60,0}}},
00361                           };
00362 
00363     int circle[65][8] = {
00364   {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00365   {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00366   {0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00367   {0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00368   {0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00369   {0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00370   {0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00371   {0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00372   {0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00373   {0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00},
00374   {0xff,0x80,0x80,0x00,0x00,0x00,0x00,0x00},
00375   {0xff,0x80,0x80,0x80,0x00,0x00,0x00,0x00},
00376   {0xff,0x80,0x80,0x80,0x80,0x00,0x00,0x00},
00377   {0xff,0x80,0x80,0x80,0x80,0x80,0x00,0x00},
00378   {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0x00},
00379   {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0x80},
00380   {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0xc0},
00381   {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0xe0},
00382   {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0xf0},
00383   {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0xf8},
00384   {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0xfc},
00385   {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0xfe},
00386   {0xff,0x80,0x80,0x80,0x80,0x80,0x80,0xff},
00387   {0xff,0x80,0x80,0x80,0x80,0x80,0x81,0xff},
00388   {0xff,0x80,0x80,0x80,0x80,0x81,0x81,0xff},
00389   {0xff,0x80,0x80,0x80,0x81,0x81,0x81,0xff},
00390   {0xff,0x80,0x80,0x81,0x81,0x81,0x81,0xff},
00391   {0xff,0x80,0x81,0x81,0x81,0x81,0x81,0xff},
00392   {0xff,0x81,0x81,0x81,0x81,0x81,0x81,0xff},
00393   {0xff,0x83,0x81,0x81,0x81,0x81,0x81,0xff},
00394   {0xff,0x87,0x81,0x81,0x81,0x81,0x81,0xff},
00395   {0xff,0x8f,0x81,0x81,0x81,0x81,0x81,0xff},
00396   {0xff,0x9f,0x81,0x81,0x81,0x81,0x81,0xff},
00397   {0xff,0xbf,0x81,0x81,0x81,0x81,0x81,0xff},
00398   {0xff,0xff,0x81,0x81,0x81,0x81,0x81,0xff},
00399   {0xff,0xff,0xc1,0x81,0x81,0x81,0x81,0xff},
00400   {0xff,0xff,0xc1,0xc1,0x81,0x81,0x81,0xff},
00401   {0xff,0xff,0xc1,0xc1,0xc1,0x81,0x81,0xff},
00402   {0xff,0xff,0xc1,0xc1,0xc1,0xc1,0x81,0xff},
00403   {0xff,0xff,0xc1,0xc1,0xc1,0xc1,0xc1,0xff},
00404   {0xff,0xff,0xc1,0xc1,0xc1,0xc1,0xe1,0xff},
00405   {0xff,0xff,0xc1,0xc1,0xc1,0xc1,0xf1,0xff},
00406   {0xff,0xff,0xc1,0xc1,0xc1,0xc1,0xf9,0xff},
00407   {0xff,0xff,0xc1,0xc1,0xc1,0xc1,0xfd,0xff},
00408   {0xff,0xff,0xc1,0xc1,0xc1,0xc1,0xff,0xff},
00409   {0xff,0xff,0xc1,0xc1,0xc1,0xc3,0xff,0xff},
00410   {0xff,0xff,0xc1,0xc1,0xc3,0xc3,0xff,0xff},
00411   {0xff,0xff,0xc1,0xc3,0xc3,0xc3,0xff,0xff},
00412   {0xff,0xff,0xc3,0xc3,0xc3,0xc3,0xff,0xff},
00413   {0xff,0xff,0xc7,0xc3,0xc3,0xc3,0xff,0xff},
00414   {0xff,0xff,0xcf,0xc3,0xc3,0xc3,0xff,0xff},
00415   {0xff,0xff,0xdf,0xc3,0xc3,0xc3,0xff,0xff},
00416   {0xff,0xff,0xff,0xc3,0xc3,0xc3,0xff,0xff},
00417   {0xff,0xff,0xff,0xe3,0xc3,0xc3,0xff,0xff},
00418   {0xff,0xff,0xff,0xe3,0xe3,0xc3,0xff,0xff},
00419   {0xff,0xff,0xff,0xe3,0xe3,0xe3,0xff,0xff},
00420   {0xff,0xff,0xff,0xe3,0xe3,0xf3,0xff,0xff},
00421   {0xff,0xff,0xff,0xe3,0xe3,0xfb,0xff,0xff},
00422   {0xff,0xff,0xff,0xe3,0xe3,0xff,0xff,0xff},
00423   {0xff,0xff,0xff,0xe3,0xe7,0xff,0xff,0xff},
00424   {0xff,0xff,0xff,0xe7,0xe7,0xff,0xff,0xff},
00425   {0xff,0xff,0xff,0xef,0xe7,0xff,0xff,0xff},
00426   {0xff,0xff,0xff,0xff,0xe7,0xff,0xff,0xff},
00427   {0xff,0xff,0xff,0xff,0xf7,0xff,0xff,0xff},
00428   {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}
00429   };
00430   int rgbcircle[3] = {0};
00431   int counter = 0;
00432   int click = 0;
00433   int extwhile = 0;
00434   t.start();
00435 while(1){
00436   for( int a=0 ; a<=64 ;a++){
00437     extwhile = extwhile+1;
00438     counter = counter+10;
00439     if( counter == 60 ){
00440     click = click+1;
00441     counter=0;
00442   }
00443     if(click == 0){
00444       rgbcircle[0] = 0;
00445       rgbcircle[1] = 0;
00446       rgbcircle[2] = counter;
00447     }
00448     else if(click == 1){
00449       rgbcircle[0] = 0;
00450       rgbcircle[1] = counter;
00451       rgbcircle[2] = 60;
00452     }
00453     else if(click == 2){
00454       rgbcircle[0] = 0;
00455       rgbcircle[1] = 60;
00456       rgbcircle[2] = 60 - counter;
00457       }
00458     else if(click == 3){
00459       rgbcircle[0] = counter;
00460       rgbcircle[1] = 60;
00461       rgbcircle[2] = 0;
00462     }
00463     else if(click == 4){
00464       rgbcircle[0] = 60;
00465       rgbcircle[1] = 60 - counter;
00466       rgbcircle[2] = 0;
00467     }
00468     else if(click == 5){
00469       rgbcircle[0] = 60;
00470       rgbcircle[1] = 0;
00471       rgbcircle[2] = counter;
00472     }
00473     else if(click == 6){
00474       rgbcircle[0] = 60 - counter;
00475       rgbcircle[1] = 0;
00476       rgbcircle[2] = 60;
00477     }
00478     else if(click == 7){
00479       rgbcircle[0] = 0;
00480       rgbcircle[1] = 0;
00481       rgbcircle[2] = 60;
00482       click = 1;
00483     }
00484     wait(0.0025);
00485       if(t.read() <= 0.8){dotmatrix.display_pic(circle[a],rgbcircle);}
00486 
00487     }
00488   break;
00489 }
00490     t.stop();
00491     t.reset();
00492     t.start();
00493 
00494     while(1){
00495       if( t.read()<=0.2){dotmatrix.display_big_array(shiprun[0]);}
00496       else if( t.read()>0.2 && t.read()<=0.4){dotmatrix.display_big_array(shiprun[1]);}
00497       else if( t.read()>0.4 && t.read()<=0.6){dotmatrix.display_big_array(shiprun[2]);}
00498       else if( t.read()>0.6 && t.read()<=0.8){dotmatrix.display_big_array(shiprun[3]);}
00499       else if( t.read()>0.8 && t.read()<=1){dotmatrix.display_big_array(shiprun[4]);}
00500       else if( t.read()>1 && t.read()<=1.2){dotmatrix.display_big_array(shiprun[5]);}
00501       else if( t.read()>1.2 && t.read()<=1.4){dotmatrix.display_big_array(shiprun[6]);}
00502       else if( t.read()>1.2 && t.read()<=1.6){dotmatrix.display_big_array(shiprun[7]);}
00503       else if( t.read()>1.6 && t.read()<=1.8){dotmatrix.display_big_array(shiprun[8]);}
00504       else if( t.read()>1.8 && t.read()<=2){dotmatrix.display_big_array(shiprun[9]);}
00505       else if( t.read()>2 && t.read()<=2.2){dotmatrix.display_big_array(shiprun[10]);}
00506       else if( t.read()>2.2 && t.read()<=2.4){dotmatrix.display_big_array(shiprun[11]);}
00507       else if( t.read()>2.4 && t.read()<=2.6){dotmatrix.display_big_array(shiprun[12]);}
00508       else if( t.read()>2.6 && t.read()<=2.8){dotmatrix.display_big_array(shiprun[13]);}
00509       else if( t.read()>2.8 && t.read()<=3){dotmatrix.display_big_array(shiprun[14]);}
00510       else if( t.read()>3 && t.read()<=3.2){dotmatrix.display_big_array(shiprun[15]);}
00511       else if( t.read()>3.2 && t.read()<=3.4){dotmatrix.display_big_array(shiprun[16]);}
00512       else if( t.read()>3.4 && t.read()<=3.6){dotmatrix.display_big_array(shiprun[17]);}
00513       else if( t.read()>3.6 && t.read()<=3.8){dotmatrix.display_big_array(shiprun[18]);}
00514       else{break;}
00515       }
00516 
00517       t.stop();
00518       t.reset();
00519       t.start();
00520 
00521 
00522     while(1) {
00523         if(t.read()<0.4){
00524             dotmatrix.display_pic(_temppic,rgb);
00525         }
00526         else if(t.read() > 0.4 && t.read() < 0.8){
00527             dotmatrix.display_pic(pic,rgb);
00528         }
00529         else{
00530             t.reset();
00531         }
00532         if(iShipType<8){
00533             Vx = VRx.read() * 1024;
00534             Vy = VRy.read() * 1024;
00535             SW = Button.read();
00536             m = check_joys(Vx,Vy);
00537             n = check_joys_int(Vx,Vy);
00538             if(n == 1){ //_______________________________________________________ For make sure coordinate is press 1 time.
00539                 iVxVy = 0;
00540                 check_ready();
00541             }
00542             if(SW == 1){ //______________________________________________________ For make sure switch is press 1 time.
00543                 iSW = 0;
00544                 check_ready();
00545             }
00546             if(m!=NULL && iVxVy==0){ //__________________________________________ Get position that wait for press switch.
00547                 check_ready();
00548                 Select_Position(m,0);
00549                 if(state_place_ship == 0){
00550                     place_ship2_4(0,m); // 4
00551                 }
00552                 else if(state_place_ship == 1){
00553                     place_ship3(m);    // 3
00554                 }
00555                 else if(state_place_ship == 2){
00556                     place_ship2_4(1,m);    // 2
00557                 }
00558                 else if(state_place_ship == 3){
00559                     place_ship2_4(2,m);   //2
00560                 }
00561                 else if(state_place_ship == 4){
00562                     place_ship2_4(3,m);    // 1
00563                 }
00564                 else if(state_place_ship == 5){
00565                     place_ship2_4(4,m);    // 1
00566                 }
00567                 else if(state_place_ship == 6){
00568                     place_ship2_4(5,m);    // 1
00569                 }
00570                 else if(state_place_ship == 7){
00571                     place_ship2_4(6,m);    // 1
00572                 }
00573                 printf("select_Position = %d\n",select_Position);
00574                 check_ready();
00575                 iVxVy = 1;
00576                 check_ready();
00577             }
00578             if(SW==0 && iSW==0){ //______________________________________________If switch pressing by human.
00579                 printf("Wait!\n");
00580 
00581                 check_ready();
00582                 if(get_ship_platform(select_Position,ship_SelectType[iShipType])==0){ //__Please read explanation in function get_ship_platform.
00583                     printf("Please input correct position\n");
00584                 }else{
00585                     iShipType++;
00586                     if(state_place_ship == 0){
00587                         for(j=0;j<8;j++){
00588                             pic[j] = temppic3[0][j]+pic[j];
00589                         }
00590                         for(j=0;j<8;j++){
00591                             _temppic[j] = temppic2[j];
00592                         }
00593                     }
00594                     else if(state_place_ship == 1){
00595                         for(j=0;j<8;j++){
00596                             pic[j] = temppic2[j]+pic[j];
00597                         }
00598                         for(j=0;j<8;j++){
00599                             _temppic[j] = temppic3[1][j];
00600                         }
00601                     }
00602                     else if(state_place_ship == 2){
00603                         for(j=0;j<8;j++){
00604                             pic[j] = temppic3[1][j]+pic[j];
00605                         }
00606                         for(j=0;j<8;j++){
00607                             _temppic[j] = temppic3[2][j];
00608                         }
00609                     }
00610                     else if(state_place_ship == 3){
00611                         for(j=0;j<8;j++){
00612                             pic[j] = temppic3[2][j]+pic[j];
00613                         }
00614                         for(j=0;j<8;j++){
00615                             _temppic[j] = temppic3[3][j];
00616                         }
00617                     }
00618                     else if(state_place_ship == 4){
00619                         for(j=0;j<8;j++){
00620                             pic[j] = temppic3[3][j]+pic[j];
00621                         }
00622                         for(j=0;j<8;j++){
00623                             _temppic[j] = temppic3[4][j];
00624                         }
00625                     }
00626                     else if(state_place_ship == 5){
00627                         for(j=0;j<8;j++){
00628                             pic[j] = temppic3[4][j]+pic[j];
00629                         }
00630                         for(j=0;j<8;j++){
00631                             _temppic[j] = temppic3[5][j];
00632                         }
00633                     }
00634                     else if(state_place_ship == 6){
00635                         for(j=0;j<8;j++){
00636                             pic[j] = temppic3[5][j]+pic[j];
00637                         }
00638                         for(j=0;j<8;j++){
00639                             _temppic[j] = temppic3[6][j];
00640                         }
00641                     }
00642                     else if(state_place_ship == 7){
00643                         for(j=0;j<8;j++){
00644                             pic[j] = temppic3[6][j]+pic[j];
00645                         }
00646                     }
00647                     state_place_ship = state_place_ship + 1;
00648                     select_Position = 0;
00649                 }
00650                 check_ready();
00651                 iSW = 1;
00652                 print_ship_platform();
00653                 check_ready();
00654             }
00655         }else{
00656             counter = 0;
00657             if(enemy_ready!=1){
00658                 printf("sent E\n");
00659                 while(uli<50){
00660                     bt.printf("E");
00661                     uli++;
00662                 }
00663             }else{
00664                 bt.putc('l');
00665                 printf("sent l\n");
00666             }
00667             printf("\n");
00668             break;
00669         }
00670     }
00671     if(enemy_ready == 0){
00672         printf("Wait for enemy ready\n");
00673         t.stop();
00674         t.reset();
00675         t.start();
00676         while(1){
00677           counter = counter+1;
00678           if( counter == 60 ){
00679             click = click+1;
00680             counter=0;
00681           }
00682           if(click == 0){
00683             rgbwait[0] = 0;
00684             rgbwait[1] = 0;
00685             rgbwait[2] = counter;
00686           }
00687           else if(click == 1){
00688             rgbwait[0] = 0;
00689             rgbwait[1] = counter;
00690             rgbwait[2] = 60;
00691           }
00692           else if(click == 2){
00693             rgb[0] = 0;
00694             rgb[1] = 60;
00695             rgb[2] = 60 - counter;
00696           }
00697           else if(click == 3){
00698             rgbwait[0] = counter;
00699             rgbwait[1] = 60;
00700             rgbwait[2] = 0;
00701           }
00702           else if(click == 4){
00703             rgbwait[0] = 60;
00704             rgbwait[1] = 60 - counter;
00705             rgbwait[2] = 0;
00706           }
00707           else if(click == 5){
00708             rgbwait[0] = 60;
00709             rgbwait[1] = 0;
00710             rgbwait[2] = counter;
00711           }
00712           else if(click == 6){
00713             rgbwait[0] = 60 - counter;
00714             rgbwait[1] = 0;
00715             rgbwait[2] = 60;
00716           }
00717           else if(click == 7){
00718             rgbwait[0] = 0;
00719             rgbwait[1] = 0;
00720             rgbwait[2] = 60;
00721             click = 1;
00722           }
00723           if(t.read()<0.2){dotmatrix.display_pic(picwait[0],rgbwait);}
00724           else if(t.read()>0.2 && t.read()<=0.4){dotmatrix.display_pic(picwait[1],rgbwait);}
00725           else if(t.read()>0.4 && t.read()<=0.6){dotmatrix.display_pic(picwait[2],rgbwait);}
00726           else if(t.read()>0.6 && t.read()<=0.8){dotmatrix.display_pic(picwait[3],rgbwait);}
00727           else if(t.read()>0.8 && t.read()<=1){dotmatrix.display_pic(picwait[4],rgbwait);}
00728           else if(t.read()>1 && t.read()<=1.2){dotmatrix.display_pic(picwait[5],rgbwait);}
00729           else if(t.read()>1.2 && t.read()<=1.4){dotmatrix.display_pic(picwait[6],rgbwait);}
00730           else if(t.read()>1.4 && t.read()<=1.6){dotmatrix.display_pic(picwait[7],rgbwait);}
00731           else if(t.read()>1.6 && t.read()<=1.8){dotmatrix.display_pic(picwait[8],rgbwait);}
00732           else if(t.read()>1.8 ){t.reset();}
00733 
00734             if(bt.readable()){
00735                 if(bt.getc()=='l'){
00736                     break;
00737                 }
00738             }
00739         }
00740         state = 0;
00741     }else{state = 1;}
00742     hex_to_array_ship(pic);
00743 
00744     t.stop();
00745     t.reset();
00746     t.start();
00747   while(1){
00748     counter = counter+1;
00749     if( counter == 60 ){
00750     click = click+1;
00751     counter=0;
00752   }
00753     if(click == 0){
00754       rgbtto[0] = 0;
00755       rgbtto[1] = 0;
00756       rgbtto[2] = counter;
00757     }
00758     else if(click == 1){
00759       rgbtto[0] = 0;
00760       rgbtto[1] = counter;
00761       rgbtto[2] = 60;
00762     }
00763     else if(click == 2){
00764       rgbtto[0] = 0;
00765       rgbtto[1] = 60;
00766       rgbtto[2] = 60 - counter;
00767       }
00768     else if(click == 3){
00769       rgbtto[0] = counter;
00770       rgbtto[1] = 60;
00771       rgbtto[2] = 0;
00772     }
00773     else if(click == 4){
00774       rgbtto[0] = 60;
00775       rgbtto[1] = 60 - counter;
00776       rgbtto[2] = 0;
00777     }
00778     else if(click == 5){
00779       rgbtto[0] = 60;
00780       rgbtto[1] = 0;
00781       rgbtto[2] = counter;
00782     }
00783     else if(click == 6){
00784       rgbtto[0] = 60 - counter;
00785       rgbtto[1] = 0;
00786       rgbtto[2] = 60;
00787     }
00788     else if(click == 7){
00789       rgbtto[0] = 0;
00790       rgbtto[1] = 0;
00791       rgbtto[2] = 60;
00792       click = 1;
00793     }
00794     if(t.read()<1.5){dotmatrix.display_pic(threetwoone[0],rgbtto);}
00795     else if(t.read()>1.5 && t.read()<3){dotmatrix.display_pic(threetwoone[1],rgbtto);}
00796     else if(t.read()>3 && t.read()<4.5){dotmatrix.display_pic(threetwoone[2],rgbtto);}
00797     else if(t.read()>4.5 && t.read()<6){dotmatrix.display_pic(threetwoone[3],rgb);}
00798     else{break;}
00799   }
00800 
00801   t.stop();
00802   t.reset();
00803 
00804     while(1) { //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Play
00805         if(state == 0){
00806             printf("Your turn.\n");
00807             atk_enemy();
00808             printf("This is enemy_platform.\n");
00809             print_enemy_platform();
00810             state = 1;
00811         }else{
00812             printf("Wait for enemy attack.\n");
00813             enemy_atk();
00814             if(check_win==1){
00815                 dotmatrix.display_pic(winlose[0],rgbwin);
00816                 printf("BOO!! You Win!\n");
00817                 break;
00818             }
00819             printf("This is atk_platform.\n");
00820             print_atk_platform();
00821             printf("This is ship_destroyed. : ");
00822             print_ship_destroyed();
00823             if(TellUrEnemy_uWin()==1){
00824                 while(uli<100){
00825                     bt.putc('u');
00826                     uli++;
00827                 }
00828                 dotmatrix.display_pic(winlose[1],rgblose);
00829                 printf("BOO!! You lost!\n");
00830                 break;
00831             }else{state = 0;}
00832         }
00833     }
00834     while(1){
00835       printf("END\n");
00836       if(check_win == 1){dotmatrix.display_pic(winlose[0],rgbwin);}
00837       else{dotmatrix.display_pic(winlose[1],rgblose);}
00838   }
00839 
00840 }
00841 
00842 /******************************************************************************/
00843 /*                                                                            */
00844 /*                                                                            */
00845 /*                              Another function                              */
00846 /*                                                                            */
00847 /*                                                                            */
00848 /******************************************************************************/
00849 
00850 char check_joys(int jx,int jy){ //-----------------------------------------------Check joystick that it up,down,left or right.
00851 
00852     if(ifUrJirat==1){
00853         if(jx < 14.0){       return 'a';}
00854         else if(jx > 1010.0){return 'd';}
00855         else if(jy < 14.0){  return 'w';}
00856         else if(jy > 1010.0){return 's';}
00857         else{return NULL;}
00858     }else{
00859         if(jx < 14.0){       return 'd';}
00860         else if(jx > 1010.0){return 'a';}
00861         else if(jy < 14.0){  return 's';}
00862         else if(jy > 1010.0){return 'w';}
00863         else{return NULL;}
00864     }
00865 }
00866 int check_joys_int(int jx,int jy){ //--------------------------------------------Check joystick that it is centre.
00867     if(jx>=450.0&&jx<=600.0){
00868         if(jy>=450.0&&jy<=600.0){
00869             return 1;
00870         }else{
00871             return 0;
00872         }
00873     }else{
00874         return 0;
00875     }
00876 }
00877 void Select_Position(char M,int SetOrPlay){ //-------------------------------------------------Change position of cursor (Joystick).
00878     int protect_ships;
00879     protect_ships = protect_ship(select_Position,ship_SelectType[iShipType]);
00880     switch(M){
00881         case 'a':
00882             if(select_Position%10!=0){
00883                 select_Position = select_Position - 1;
00884             }
00885             break;
00886         case 'd':
00887             if(select_Position%10!=7){
00888                 if(SetOrPlay==1){
00889                     select_Position = select_Position + 1;
00890                 }else{
00891                     if(protect_ships==1 or protect_ships==0){
00892                         select_Position = select_Position + 1;
00893                     }
00894                 }
00895             }
00896             break;
00897         case 'w':
00898             if(select_Position/10!=0){
00899                 select_Position = select_Position - 10;
00900             }
00901             break;
00902         case 's':
00903             if(select_Position/10!=7){
00904                 if(SetOrPlay==1){
00905                     select_Position = select_Position + 10;
00906                 }else{
00907                     if(protect_ships==1 or protect_ships==2){
00908                         select_Position = select_Position + 10;
00909                     }
00910                 }
00911             }
00912             break;
00913     }
00914 }
00915 int protect_ship(int head_position,int ship_type){
00916     int x,y = 0;
00917     y = head_position/10;
00918     x = head_position%10;
00919     if(ship_type==4){if((y+4)>7){return 0;}else{return 1;}}
00920     else if(ship_type==3){if((x+3)>7){return 2;}else{return 1;}}
00921     else if(ship_type==2){if((y+2)>7){return 0;}else{return 1;}}
00922     else{return 1;}
00923 }
00924 int get_ship_platform(int input_position,int ship_type){ //-----------------------Plot ship in ship area.
00925     int i,x,y = 0;
00926     int error = 0;
00927 
00928     y = input_position/10;
00929     x = input_position%10;
00930 
00931     for(i=0;i<ship_type;i++){
00932         if(check_correctPosition(y,x) == 1){
00933             if(ship_type == 4){ship4[i] = (y*10)+x;}
00934             else if(ship_type == 3){ship3[i] = (y*10)+x;}
00935             else if(ship_type == 2){ship2[check_ship2][i] = (y*10)+x;}
00936             else if(ship_type == 1){ship1[check_ship1] = (y*10)+x;check_ship1++;}
00937         }else{error = 1;break;}
00938         if(ship_type%2 == 0){y++;}else{x++;}
00939     }
00940     if(ship_type==2){check_ship2++;}
00941     if(error == 1){return 0;}else{
00942         y = input_position/10;
00943         x = input_position%10;
00944         for(i=0;i<ship_type;i++){
00945             if(ship_type == 2 and check_ship2==1){
00946                 ship_platform[y][x] = ship_type + 3;
00947             }else{ship_platform[y][x] = ship_type;}
00948             if(ship_type%2 == 0){y++;}else{x++;}
00949         }
00950         return 1;
00951     }
00952 }
00953 int check_correctPosition(int X,int Y){
00954     if(X<=7){
00955         if(Y<=7){
00956             if(ship_platform[X][Y] == 0){return 1;}else{return 0;}
00957         }else{return 0;}
00958     }else{return 0;}
00959 }
00960 void print_ship_platform(){
00961     for(int i=0;i<8;i++){
00962         for(int j=0;j<8;j++){
00963             printf("| %d |",ship_platform[i][j]);
00964         }
00965         printf("\n");
00966     }
00967 }
00968 void print_enemy_platform(){
00969     for(int i=0;i<8;i++){
00970         for(int j=0;j<8;j++){
00971             printf("| %d |",enemy_platform[i][j]);
00972         }
00973         printf("\n");
00974     }
00975 }
00976 void print_atk_platform(){
00977     for(int i=0;i<8;i++){
00978         for(int j=0;j<8;j++){
00979             printf("| %d |",atk_platform[i][j]);
00980         }
00981         printf("\n");
00982     }
00983 }
00984 void print_ship_destroyed(){
00985     printf("{");
00986     for(int i=0;i<8;i++){
00987         printf("%d",ship_destroyed[i]);
00988         if(i!=14){printf(",");}
00989     }
00990     printf("}\n");
00991 }
00992 void check_ready(){
00993     if(bt.readable()){enemy_ready = 1;}
00994 }
00995 char posit2char(int posit){
00996     int as = posit+48;
00997     char ch = as;
00998     return ch ;
00999 }
01000 int char2posit(char cha){
01001     int as = cha;
01002     as = as-48;
01003     return as;
01004 }
01005 void get_atk_platform(int atkpos){
01006     int i,j,k,x,y,error = 0;
01007 
01008     x = atkpos/10;
01009     y = atkpos%10;
01010 
01011     if(ship_platform[x][y]!=0){
01012         change_orange_myship(x,y);
01013 
01014         if(atk_platform[x][y]==0){
01015             atk_platform[x][y] = ship_platform[x][y];
01016             printf("posit2char : %c\n",posit2char(atk_platform[x][y]));
01017             bt.putc(posit2char(atk_platform[x][y]));
01018             for(k=0;k<15;k++){
01019               if(ship_underATK[k]==atkpos){error=1;break;}
01020             }
01021             if (error!=1) {
01022               ship_underATK[check_ship_underATK] = atkpos;
01023               check_ship_underATK++;
01024               if(atk_platform[x][y]==4){
01025                   for(i=0;i<4;i++){
01026                       for(j=0;j<15;j++){
01027                           if(ship4[i]==ship_underATK[j]){ship_destroyed[0]++;}
01028                       }
01029                   }
01030               }else if(atk_platform[x][y]==3){
01031                   for(i=0;i<3;i++){
01032                       for(j=0;j<15;j++){
01033                           if(ship3[i]==ship_underATK[j]){ship_destroyed[1]++;}
01034                       }
01035                   }
01036               }else if(atk_platform[x][y]==5){
01037                   for(i=0;i<2;i++){
01038                       for(j=0;j<15;j++){
01039                           if(ship2[0][i]==ship_underATK[j]){ship_destroyed[2]++;}
01040                       }
01041                   }
01042               }else if(atk_platform[x][y]==2){
01043                   for(i=0;i<2;i++){
01044                       for(j=0;j<15;j++){
01045                           if(ship2[1][i]==ship_underATK[j]){ship_destroyed[3]++;}
01046                       }
01047                   }
01048               }else if(atk_platform[x][y]==1){
01049                 atk_platform[x][y] = 11;
01050                 ship_myShipsRdestroyed[iGSU] = atkpos;
01051                   for(i=0;i<4;i++){
01052                       for(j=0;j<15;j++){
01053                           if(ship3[i]==ship_underATK[j]){
01054                               ship_destroyed[4+i]++;
01055                               iGSU++;
01056                           }
01057                       }
01058                   }
01059               }
01060             }
01061         }else{
01062             printf("You repeatedly attacked.\n");
01063         }
01064     }else{
01065         change_green_myship(x,y);
01066         atk_platform[x][y] = 8;
01067         bt.putc(posit2char(atk_platform[x][y]));
01068     }
01069 
01070 }
01071 void get_ship_UShipsRdestroyed(){
01072     int error=0;
01073     int ship[8] = {0};
01074     for(int k=0;k<2;k++){
01075         for(int i=0;i<8;i++){
01076             for(int j=0;j<8;j++){
01077                 if(enemy_platform[i][j]==4){
01078                   error=0;
01079                     if(k==0){ship[0]++;}
01080                     if(ship[4]==1){
01081                       for(int l=0;l<15;l++){
01082                         if(ship_UShipsRdestroyed[l]==(i*10)+j){error=1;break;}
01083                       }
01084                       if(error!=1){
01085                         ship_UShipsRdestroyed[iSUSPD] = (i*10)+j;
01086                         iSUSPD++;
01087                       }
01088                     }
01089                 }
01090                 else if(enemy_platform[i][j]==3){
01091                   error=0;
01092                     if(k==0){
01093                       ship[1]++;
01094                     }
01095                     if(ship[5]==1){
01096                       for(int l=0;l<15;l++){
01097                         if(ship_UShipsRdestroyed[l]==(i*10)+j){error=1;break;}
01098                       }
01099                       if(error!=1){
01100                         ship_UShipsRdestroyed[iSUSPD] = (i*10)+j;
01101                         iSUSPD++;
01102                       }
01103                     }
01104                 }
01105                 else if(enemy_platform[i][j]==2){
01106                   error=0;
01107                     if(k==0){
01108                       ship[2]++;
01109                     }
01110                     if(ship[6]==1){
01111                       for(int l=0;l<15;l++){
01112                         if(ship_UShipsRdestroyed[l]==(i*10)+j){error=1;break;}
01113                       }
01114                       if(error!=1){
01115                         ship_UShipsRdestroyed[iSUSPD] = (i*10)+j;
01116                         iSUSPD++;
01117                       }
01118                     }
01119                 }
01120                 else if(enemy_platform[i][j]==5){
01121                   error=0;
01122                     if(k==0){
01123                       ship[3]++;
01124                     }
01125                     if(ship[7]==1){
01126                       for(int l=0;l<15;l++){
01127                         if(ship_UShipsRdestroyed[l]==(i*10)+j){error=1;break;}
01128                       }
01129                       if(error!=1){
01130                         ship_UShipsRdestroyed[iSUSPD] = (i*10)+j;
01131                         iSUSPD++;
01132                       }
01133                     }
01134                 }
01135                 else if(enemy_platform[i][j]==1){
01136                   for(int l=0;l<15;l++){
01137                     if(ship_UShipsRdestroyed[l]==(i*10)+j){error=1;break;}
01138                   }
01139                   if(error!=1){
01140                     ship_UShipsRdestroyed[iSUSPD] = (i*10)+j;
01141                     iSUSPD++;
01142                   }
01143                 }
01144             }
01145         }
01146         if(ship[0]==4){ship[4]=1;}
01147         if(ship[1]==3){ship[5]=1;}
01148         if(ship[2]==2){ship[6]=1;}
01149         if(ship[3]==2){ship[7]=1;}
01150     }/*
01151     printf("ship[] : ");
01152     for (int i=0;i<8;i++) {
01153       printf("| %d |", ship[i]);
01154     }
01155     printf("\n");
01156     for(int i=0;i<15;i++){
01157       printf("| %d ",ship_UShipsRdestroyed[i] );
01158     }
01159     printf("\n");*/
01160 }
01161 void mark_ship_destroyed(){
01162     int i,j,k = 0;
01163 
01164     if(ship_destroyed[0]==10){
01165         for(i=0;i<8;i++){
01166             for(j=0;j<8;j++){
01167                 if(atk_platform[i][j]==4){
01168                   atk_platform[i][j] = 11;
01169                   ship_myShipsRdestroyed[iGSU] = (i*10)+j;
01170                   iGSU++;
01171                 }
01172             }
01173         }
01174     }
01175     if(ship_destroyed[1]==6){
01176         for(i=0;i<8;i++){
01177             for(j=0;j<8;j++){
01178                 if(atk_platform[i][j]==3){
01179                   atk_platform[i][j] = 11;
01180                   ship_myShipsRdestroyed[iGSU] = (i*10)+j;
01181                   iGSU++;
01182                 }
01183             }
01184         }
01185     }
01186     if(ship_destroyed[2]==3){
01187         for(k=0;k<2;k++){
01188             i = ship2[0][k]/10;
01189             j = ship2[0][k]%10;
01190             atk_platform[i][j] = 11;
01191             ship_myShipsRdestroyed[iGSU] = (i*10)+j;
01192             iGSU++;
01193         }
01194     }
01195     if(ship_destroyed[3]==3){
01196         for(k=0;k<2;k++){
01197             i = ship2[1][k]/10;
01198             j = ship2[1][k]%10;
01199             atk_platform[i][j] = 11;
01200             ship_myShipsRdestroyed[iGSU] = (i*10)+j;
01201             iGSU++;
01202         }
01203     }
01204 }
01205 void atk_enemy(){
01206     // comment for display : see only bomb and history of planting
01207     float Vx;
01208     float Vy;
01209     int SW,iVxVy,iSW,n = 0;
01210     char m;
01211 
01212     select_Position = 0;
01213     t.start();
01214     while(1){
01215       for(int i = 0;i<8;i++){
01216         for (int j = 0 ;j < 8; j++) {
01217           main_frame1[i][j][0] = plot_bombed_usage[i][j][0] + bomb[i][j][0];
01218           main_frame1[i][j][1] = plot_bombed_usage[i][j][1] + bomb[i][j][1];
01219           main_frame1[i][j][2] = plot_bombed_usage[i][j][2] + bomb[i][j][2];
01220         }
01221       }
01222 
01223         if(t.read()<0.4){
01224             dotmatrix.display_big_array(main_frame1);
01225         }
01226         else if(t.read() > 0.4 && t.read() < 0.8){
01227             dotmatrix.display_big_array(plot_bombed_usage);
01228         }
01229         else{
01230             t.reset();
01231         }
01232         Vx = VRx.read() * 1024;
01233         Vy = VRy.read() * 1024;
01234         SW = Button.read();
01235         m = check_joys(Vx,Vy);
01236         n = check_joys_int(Vx,Vy);
01237         if(n == 1){ iVxVy = 0;}
01238         if(SW == 1){
01239             iSW = 0;
01240         }
01241         if(iSW == 1){
01242             if(bt.readable()){
01243                 enemy_platform[select_Position/10][select_Position%10] = char2posit(bt.getc());
01244                 if(enemy_platform[select_Position/10][select_Position%10] == 8){
01245                   change_green_hisship(select_Position/10,select_Position%10);
01246                 }
01247                 else{
01248                   change_orange_hisship(select_Position/10,select_Position%10);
01249                 }
01250                 get_ship_UShipsRdestroyed();
01251                 change_red_deadship(ship_UShipsRdestroyed,1);
01252                 t.stop();
01253                 t.reset();
01254                 t.start();
01255                 while (1) {
01256                   if(t.read()<1){dotmatrix.display_big_array(plot_bombed_usage);}
01257                   else{break;} // try++++++++++++++++++++++++++++++++++
01258                 }
01259                 set_zero();
01260                 break;
01261             }
01262         }
01263         if(m!=NULL and iVxVy==0){
01264             Select_Position(m,1);
01265             plant_bomb(m);
01266             printf("select_Position = %d\n",select_Position);
01267             bt.putc(posit2char(select_Position));
01268             iVxVy = 1;
01269         }
01270         if(SW==0 && iSW==0){
01271             bt.putc('B');
01272             printf("You attacking at position %d\n",select_Position);
01273             iSW = 1;
01274         }
01275     }
01276 }
01277 void enemy_atk(){
01278     int data_fromEnemy;
01279     char replica_data_fromEnemy;
01280     select_Position = 0;
01281     t.start();
01282     while(1){
01283         for(int i = 0;i<8;i++){
01284           for (int j = 0 ;j < 8; j++) {
01285             main_frame2[i][j][0] = ship[i][j][0] + bomb_enemy[i][j][0];
01286             main_frame2[i][j][1] = ship[i][j][1] + bomb_enemy[i][j][1];
01287             main_frame2[i][j][2] = ship[i][j][2] + bomb_enemy[i][j][2];
01288           }
01289         }
01290         if(t.read()<0.4){
01291             dotmatrix.display_big_array(main_frame2);
01292         }
01293         else if(t.read() > 0.4 && t.read() < 0.8){
01294             dotmatrix.display_big_array(ship);
01295         }
01296         else{
01297             t.reset();
01298         }
01299         if(bt.readable()){
01300             replica_data_fromEnemy = bt.getc();
01301             if(replica_data_fromEnemy!='u' and replica_data_fromEnemy!=8){
01302                 data_fromEnemy = char2posit(replica_data_fromEnemy);
01303                 if(data_fromEnemy != 18){
01304                     select_Position = data_fromEnemy;
01305                     display_bomb_enemy(select_Position/10,select_Position%10);
01306                     printf("enemy select_Position = %d\n",select_Position);
01307                 }else{
01308                     ATKposition = select_Position;
01309 
01310                     break;
01311                 }
01312             }
01313             if(replica_data_fromEnemy=='u'){
01314                 check_win = 1;
01315                 break;
01316             }
01317         }
01318     }
01319     if(check_win!=1){
01320         printf("Enemy attack at your area %d\n",ATKposition);
01321         get_atk_platform(ATKposition);
01322         t.stop();
01323         t.reset();
01324         t.start();
01325         while (1) {
01326           if(t.read()<1){dotmatrix.display_big_array(ship);}
01327           else{break;} // try++++++++++++++++++++++++++++++++++
01328         }
01329         mark_ship_destroyed();
01330         change_red_deadship(ship_myShipsRdestroyed,0);
01331     }
01332     for (int i = 0; i < 15; i++) {
01333       printf("! %d !", ship_underATK[i]);
01334     }
01335 
01336 }
01337 int TellUrEnemy_uWin(){
01338     int sub_end = 0;
01339 
01340     for(int i=0;i<15;i++){
01341         if(ship_underATK[i]!=9){sub_end++;}
01342     }
01343     if(sub_end==15){return 1;}else{return 0;}
01344 }
01345 int IamWin(){
01346     char chare;
01347     if(bt.readable()){
01348         chare = bt.getc();
01349         if(chare=='u'){return 1;}else{return 0;}
01350     }else{return 0;}
01351 }
01352 
01353 
01354 
01355 
01356 
01357 
01358 
01359 
01360 
01361 
01362 
01363 
01364 
01365 
01366 
01367 
01368 
01369 
01370 
01371 
01372 
01373 
01374 
01375 
01376 
01377 
01378 // ____________________________________________________________________________________________________________________________________Nasarun's function.
01379 
01380 void hex_to_array(int* ar){
01381     int i;
01382     int j;
01383     int temp;
01384     for(i = 0;i<8;i++){
01385         temp = ar[i];
01386         for(j = 0;j<8;j++){
01387             if(0x80 & temp){
01388                 return_position[i][j] = 1;
01389             }
01390             else{
01391                 return_position[i][j] = 0;
01392             }
01393             temp = temp << 1;
01394         }
01395     }
01396 }
01397 
01398 void ch_same_position(int ar1[8][8],int ar2[8][8]){
01399     int i;
01400     int j;
01401     for(i = 0;i<8;i++){
01402         for(j = 0;j<8;j++){
01403             if(ar1[i][j] == 1 && ar2[i][j] == 1){
01404                 ch_post[i][j] = 1;
01405             }
01406             else{
01407                 ch_post[i][j] = 0;
01408             }
01409         }
01410     }
01411 
01412 }
01413 
01414 void discard_same_position(int ar1[8][8],int ar2[8][8]){
01415     int i;
01416     int j;
01417     for(i = 0;i<8;i++){
01418         for(j = 0;j<8;j++){
01419             if(ar1[i][j] == ch_post[i][j] && ar2[i][j] == ch_post[i][j] ){
01420                 ar1[i][j] = 0;
01421                 ar2[i][j] = 0;
01422             }
01423         }
01424     }
01425 }
01426 
01427 
01428 int _power(int number , int power){
01429   int i = 0;
01430   int number1 = number;
01431   if(power == 0){return 1;}
01432   for(i = 1 ; i <= power ; i++ ){
01433     if(power == 1){return number;}
01434     if(i == 1){number = number * 1;}
01435     else{number1 = number1 * number;}
01436   }
01437 return number1;
01438 }
01439 
01440 
01441 void array_to_hex(int ar1[8][8]){
01442     int prompt;
01443     int i;
01444     int j;
01445     for(i = 0;i<8;i++){
01446         for(j = 0;j<8;j++){
01447             prompt = _power(2,7-j);
01448             if(ar1[i][j] == 1){
01449                 for_hex = for_hex + prompt;
01450             }
01451             else{
01452                 for_hex = for_hex + 0;
01453             }
01454         }
01455         return_hex[i] = for_hex;
01456         prompt = 0;
01457         for_hex = 0;
01458     }
01459 }
01460 
01461 void place_ship3(char dir){
01462     int post1[8][8] = {0};
01463     int post2[8][8] = {0};
01464     int hex_post1[8] = {0};
01465     int hex_post2[8] = {0};
01466     int hex_post_cut[8] = {0};
01467     int get_same_position[8][8];
01468     int wow=0;
01469 
01470     if(dir == 'w'&& temppic2[0] == 0){
01471         for(j=0;j<8;j++){
01472             if(j == 7){
01473                 forshift[7] = 0;
01474             }
01475             else{
01476                 forshift[j] = temppic2[j+1];
01477             }
01478         }
01479         for(j=0;j<8;j++){
01480             temppic2[j] = forshift[j];
01481             _temppic[j] = temppic2[j];
01482         }
01483         // begin to compare and combine two frame
01484         hex_to_array(_temppic);
01485         for(i = 0;i<8;i++){
01486             for(j = 0;j<8;j++){
01487                 post1[i][j] = return_position[i][j];
01488             }
01489         }
01490         hex_to_array(pic);
01491         for(i = 0;i<8;i++){
01492             for(j = 0;j<8;j++){
01493                 post2[i][j] = return_position[i][j];
01494             }
01495         }
01496 
01497         // begin to check boypeacemaker
01498         ch_same_position(post1,post2);
01499         for(i=0;i<8;i++){
01500             for(j=0;j<8;j++){
01501                 get_same_position[i][j] = ch_post[i][j];
01502                 if(get_same_position[i][j] == 1){
01503                     wow = 1;
01504                 }
01505             }
01506         }
01507         if(wow == 0){
01508             for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];}
01509         }
01510         else{
01511             discard_same_position(post1,post2);
01512             array_to_hex(post1);
01513             for(i = 0;i<8;i++){
01514                 hex_post1[i] = return_hex[i];
01515             }
01516             array_to_hex(post2);
01517             for(i = 0;i<8;i++){
01518                 hex_post2[i] = return_hex[i];
01519             }
01520             array_to_hex(get_same_position);
01521             for(i = 0;i<8;i++){
01522                 hex_post_cut[i] = return_hex[i];
01523             }
01524             for(i = 0;i<8;i++){
01525                 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
01526             }
01527         }
01528     }
01529     if(dir == 'd'){
01530         for(i=0;i<8;i++){
01531             if(temppic2[i] == 0xe0){
01532                 check_boat3 = 1;
01533             }
01534         }
01535         if(check_boat3 == 0){
01536             for(j=0;j<8;j++){
01537                 if(temppic2[j] != 0){
01538                     temppic2[j] = temppic2[j]*2;
01539                 }
01540                 else{
01541                     temppic2[j] = 0;
01542                 }
01543                 _temppic[j] = temppic2[j];
01544             }
01545             // begin to compare and combine two frame
01546             hex_to_array(_temppic);
01547             for(i = 0;i<8;i++){
01548                 for(j = 0;j<8;j++){
01549                     post1[i][j] = return_position[i][j];
01550                 }
01551             }
01552             hex_to_array(pic);
01553             for(i = 0;i<8;i++){
01554                 for(j = 0;j<8;j++){
01555                     post2[i][j] = return_position[i][j];
01556                 }
01557             }
01558 
01559             // begin to check boypeacemaker
01560             ch_same_position(post1,post2);
01561             for(i=0;i<8;i++){
01562                 for(j=0;j<8;j++){
01563                     get_same_position[i][j] = ch_post[i][j];
01564                     if(get_same_position[i][j] == 1){
01565                         wow = 1;
01566                     }
01567                 }
01568             }
01569             if(wow == 0){
01570                 for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];}
01571             }
01572             else{
01573                 discard_same_position(post1,post2);
01574                 array_to_hex(post1);
01575                 for(i = 0;i<8;i++){
01576                     hex_post1[i] = return_hex[i];
01577                 }
01578                 array_to_hex(post2);
01579                 for(i = 0;i<8;i++){
01580                     hex_post2[i] = return_hex[i];
01581                 }
01582                 array_to_hex(get_same_position);
01583                 for(i = 0;i<8;i++){
01584                     hex_post_cut[i] = return_hex[i];
01585                 }
01586                 for(i = 0;i<8;i++){
01587                     _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
01588                 }
01589             }
01590         }
01591         check_boat3 = 0;
01592     }
01593     if(dir == 'a'){
01594         for(i=0;i<8;i++){
01595             if(temppic2[i] == 0x07){
01596                 check_boat3 = 1;
01597             }
01598         }
01599         if(check_boat3 == 0){
01600             for(j=0;j<8;j++){
01601                 if(temppic2[j] != 0){
01602                     temppic2[j] = temppic2[j]/2;
01603                 }
01604                 else{
01605                     temppic2[j] = 0;
01606                 }
01607                 _temppic[j] = temppic2[j];
01608             }
01609             // begin to compare and combine two frame
01610             hex_to_array(_temppic);
01611             for(i = 0;i<8;i++){
01612                 for(j = 0;j<8;j++){
01613                     post1[i][j] = return_position[i][j];
01614                 }
01615             }
01616             hex_to_array(pic);
01617             for(i = 0;i<8;i++){
01618                 for(j = 0;j<8;j++){
01619                     post2[i][j] = return_position[i][j];
01620                 }
01621             }
01622 
01623             // begin to check boypeacemaker
01624             ch_same_position(post1,post2);
01625             for(i=0;i<8;i++){
01626                 for(j=0;j<8;j++){
01627                     get_same_position[i][j] = ch_post[i][j];
01628                     if(get_same_position[i][j] == 1){
01629                         wow = 1;
01630                     }
01631                 }
01632             }
01633             if(wow == 0){
01634                 for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];}
01635             }
01636             else{
01637                 discard_same_position(post1,post2);
01638                 array_to_hex(post1);
01639                 for(i = 0;i<8;i++){
01640                     hex_post1[i] = return_hex[i];
01641                 }
01642                 array_to_hex(post2);
01643                 for(i = 0;i<8;i++){
01644                     hex_post2[i] = return_hex[i];
01645                 }
01646                 array_to_hex(get_same_position);
01647                 for(i = 0;i<8;i++){
01648                     hex_post_cut[i] = return_hex[i];
01649                 }
01650                 for(i = 0;i<8;i++){
01651                     _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
01652                 }
01653             }
01654         }
01655         check_boat3 = 0;
01656     }
01657     if(dir == 's' && temppic2[7] == 0){
01658         for(j=0;j<8;j++){
01659             if(j == 0){
01660                 forshift[0] = 0;
01661             }
01662             else{
01663                 forshift[j] = temppic2[j-1];
01664             }
01665         }
01666         for(j=0;j<8;j++){
01667             temppic2[j] = forshift[j];
01668             _temppic[j] = temppic2[j];
01669         }
01670         // begin to compare and combine two frame
01671         hex_to_array(_temppic);
01672         for(i = 0;i<8;i++){
01673             for(j = 0;j<8;j++){
01674                 post1[i][j] = return_position[i][j];
01675             }
01676         }
01677         hex_to_array(pic);
01678         for(i = 0;i<8;i++){
01679             for(j = 0;j<8;j++){
01680                 post2[i][j] = return_position[i][j];
01681             }
01682         }
01683 
01684         // begin to check boypeacemaker
01685         ch_same_position(post1,post2);
01686         for(i=0;i<8;i++){
01687             for(j=0;j<8;j++){
01688                 get_same_position[i][j] = ch_post[i][j];
01689                 if(get_same_position[i][j] == 1){
01690                     wow = 1;
01691                 }
01692             }
01693         }
01694         if(wow == 0){
01695             for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];}
01696         }
01697         else{
01698             discard_same_position(post1,post2);
01699             array_to_hex(post1);
01700             for(i = 0;i<8;i++){
01701                 hex_post1[i] = return_hex[i];
01702             }
01703             array_to_hex(post2);
01704             for(i = 0;i<8;i++){
01705                 hex_post2[i] = return_hex[i];
01706             }
01707             array_to_hex(get_same_position);
01708             for(i = 0;i<8;i++){
01709                 hex_post_cut[i] = return_hex[i];
01710             }
01711             for(i = 0;i<8;i++){
01712                 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
01713             }
01714         }
01715 
01716     }
01717 }
01718 // ******************************************************************** ship 2 channal ******************************************************************
01719 
01720 void place_ship2_4(int ship,char dir){
01721 
01722     int post1[8][8] = {0};
01723     int post2[8][8] = {0};
01724     int hex_post1[8] = {0};
01725     int hex_post2[8] = {0};
01726     int hex_post_cut[8] = {0};
01727     int get_same_position[8][8];
01728     int wow=0;
01729 
01730     if(dir == 'w'&& temppic3[ship][0] == 0 ){
01731         for(j=0;j<8;j++){
01732             if(j == 7){
01733                 forshift[7] = 0;
01734             }
01735             else{
01736                 forshift[j] = temppic3[ship][j+1];
01737             }
01738         }
01739         for(j=0;j<8;j++){
01740             temppic3[ship][j] = forshift[j];
01741             _temppic[j] = temppic3[ship][j];
01742         }
01743         // begin to compare and combine two frame
01744         hex_to_array(_temppic);
01745         for(i = 0;i<8;i++){
01746             for(j = 0;j<8;j++){
01747                 post1[i][j] = return_position[i][j];
01748             }
01749         }
01750         hex_to_array(pic);
01751         for(i = 0;i<8;i++){
01752             for(j = 0;j<8;j++){
01753                 post2[i][j] = return_position[i][j];
01754             }
01755         }
01756 
01757         // begin to check boypeacemaker
01758         ch_same_position(post1,post2);
01759         for(i=0;i<8;i++){
01760             for(j=0;j<8;j++){
01761                 get_same_position[i][j] = ch_post[i][j];
01762                 if(get_same_position[i][j] == 1){
01763                     wow = 1;
01764                 }
01765             }
01766         }
01767         if(wow == 0){
01768             for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];}
01769         }
01770         else{
01771             discard_same_position(post1,post2);
01772             array_to_hex(post1);
01773             for(i = 0;i<8;i++){
01774                 hex_post1[i] = return_hex[i];
01775             }
01776             array_to_hex(post2);
01777             for(i = 0;i<8;i++){
01778                 hex_post2[i] = return_hex[i];
01779             }
01780             array_to_hex(get_same_position);
01781             for(i = 0;i<8;i++){
01782                 hex_post_cut[i] = return_hex[i];
01783             }
01784             for(i = 0;i<8;i++){
01785                 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
01786             }
01787         }
01788 
01789     }
01790     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 ){
01791         for(j=0;j<8;j++){
01792             if(temppic3[j] != 0){
01793                 temppic3[ship][j] = temppic3[ship][j]*2;
01794             }
01795             else{
01796                 temppic3[ship][j] = 0;
01797             }
01798             _temppic[j] = temppic3[ship][j];
01799         }
01800         // begin to compare and combine two frame
01801         hex_to_array(_temppic);
01802         for(i = 0;i<8;i++){
01803             for(j = 0;j<8;j++){
01804                 post1[i][j] = return_position[i][j];
01805             }
01806         }
01807         hex_to_array(pic);
01808         for(i = 0;i<8;i++){
01809             for(j = 0;j<8;j++){
01810                 post2[i][j] = return_position[i][j];
01811             }
01812         }
01813 
01814         // begin to check boypeacemaker
01815         ch_same_position(post1,post2);
01816         for(i=0;i<8;i++){
01817             for(j=0;j<8;j++){
01818                 get_same_position[i][j] = ch_post[i][j];
01819                 if(get_same_position[i][j] == 1){
01820                     wow = 1;
01821                 }
01822             }
01823         }
01824         if(wow == 0){
01825             for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];}
01826         }
01827         else{
01828             discard_same_position(post1,post2);
01829             array_to_hex(post1);
01830             for(i = 0;i<8;i++){
01831                 hex_post1[i] = return_hex[i];
01832             }
01833             array_to_hex(post2);
01834             for(i = 0;i<8;i++){
01835                 hex_post2[i] = return_hex[i];
01836             }
01837             array_to_hex(get_same_position);
01838             for(i = 0;i<8;i++){
01839                 hex_post_cut[i] = return_hex[i];
01840             }
01841             for(i = 0;i<8;i++){
01842                 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
01843             }
01844         }
01845 
01846     }
01847     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){
01848         for(j=0;j<8;j++){
01849             if(temppic3[ship][j] != 0){
01850                 temppic3[ship][j] = temppic3[ship][j]/2;
01851             }
01852             else{
01853                 temppic3[ship][j] = 0;
01854             }
01855             _temppic[j] = temppic3[ship][j];
01856         }
01857         // begin to compare and combine two frame
01858         hex_to_array(_temppic);
01859         for(i = 0;i<8;i++){
01860             for(j = 0;j<8;j++){
01861                 post1[i][j] = return_position[i][j];
01862             }
01863         }
01864         hex_to_array(pic);
01865         for(i = 0;i<8;i++){
01866             for(j = 0;j<8;j++){
01867                 post2[i][j] = return_position[i][j];
01868             }
01869         }
01870 
01871         // begin to check boypeacemaker
01872         ch_same_position(post1,post2);
01873         for(i=0;i<8;i++){
01874             for(j=0;j<8;j++){
01875                 get_same_position[i][j] = ch_post[i][j];
01876                 if(get_same_position[i][j] == 1){
01877                     wow = 1;
01878                 }
01879             }
01880         }
01881         if(wow == 0){
01882             for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];}
01883         }
01884         else{
01885             discard_same_position(post1,post2);
01886             array_to_hex(post1);
01887             for(i = 0;i<8;i++){
01888                 hex_post1[i] = return_hex[i];
01889             }
01890             array_to_hex(post2);
01891             for(i = 0;i<8;i++){
01892                 hex_post2[i] = return_hex[i];
01893             }
01894             array_to_hex(get_same_position);
01895             for(i = 0;i<8;i++){
01896                 hex_post_cut[i] = return_hex[i];
01897             }
01898             for(i = 0;i<8;i++){
01899                 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
01900             }
01901         }
01902 
01903     }
01904     if(dir == 's' && temppic3[ship][7] == 0){
01905         for(j=0;j<8;j++){
01906             if(j == 0){
01907                 forshift[0] = 0;
01908             }
01909             else{
01910                 forshift[j] = temppic3[ship][j-1];
01911             }
01912         }
01913         for(j=0;j<8;j++){
01914             temppic3[ship][j] = forshift[j];
01915             _temppic[j] = temppic3[ship][j];
01916         }
01917         // begin to compare and combine two frame
01918         hex_to_array(_temppic);
01919         for(i = 0;i<8;i++){
01920             for(j = 0;j<8;j++){
01921                 post1[i][j] = return_position[i][j];
01922             }
01923         }
01924         hex_to_array(pic);
01925         for(i = 0;i<8;i++){
01926             for(j = 0;j<8;j++){
01927                 post2[i][j] = return_position[i][j];
01928             }
01929         }
01930 
01931         // begin to check boypeacemaker
01932         ch_same_position(post1,post2);
01933         for(i=0;i<8;i++){
01934             for(j=0;j<8;j++){
01935                 get_same_position[i][j] = ch_post[i][j];
01936                 if(get_same_position[i][j] == 1){
01937                     wow = 1;
01938                 }
01939             }
01940         }
01941         if(wow == 0){
01942             for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];}
01943         }
01944         else{
01945             discard_same_position(post1,post2);
01946             array_to_hex(post1);
01947             for(i = 0;i<8;i++){
01948                 hex_post1[i] = return_hex[i];
01949             }
01950             array_to_hex(post2);
01951             for(i = 0;i<8;i++){
01952                 hex_post2[i] = return_hex[i];
01953             }
01954             array_to_hex(get_same_position);
01955             for(i = 0;i<8;i++){
01956                 hex_post_cut[i] = return_hex[i];
01957             }
01958             for(i = 0;i<8;i++){
01959                 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
01960             }
01961         }
01962 
01963     }
01964 }
01965 void hex_to_array_ship(int *hex_array){
01966   int i,j;
01967   int temp;
01968   for(i = 0; i<8;i++){
01969       temp = hex_array[i];
01970       for(j = 0;j<8;j++){
01971           if(temp & 0x80){
01972               ship[i][7-j][0] = 80;
01973               ship[i][7-j][1] = 20;
01974           }
01975           else{
01976               ship[i][7-j][0] = 0;
01977               ship[i][7-j][1] = 0;
01978               ship[i][7-j][2] = 0;
01979           }
01980           temp = temp << 1;
01981       }
01982   }
01983 }
01984 
01985 void plant_bomb(char dir){
01986 
01987     //scanf("%c",&dir);
01988     if(dir == 'w' && row>0){
01989         row = row - 1;
01990         for(i=0;i<3;i++){
01991             temp_array[i] = bomb[row][col][i];
01992         }
01993         for(i=0;i<3;i++){
01994             bomb[row][col][i] = bomb[row+1][col][i];
01995             bomb[row+1][col][i] = temp_array[i];
01996         }
01997         iCheck = 0;
01998     }else if(dir == 'a' && col>0){
01999         col = col - 1;
02000         for(i=0;i<3;i++){
02001             temp_array[i] = bomb[row][col][i];
02002         }
02003         for(i=0;i<3;i++){
02004             bomb[row][col][i] = bomb[row][col+1][i];
02005             bomb[row][col+1][i] = temp_array[i];
02006         }
02007         iCheck = 0;
02008     }else if(dir == 's' && row<7){
02009         row = row + 1;
02010         for(i=0;i<3;i++){
02011             temp_array[i] = bomb[row][col][i];
02012         }
02013         for(i=0;i<3;i++){
02014             bomb[row][col][i] = bomb[row-1][col][i];
02015             bomb[row-1][col][i] = temp_array[i];
02016         }
02017         iCheck = 0;
02018     }else if(dir == 'd' && col<7){
02019         col = col + 1;
02020         for(i=0;i<3;i++){
02021             temp_array[i] = bomb[row][col][i];
02022         }
02023         for(i=0;i<3;i++){
02024             bomb[row][col][i] = bomb[row][col-1][i];
02025             bomb[row][col-1][i] = temp_array[i];
02026         }
02027         iCheck = 0;
02028     }
02029     // if change state pls use set_zero
02030 }
02031 
02032 void set_zero(){
02033     memcpy(bomb,zero,sizeof bomb);
02034     bomb[0][0][0] = 20;
02035     bomb[0][0][1] = 20;
02036     bomb[0][0][2] = 10;
02037     row = 0;
02038     col = 0;
02039 }
02040 
02041 void change_orange_myship(int row,int col){ // change to orange
02042   //printf("plot orange (myship) at |%d,%d| \n",row,col);
02043   for(int i = 0; i<8;i++){
02044     for(int j = 0;j<8;j++){
02045         if(i == row && j == col){
02046             ship[i][j][0] = 0;  //b
02047             ship[i][j][1] = 150; //g
02048             ship[i][j][2] = 250; //r
02049         }
02050     }
02051   }
02052 }
02053 void change_orange_hisship(int row,int col){ // change to orange
02054   //printf("plot orange (enemy ship) at |%d,%d| \n",row,col);
02055   for(int i = 0; i<8;i++){
02056     for(int j = 0;j<8;j++){
02057         if(i == row && j == col){
02058             plot_bombed_usage[i][j][0] = 0;  //b
02059             plot_bombed_usage[i][j][1] = 150; //g
02060             plot_bombed_usage[i][j][2] = 250; //r
02061         }
02062     }
02063   }
02064 }
02065 void change_red_hisship(int row,int col){ // change to red
02066   //printf("plot red (enemy ship) at |%d,%d| \n",row,col);
02067   for(int i = 0; i<8;i++){
02068     for(int j = 0;j<8;j++){
02069         if(i == row && j == col){
02070             plot_bombed_usage[i][j][0] = 0;
02071             plot_bombed_usage[i][j][1] = 0;
02072             plot_bombed_usage[i][j][2] = 200;
02073         }
02074     }
02075   }
02076 }
02077 void change_red_myship(int row,int col){ // change to red
02078   //printf("plot red (my ship) at |%d,%d| \n",row,col);
02079   for(int i = 0; i<8;i++){
02080     for(int j = 0;j<8;j++){
02081         if(i == row && j == col){
02082             ship[i][j][0] = 0;
02083             ship[i][j][1] = 0;
02084             ship[i][j][2] = 200;
02085         }
02086     }
02087   }
02088 }
02089 
02090 void change_red_deadship(int* array_coordinate,int mode){ // change to red
02091   int row = 0;
02092   int col = 0;
02093   for(int i = 0;i<15;i++){
02094     if(array_coordinate[i] != 9){
02095       row = array_coordinate[i] / 10;
02096       col = array_coordinate[i] % 10;
02097       if(mode == 0){
02098         change_red_myship(row,col);
02099       }
02100       else if(mode == 1){
02101         change_red_hisship(row,col);
02102       }
02103     }
02104   }
02105 }
02106 void change_green_myship(int row,int col){
02107   for(int i = 0; i<8;i++){
02108     for(int j = 0;j<8;j++){
02109         if(i == row && j == col){
02110             ship[i][j][0] = 0;
02111             ship[i][j][1] = 200;
02112             ship[i][j][2] = 0;
02113         }
02114     }
02115   }
02116 }
02117 void change_green_hisship(int row,int col){
02118   for(int i = 0; i<8;i++){
02119     for(int j = 0;j<8;j++){
02120         if(i == row && j == col){
02121             plot_bombed_usage[i][j][0] = 0;
02122             plot_bombed_usage[i][j][1] = 200;
02123             plot_bombed_usage[i][j][2] = 0;
02124         }
02125     }
02126   }
02127 }
02128 void display_bomb_enemy(int row,int col){
02129   int zero_array[8][8][3] = {{{0}}};
02130   memcpy(bomb_enemy,zero_array,sizeof bomb_enemy);
02131   for(int i = 0; i<8;i++){
02132     for(int j = 0;j<8;j++){
02133         if(i == row && j == col){
02134             bomb_enemy[i][j][0] = 20;
02135             bomb_enemy[i][j][1] = 20;
02136             bomb_enemy[i][j][2] = 10;
02137         }
02138     }
02139   }
02140 }