@@ -14,25 +14,35 @@ typedef struct Coordinates {
1414coord clickToCoordinates (COORD click )
1515{
1616 coord retValue ;
17+
18+ click .X -- ;
19+ retValue .i = -1 ;
20+ retValue .j = -1 ;
1721
18- for (int count = 0 ; count < 37 ; count += 9 )
22+ for (int count = 0 ; count < 37 ; count += 4 )
1923 {
20- if (click .Y > count && click .Y < count + 9 )
21- retValue .i = count /9 ;
24+ if (click .Y > count && click .Y < count + 4 )
25+ {
26+ retValue .i = count / 4 ;
27+ break ;
28+ }
2229 }
23- for (int count = 0 ; count < 109 ; count += 4 )
30+ for (int count = 0 ; count < 109 ; count += 9 )
2431 {
25- if (click .X > count && click .X < count + 4 )
26- retValue .j = count /4 ;
32+ if (click .X > count && click .X < count + 9 )
33+ {
34+ retValue .j = count / 9 ;
35+ break ;
36+ }
2737 }
2838 return retValue ;
2939}
3040
31- void createDisplayeGrid (char displayGrid [37 ][109 ])
41+ void createDisplayeGrid (char displayGrid [37 ][100 ])
3242{
3343 for (int i = 0 ; i < 37 ; i ++ )
3444 {
35- for (int j = 0 ; j < 109 ; j ++ )
45+ for (int j = 0 ; j < 100 ; j ++ )
3646 {
3747 if (j % 9 == 0 || i % 4 == 0 )
3848 {
@@ -48,7 +58,7 @@ void createDisplayeGrid(char displayGrid[37][109])
4858 }
4959}
5060
51- void modifyDisplayGrid (char displayGrid [37 ][109 ], coord coordinates , char symbol )
61+ void modifyDisplayGrid (char displayGrid [37 ][100 ], coord coordinates , char symbol )
5262{
5363 char horizontalBow [3 ][8 ] = { {' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , '_' } ,
5464 {' ' , ' ' , ' ' , ' ' , '_' , '_' , '/' , ' ' } ,
@@ -74,58 +84,87 @@ void modifyDisplayGrid(char displayGrid[37][109], coord coordinates, char symbol
7484 {' ' , '|' , '_' , '_' , '_' , '_' , '|' , ' ' } ,
7585 {' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' } };
7686
77- char nope [3 ][8 ] = { {' ' , ' ' , '\\' , '_' , '_' , ' / ' , ' ' , ' ' } ,
87+ char nope [3 ][8 ] = { {' ' , ' ' , '\\' , '_' , '_' , '/ ' , ' ' , ' ' } ,
7888 {' ' , '-' , '|' , '_' , '_' , '|' , '-' , ' ' } ,
7989 {' ' , ' ' , '/' , ' ' , ' ' , '\\' , ' ' , ' ' } };
8090
81- char submarine [3 ][18 ] = { {' ' , ' ' , ' ' , ' ' , '_' , ' ' , ' ' , ' ' } ,
82- {' ' , '_' , '_' , '/' , 'o' , '\\' , '_' , ' ' } ,
83- {'|' , '_' , '_' , '_' , '_' , '_' , '_' , '|' } };
91+ char submarine [3 ][8 ] = { {' ' , ' ' , ' ' , ' ' , '_' , ' ' , ' ' , ' ' } ,
92+ {' ' , '_' , '_' , '/' , 'o' , '\\' , '_' , ' ' } ,
93+ {'|' , '_' , '_' , '_' , '_' , '_' , '_' , '|' } };
8494
8595 coord start ;
8696
8797 for (int count = 0 ; count < 9 ; count ++ )
8898 {
8999 if (coordinates .i == count )
100+ {
90101 start .i = (count * 4 ) + 1 ;
102+ break ;
103+ }
91104 }
92105 for (int count = 0 ; count < 11 ; count ++ )
93106 {
94107 if (coordinates .j == count )
108+ {
95109 start .j = (count * 9 ) + 1 ;
110+ break ;
111+ }
96112 }
97113
98114 for (int i = 0 ; i < 3 ; i ++ )
99115 {
100- for (int j = 0 ; j < 18 ; j ++ )
116+ for (int j = 0 ; j < 8 ; j ++ )
101117 {
102118 if (symbol == '<' )
119+ {
103120 displayGrid [start .i + i ][start .j + j ] = horizontalBow [i ][j ];
121+ continue ;
122+ }
104123 if (symbol == '=' )
124+ {
105125 displayGrid [start .i + i ][start .j + j ] = horizontalMiddle [i ][j ];
126+ continue ;
127+ }
106128 if (symbol == '>' )
129+ {
107130 displayGrid [start .i + i ][start .j + j ] = horizontalStern [i ][j ];
131+ continue ;
132+ }
108133 if (symbol == '^' )
134+ {
109135 displayGrid [start .i + i ][start .j + j ] = verticalBow [i ][j ];
136+ continue ;
137+ }
110138 if (symbol == '|' )
139+ {
111140 displayGrid [start .i + i ][start .j + j ] = verticalMiddle [i ][j ];
141+ continue ;
142+ }
112143 if (symbol == '~' )
144+ {
113145 displayGrid [start .i + i ][start .j + j ] = verticalStern [i ][j ];
146+ }
114147 if (symbol == ' ' )
148+ {
115149 displayGrid [start .i + i ][start .j + j ] = nope [i ][j ];
150+ continue ;
151+ }
116152 if (symbol == 'o' )
153+ {
117154 displayGrid [start .i + i ][start .j + j ] = submarine [i ][j ];
155+ continue ;
156+ }
118157 }
119158 }
120159
121160}
122161
123- void printDisplayGrid (char displayGrid [37 ][109 ])
162+ void printDisplayGrid (char displayGrid [37 ][100 ])
124163{
125164 for (int i = 0 ; i < 37 ; i ++ )
126165 {
127166 moveRight (1 );
128- for (int j = 0 ; j < 109 ; j ++ )
167+ for (int j = 0 ; j < 100 ; j ++ )
129168 printf ("%c" , displayGrid [i ][j ]);
130169 printf ("\n" );
131170 }
@@ -159,7 +198,7 @@ int main(int argc, char** argv)
159198 return -2 ;
160199 }
161200
162- char displayGrid [37 ][109 ];
201+ char displayGrid [37 ][100 ];
163202 char grid [9 ][11 ];
164203 char playGrid [9 ][11 ];
165204 coord play ;
@@ -229,13 +268,13 @@ int main(int argc, char** argv)
229268 retEvent .event .mouseEvent = 0xc00 ;
230269 retEvent = eventMain ();
231270 mouseCoord = retEvent .event .mouseCoord ;
232- if (retEvent .event .mouseEvent == FROM_LEFT_1ST_BUTTON_PRESSED )
271+ if (retEvent .event .mouseEvent == FROM_LEFT_1ST_BUTTON_PRESSED )
233272 break ;
234273 }
235- printf ( "%i %i\n" , mouseCoord . Y , mouseCoord . X );
274+
236275 play = clickToCoordinates (mouseCoord );
237- printf ( "%i %i\n" , play .i , play .j );
238- fgets ( trashcan , 5 , stdin ) ;
276+ if ( play .i == -1 || play .j == -1 )
277+ continue ;
239278
240279 modifyDisplayGrid (displayGrid , play , grid [play .i ][play .j ]);
241280 clearScreenToTop ;
@@ -245,6 +284,7 @@ int main(int argc, char** argv)
245284 if (isEnd (grid , playGrid ))
246285 {
247286 puts ("Game Over!" );
287+ playing = false;
248288 fgets (trashcan , 5 , stdin );
249289 break ;
250290 }
0 commit comments