comparison src/ui3/bmi/mmiGame.c @ 421:6a4d9f47793e

src/ui3/bmi: file renames to make the case consistent
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 Jan 2018 03:28:53 +0000
parents src/ui3/bmi/Mmigame.c@e8ddbb0837ed
children
comparison
equal deleted inserted replaced
420:e8ddbb0837ed 421:6a4d9f47793e
1 /*******************************************************************************
2
3 CONDAT (UK)
4
5 ********************************************************************************
6
7 This software product is the property of Condat (UK) Ltd and may not be
8 disclosed to any third party without the express permission of the owner.
9
10 ********************************************************************************
11
12 $Project name: Basic MMI
13 $Project code: BMI (6349)
14 $Module: Game
15 $File: Mmigame.c
16 $Revision: 1.0
17
18 $Author: Condat(UK)
19 $Date: 03/07/01
20
21 ********************************************************************************
22
23 Description
24 Aug 16, 2004 REF: CRR 24323 Deepa M.D
25 Bug:Clenup of sprintf used for tracing
26 Fix:Replace the char buf[]; sprintf (buf, "...", ...); TRACE_EVENT (buf); statements by TRACE_EVENT_PX
27
28 This provides the main game (four in a row) functionality
29
30
31 ********************************************************************************/
32
33
34 /*******************************************************************************
35
36 Include files
37
38 *******************************************************************************/
39
40 #define ENTITY_MFW
41
42 /* includes */
43 #include <string.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46
47 #if defined (NEW_FRAME)
48
49 #include "typedefs.h"
50 #include "vsi.h"
51 #include "pei.h"
52 #include "custom.h"
53 #include "gsm.h"
54
55 #else
56
57 #include "STDDEFS.H"
58 #include "custom.h"
59 #include "gsm.h"
60 #include "vsi.h"
61
62 #endif
63 #include "mfw_sys.h"
64
65 #include "cus_aci.h"
66
67 #include "mfw_mfw.h"
68 #include "mfw_win.h"
69 #include "mfw_kbd.h"
70 /* SPR#1428 - SH - New Editor changes */
71 #ifndef NEW_EDITOR
72 #include "mfw_edt.h"
73 #endif
74 #include "mfw_lng.h"
75 #include "mfw_tim.h"
76 #include "mfw_icn.h"
77 #include "mfw_mnu.h"
78 #include "mfw_phb.h"
79 #include "mfw_cm.h"
80 #include "mfw_sim.h"
81 #include "mfw_nm.h"
82 #include "mfw_sat.h"
83 #include "mfw_ss.h" /*for convert*/
84 #include "mfw_phb.h"
85 #include "ksd.h"
86 #include "psa.h"
87 #include "mfw_sms.h"
88 #include "mfw_cphs.h"
89 #include "mfw_sat.h"
90 #include "Mfw_band.h"
91 #include "mfw_ffs.h"
92 #include "Mmigame.h"
93
94 #include "dspl.h"
95
96 #include "MmiMmi.h"
97 #include "MmiDialogs.h"
98 #include "MmiLists.h"
99 #include "MmiBand.h"
100 #include "MmiCPHS.h"
101 /* SPR#1428 - SH - New Editor changes */
102 #ifdef NEW_EDITOR
103 #include "ATBCommon.h"
104 #include "ATBDisplay.h"
105 #include "ATBEditor.h"
106 #include "AUIEditor.h"
107 #else
108 #include "MmiEditor.h"
109 #endif
110 #include"MmiBookShared.h"
111
112
113
114
115 #include "font_bitmaps.h"
116 #include "mmiColours.h"
117 #include "MmiResources.h"
118
119 #include "Mmigame.h"
120 //GW 14/09/01 Disable game when not required.
121 #ifdef MMIGAME
122 void dspl_show_bitmap(int x,int y,t_font_bitmap* current_bitmap,U32 attr );
123 /*******************************************************************************
124
125 internal data
126
127 *******************************************************************************/
128
129 #define FOUR_IN_A_ROW_INIT 121
130 #define MAX_X_BOARD 11
131 #define MAX_Y_BOARD 8
132 /*
133 * The information related to every window must be encapsulated in such an structure
134 */
135
136 typedef struct
137 {
138 T_MMI_CONTROL mmi_control; // common control parameter
139 T_MFW_HND win;
140 T_MFW_HND kbd;
141 T_MFW_HND menu;
142 T_MFW_HND parent_win;
143 T_MFW_HND info_win;
144 char board_array[MAX_Y_BOARD][MAX_X_BOARD]; //the virtual board
145 } T_four_in_a_row;
146
147 typedef struct
148 {
149 /* administrative data */
150
151 T_MMI_CONTROL mmi_control;
152 T_MFW_HND win;
153 T_MFW_HND parent_win;
154 /* SPR#1428 - SH - New editor data */
155 #ifdef NEW_EDITOR
156 T_AUI_EDITOR_DATA editor_data;
157 #else /* NEW_EDITOR */
158 T_EDITOR_DATA editor_data;
159 #endif /* NEW_EDITOR */
160
161 /* internal data */
162 char buffer[80];
163 UBYTE status;
164
165 } tShowInfo;
166
167
168 /*
169 * These are common functions xxx_create and xxx_destroy
170 */
171 T_MFW_HND four_in_a_row_create(MfwHnd parent);
172 void four_in_a_row_destroy (T_MFW_HND);
173
174
175 /*
176 * This dialog function (the same name as the window)
177 * is used to handle the comunication between different windows. The global macro SEND_EVENT can be used with parameter win
178 * and the corresponding events to send from one mmi dialog to another.
179 */
180 void four_in_a_row (T_MFW_HND win, USHORT event, SHORT value, void * parameter);
181
182
183 /*
184 * These are common optional functions handler
185 */
186 int four_in_a_row_kbd_cb (MfwEvt e, MfwKbd *k);
187 int four_in_a_row_win_cb (MfwEvt e, MfwWin *w);
188
189 int Game_Result;
190
191
192 /*
193 * This an optional function, used often to call, create and init a new dialog, with different parameters depending
194 * on the context
195 */
196 T_MFW_HND four_in_a_row_start (T_MFW_HND win_parent,char *character);
197 int four_in_a_row_aktivate(MfwMnu* m, MfwMnuItem* i);
198
199 int check_column(T_four_in_a_row *data, int where_from);
200 void drop_stone(T_four_in_a_row *data);
201
202 int mobile_thinking(T_four_in_a_row *data);
203 int check_line(T_four_in_a_row *data, int x_value, int drop_position, int dx, int dy, BOOL where_from);
204 void check_for_winner(T_four_in_a_row *data, int check_out_position);
205 int random_scoring(void); // RAVI
206
207 T_MFW_HND Game_Info(T_MFW_HND parent_window);
208 static T_MFW_HND ShowGame_Information(MfwHnd parent_window);
209 static void ShowGame_DialogCB(T_MFW_HND win, USHORT e, SHORT identifier, void *parameter);
210 void ShowGameInfoEditor(T_MFW_HND win);
211 static void ShowInfoCB( T_MFW_HND win, USHORT Identifier,UBYTE reason);
212 void showGameInfo_destroy(MfwHnd own_window);
213
214 const char * info = "Welcome to Connect 4!";
215 const char * playAgain = "Play Again?";
216
217
218 //internal datas
219
220 int column; //this is the current position of white player cursor
221 int x_runer; //goes through the horizontal lines
222 int y_runer; //goes through the vertical lines
223 char winner; //describes the winner 0->nobody 'B'->black(mobile) 'W'->white(human player)
224 int column_black; //this is the current position of black player cursor
225 int request_stone; //helps to decide between black or white (for strategical things)
226
227
228
229 #ifndef BMP_FORMAT_BW_UNPACKED
230 #define BMP_FORMAT_BW_UNPACKED 1
231 #endif
232
233
234 t_font_bitmap plWin1 ={ 0, BMP_FORMAT_BW_UNPACKED, 21, 24, 0, (char*)player_win1};
235 t_font_bitmap plWin2 ={ 0, BMP_FORMAT_BW_UNPACKED, 21, 24, 0, (char*)player_win2};
236 t_font_bitmap plLost1 ={ 0, BMP_FORMAT_BW_UNPACKED, 21, 24, 0, (char*)player_lost1};
237 t_font_bitmap plLost2 ={ 0, BMP_FORMAT_BW_UNPACKED, 21, 24, 0, (char*)player_lost2};
238 t_font_bitmap draw1 ={ 0, BMP_FORMAT_BW_UNPACKED, 21, 24, 0, (char*)board_full1};
239 t_font_bitmap draw2 ={ 0, BMP_FORMAT_BW_UNPACKED, 21, 24, 0, (char*)board_full2};
240 t_font_bitmap gameName1 ={ 0, BMP_FORMAT_BW_UNPACKED, 18, 24, 0, (char*)game_name1};
241 t_font_bitmap gameName2 ={ 0, BMP_FORMAT_BW_UNPACKED, 24, 24, 0, (char*)game_name2};
242
243 #ifdef COLOURDISPLAY
244 char colBmp[256*4];
245 t_font_bitmap allCol ={ 0, BMP_FORMAT_256_COLOUR, 32, 32, 0, colBmp };
246 t_font_bitmap stone_colour ={ 0, BMP_FORMAT_BW_UNPACKED, 8, 8, 0, (char*)black_stone_bw};
247 t_font_bitmap gameCursor = { 0, BMP_FORMAT_BW_UNPACKED, 8, 8, 0, (char*)game_cursor};
248 #else
249 #ifdef LSCREEN
250 t_font_bitmap blackStone_bw ={ 0, BMP_FORMAT_BW_UNPACKED, 8, 8, 0, (char*)black_stone_bw};
251 t_font_bitmap whiteStone_bw ={ 0, BMP_FORMAT_BW_UNPACKED, 8, 8, 0, (char*)white_stone_bw};
252 t_font_bitmap gameCursor = { 0, BMP_FORMAT_BW_UNPACKED, 8, 8, 0, (char*)game_cursor};
253 #else
254 t_font_bitmap blackStone_bw ={ 0, BMP_FORMAT_BW_UNPACKED, 4, 4, 0, (char*)black_stone_bw};
255 t_font_bitmap whiteStone_bw ={ 0, BMP_FORMAT_BW_UNPACKED, 4, 4, 0, (char*)white_stone_bw};
256 t_font_bitmap gameCursor = { 0, BMP_FORMAT_BW_UNPACKED, 6, 6, 0, (char*)game_cursor};
257 #endif
258 #endif
259
260 t_font_bitmap *blackStone, *whiteStone;
261
262 /*******************************************************************************
263
264 $Function: four_in_a_row_create
265
266 $Description:
267
268 $Returns:
269
270 $Arguments:
271
272 *******************************************************************************/
273
274
275 T_MFW_HND four_in_a_row_create (T_MFW_HND parent_window)
276 {
277
278 T_MFW_WIN * win;
279
280 /*
281 * This window is dynamic, for that reason the associated data are allocated in the mfw heap
282 */
283 T_four_in_a_row * data = (T_four_in_a_row *)ALLOC_MEMORY (sizeof (T_four_in_a_row));
284
285 TRACE_FUNCTION ("four_in_a_row_create()");
286
287 /*
288 * Create window handler
289 */
290
291 data->win = win_create (parent_window, 0, E_WIN_VISIBLE, (T_MFW_CB)four_in_a_row_win_cb);
292
293 if (data->win EQ 0)
294 return 0;
295
296 /*
297 * These assignments are necessary to attach the data to the window, and to handle the mmi event communication.
298 */
299
300 data->mmi_control.dialog = (T_DIALOG_FUNC)four_in_a_row;
301 data->mmi_control.data = data;
302 data->parent_win = parent_window;
303 win = ((T_MFW_HDR *)data->win)->data;
304 win->user = (void *) data;
305
306 /*
307 * Create any other handler
308 */
309
310 data->kbd = kbd_create (data->win,KEY_ALL,(T_MFW_CB)four_in_a_row_kbd_cb);
311
312 column=0; //set start value for game cursor
313 winner ='0'; //game starts, so set winner to nobody
314
315 /*clear the board*/
316 for (y_runer=0;y_runer<MAX_Y_BOARD;y_runer++){
317 for(x_runer=0;x_runer<MAX_X_BOARD;x_runer++){
318 data->board_array[y_runer][x_runer] ='0';
319 }
320 }
321 winShow(data->win);
322
323 return data->win;
324 }
325
326 /*******************************************************************************
327
328 $Function: four_in_a_rowr_destroy
329
330 $Description:
331
332 $Returns:
333
334 $Arguments:
335
336 *******************************************************************************/
337
338 void four_in_a_row_destroy (T_MFW_HND own_window)
339 {
340 T_MFW_WIN * win;
341 T_four_in_a_row * data;
342
343 TRACE_EVENT("four_in_a_row_destroy");
344
345 if (own_window)
346 {
347 win = ((T_MFW_HDR *)own_window)->data;
348 data = (T_four_in_a_row *)win->user;
349
350 if (data)
351 {
352 /*
353 * Exit Keyboard Handler
354 */
355 /*
356 * Delete WIN Handler
357 */
358 win_delete (data->win);
359 }
360
361 /*
362 * In this case the data attached to window must be also deleted.
363 */
364 FREE_MEMORY ((void *)data, sizeof (T_four_in_a_row));
365
366 column=0; //set the current column back to 0
367
368 }
369 }
370
371 /*******************************************************************************
372
373 $Function: four_in_a_row_start
374
375 $Description: This function just creates and inits the new dialog
376
377 $Returns:
378
379 $Arguments:
380
381 *******************************************************************************/
382 T_MFW_HND four_in_a_row_start (T_MFW_HND win_parent,char *character)
383 {
384 T_MFW_HND win;
385 /*
386 MmiTetrisStart();
387 return;
388 */
389 win = four_in_a_row_create (win_parent);
390 TRACE_EVENT("four_in_a_row_start");
391
392 if (win NEQ NULL)
393 {
394 SEND_EVENT(win,FOUR_IN_A_ROW_INIT,0,character);
395 }
396 return win;
397
398 }
399
400 /*******************************************************************************
401
402 $Function: four_in_a_row
403
404 $Description:
405
406 $Returns:
407
408 $Arguments:
409
410 *******************************************************************************/
411
412
413
414 void four_in_a_row (T_MFW_HND win, USHORT event, SHORT value, void * parameter)
415 {
416 T_MFW_WIN * win_data = ((T_MFW_HDR *) win)->data;
417 T_four_in_a_row * data = (T_four_in_a_row *)win_data->user;
418
419 TRACE_FUNCTION ("four_in_a_row()");
420
421 /*
422 * In this case the communication is very simple (only one intern event)
423 */
424
425
426 switch (event)
427 {
428 case FOUR_IN_A_ROW_INIT:
429 softKeys_displayId(TxtSearchName,TxtNull,0,COLOUR_IDLE);
430 winShow(data->win);
431 break;
432
433 default:
434 return;
435 }
436
437 }
438
439 /*******************************************************************************
440
441 $Function: four_in_a_row_win_cb
442
443 $Description: win calback function of four in a row
444
445 $Returns:
446
447 $Arguments:
448
449 *******************************************************************************/
450
451
452 int four_in_a_row_win_cb (MfwEvt e, MfwWin *w)
453 {
454 // T_DISPLAY_DATA display_info; // RAVI
455 T_four_in_a_row * data = (T_four_in_a_row *)w->user;
456 int xOfs,yOfs, xScale, yScale;
457 int manOfsX,manOfsY;
458 int xPos,yPos;
459 int y_axis; //goes through the vertical lines
460 int x_axis; //goes through the horizontal lines
461 // int x,y,i,b; // RAVI
462 int displayPosX, temp;
463
464 TRACE_FUNCTION ("four_in_a_row_win_cb()");
465
466 switch (e)
467 {
468 case MfwWinVisible:
469 #ifdef COLOURDISPLAY
470 whiteStone = &stone_colour;
471 blackStone = &stone_colour;
472
473 #else
474 whiteStone = &blackStone_bw;
475 blackStone = &whiteStone_bw;
476
477 #endif
478 #ifdef LSCREEN
479 manOfsX = GAME_POS_X + 3;
480 manOfsY = GAME_POS_Y + 3;
481 #else
482 manOfsX = GAME_POS_X + 1;
483 manOfsY = GAME_POS_Y + 1;
484 #endif
485 xOfs = GAME_POS_X;
486 yOfs = GAME_POS_Y;
487 xScale = GAME_SCALE_X;
488 yScale = GAME_SCALE_Y;
489
490 //dspl_ClearAll(); //Clears to white, not BGD!
491 TRACE_EVENT("display clear");
492 resources_setColour( COLOUR_GAME );
493 dspl_Clear( 0,0, SCREEN_SIZE_X,SCREEN_SIZE_Y);
494 #ifdef LSCREEN
495 softKeys_displayId(TxtHelp,TxtExit,0,COLOUR_LIST_SUBMENU);
496 #endif
497
498 resources_setColour( COLOUR_GAME );
499 dspl_Clear( xOfs, yOfs, xOfs+MAX_X_BOARD*xScale, yOfs+MAX_Y_BOARD*yScale ); //Clears to white, not BGD!
500 //dspl_BitBlt(column*xScale+xOfs+1,yOfs-yScale,8,8,0,(void*)game_cursor,0); //place the cursor bitmap
501 dspl_show_bitmap(column*xScale+xOfs+1,yOfs-yScale, &gameCursor, 0 );
502 for (y_axis=0;y_axis<=MAX_Y_BOARD;y_axis++)
503 {
504 dspl_DrawLine( xOfs, yOfs+y_axis*yScale,
505 xOfs+MAX_X_BOARD*xScale, yOfs+y_axis*yScale);
506 }
507 for(x_axis=0;x_axis<=MAX_X_BOARD;x_axis++)
508 {
509 dspl_DrawLine( xOfs+x_axis*xScale, yOfs,
510 xOfs+x_axis*xScale, yOfs+MAX_Y_BOARD*yScale);
511 }
512
513 //go through the board-array and check for W or B and set the stones
514 for (y_axis=0;y_axis<MAX_Y_BOARD;y_axis++)
515 {
516 for(x_axis=0;x_axis<MAX_X_BOARD;x_axis++)
517 {
518 xPos = manOfsX+x_axis*xScale;
519 yPos = manOfsY+y_axis*yScale;
520 if(data->board_array[y_axis][x_axis] EQ 'W'){ //found white
521 //set white_stone bitmap
522 dspl_SetFgdColour( COL_R );
523 dspl_show_bitmap(xPos,yPos, whiteStone, 0 );
524 }
525 if(data->board_array[y_axis][x_axis] EQ 'B'){ //found black
526 //set black_stone bitmap
527 dspl_SetFgdColour( COL_G ); //0x00404040
528 dspl_show_bitmap(xPos,yPos, blackStone, 0 );
529 }
530 }
531 }
532 dspl_SetFgdColour( COL_RB );
533 dspl_SetBgdColour( COL_RG );
534 dspl_show_bitmap(GAME_NAMEPOSX1, GAME_NAMEPOSY1, &gameName1, 0 );
535 displayPosX = (SCREEN_SIZE_X/2);
536 temp = strlen((char*)playAgain);
537 //this if-clause is to set the bitmap, for win or lost game
538 if(winner EQ 'W'){
539 //human player wins, so set win bitmap
540 #ifdef LSCREEN
541 dspl_SetFgdColour( COL_BLK );
542 dspl_SetBgdColour( COL_TRANSPARENT );
543 Game_Result = TRUE;
544 softKeys_displayId(TxtYes,TxtNo,0,COLOUR_LIST_SUBMENU);
545 dspl_TextOut((displayPosX-((temp*CHAR_WIDTH)/2)),170,DSPL_TXTATTR_NORMAL,(char*)playAgain);
546 #endif
547 dspl_SetFgdColour( COL_RB );
548 dspl_SetBgdColour( COL_GB );
549 dspl_show_bitmap(GAME_WINPOSX1, GAME_WINPOSY1, &plWin1, 0 );
550 dspl_show_bitmap(GAME_WINPOSX2, GAME_WINPOSY2, &plWin2, 0 );
551 }
552 else
553 if(winner EQ 'B'){
554 //human player lost, so set lost bitmap
555 #ifdef LSCREEN
556 dspl_SetFgdColour( COL_BLK );
557 dspl_SetBgdColour( COL_TRANSPARENT );
558 Game_Result = TRUE;
559 softKeys_displayId(TxtYes,TxtNo,0,COLOUR_LIST_SUBMENU);
560 dspl_TextOut((displayPosX-((temp*CHAR_WIDTH)/2)),170,DSPL_TXTATTR_NORMAL,(char*)playAgain);
561 #endif
562 dspl_SetFgdColour( COL_RB );
563 dspl_SetBgdColour( COL_GB );
564 dspl_show_bitmap(GAME_WINPOSX1, GAME_WINPOSY1, &plLost1, 0 );
565 dspl_show_bitmap(GAME_WINPOSX2, GAME_WINPOSY2, &plLost2, 0 );
566 }
567 else
568 if(winner EQ 'N'){
569 //board is full, nobody (N) wins
570 #ifdef LSCREEN
571 dspl_SetFgdColour( COL_BLK );
572 dspl_SetBgdColour( COL_TRANSPARENT );
573 Game_Result = TRUE;
574 softKeys_displayId(TxtYes,TxtNo,0,COLOUR_LIST_SUBMENU);
575 dspl_TextOut((displayPosX-((temp*CHAR_WIDTH)/2)),170,DSPL_TXTATTR_NORMAL,(char*)playAgain);
576 #endif
577
578 dspl_SetFgdColour( COL_R );
579 dspl_SetBgdColour( COL_G );
580 dspl_show_bitmap(GAME_WINPOSX1, GAME_WINPOSY1, &draw1, 0 );
581 dspl_show_bitmap(GAME_WINPOSX2, GAME_WINPOSY2, &draw2, 0 );
582 }
583 else
584 {
585 dspl_SetFgdColour( COL_RB );
586 dspl_SetBgdColour( COL_RG );
587 dspl_show_bitmap(GAME_NAMEPOSX1, GAME_NAMEPOSY1, &gameName1, 0 );
588 dspl_show_bitmap(GAME_NAMEPOSX2, GAME_NAMEPOSY2, &gameName2, 0 );
589 dspl_show_bitmap(GAME_NAMEPOSX3, GAME_NAMEPOSY3, &gameName2, 0 );
590 }
591 break;
592
593 default:
594 return 0;
595 }
596
597 return 1;
598 }
599
600 /*******************************************************************************
601
602 $Function: four_in_a_row_kbd_cb
603
604 $Description:
605
606 $Returns:
607
608 $Arguments:
609
610 *******************************************************************************/
611
612 int four_in_a_row_kbd_cb (MfwEvt e, MfwKbd *k)
613 {
614
615 T_MFW_HND win = mfw_parent (mfw_header());
616 T_MFW_WIN * win_data = ((T_MFW_HDR *)win)->data;
617 T_four_in_a_row * data = (T_four_in_a_row *)win_data->user;
618
619 TRACE_EVENT ("four_in_a_row_kbd_cb()");
620
621 switch (k->code)
622 {
623 case KCD_HUP: //quit the game "four in a row"
624 case KCD_RIGHT: //quit the game "four in a row"
625 TRACE_EVENT ("quit four_in_a_row");
626 dspl_ClearAll(); //clear mobile screen
627 four_in_a_row_destroy (win); //destroy win-handler
628 break;
629
630 case KCD_MNULEFT:
631 case KCD_1:
632 if(winner EQ '0'){ //while nobody has won....
633 TRACE_EVENT ("KCD_1");
634 if(column > 0)
635 { //cursor must be greater than 0
636 column=column-1;
637 }
638 winShow(data->win);
639 }
640 break;
641 case KCD_MNUSELECT:
642 case KCD_2:
643 if(winner EQ '0'){ //while nobody has won....
644 TRACE_EVENT ("KCD_2");
645 drop_stone(data); //drop stone
646 }
647 winShow(data->win);
648 break;
649 case KCD_MNURIGHT:
650 case KCD_3:
651 if(winner EQ '0'){ //while nobody has won....
652 TRACE_EVENT ("KCD_3");
653 if(column<MAX_X_BOARD-1 ){ //cursor must be less than 50
654 column=column+1;
655 }
656 winShow(data->win);
657 }
658 break;
659 case KCD_LEFT:
660 if(Game_Result == TRUE)
661 {
662 Game_Result = FALSE;
663 four_in_a_row_destroy(win); //destroy win-handler
664 four_in_a_row_start(win,0);
665 }
666 else
667 Game_Info(win);
668 break;
669 }
670 return MFW_EVENT_CONSUMED;
671 }
672
673 /*******************************************************************************
674
675 $Function: four_in_a_row_aktivate
676
677 $Description: Starts the game function on user selection
678
679 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise
680 MFW_EVENT_PASSED
681
682 $Arguments: menu, menu item
683
684 *******************************************************************************/
685 int four_in_a_row_aktivate(MfwMnu* m, MfwMnuItem* i)
686 {
687
688 T_MFW_HND parent = mfwParent( mfw_header());
689 TRACE_EVENT("four_in_a_row_aktivate()");
690 four_in_a_row_start(parent,0);
691 return MFW_EVENT_CONSUMED;
692 }
693
694 /*******************************************************************************
695
696 $Function: drop_stone
697
698 $Description: decide whether a stone can be droped and where it can be droped
699
700 $Returns:
701
702 $Arguments: T_four_in_a_row
703
704 *******************************************************************************/
705 void drop_stone(T_four_in_a_row *data)
706 {
707 int drop_position; //position (y in current board column) where to drop the stone
708
709 TRACE_EVENT("drop_stone()");
710 request_stone=0; //white is on turn
711 drop_position=check_column(data,request_stone); //set the drop position for the white stone in the current white, board column
712 if(drop_position>=0){ //if the current column is not filled up set stone
713 data->board_array[drop_position][column]='W'; //white is first and set a 'W' in the virtual board for a white stone
714 check_for_winner(data,drop_position); //check whether the last move(white) was a win-move...
715 if(winner EQ '0'){ //...if not, then the mobile(black) is on turn
716 drop_position=mobile_thinking(data); //set the drop position for the black stone in the current black, board column
717 data->board_array[drop_position][column_black]='B'; //set a 'B' for in the virtual board for a black stone
718 check_for_winner(data,drop_position); //check whether the last move(black) was a win-move...
719 }
720 }
721 }
722
723 /*******************************************************************************
724
725 $Function: check_for_winner
726
727 $Description: checks the current drop position for a win-position
728
729 $Returns:
730
731 $Arguments: T_four_in_a_row
732
733 *******************************************************************************/
734 void check_for_winner(T_four_in_a_row *data, int check_out_position)
735 {
736 int check_with_this_color; //set the color to check for
737 int color_regulator; //helps to switch between both colors
738 int check_this_column; //declares the column to check for
739
740 TRACE_EVENT("check_for_winner()");
741 if(data==NULL || check_out_position<0 || check_out_position>=MAX_Y_BOARD)
742 {
743 TRACE_ERROR("check_for_winner() invalid parameters");
744 return;
745 }
746 color_regulator=0; //at first, use white to check for
747 winner='0'; //at first we don't know who wins, so nobody is set as winner
748 while(color_regulator<2){ //while checking for white(0) and black(1) is not ready....
749 if(color_regulator EQ 0){ //if color_regulator is 0, the board will be checked for white stones ('W')
750 check_with_this_color='W';
751 }else{ //if color_regulator is 1, the board will be checked for black stones ('B')
752 check_with_this_color='B';
753 }
754
755 if(request_stone EQ 0){ //if the board will be checked for white, use column as the current column
756 check_this_column=column;
757 }else{ //if the board will be checked for black, use column_black as the current column
758 check_this_column=column_black;
759 }
760 if(check_this_column<0 || check_this_column>=MAX_X_BOARD)
761 {
762 TRACE_ERROR("check_for_winner() invalid index check_this_column");
763 break;
764 }
765 /*Begin with the checks, the mobile checks for vertical, horizontal and diagonal possibilities*/
766 //check row
767 if(check_this_column>=3 && check_this_column<=10 &&
768 data->board_array[check_out_position][check_this_column-3] EQ check_with_this_color &&
769 data->board_array[check_out_position][check_this_column-2] EQ check_with_this_color &&
770 data->board_array[check_out_position][check_this_column-1] EQ check_with_this_color &&
771 data->board_array[check_out_position][check_this_column] EQ check_with_this_color){
772 winner=check_with_this_color; //set the current color to check for as the winner
773 break;
774 }else if(check_this_column>=2 && check_this_column<=9 &&
775 data->board_array[check_out_position][check_this_column-1] EQ check_with_this_color &&
776 data->board_array[check_out_position][check_this_column-2] EQ check_with_this_color &&
777 data->board_array[check_out_position][check_this_column+1] EQ check_with_this_color &&
778 data->board_array[check_out_position][check_this_column] EQ check_with_this_color){
779 winner=check_with_this_color; //set the current color to check for as the winner
780 break;
781 }else if(check_this_column>=0 && check_this_column<=7 &&
782 data->board_array[check_out_position][check_this_column+1] EQ check_with_this_color &&
783 data->board_array[check_out_position][check_this_column+2] EQ check_with_this_color &&
784 data->board_array[check_out_position][check_this_column+3] EQ check_with_this_color &&
785 data->board_array[check_out_position][check_this_column] EQ check_with_this_color){
786 winner=check_with_this_color; //set the current color to check for as the winner
787 break;
788 }else if(check_this_column>=1 && check_this_column<=8 &&
789 data->board_array[check_out_position][check_this_column-1] EQ check_with_this_color &&
790 data->board_array[check_out_position][check_this_column+1] EQ check_with_this_color &&
791 data->board_array[check_out_position][check_this_column+2] EQ check_with_this_color &&
792 data->board_array[check_out_position][check_this_column] EQ check_with_this_color){
793 winner=check_with_this_color; //set the current color to check for as the winner
794 break;
795 //check column
796 }else if(check_out_position<=4 &&
797 data->board_array[check_out_position+1][check_this_column] EQ check_with_this_color &&
798 data->board_array[check_out_position+2][check_this_column] EQ check_with_this_color &&
799 data->board_array[check_out_position+3][check_this_column] EQ check_with_this_color &&
800 data->board_array[check_out_position][check_this_column] EQ check_with_this_color){
801 winner=check_with_this_color; //set the current color to check for as the winner
802 break;
803 //check diagonal
804 }else if(check_out_position<=4 && check_this_column>=3 && check_this_column<=10 &&
805 data->board_array[check_out_position+1][check_this_column-1] EQ check_with_this_color &&
806 data->board_array[check_out_position+2][check_this_column-2] EQ check_with_this_color &&
807 data->board_array[check_out_position+3][check_this_column-3] EQ check_with_this_color &&
808 data->board_array[check_out_position][check_this_column] EQ check_with_this_color){
809 winner=check_with_this_color; //set the current color to check for as the winner
810 break;
811 }else if(check_out_position<=4 && check_this_column>=0 && check_this_column<=7 &&
812 data->board_array[check_out_position+1][check_this_column+1] EQ check_with_this_color &&
813 data->board_array[check_out_position+2][check_this_column+2] EQ check_with_this_color &&
814 data->board_array[check_out_position+3][check_this_column+3] EQ check_with_this_color &&
815 data->board_array[check_out_position][check_this_column] EQ check_with_this_color){
816 winner=check_with_this_color; //set the current color to check for as the winner
817 break;
818 }else if(check_out_position>=3 && check_this_column>=0 && check_this_column<=7 &&
819 data->board_array[check_out_position-1][check_this_column+1] EQ check_with_this_color &&
820 data->board_array[check_out_position-2][check_this_column+2] EQ check_with_this_color &&
821 data->board_array[check_out_position-3][check_this_column+3] EQ check_with_this_color &&
822 data->board_array[check_out_position][check_this_column] EQ check_with_this_color){
823 winner=check_with_this_color; //set the current color to check for as the winner
824 break;
825 }else if(check_out_position>=3 && check_this_column>=3 && check_this_column<=10 &&
826 data->board_array[check_out_position-1][check_this_column-1] EQ check_with_this_color &&
827 data->board_array[check_out_position-2][check_this_column-2] EQ check_with_this_color &&
828 data->board_array[check_out_position-3][check_this_column-3] EQ check_with_this_color &&
829 data->board_array[check_out_position][check_this_column] EQ check_with_this_color){
830 winner=check_with_this_color; //set the current color to check for as the winner
831 break;
832 }else if(check_out_position<=6 && check_out_position>=2 && check_this_column>=1 && check_this_column<=8 &&
833 data->board_array[check_out_position+1][check_this_column-1] EQ check_with_this_color &&
834 data->board_array[check_out_position-1][check_this_column+1] EQ check_with_this_color &&
835 data->board_array[check_out_position-2][check_this_column+2] EQ check_with_this_color &&
836 data->board_array[check_out_position][check_this_column] EQ check_with_this_color){
837 winner=check_with_this_color; //set the current color to check for as the winner
838 break;
839 }else if(check_out_position<=5 && check_out_position>=1 && check_this_column>=2 && check_this_column<=9 &&
840 data->board_array[check_out_position+1][check_this_column-1] EQ check_with_this_color &&
841 data->board_array[check_out_position+2][check_this_column-2] EQ check_with_this_color &&
842 data->board_array[check_out_position-1][check_this_column+1] EQ check_with_this_color &&
843 data->board_array[check_out_position][check_this_column] EQ check_with_this_color){
844 winner=check_with_this_color; //set the current color to check for as the winner
845 break;
846 }else if(check_out_position<=5 && check_out_position>=1 && check_this_column>=1 && check_this_column<=8 &&
847 data->board_array[check_out_position-1][check_this_column-1] EQ check_with_this_color &&
848 data->board_array[check_out_position+1][check_this_column+1] EQ check_with_this_color &&
849 data->board_array[check_out_position+2][check_this_column+2] EQ check_with_this_color &&
850 data->board_array[check_out_position][check_this_column] EQ check_with_this_color){
851 winner=check_with_this_color; //set the current color to check for as the winner
852 break;
853 }else if(check_out_position>=2 && check_out_position<=6 && check_this_column>=2 && check_this_column<=9 &&
854 data->board_array[check_out_position-1][check_this_column-1] EQ check_with_this_color &&
855 data->board_array[check_out_position-2][check_this_column-2] EQ check_with_this_color &&
856 data->board_array[check_out_position+1][check_this_column+1] EQ check_with_this_color &&
857 data->board_array[check_out_position][check_this_column] EQ check_with_this_color){
858 winner=check_with_this_color; //set the current color to check for as the winner
859 break;
860 }else{
861 winner='0'; //no win-moves found, so nobody is the winner and the game goes on
862 }
863 color_regulator++; //set the check color one up (to black)
864 }
865 }
866 /*******************************************************************************
867
868 $Function: check_column
869
870 $Description: checks for already set stones
871
872 $Returns: int unused_position
873
874 $Arguments: T_four_in_a_row
875
876 *******************************************************************************/
877 int check_column(T_four_in_a_row *data, int where_from)
878 {
879 int unused_position; //is for a free drop position
880 int column_for_check; //column (vertical board line) to check for
881
882 if(where_from EQ 0){ //is the current game color(player) 0 then use column
883 column_for_check=column;
884 }else{ //is the current game color(player) 1 then use column_black
885 column_for_check=column_black;
886 }
887 unused_position=-9999;
888 for(y_runer=0;y_runer<MAX_Y_BOARD;y_runer++){ //test all vertical fields whether they are empty('0') or not
889 if(data->board_array[y_runer][column_for_check] EQ '0'){
890 unused_position=y_runer; //.this field is empty, so it is a unused position
891 }
892 }
893 return unused_position; //return the unused position
894 }
895
896
897 /*******************************************************************************
898
899 $Function: mobile_thinking
900
901 $Description: mobile moves
902
903 $Returns: drop position of black stone (drop_me)
904
905 $Arguments: T_four_in_a_row
906
907 *******************************************************************************/
908 int mobile_thinking(T_four_in_a_row *data)
909 {
910 int position_score[11]; //this array takes the scoring values of each column in the game board
911 int drop_position; //drop position for stone
912 int drop_me; //buffer value
913 int scores[4]; //this array keeps the scores for row, column and diagonals
914 int add_random_score;
915
916 TRACE_EVENT("mobile_thinking()");
917
918 request_stone=1; //black is
919 //check for good spots to drop the black stone
920 for(x_runer=0;x_runer<MAX_X_BOARD;x_runer++){
921 //found the possible drop position
922 column_black=x_runer; //set the x_runer to the current column (column_black)
923 drop_position=check_column(data,request_stone); //check for possible drop positions
924 if(drop_position>=0){ //if there is a possible drop position.....
925 //check the scoring of the current point
926 add_random_score=random_scoring();
927 data->board_array[drop_position][x_runer]='B'; //set a test black stone
928 scores[0]=check_line(data,x_runer,drop_position,1,0,0); //scores row
929 scores[1]=check_line(data,x_runer,drop_position,1,1,0); //scores diagonal right-up/left-down
930 scores[2]=check_line(data,x_runer,drop_position,1,-1,0); //scores diagonal left-up/right-down
931 scores[3]=check_line(data,x_runer,drop_position,0,1,0); //scores down(column)
932 position_score[x_runer]=scores[0]+scores[1]+scores[2]+scores[3]; //count all scores together to one total score
933 if(drop_position-1 >=0){ //Is it possible to set a future stone here? If Yes go on...
934 data->board_array[drop_position-1][x_runer]='W'; //set a test white stone for a possible next opponent move
935 scores[0]=check_line(data,x_runer,drop_position-1,1,0,1); //scores row
936 scores[1]=check_line(data,x_runer,drop_position-1,1,1,1); //scores diagonal right-up/left-down
937 scores[2]=check_line(data,x_runer,drop_position-1,1,-1,1); //scores diagonal left-up/right-down
938 scores[3]=check_line(data,x_runer,drop_position-1,0,1,1); //scores down(column)
939 position_score[x_runer]=position_score[x_runer]-scores[0]-scores[1]-scores[2]-scores[3]+add_random_score; //substraction of the future score from the normal score
940 data->board_array[drop_position-1][x_runer]='0'; //remove test white stone
941 }
942 data->board_array[drop_position][x_runer]='0'; //remove test black stone
943 }else{ //if there is no possible drop position set the score to -1
944 position_score[x_runer]=-9999;
945 }
946 }
947
948 drop_me=-9999; //buffer is set to absolutely minus
949 column_black=-9999; //position of black cursor is left outer side of board
950 for(x_runer=0;x_runer<MAX_X_BOARD;x_runer++){ //goes through the scoring array to find the highest score
951 if(position_score[x_runer]>drop_me){
952 drop_me=position_score[x_runer];
953 column_black=x_runer; //set the x_runer to the current column(column_black)
954 drop_position=check_column(data,request_stone); //this is the best drop position for the mobile
955 }
956 }
957 if(column_black EQ -9999){ //if the column is -1, then the game board is filled up and nobody has won
958 TRACE_EVENT("Board Full!!!");
959 winner='N'; //set winner to nobody (N)
960 }
961 return drop_position; //return the mobile drop position
962 }
963
964 /*******************************************************************************
965
966 $Function: check_line
967
968 $Description: set score points for the mobile, so the mobile knows where to set the next stone
969
970 $Returns: total_score
971
972 $Arguments: T_four_in_a_row, x_value, drop_position, dx, dy, where_from
973
974 *******************************************************************************/
975 int check_line(T_four_in_a_row *data, int x_value, int y_value, int dx, int dy, BOOL where_from)
976 {
977 int lSc,nSc,oSc,total_score,sx,sy,i,j;
978 int pl_nSc; //no of empty squares that have a man under them (i.e. we/opponent can use next shot)
979 total_score=0;
980 for (i=0;i<4;i++){
981 sx = x_value-i*dx;
982 sy = y_value-i*dy;
983 lSc=0;
984 nSc=0; pl_nSc=0;
985 oSc=0;
986 for (j=0;j<4;j++){
987 if ((sx<0) || (sx>=MAX_X_BOARD) ||(sy<0) || (sy>=MAX_Y_BOARD)){ /*a0393213 lint warnings removal - 'Possible access of out-of-bounds pointer'*/
988 lSc = -1;
989 }else if (lSc>=0){
990 if(where_from EQ 0){
991 if (data->board_array[sy][sx] EQ 'B'){
992 lSc++;
993 }else if (data->board_array[sy][sx] EQ '0'){
994 nSc++;
995 if ((sy EQ (MAX_Y_BOARD-1)) || (data->board_array[sy+1][sx] NEQ '0')) /*a0393213 lint warnings removal - 'Possible access of out-of-bounds pointer'*/
996 pl_nSc++;
997 }else if (data->board_array[sy][sx] EQ 'W'){
998 oSc++;
999
1000 }else //edge of board found
1001 lSc=-1;
1002 sx = sx+dx;
1003 sy = sy+dy;
1004 }else{
1005 if (data->board_array[sy][sx] EQ 'W'){
1006 lSc++;
1007 }else if (data->board_array[sy][sx] EQ '0'){
1008 nSc++;
1009 if ((sy EQ (MAX_Y_BOARD-1)) || (data->board_array[sy+1][sx] NEQ '0')) /*a0393213 lint warnings removal - 'Possible access of out-of-bounds pointer'*/
1010 pl_nSc++;
1011 }else if (data->board_array[sy][sx] EQ 'B'){
1012 oSc++;
1013
1014 }else //edge of board found
1015 lSc=-1;
1016 sx = sx+dx;
1017 sy = sy+dy;
1018 }
1019 }
1020 }
1021 if (lSc >= 0){
1022 if (lSc EQ 4){
1023 return(9999);//got 4 in a row.
1024 }else if (oSc EQ 3) //and ISc==1
1025 {
1026 // 3 opp men - good spot!
1027 if(where_from EQ 0){
1028 total_score = total_score + 1000; //this is for the normal, current position score
1029 }else{
1030 total_score = -total_score - 1000; //this is for the possible future score, it must be minus, because it will be substracted from normal score
1031 }
1032 }else if ((lSc EQ 3) && (nSc EQ 1)){
1033 //playing here will form 3 in a row and a blank - good spot
1034 if (pl_nSc EQ 0) //can't reach the 4th position
1035 total_score = total_score + 75;
1036 else
1037 total_score = total_score + 125;//better if we can reach 4th position
1038 }else if ((oSc EQ 2) && (nSc EQ 1)){
1039 // 2 opp men + 1 blank- good spot!
1040 if (pl_nSc EQ 0) //can't reach the 4th position-not too bad
1041 total_score = total_score + 50;
1042 else
1043 total_score = total_score + 200;//can get to both positions - have to block.
1044 }else if ((lSc EQ 2) && (nSc EQ 2)){
1045 // 2 in a row and 2 blanks - OK spot
1046 if (pl_nSc EQ 0) //can't reach the 3rd or 4th position-not too good
1047 total_score = total_score + 20;
1048 else if (pl_nSc EQ 1) //can reach one of the 3rd or 4th position - good
1049 total_score = total_score + 45;
1050 else if (pl_nSc EQ 2) //can reach both 3rd and 4th position - very good
1051 total_score = total_score + 95;
1052 }else if ((lSc EQ 1) && (nSc EQ 3)){
1053 // 1 in a row and 3 blanks - OK spot, better if we can reach the other 3 points.
1054 total_score = total_score + 2*(pl_nSc+1); //pl_nSc=0,1,2 or 3 sc=sc+2,4,6 or 8
1055 }
1056 //else //line is neither good nor bad.
1057 }
1058 else //line is not valid
1059 total_score = total_score - 1;
1060 }
1061 return(total_score);
1062 }
1063 /*******************************************************************************
1064
1065 $Function: check_line
1066
1067 $Description: generates a random number to add on the field scores
1068
1069 $Returns: random_score_result
1070
1071 $Arguments:
1072
1073 *******************************************************************************/
1074 int random_scoring(void)
1075 {
1076 return(rand()%100);
1077 }
1078
1079
1080
1081 #define MAX_TET_X 11
1082 #define MAX_TET_Y 20
1083
1084 typedef struct
1085 {
1086
1087 T_MMI_CONTROL mmi_control; // common control parameter
1088 T_MFW_HND win;
1089 T_MFW_HND hKbd;
1090 T_MFW_HND menu;
1091 T_MFW_HND parent_win;
1092 T_MFW_HND info_tim;
1093
1094 int dropTime;
1095 int maxDropTime;
1096 int timeStep;
1097
1098 int xPos;
1099 int yPos;
1100
1101 int px;
1102 int py;
1103 int shapeId;
1104 char shapeStr[20];
1105 int rotateId;
1106
1107 int score;
1108 int level;
1109 int linesToGo;
1110
1111 int resetSpeed;
1112
1113 int gameOver;
1114
1115 char tetrisScreen[MAX_TET_X][MAX_TET_Y];
1116
1117 } T_TETRIS;
1118
1119
1120 static MfwHnd TetrisCreate(MfwHnd hParentWin);
1121 static void TetrisExecCb (MfwHnd hWin, USHORT uiE, SHORT iValue, void *pParameter);
1122 static int TetrisKbdCb (MfwEvt uiE, MfwKbd *psK);
1123 static int tetris_tim_cb(MfwEvt e, MfwTim *t);
1124 static int TetrisWinCb (MfwEvt uiE, MfwWin *psWin);
1125
1126
1127 #define E_INIT 0x5000
1128 #define E_EXIT 0x5001
1129
1130 void initTetGame(T_TETRIS *data)
1131 {
1132 int x,y;
1133 for (y=0;y<MAX_TET_Y;y++)
1134 {
1135 for (x=0;x<MAX_TET_X;x++)
1136 data->tetrisScreen[x][y]=' ';
1137 data->tetrisScreen[0][y]='#';
1138 data->tetrisScreen[MAX_TET_X-1][y]='#';
1139
1140 }
1141 for (x=0;x<MAX_TET_X;x++)
1142 data->tetrisScreen[x][MAX_TET_Y-1]='#';
1143 }
1144
1145 #define MAX_SHAPE 7
1146 void tetris_getShape(int shapeId, int rotate, char* shapeStr)
1147 {
1148 int j,k;
1149 int index;
1150 const char* tetShape[4*4*MAX_SHAPE] =
1151 { " ", " A ", " B ", " C ", " ", "F ", " G ",
1152 "EEEE", " AA ", " BB ", "CCC ", " DD ", "FFF ", "GGG ",
1153 " ", " A ", " B ", " ", " DD ", " ", " ",
1154 " ", " ", " ", " ", " ", " ", " ",
1155 " E ", " AA ", "BB ", " C ", " ", " FF ", " G ",
1156 " E ", "AA ", " BB ", " CC ", " DD ", " F ", " G ",
1157 " E ", " ", " ", " C ", " DD ", " F ", " GG ",
1158 " E ", " ", " ", " ", " ", " ", " ",
1159 " ", " A ", " B ", " ", " ", " ", " ",
1160 "EEEE", " AA ", " BB ", "CCC ", " DD ", "FFF ", "GGG ",
1161 " ", " A ", " B ", " C ", " DD ", " F ", "G ",
1162 " ", " ", " ", " ", " ", " ", " ",
1163 " E ", " AA ", "BB ", " C ", " ", " F ", "GG ",
1164 " E ", "AA ", " BB ", "CC ", " DD ", " F ", " G ",
1165 " E ", " ", " ", " C ", " DD ", "FF ", " G ",
1166 " E ", " ", " ", " ", " ", " ", " "
1167 };
1168
1169
1170 for (k=0;k<4;k++)
1171 {
1172 index = rotate*4*MAX_SHAPE+k*MAX_SHAPE;
1173 for (j=0;j<4;j++)
1174 shapeStr[j+k*4] = tetShape[index+shapeId][j];
1175 }
1176 }
1177
1178 int tetris_getNextShapeId( void )
1179 {
1180 static int shapeIndex = 0;
1181 shapeIndex = (shapeIndex+1) % MAX_SHAPE;
1182 return (shapeIndex);
1183 }
1184
1185
1186
1187 void tetris_getNextShape(T_TETRIS *data)
1188 {
1189 data->shapeId = tetris_getNextShapeId( );
1190 data->rotateId = 0;
1191 tetris_getShape(data->shapeId, data->rotateId, data->shapeStr);
1192 data->px = (MAX_TET_X-2)/2;
1193 data->py = 0;
1194 }
1195
1196 void tetris_getNextLevel(T_TETRIS *data)
1197 {
1198 initTetGame(data);
1199 tetris_getNextShape(data);
1200 data->level = data->level+1;
1201 data->linesToGo = 5*(data->level+1);
1202 data->resetSpeed = 0;
1203 data->maxDropTime = (120-data->level*5);
1204 }
1205
1206 void initTetrisData( T_TETRIS *data )
1207 {
1208 data->level = 0;
1209 data->score = 0;
1210 data->gameOver = 0;
1211 tetris_getNextLevel(data);
1212 }
1213
1214 void dspl_FillRect( int x1, int y1, int sx, int sy)
1215 {
1216 dspl_DrawFilledBgdRect(x1,y1,x1+sx,y1+sy);
1217 }
1218
1219 void tetris_drawScreen( int allScreen, T_TETRIS *data)
1220 {
1221 int x1,y1,x2,y2;
1222 int bCol;
1223 int xOfs =5;
1224 int yOfs=10;
1225 int xOfs2=30;
1226 int yOfs2=10;
1227 int sx,sy;
1228 int px,py;
1229 // U32 oldfCol=0; // RAVI
1230 // U32 oldbCol=0; // RAVI
1231 int x = data->px;
1232 int y = data->py;
1233
1234 // char dbg[80]; // RAVI
1235
1236
1237 #ifdef LSCREEN
1238 //Calculate size based on the screen properties
1239 sx = (SCREEN_SIZE_X-xOfs-xOfs2)/MAX_TET_X;
1240 sy = (SCREEN_SIZE_Y-yOfs-yOfs2-Mmi_layout_softkeyHeight())/MAX_TET_Y;
1241 #else
1242 //Screen is very small - ensure shapes are as large as possible
1243 sy = SCREEN_SIZE_Y/MAX_TET_Y;
1244 sx = SCREEN_SIZE_X/MAX_TET_X;
1245 if (sx >sy+1)
1246 sx = sy+1;
1247 xOfs = 5;
1248 xOfs2 = SCREEN_SIZE_X - (sx*MAX_TET_X+xOfs);
1249 yOfs = 0;
1250 yOfs2 = SCREEN_SIZE_Y - (sy*MAX_TET_Y+xOfs);
1251 #endif
1252 //allScreen= 1;
1253
1254 resources_setColour(COLOUR_GAME);
1255
1256 if (allScreen)
1257 { //redraw everything
1258 x1 = 0;
1259 y1 = 0;
1260 x2 = MAX_TET_X;
1261 y2 = MAX_TET_Y;
1262
1263 }
1264 else //just draw+1 box around current man
1265 {
1266 x1 = x-1;
1267 y1 = y-1;
1268 x2 = x+5;
1269 y2 = y+4;
1270 if (x1<1)x1=1;
1271 if (y1<0)y1=0;
1272 if (x2>MAX_TET_X-1) x2=MAX_TET_X-1;
1273 if (y2>MAX_TET_Y-1) y2=MAX_TET_Y-1;
1274 }
1275
1276 #ifndef COLOURDISPLAY
1277 dspl_Clear (xOfs+x1*sx,yOfs+y1*sy,xOfs+x2*sx-1,yOfs+y2*sy-1);
1278 #endif
1279 for (px = x1;px<x2;px++)
1280 {
1281 for (py = y1;py<y2;py++)
1282 {
1283 char boardChr = data->tetrisScreen[px][py];
1284 if ((px >= x ) && (px < x+4) &&
1285 (py >= y ) && (py < y+4))
1286 {
1287 int shapeX,shapeY;
1288 shapeX = px-x;
1289 shapeY = py-y;
1290 if (data->shapeStr[shapeX+shapeY*4] != ' ')
1291 boardChr = data->shapeStr[shapeX+shapeY*4];
1292 }
1293 #ifdef COLOURDISPLAY
1294 switch (boardChr)
1295 {
1296 case '#': bCol = 0x00FFFFFF; break;
1297 case ' ': bCol = 0x00404040; break;
1298 case 'A': bCol = 0x000000FF; break;
1299 case 'B': bCol = 0x0000FF00; break;
1300 case 'C': bCol = 0x00FF0000; break;
1301 case 'D': bCol = 0x0000FFFF; break;
1302 case 'E': bCol = 0x00FF00FF; break;
1303 case 'F': bCol = 0x00FFFF00; break;
1304 default: bCol = 0x00FFFFFF; break;
1305 }
1306 dspl_SetBgdColour(bCol);
1307 dspl_FillRect(xOfs+px*sx,yOfs+py*sy,sx,sy);
1308 // dspl_SetFgdColour(0x00802040);
1309 if (boardChr != ' ')
1310 dspl_DrawRect (xOfs+px*sx,yOfs+py*sy,xOfs+px*sx+sx-1,yOfs+py*sy+sy-1);
1311 #else
1312 if (boardChr != ' ')
1313 dspl_DrawRect (xOfs+px*sx,yOfs+py*sy,xOfs+px*sx+sx-1,yOfs+py*sy+sy-1);
1314 #endif
1315 }
1316 }
1317 if (data->gameOver)
1318 {
1319 int oldfCol = dspl_SetFgdColour(0x00FFFF00);
1320 dspl_SetBgdColour(0x008000FF);
1321 dspl_FillRect(xOfs+sx*3-5,yOfs+sy*3-5, xOfs+sx*3+5+6*4,yOfs+sy*3+5+18);
1322 dspl_TextOut(xOfs+sx*3,yOfs+sy*3, 0, "GAME");
1323 dspl_TextOut(xOfs+sx*3,yOfs+sy*3+Mmi_layout_line_height()+4, 0, "OVER");
1324 dspl_SetFgdColour(oldfCol);
1325
1326 }
1327 resources_restoreColour();
1328 }
1329
1330
1331
1332 int tetris_addShapeToScreen(T_TETRIS *data)
1333 {
1334 int x,y;
1335 for (x=0;x<4;x++)
1336 for (y=0;y<4;y++)
1337 if (data->shapeStr[x+y*4] != ' ')
1338 {
1339 if (data->tetrisScreen[data->px+x][data->py+y]!= ' ')
1340 return(1);
1341 else
1342 data->tetrisScreen[data->px+x][data->py+y] = data->shapeStr[x+y*4];
1343 }
1344 return(0);
1345
1346 }
1347
1348 int tetris_testForCompleteLines( T_TETRIS *data )
1349 {
1350 int nLines=0;
1351 int x,y;
1352 int blanks;
1353 for (y=MAX_TET_Y-2;y>0;y--)
1354 {
1355 blanks = 0;
1356
1357 for (x=1;x<MAX_TET_X-1;x++)
1358 {
1359 if (data->tetrisScreen[x][y] == ' ')
1360 blanks++;
1361 if (nLines >0)
1362 data->tetrisScreen[x][y+nLines] = data->tetrisScreen[x][y];
1363 }
1364 if (blanks==0)
1365 nLines++;
1366
1367 }
1368 return (nLines);
1369 }
1370
1371
1372 void tetris_testGameOver( T_TETRIS *data )
1373 {
1374 int linesComplete;
1375
1376 data->gameOver = tetris_addShapeToScreen(data);
1377 if (!data->gameOver)
1378 {
1379
1380 linesComplete = tetris_testForCompleteLines(data);
1381 if (linesComplete >0)
1382 {
1383 data->score = data->score + linesComplete*linesComplete;
1384 data->linesToGo = data->linesToGo - linesComplete;
1385 if (data->linesToGo <0)
1386 tetris_getNextLevel(data);
1387 }
1388 tetris_getNextShape(data);
1389 }
1390 }
1391
1392
1393
1394
1395
1396 void tetris_destroy (T_MFW_HND own_window)
1397 {
1398 T_MFW_WIN * win = ((T_MFW_HDR *)own_window)->data;
1399 T_TETRIS * data = (T_TETRIS *)win->user;
1400
1401 TRACE_EVENT ("tetris_destroy()");
1402
1403 if (own_window == NULL)
1404 {
1405 TRACE_EVENT ("Error :- Called with NULL Pointer");
1406 return;
1407 }
1408
1409 if (data)
1410 {
1411 /*
1412 * Exit ICON & KEYBOARD Handle
1413 */
1414 kbdDelete (data->hKbd);
1415 timDelete(data->info_tim);
1416 /*
1417 * Delete WIN Handler
1418 */
1419 winDelete (data->win);
1420 /*
1421 * Free Memory
1422 */
1423 FREE_MEMORY ((void *)data, sizeof (T_TETRIS));
1424 }
1425 }
1426
1427
1428
1429 int MmiTetrisStart(void )
1430 {
1431 MfwHnd hWin;
1432
1433 MfwHnd hParentWin = mfwParent(mfwHeader());
1434
1435 TRACE_FUNCTION ("TetrisStart()");
1436
1437 hWin = TetrisCreate (hParentWin);
1438
1439 if (hWin NEQ NULL)
1440 {
1441 SEND_EVENT (hWin, E_INIT, NULL, NULL);
1442 }
1443
1444 return 1;
1445 }
1446
1447 void initTetrisData( T_TETRIS *data );
1448 static MfwHnd TetrisCreate(MfwHnd hParentWin)
1449 {
1450 T_TETRIS *psData = (T_TETRIS *)ALLOC_MEMORY (sizeof( T_TETRIS));
1451 MfwWin *psWin;
1452 MfwWinAttr *win_attr;
1453
1454 TRACE_FUNCTION ("TetrisCreate()");
1455
1456 if (psData == NULL)
1457 {
1458 TRACE_EVENT ("ALLOC_MEMORY() failed");
1459 return NULL;
1460 }
1461
1462 win_attr = (MfwWinAttr *) ALLOC_MEMORY (sizeof(MfwWinAttr));
1463 if (win_attr)
1464 {
1465 win_attr->win.px = 0;
1466 win_attr->win.py = 0;
1467 win_attr->win.sx = SCREEN_SIZE_X;
1468 win_attr->win.sy = SCREEN_SIZE_Y;
1469 }
1470 psData->win = winCreate (hParentWin, win_attr, E_WIN_VISIBLE, (T_MFW_CB)TetrisWinCb);
1471 if (psData->win == NULL)
1472 {
1473 mfwFree((U8*) win_attr, sizeof(MfwWinAttr));
1474 FREE_MEMORY((void *)psData, sizeof (T_TETRIS));
1475 return NULL;
1476 }
1477 psData->mmi_control.dialog = (T_DIALOG_FUNC)TetrisExecCb;
1478 psData->mmi_control.data = psData;
1479 psData->timeStep = 150;
1480 psData->maxDropTime = 120;
1481 psData->dropTime = psData->maxDropTime;
1482 psWin = ((MfwHdr *)psData->win)->data;
1483 psWin->user = (void *)psData;
1484 psData->parent_win = hParentWin;
1485 initTetrisData( psData );
1486
1487 return psData->win;
1488 }
1489
1490 static int TetrisWinCb (MfwEvt uiE, MfwWin *psWin)
1491 {
1492 T_TETRIS *psData = (T_TETRIS *)psWin->user;
1493
1494 TRACE_FUNCTION ("TetrisWinCb()");
1495
1496 switch (uiE)
1497 {
1498 case MfwWinVisible:
1499 dspl_ResetWindow();
1500 dspl_SetBgdColour(0x000000FF);
1501 dspl_Clear(0,0,SCREEN_SIZE_X-1,SCREEN_SIZE_Y-1 );
1502 tetris_drawScreen( 1, psData);
1503
1504 break;
1505
1506 case MfwWinFocussed:
1507 case MfwWinDelete:
1508 default:
1509 return MFW_EVENT_REJECTED;
1510 }
1511 TRACE_FUNCTION ("TetrisWinCb() - end");
1512 return MFW_EVENT_CONSUMED;
1513 }
1514
1515 static void TetrisExecCb (MfwHnd hWin, USHORT uiE, SHORT iValue, void *pParameter)
1516 {
1517 MfwWin *psWin = ((MfwHdr *) hWin)->data;
1518 T_TETRIS *psData = (T_TETRIS *)psWin->user;
1519
1520 TRACE_FUNCTION ("TetrisExecCb()");
1521
1522 switch (uiE)
1523 {
1524 case E_INIT:
1525
1526 psData->info_tim = timCreate(hWin, psData->timeStep, (MfwCb)tetris_tim_cb);
1527 psData->hKbd = kbdCreate(psData->win, KEY_ALL, (MfwCb)TetrisKbdCb);
1528 timStart(psData->info_tim);
1529
1530 /* */
1531 winShow(hWin);
1532
1533 break;
1534
1535 case E_EXIT:
1536 tetris_destroy(hWin);
1537 break;
1538
1539 default:
1540 return;
1541 }
1542
1543 return;
1544 }
1545
1546
1547 static int tetris_checkPos( T_TETRIS *data, int px, int py, char* shape)
1548 {
1549 int x,y;
1550 for (x=0;x<4;x++)
1551 for (y=0;y<4;y++)
1552 if (shape[x+y*4] != ' ')
1553 {
1554 if (data->tetrisScreen[px+x][py+y]!= ' ')
1555 return(1);
1556 }
1557 return(0);
1558 }
1559
1560 static int tetris_moveDown(T_TETRIS *data,int *px, int *py)
1561 {
1562 int cannotMove;
1563 cannotMove = tetris_checkPos(data,*px,*py+1,data->shapeStr);
1564 if (cannotMove)
1565 return (1);
1566 else
1567 *py = *py+1;
1568 return (0);
1569 }
1570 static int tetris_moveLeft(T_TETRIS *data, int *px, int *py)
1571 {
1572 int cannotMove;
1573 cannotMove = tetris_checkPos(data,*px-1,*py,data->shapeStr);
1574 if (cannotMove)
1575 return (1);
1576 else
1577 *px = *px-1;
1578 return (0);
1579 }
1580 static int tetris_moveRight( T_TETRIS *data, int *px, int *py)
1581 {
1582 int cannotMove;
1583 cannotMove = tetris_checkPos(data,*px+1,*py,data->shapeStr);
1584 if (cannotMove)
1585 return (1);
1586 else
1587 *px = *px+1;
1588 return (0);
1589 }
1590
1591 static int tetris_rotateLeft( T_TETRIS *data, int *px, int *py )
1592 {
1593 int i;
1594 int cannotMove;
1595 char tmpShape[20];
1596 tetris_getShape(data->shapeId,(data->rotateId+1)%4,tmpShape);
1597 cannotMove = tetris_checkPos(data,*px,*py,tmpShape);
1598 if (cannotMove)
1599 return (1);
1600 for (i=0;i<16;i++)
1601 data->shapeStr[i] = tmpShape[i];
1602 data->rotateId = (data->rotateId+1)%4;
1603 return (0);
1604 }
1605
1606 static int tetris_rotateRight( T_TETRIS *data, int *px, int *py )
1607 {
1608 int i;
1609 int cannotMove;
1610 char tmpShape[20];
1611 tetris_getShape(data->shapeId,(data->rotateId+3)%4,tmpShape);
1612 cannotMove = tetris_checkPos(data,*px,*py,tmpShape);
1613 if (cannotMove)
1614 return (1);
1615 for (i=0;i<16;i++)
1616 data->shapeStr[i] = tmpShape[i];
1617 data->rotateId = (data->rotateId+3)%4;
1618 return (0);
1619 }
1620 #define KEY_TET_MOVELEFT KCD_1
1621 #define KEY_TET_MOVERIGHT KCD_3
1622 #define KEY_TET_ROTATELEFT KCD_4
1623 #define KEY_TET_ROTATERIGHT KCD_6
1624 #define KEY_TET_DROPALL KCD_5
1625 #define KEY_TET_DROP KCD_2
1626
1627
1628 static int TetrisKbdCb (MfwEvt uiE, MfwKbd *psK)
1629 {
1630 MfwHnd hWin = mfwParent(mfwHeader());
1631 MfwWin *psWin = ((MfwHdr *)hWin)->data;
1632 T_TETRIS *psData = (T_TETRIS *)psWin->user;
1633 int cannotMove=0;
1634
1635
1636 TRACE_FUNCTION ("TetrisKbdCb()");
1637 /***************************Go-lite Optimization changes Start***********************/
1638 // Aug 16, 2004 REF: CRR 24323 Deepa M.D
1639 TRACE_EVENT_P1 ("Code : %d",(int)psK->code);
1640 /***************************Go-lite Optimization changes Start***********************/
1641
1642
1643 switch(psK->code )
1644 {
1645 case KEY_TET_MOVELEFT:
1646 case KCD_MNULEFT:
1647 tetris_moveLeft(psData,&psData->px,&psData->py);
1648 break;
1649 case KEY_TET_MOVERIGHT:
1650 case KCD_MNURIGHT:
1651 tetris_moveRight(psData,&psData->px,&psData->py);
1652 break;
1653 case KEY_TET_ROTATELEFT:
1654 tetris_rotateLeft(psData,&psData->px,&psData->py);
1655 break;
1656 case KCD_MNUSELECT:
1657 case KEY_TET_ROTATERIGHT:
1658 tetris_rotateRight(psData,&psData->px,&psData->py);
1659 break;
1660 case KEY_TET_DROP:
1661 cannotMove = tetris_moveDown(psData,&psData->px,&psData->py);
1662 if (cannotMove)
1663 tetris_testGameOver( psData );
1664 break;
1665 case KEY_TET_DROPALL:
1666 while(tetris_moveDown(psData,&psData->px,&psData->py) ==0)
1667 { //loop until we hit the bottom
1668
1669 }
1670 cannotMove = 1;
1671 tetris_testGameOver( psData );
1672 break;
1673
1674
1675 case KCD_RIGHT:
1676 SEND_EVENT (hWin, E_EXIT, 0, 0);
1677 return MFW_EVENT_CONSUMED;
1678
1679 default:
1680
1681 return MFW_EVENT_CONSUMED;
1682 }
1683 tetris_drawScreen(cannotMove, psData);
1684
1685 TRACE_FUNCTION ("TetrisKbdCb()-end");
1686 return MFW_EVENT_CONSUMED;
1687 }
1688
1689 static int tetris_tim_cb(MfwEvt e, MfwTim *t)
1690 {
1691 T_MFW_HND win = mfw_parent (mfw_header());
1692 T_MFW_WIN * win_data = ((T_MFW_HDR *)win)->data;
1693 T_TETRIS * data = (T_TETRIS *)win_data->user;
1694 static int nCycles = 0;
1695 int cannotMove;
1696
1697 char bfr[80];
1698 nCycles = nCycles+ data->timeStep;
1699 if (nCycles > 1000)
1700 {
1701 nCycles = nCycles - 1000;
1702 data->maxDropTime = data->maxDropTime-1;
1703 }
1704 TRACE_EVENT("tetris_tim_cb");
1705 data->dropTime = data->dropTime - data->timeStep;
1706 if (data->dropTime < 0)
1707 {
1708 if (data->maxDropTime > 90)
1709 data->dropTime = data->dropTime+75*10;
1710 else if (data->maxDropTime > 60)
1711 data->dropTime = data->dropTime+(60+(data->maxDropTime-60)/2)*10;
1712 else if (data->maxDropTime > 30)
1713 data->dropTime = data->dropTime+data->maxDropTime*10;
1714 else
1715 data->dropTime = data->dropTime+(data->maxDropTime+90)/4*10;
1716
1717 if (data->dropTime < data->timeStep)
1718 data->dropTime = data->timeStep;
1719 else if (data->dropTime < data->timeStep)
1720 data->dropTime = data->timeStep;
1721
1722 resources_setColour(COLOUR_GAME);
1723 sprintf(bfr,"%d ",data->score);
1724 dspl_TextOut(SCREEN_SIZE_X-30 ,10, 0, bfr);
1725 sprintf(bfr,"%d ",data->linesToGo);
1726 dspl_TextOut(SCREEN_SIZE_X-30 ,12+Mmi_layout_line_height(), 0, bfr);
1727 resources_restoreColour();
1728 cannotMove = tetris_moveDown(data,&data->px,&data->py);
1729 tetris_getNextShapeId( );//To randomize it
1730
1731 if (cannotMove)
1732 {
1733 tetris_testGameOver( data );
1734 }
1735 tetris_drawScreen(cannotMove, data);
1736 }
1737
1738 timStart(data->info_tim);
1739 TRACE_EVENT("tetris_tim_cb-end");
1740 return 1;
1741 }
1742
1743 T_MFW_HND Game_Info(T_MFW_HND parent_window)
1744 {
1745 T_MFW_HND win = ShowGame_Information(parent_window);
1746 TRACE_FUNCTION("ShowVerion()");
1747 if (win NEQ NULL)
1748 {
1749 SEND_EVENT (win, SHOWGAMEINFO_INIT, 0, 0);
1750 }
1751
1752 return win;
1753 }
1754
1755 static T_MFW_HND ShowGame_Information(MfwHnd parent_window)
1756 {
1757 tShowInfo* data = (tShowInfo*)ALLOC_MEMORY (sizeof (tShowInfo));
1758 T_MFW_WIN* win;
1759
1760 if (data EQ NULL)
1761 {
1762 return NULL;
1763 }
1764
1765 // Create the window handler
1766 data->win = win_create (parent_window, 0, E_WIN_VISIBLE, NULL);
1767 if (data->win EQ NULL)
1768 {
1769 return NULL;
1770 }
1771
1772 // connect the dialog data to the MFW window
1773 data->mmi_control.dialog = (T_DIALOG_FUNC)ShowGame_DialogCB;
1774 data->mmi_control.data = data;
1775
1776 win = ((T_MFW_HDR *)data->win)->data;
1777 win->user = (void *)data;
1778 data->parent_win = parent_window;
1779
1780 return data->win;
1781 }
1782
1783 static void ShowGame_DialogCB(T_MFW_HND win, USHORT e, SHORT identifier, void *parameter)
1784 {
1785 T_MFW_WIN *win_data = ((T_MFW_HDR *) win)->data;
1786 tShowInfo* data = (tShowInfo*) win_data->user;
1787 /* SPR#1428 - SH - New editor data */
1788 #ifdef NEW_EDITOR
1789 // T_AUI_EDITOR_DATA editor_data; // RAVI
1790 #else /* NEW_EDITOR */
1791 // T_EDITOR_DATA editor_data; // RAVI
1792 #endif /* NEW_EDITOR */
1793
1794 switch (e)
1795 {
1796 case SHOWGAMEINFO_INIT:
1797 {
1798 strcat(data->buffer, info);
1799
1800 ShowGameInfoEditor(win);
1801
1802 /* SPR#1428 - SH - New editor changes */
1803 #ifdef NEW_EDITOR
1804 data->editor_data.Callback = (T_AUI_EDIT_CB)ShowInfoCB;
1805 AUI_edit_Start(win, &(data->editor_data));
1806 #else /* NEW_EDITOR */
1807 data->editor_data.Callback = (T_EDIT_CB)ShowInfoCB;
1808 editor_start(win, &(data->editor_data));
1809 #endif /* NEW_EDITOR */
1810
1811 winShow(data->win);
1812 }
1813 break;
1814
1815 default:
1816 {
1817 TRACE_EVENT("Show Game Info : Unknown Event");
1818 }
1819 break;
1820 }
1821 }
1822
1823 void ShowGameInfoEditor (T_MFW_HND win)
1824 {
1825 T_MFW_WIN *win_data = ((T_MFW_HDR *) win)->data;
1826 tShowInfo* data = (tShowInfo*) win_data->user;
1827
1828 /* SPR#1428 - SH - New editor changes */
1829 #ifdef NEW_EDITOR
1830 AUI_edit_SetDefault(&data->editor_data);
1831 AUI_edit_SetDisplay(&data->editor_data, NULL, COLOUR_EDITOR, EDITOR_FONT);
1832 AUI_edit_SetTextStr(&data->editor_data, TxtSoftBack, TxtNull, TxtNull, NULL);
1833 AUI_edit_SetEvents(&data->editor_data, 0, TRUE, FOREVER, NULL);
1834 AUI_edit_SetBuffer(&data->editor_data, ATB_DCS_ASCII, (UBYTE *)data->buffer, 35);
1835 AUI_edit_SetMode(&data->editor_data, ED_MODE_READONLY, ED_CURSOR_NONE);
1836 #else /* NEW_EDITOR */
1837 editor_attr_init(&((data->editor_data).editor_attr), NULL, edtCurNone, 0, (char*)data->buffer, 35, COLOUR_EDITOR);
1838 editor_data_init(&data->editor_data, NULL, TxtSoftBack, TxtNull, 0, 1, READ_ONLY_MODE, FOREVER);
1839
1840 data->editor_data.hide = FALSE;
1841 data->editor_data.Identifier = 0;
1842 data->editor_data.TextString = NULL;
1843 data->editor_data.destroyEditor = TRUE;
1844 #endif /* NEW_EDITOR */
1845 }
1846
1847 static void ShowInfoCB( T_MFW_HND win, USHORT Identifier,UBYTE reason)
1848 {
1849 T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data;
1850 tShowInfo*data = (tShowInfo*) win_data->user;
1851
1852
1853 TRACE_FUNCTION("ShowVerionCB()");
1854
1855 switch (reason )
1856 {
1857 case INFO_KCD_LEFT:
1858 case INFO_KCD_HUP:
1859 case INFO_KCD_RIGHT:
1860
1861 default:
1862 showGameInfo_destroy(data->win);
1863 break;
1864 }
1865 }
1866
1867 /*******************************************************************************
1868
1869 $Function: showVersion_destroy
1870
1871 $Description: Destroys the editor
1872
1873 $Returns:
1874
1875 $Arguments:
1876
1877 *******************************************************************************/
1878 void showGameInfo_destroy(MfwHnd own_window)
1879 {
1880 T_MFW_WIN * win_data;
1881
1882 tShowInfo* data = NULL;
1883
1884 if (own_window == NULL)
1885 {
1886 TRACE_EVENT ("Error : showGameInfo_destroy called with NULL Pointer");
1887 return;
1888 }
1889
1890
1891 win_data = ((T_MFW_HDR *)own_window)->data;
1892 if (win_data != NULL)
1893 data = (tShowInfo*)win_data->user;
1894
1895 if (data)
1896 {
1897 TRACE_EVENT ("calc_destroy()");
1898
1899 win_delete (data->win);
1900 // Free Memory
1901 FREE_MEMORY ((void *)data, sizeof (tShowInfo));
1902
1903 }
1904 else
1905 {
1906 TRACE_EVENT ("calc_destroy() called twice");
1907 }
1908 }
1909 #endif
1910