comparison src/ui/bmi/mmiGame.c @ 92:c0052fe355d3

src/ui/bmi/*.[ch]: rm trailing white space
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 08 Nov 2020 06:39:16 +0000
parents 67bfe9f274f6
children
comparison
equal deleted inserted replaced
91:c3d28a37caad 92:c0052fe355d3
1 /******************************************************************************* 1 /*******************************************************************************
2 2
3 CONDAT (UK) 3 CONDAT (UK)
4 4
5 ******************************************************************************** 5 ********************************************************************************
6 6
7 This software product is the property of Condat (UK) Ltd and may not be 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. 8 disclosed to any third party without the express permission of the owner.
9 9
10 ******************************************************************************** 10 ********************************************************************************
11 11
12 $Project name: Basic MMI 12 $Project name: Basic MMI
13 $Project code: BMI (6349) 13 $Project code: BMI (6349)
14 $Module: Game 14 $Module: Game
15 $File: Mmigame.c 15 $File: Mmigame.c
16 $Revision: 1.0 16 $Revision: 1.0
17 17
18 $Author: Condat(UK) 18 $Author: Condat(UK)
19 $Date: 03/07/01 19 $Date: 03/07/01
20 20
21 ******************************************************************************** 21 ********************************************************************************
22 22
23 Description 23 Description
24 Aug 16, 2004 REF: CRR 24323 Deepa M.D 24 Aug 16, 2004 REF: CRR 24323 Deepa M.D
25 Bug:Clenup of sprintf used for tracing 25 Bug:Clenup of sprintf used for tracing
26 Fix:Replace the char buf[]; sprintf (buf, "...", ...); TRACE_EVENT (buf); statements by TRACE_EVENT_PX 26 Fix:Replace the char buf[]; sprintf (buf, "...", ...); TRACE_EVENT (buf); statements by TRACE_EVENT_PX
27 27
28 This provides the main game (four in a row) functionality 28 This provides the main game (four in a row) functionality
29 29
30 30
31 ********************************************************************************/ 31 ********************************************************************************/
32 32
33 33
34 /******************************************************************************* 34 /*******************************************************************************
35 35
36 Include files 36 Include files
37 37
38 *******************************************************************************/ 38 *******************************************************************************/
39 39
40 #define ENTITY_MFW 40 #define ENTITY_MFW
41 41
42 /* includes */ 42 /* includes */
117 #include "MmiResources.h" 117 #include "MmiResources.h"
118 118
119 #include "Mmigame.h" 119 #include "Mmigame.h"
120 //GW 14/09/01 Disable game when not required. 120 //GW 14/09/01 Disable game when not required.
121 #ifdef MMIGAME 121 #ifdef MMIGAME
122 void dspl_show_bitmap(int x,int y,t_font_bitmap* current_bitmap,U32 attr ); 122 void dspl_show_bitmap(int x,int y,t_font_bitmap* current_bitmap,U32 attr );
123 /******************************************************************************* 123 /*******************************************************************************
124 124
125 internal data 125 internal data
126 126
127 *******************************************************************************/ 127 *******************************************************************************/
128 128
129 #define FOUR_IN_A_ROW_INIT 121 129 #define FOUR_IN_A_ROW_INIT 121
130 #define MAX_X_BOARD 11 130 #define MAX_X_BOARD 11
131 #define MAX_Y_BOARD 8 131 #define MAX_Y_BOARD 8
137 { 137 {
138 T_MMI_CONTROL mmi_control; // common control parameter 138 T_MMI_CONTROL mmi_control; // common control parameter
139 T_MFW_HND win; 139 T_MFW_HND win;
140 T_MFW_HND kbd; 140 T_MFW_HND kbd;
141 T_MFW_HND menu; 141 T_MFW_HND menu;
142 T_MFW_HND parent_win; 142 T_MFW_HND parent_win;
143 T_MFW_HND info_win; 143 T_MFW_HND info_win;
144 char board_array[MAX_Y_BOARD][MAX_X_BOARD]; //the virtual board 144 char board_array[MAX_Y_BOARD][MAX_X_BOARD]; //the virtual board
145 } T_four_in_a_row; 145 } T_four_in_a_row;
146 146
147 typedef struct 147 typedef struct
261 261
262 /******************************************************************************* 262 /*******************************************************************************
263 263
264 $Function: four_in_a_row_create 264 $Function: four_in_a_row_create
265 265
266 $Description: 266 $Description:
267 267
268 $Returns: 268 $Returns:
269 269
270 $Arguments: 270 $Arguments:
271 271
272 *******************************************************************************/ 272 *******************************************************************************/
273 273
274 274
275 T_MFW_HND four_in_a_row_create (T_MFW_HND parent_window) 275 T_MFW_HND four_in_a_row_create (T_MFW_HND parent_window)
276 { 276 {
277 277
278 T_MFW_WIN * win; 278 T_MFW_WIN * win;
279 279
280 /* 280 /*
281 * This window is dynamic, for that reason the associated data are allocated in the mfw heap 281 * This window is dynamic, for that reason the associated data are allocated in the mfw heap
282 */ 282 */
283 T_four_in_a_row * data = (T_four_in_a_row *)ALLOC_MEMORY (sizeof (T_four_in_a_row)); 283 T_four_in_a_row * data = (T_four_in_a_row *)ALLOC_MEMORY (sizeof (T_four_in_a_row));
284 284
317 for(x_runer=0;x_runer<MAX_X_BOARD;x_runer++){ 317 for(x_runer=0;x_runer<MAX_X_BOARD;x_runer++){
318 data->board_array[y_runer][x_runer] ='0'; 318 data->board_array[y_runer][x_runer] ='0';
319 } 319 }
320 } 320 }
321 winShow(data->win); 321 winShow(data->win);
322 322
323 return data->win; 323 return data->win;
324 } 324 }
325 325
326 /******************************************************************************* 326 /*******************************************************************************
327 327
328 $Function: four_in_a_rowr_destroy 328 $Function: four_in_a_rowr_destroy
329 329
330 $Description: 330 $Description:
331 331
332 $Returns: 332 $Returns:
333 333
334 $Arguments: 334 $Arguments:
335 335
336 *******************************************************************************/ 336 *******************************************************************************/
337 337
338 void four_in_a_row_destroy (T_MFW_HND own_window) 338 void four_in_a_row_destroy (T_MFW_HND own_window)
339 { 339 {
340 T_MFW_WIN * win; 340 T_MFW_WIN * win;
371 /******************************************************************************* 371 /*******************************************************************************
372 372
373 $Function: four_in_a_row_start 373 $Function: four_in_a_row_start
374 374
375 $Description: This function just creates and inits the new dialog 375 $Description: This function just creates and inits the new dialog
376 376
377 $Returns: 377 $Returns:
378 378
379 $Arguments: 379 $Arguments:
380 380
381 *******************************************************************************/ 381 *******************************************************************************/
382 T_MFW_HND four_in_a_row_start (T_MFW_HND win_parent,char *character) 382 T_MFW_HND four_in_a_row_start (T_MFW_HND win_parent,char *character)
383 { 383 {
384 T_MFW_HND win; 384 T_MFW_HND win;
385 /* 385 /*
386 MmiTetrisStart(); 386 MmiTetrisStart();
387 return; 387 return;
388 */ 388 */
389 win = four_in_a_row_create (win_parent); 389 win = four_in_a_row_create (win_parent);
399 399
400 /******************************************************************************* 400 /*******************************************************************************
401 401
402 $Function: four_in_a_row 402 $Function: four_in_a_row
403 403
404 $Description: 404 $Description:
405 405
406 $Returns: 406 $Returns:
407 407
408 $Arguments: 408 $Arguments:
409 409
410 *******************************************************************************/ 410 *******************************************************************************/
411 411
412 412
413 413
414 void four_in_a_row (T_MFW_HND win, USHORT event, SHORT value, void * parameter) 414 void four_in_a_row (T_MFW_HND win, USHORT event, SHORT value, void * parameter)
424 424
425 425
426 switch (event) 426 switch (event)
427 { 427 {
428 case FOUR_IN_A_ROW_INIT: 428 case FOUR_IN_A_ROW_INIT:
429 softKeys_displayId(TxtSearchName,TxtNull,0,COLOUR_IDLE); 429 softKeys_displayId(TxtSearchName,TxtNull,0,COLOUR_IDLE);
430 winShow(data->win); 430 winShow(data->win);
431 break; 431 break;
432 432
433 default: 433 default:
434 return; 434 return;
439 /******************************************************************************* 439 /*******************************************************************************
440 440
441 $Function: four_in_a_row_win_cb 441 $Function: four_in_a_row_win_cb
442 442
443 $Description: win calback function of four in a row 443 $Description: win calback function of four in a row
444 444
445 $Returns: 445 $Returns:
446 446
447 $Arguments: 447 $Arguments:
448 448
449 *******************************************************************************/ 449 *******************************************************************************/
450 450
451 451
452 int four_in_a_row_win_cb (MfwEvt e, MfwWin *w) 452 int four_in_a_row_win_cb (MfwEvt e, MfwWin *w)
453 { 453 {
460 int x_axis; //goes through the horizontal lines 460 int x_axis; //goes through the horizontal lines
461 // int x,y,i,b; // RAVI 461 // int x,y,i,b; // RAVI
462 int displayPosX, temp; 462 int displayPosX, temp;
463 463
464 TRACE_FUNCTION ("four_in_a_row_win_cb()"); 464 TRACE_FUNCTION ("four_in_a_row_win_cb()");
465 465
466 switch (e) 466 switch (e)
467 { 467 {
468 case MfwWinVisible: 468 case MfwWinVisible:
469 #ifdef COLOURDISPLAY 469 #ifdef COLOURDISPLAY
470 whiteStone = &stone_colour; 470 whiteStone = &stone_colour;
471 blackStone = &stone_colour; 471 blackStone = &stone_colour;
472 472
473 #else 473 #else
474 whiteStone = &blackStone_bw; 474 whiteStone = &blackStone_bw;
475 blackStone = &whiteStone_bw; 475 blackStone = &whiteStone_bw;
476 476
477 #endif 477 #endif
478 #ifdef LSCREEN 478 #ifdef LSCREEN
479 manOfsX = GAME_POS_X + 3; 479 manOfsX = GAME_POS_X + 3;
480 manOfsY = GAME_POS_Y + 3; 480 manOfsY = GAME_POS_Y + 3;
481 #else 481 #else
491 TRACE_EVENT("display clear"); 491 TRACE_EVENT("display clear");
492 resources_setColour( COLOUR_GAME ); 492 resources_setColour( COLOUR_GAME );
493 dspl_Clear( 0,0, SCREEN_SIZE_X,SCREEN_SIZE_Y); 493 dspl_Clear( 0,0, SCREEN_SIZE_X,SCREEN_SIZE_Y);
494 #ifdef LSCREEN 494 #ifdef LSCREEN
495 softKeys_displayId(TxtHelp,TxtExit,0,COLOUR_LIST_SUBMENU); 495 softKeys_displayId(TxtHelp,TxtExit,0,COLOUR_LIST_SUBMENU);
496 #endif 496 #endif
497 497
498 resources_setColour( COLOUR_GAME ); 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! 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 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 ); 501 dspl_show_bitmap(column*xScale+xOfs+1,yOfs-yScale, &gameCursor, 0 );
531 } 531 }
532 dspl_SetFgdColour( COL_RB ); 532 dspl_SetFgdColour( COL_RB );
533 dspl_SetBgdColour( COL_RG ); 533 dspl_SetBgdColour( COL_RG );
534 dspl_show_bitmap(GAME_NAMEPOSX1, GAME_NAMEPOSY1, &gameName1, 0 ); 534 dspl_show_bitmap(GAME_NAMEPOSX1, GAME_NAMEPOSY1, &gameName1, 0 );
535 displayPosX = (SCREEN_SIZE_X/2); 535 displayPosX = (SCREEN_SIZE_X/2);
536 temp = strlen((char*)playAgain); 536 temp = strlen((char*)playAgain);
537 //this if-clause is to set the bitmap, for win or lost game 537 //this if-clause is to set the bitmap, for win or lost game
538 if(winner EQ 'W'){ 538 if(winner EQ 'W'){
539 //human player wins, so set win bitmap 539 //human player wins, so set win bitmap
540 #ifdef LSCREEN 540 #ifdef LSCREEN
541 dspl_SetFgdColour( COL_BLK ); 541 dspl_SetFgdColour( COL_BLK );
542 dspl_SetBgdColour( COL_TRANSPARENT ); 542 dspl_SetBgdColour( COL_TRANSPARENT );
543 Game_Result = TRUE; 543 Game_Result = TRUE;
544 softKeys_displayId(TxtYes,TxtNo,0,COLOUR_LIST_SUBMENU); 544 softKeys_displayId(TxtYes,TxtNo,0,COLOUR_LIST_SUBMENU);
545 dspl_TextOut((displayPosX-((temp*CHAR_WIDTH)/2)),170,DSPL_TXTATTR_NORMAL,(char*)playAgain); 545 dspl_TextOut((displayPosX-((temp*CHAR_WIDTH)/2)),170,DSPL_TXTATTR_NORMAL,(char*)playAgain);
546 #endif 546 #endif
547 dspl_SetFgdColour( COL_RB ); 547 dspl_SetFgdColour( COL_RB );
548 dspl_SetBgdColour( COL_GB ); 548 dspl_SetBgdColour( COL_GB );
549 dspl_show_bitmap(GAME_WINPOSX1, GAME_WINPOSY1, &plWin1, 0 ); 549 dspl_show_bitmap(GAME_WINPOSX1, GAME_WINPOSY1, &plWin1, 0 );
550 dspl_show_bitmap(GAME_WINPOSX2, GAME_WINPOSY2, &plWin2, 0 ); 550 dspl_show_bitmap(GAME_WINPOSX2, GAME_WINPOSY2, &plWin2, 0 );
551 } 551 }
552 else 552 else
553 if(winner EQ 'B'){ 553 if(winner EQ 'B'){
554 //human player lost, so set lost bitmap 554 //human player lost, so set lost bitmap
555 #ifdef LSCREEN 555 #ifdef LSCREEN
556 dspl_SetFgdColour( COL_BLK ); 556 dspl_SetFgdColour( COL_BLK );
557 dspl_SetBgdColour( COL_TRANSPARENT ); 557 dspl_SetBgdColour( COL_TRANSPARENT );
558 Game_Result = TRUE; 558 Game_Result = TRUE;
559 softKeys_displayId(TxtYes,TxtNo,0,COLOUR_LIST_SUBMENU); 559 softKeys_displayId(TxtYes,TxtNo,0,COLOUR_LIST_SUBMENU);
560 dspl_TextOut((displayPosX-((temp*CHAR_WIDTH)/2)),170,DSPL_TXTATTR_NORMAL,(char*)playAgain); 560 dspl_TextOut((displayPosX-((temp*CHAR_WIDTH)/2)),170,DSPL_TXTATTR_NORMAL,(char*)playAgain);
561 #endif 561 #endif
562 dspl_SetFgdColour( COL_RB ); 562 dspl_SetFgdColour( COL_RB );
563 dspl_SetBgdColour( COL_GB ); 563 dspl_SetBgdColour( COL_GB );
564 dspl_show_bitmap(GAME_WINPOSX1, GAME_WINPOSY1, &plLost1, 0 ); 564 dspl_show_bitmap(GAME_WINPOSX1, GAME_WINPOSY1, &plLost1, 0 );
565 dspl_show_bitmap(GAME_WINPOSX2, GAME_WINPOSY2, &plLost2, 0 ); 565 dspl_show_bitmap(GAME_WINPOSX2, GAME_WINPOSY2, &plLost2, 0 );
566 } 566 }
567 else 567 else
568 if(winner EQ 'N'){ 568 if(winner EQ 'N'){
569 //board is full, nobody (N) wins 569 //board is full, nobody (N) wins
570 #ifdef LSCREEN 570 #ifdef LSCREEN
571 dspl_SetFgdColour( COL_BLK ); 571 dspl_SetFgdColour( COL_BLK );
572 dspl_SetBgdColour( COL_TRANSPARENT ); 572 dspl_SetBgdColour( COL_TRANSPARENT );
573 Game_Result = TRUE; 573 Game_Result = TRUE;
574 softKeys_displayId(TxtYes,TxtNo,0,COLOUR_LIST_SUBMENU); 574 softKeys_displayId(TxtYes,TxtNo,0,COLOUR_LIST_SUBMENU);
575 dspl_TextOut((displayPosX-((temp*CHAR_WIDTH)/2)),170,DSPL_TXTATTR_NORMAL,(char*)playAgain); 575 dspl_TextOut((displayPosX-((temp*CHAR_WIDTH)/2)),170,DSPL_TXTATTR_NORMAL,(char*)playAgain);
576 #endif 576 #endif
577 577
578 dspl_SetFgdColour( COL_R ); 578 dspl_SetFgdColour( COL_R );
579 dspl_SetBgdColour( COL_G ); 579 dspl_SetBgdColour( COL_G );
580 dspl_show_bitmap(GAME_WINPOSX1, GAME_WINPOSY1, &draw1, 0 ); 580 dspl_show_bitmap(GAME_WINPOSX1, GAME_WINPOSY1, &draw1, 0 );
581 dspl_show_bitmap(GAME_WINPOSX2, GAME_WINPOSY2, &draw2, 0 ); 581 dspl_show_bitmap(GAME_WINPOSX2, GAME_WINPOSY2, &draw2, 0 );
582 } 582 }
599 599
600 /******************************************************************************* 600 /*******************************************************************************
601 601
602 $Function: four_in_a_row_kbd_cb 602 $Function: four_in_a_row_kbd_cb
603 603
604 $Description: 604 $Description:
605 605
606 $Returns: 606 $Returns:
607 607
608 $Arguments: 608 $Arguments:
609 609
610 *******************************************************************************/ 610 *******************************************************************************/
611 611
612 int four_in_a_row_kbd_cb (MfwEvt e, MfwKbd *k) 612 int four_in_a_row_kbd_cb (MfwEvt e, MfwKbd *k)
613 { 613 {
614 614
615 T_MFW_HND win = mfw_parent (mfw_header()); 615 T_MFW_HND win = mfw_parent (mfw_header());
616 T_MFW_WIN * win_data = ((T_MFW_HDR *)win)->data; 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; 617 T_four_in_a_row * data = (T_four_in_a_row *)win_data->user;
618 618
619 TRACE_EVENT ("four_in_a_row_kbd_cb()"); 619 TRACE_EVENT ("four_in_a_row_kbd_cb()");
620 620
621 switch (k->code) 621 switch (k->code)
622 { 622 {
623 case KCD_HUP: //quit the game "four in a row" 623 case KCD_HUP: //quit the game "four in a row"
624 case KCD_RIGHT: //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"); 625 TRACE_EVENT ("quit four_in_a_row");
626 dspl_ClearAll(); //clear mobile screen 626 dspl_ClearAll(); //clear mobile screen
627 four_in_a_row_destroy (win); //destroy win-handler 627 four_in_a_row_destroy (win); //destroy win-handler
628 break; 628 break;
629 629
630 case KCD_MNULEFT: 630 case KCD_MNULEFT:
631 case KCD_1: 631 case KCD_1:
632 if(winner EQ '0'){ //while nobody has won.... 632 if(winner EQ '0'){ //while nobody has won....
658 break; 658 break;
659 case KCD_LEFT: 659 case KCD_LEFT:
660 if(Game_Result == TRUE) 660 if(Game_Result == TRUE)
661 { 661 {
662 Game_Result = FALSE; 662 Game_Result = FALSE;
663 four_in_a_row_destroy(win); //destroy win-handler 663 four_in_a_row_destroy(win); //destroy win-handler
664 four_in_a_row_start(win,0); 664 four_in_a_row_start(win,0);
665 } 665 }
666 else 666 else
667 Game_Info(win); 667 Game_Info(win);
668 break; 668 break;
673 /******************************************************************************* 673 /*******************************************************************************
674 674
675 $Function: four_in_a_row_aktivate 675 $Function: four_in_a_row_aktivate
676 676
677 $Description: Starts the game function on user selection 677 $Description: Starts the game function on user selection
678 678
679 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise 679 $Returns: MFW_EVENT_CONSUMED if event handled, otherwise
680 MFW_EVENT_PASSED 680 MFW_EVENT_PASSED
681 681
682 $Arguments: menu, menu item 682 $Arguments: menu, menu item
683 683
684 *******************************************************************************/ 684 *******************************************************************************/
685 int four_in_a_row_aktivate(MfwMnu* m, MfwMnuItem* i) 685 int four_in_a_row_aktivate(MfwMnu* m, MfwMnuItem* i)
686 { 686 {
687 687
688 T_MFW_HND parent = mfwParent( mfw_header()); 688 T_MFW_HND parent = mfwParent( mfw_header());
689 TRACE_EVENT("four_in_a_row_aktivate()"); 689 TRACE_EVENT("four_in_a_row_aktivate()");
690 four_in_a_row_start(parent,0); 690 four_in_a_row_start(parent,0);
691 return MFW_EVENT_CONSUMED; 691 return MFW_EVENT_CONSUMED;
692 } 692 }
694 /******************************************************************************* 694 /*******************************************************************************
695 695
696 $Function: drop_stone 696 $Function: drop_stone
697 697
698 $Description: decide whether a stone can be droped and where it can be droped 698 $Description: decide whether a stone can be droped and where it can be droped
699 699
700 $Returns: 700 $Returns:
701 701
702 $Arguments: T_four_in_a_row 702 $Arguments: T_four_in_a_row
703 703
704 *******************************************************************************/ 704 *******************************************************************************/
705 void drop_stone(T_four_in_a_row *data) 705 void drop_stone(T_four_in_a_row *data)
706 { 706 {
707 int drop_position; //position (y in current board column) where to drop the stone 707 int drop_position; //position (y in current board column) where to drop the stone
708 708
709 TRACE_EVENT("drop_stone()"); 709 TRACE_EVENT("drop_stone()");
710 request_stone=0; //white is on turn 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 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 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 713 data->board_array[drop_position][column]='W'; //white is first and set a 'W' in the virtual board for a white stone
723 /******************************************************************************* 723 /*******************************************************************************
724 724
725 $Function: check_for_winner 725 $Function: check_for_winner
726 726
727 $Description: checks the current drop position for a win-position 727 $Description: checks the current drop position for a win-position
728 728
729 $Returns: 729 $Returns:
730 730
731 $Arguments: T_four_in_a_row 731 $Arguments: T_four_in_a_row
732 732
733 *******************************************************************************/ 733 *******************************************************************************/
734 void check_for_winner(T_four_in_a_row *data, int check_out_position) 734 void check_for_winner(T_four_in_a_row *data, int check_out_position)
735 { 735 {
736 int check_with_this_color; //set the color to check for 736 int check_with_this_color; //set the color to check for
737 int color_regulator; //helps to switch between both colors 737 int color_regulator; //helps to switch between both colors
749 if(color_regulator EQ 0){ //if color_regulator is 0, the board will be checked for white stones ('W') 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'; 750 check_with_this_color='W';
751 }else{ //if color_regulator is 1, the board will be checked for black stones ('B') 751 }else{ //if color_regulator is 1, the board will be checked for black stones ('B')
752 check_with_this_color='B'; 752 check_with_this_color='B';
753 } 753 }
754 754
755 if(request_stone EQ 0){ //if the board will be checked for white, use column as the current column 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; 756 check_this_column=column;
757 }else{ //if the board will be checked for black, use column_black as the current column 757 }else{ //if the board will be checked for black, use column_black as the current column
758 check_this_column=column_black; 758 check_this_column=column_black;
759 } 759 }
763 break; 763 break;
764 } 764 }
765 /*Begin with the checks, the mobile checks for vertical, horizontal and diagonal possibilities*/ 765 /*Begin with the checks, the mobile checks for vertical, horizontal and diagonal possibilities*/
766 //check row 766 //check row
767 if(check_this_column>=3 && check_this_column<=10 && 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 && 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 && 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 && 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){ 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 772 winner=check_with_this_color; //set the current color to check for as the winner
773 break; 773 break;
774 }else if(check_this_column>=2 && check_this_column<=9 && 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 && 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 && 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 && 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){ 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 779 winner=check_with_this_color; //set the current color to check for as the winner
780 break; 780 break;
781 }else if(check_this_column>=0 && check_this_column<=7 && 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 && 782 data->board_array[check_out_position][check_this_column+1] EQ check_with_this_color &&
866 /******************************************************************************* 866 /*******************************************************************************
867 867
868 $Function: check_column 868 $Function: check_column
869 869
870 $Description: checks for already set stones 870 $Description: checks for already set stones
871 871
872 $Returns: int unused_position 872 $Returns: int unused_position
873 873
874 $Arguments: T_four_in_a_row 874 $Arguments: T_four_in_a_row
875 875
876 *******************************************************************************/ 876 *******************************************************************************/
877 int check_column(T_four_in_a_row *data, int where_from) 877 int check_column(T_four_in_a_row *data, int where_from)
878 { 878 {
879 int unused_position; //is for a free drop position 879 int unused_position; //is for a free drop position
880 int column_for_check; //column (vertical board line) to check for 880 int column_for_check; //column (vertical board line) to check for
881 881
882 if(where_from EQ 0){ //is the current game color(player) 0 then use column 882 if(where_from EQ 0){ //is the current game color(player) 0 then use column
883 column_for_check=column; 883 column_for_check=column;
884 }else{ //is the current game color(player) 1 then use column_black 884 }else{ //is the current game color(player) 1 then use column_black
885 column_for_check=column_black; 885 column_for_check=column_black;
886 } 886 }
887 unused_position=-9999; 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 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'){ 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 890 unused_position=y_runer; //.this field is empty, so it is a unused position
891 } 891 }
892 } 892 }
897 /******************************************************************************* 897 /*******************************************************************************
898 898
899 $Function: mobile_thinking 899 $Function: mobile_thinking
900 900
901 $Description: mobile moves 901 $Description: mobile moves
902 902
903 $Returns: drop position of black stone (drop_me) 903 $Returns: drop position of black stone (drop_me)
904 904
905 $Arguments: T_four_in_a_row 905 $Arguments: T_four_in_a_row
906 906
907 *******************************************************************************/ 907 *******************************************************************************/
908 int mobile_thinking(T_four_in_a_row *data) 908 int mobile_thinking(T_four_in_a_row *data)
909 { 909 {
910 int position_score[11]; //this array takes the scoring values of each column in the game board 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 911 int drop_position; //drop position for stone
922 column_black=x_runer; //set the x_runer to the current column (column_black) 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 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..... 924 if(drop_position>=0){ //if there is a possible drop position.....
925 //check the scoring of the current point 925 //check the scoring of the current point
926 add_random_score=random_scoring(); 926 add_random_score=random_scoring();
927 data->board_array[drop_position][x_runer]='B'; //set a test black stone 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 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 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 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) 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 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... 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 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 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 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 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) 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 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 940 data->board_array[drop_position-1][x_runer]='0'; //remove test white stone
941 } 941 }
942 data->board_array[drop_position][x_runer]='0'; //remove test black stone 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 943 }else{ //if there is no possible drop position set the score to -1
944 position_score[x_runer]=-9999; 944 position_score[x_runer]=-9999;
945 } 945 }
946 } 946 }
947 947
948 drop_me=-9999; //buffer is set to absolutely minus 948 drop_me=-9999; //buffer is set to absolutely minus
949 column_black=-9999; //position of black cursor is left outer side of board 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 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){ 951 if(position_score[x_runer]>drop_me){
952 drop_me=position_score[x_runer]; 952 drop_me=position_score[x_runer];
964 /******************************************************************************* 964 /*******************************************************************************
965 965
966 $Function: check_line 966 $Function: check_line
967 967
968 $Description: set score points for the mobile, so the mobile knows where to set the next stone 968 $Description: set score points for the mobile, so the mobile knows where to set the next stone
969 969
970 $Returns: total_score 970 $Returns: total_score
971 971
972 $Arguments: T_four_in_a_row, x_value, drop_position, dx, dy, where_from 972 $Arguments: T_four_in_a_row, x_value, drop_position, dx, dy, where_from
973 973
974 *******************************************************************************/ 974 *******************************************************************************/
975 int check_line(T_four_in_a_row *data, int x_value, int y_value, int dx, int dy, BOOL where_from) 975 int check_line(T_four_in_a_row *data, int x_value, int y_value, int dx, int dy, BOOL where_from)
976 { 976 {
977 int lSc,nSc,oSc,total_score,sx,sy,i,j; 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) 978 int pl_nSc; //no of empty squares that have a man under them (i.e. we/opponent can use next shot)
985 oSc=0; 985 oSc=0;
986 for (j=0;j<4;j++){ 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'*/ 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; 988 lSc = -1;
989 }else if (lSc>=0){ 989 }else if (lSc>=0){
990 if(where_from EQ 0){ 990 if(where_from EQ 0){
991 if (data->board_array[sy][sx] EQ 'B'){ 991 if (data->board_array[sy][sx] EQ 'B'){
992 lSc++; 992 lSc++;
993 }else if (data->board_array[sy][sx] EQ '0'){ 993 }else if (data->board_array[sy][sx] EQ '0'){
994 nSc++; 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'*/ 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++; 996 pl_nSc++;
997 }else if (data->board_array[sy][sx] EQ 'W'){ 997 }else if (data->board_array[sy][sx] EQ 'W'){
998 oSc++; 998 oSc++;
999 999
1000 }else //edge of board found 1000 }else //edge of board found
1001 lSc=-1; 1001 lSc=-1;
1002 sx = sx+dx; 1002 sx = sx+dx;
1003 sy = sy+dy; 1003 sy = sy+dy;
1004 }else{ 1004 }else{
1005 if (data->board_array[sy][sx] EQ 'W'){ 1005 if (data->board_array[sy][sx] EQ 'W'){
1006 lSc++; 1006 lSc++;
1007 }else if (data->board_array[sy][sx] EQ '0'){ 1007 }else if (data->board_array[sy][sx] EQ '0'){
1008 nSc++; 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'*/ 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++; 1010 pl_nSc++;
1011 }else if (data->board_array[sy][sx] EQ 'B'){ 1011 }else if (data->board_array[sy][sx] EQ 'B'){
1012 oSc++; 1012 oSc++;
1013 1013
1014 }else //edge of board found 1014 }else //edge of board found
1015 lSc=-1; 1015 lSc=-1;
1016 sx = sx+dx; 1016 sx = sx+dx;
1017 sy = sy+dy; 1017 sy = sy+dy;
1018 } 1018 }
1063 /******************************************************************************* 1063 /*******************************************************************************
1064 1064
1065 $Function: check_line 1065 $Function: check_line
1066 1066
1067 $Description: generates a random number to add on the field scores 1067 $Description: generates a random number to add on the field scores
1068 1068
1069 $Returns: random_score_result 1069 $Returns: random_score_result
1070 1070
1071 $Arguments: 1071 $Arguments:
1072 1072
1073 *******************************************************************************/ 1073 *******************************************************************************/
1074 int random_scoring(void) 1074 int random_scoring(void)
1075 { 1075 {
1076 return(rand()%100); 1076 return(rand()%100);
1077 } 1077 }
1086 1086
1087 T_MMI_CONTROL mmi_control; // common control parameter 1087 T_MMI_CONTROL mmi_control; // common control parameter
1088 T_MFW_HND win; 1088 T_MFW_HND win;
1089 T_MFW_HND hKbd; 1089 T_MFW_HND hKbd;
1090 T_MFW_HND menu; 1090 T_MFW_HND menu;
1091 T_MFW_HND parent_win; 1091 T_MFW_HND parent_win;
1092 T_MFW_HND info_tim; 1092 T_MFW_HND info_tim;
1093 1093
1094 int dropTime; 1094 int dropTime;
1095 int maxDropTime; 1095 int maxDropTime;
1096 int timeStep; 1096 int timeStep;
1145 #define MAX_SHAPE 7 1145 #define MAX_SHAPE 7
1146 void tetris_getShape(int shapeId, int rotate, char* shapeStr) 1146 void tetris_getShape(int shapeId, int rotate, char* shapeStr)
1147 { 1147 {
1148 int j,k; 1148 int j,k;
1149 int index; 1149 int index;
1150 const char* tetShape[4*4*MAX_SHAPE] = 1150 const char* tetShape[4*4*MAX_SHAPE] =
1151 { " ", " A ", " B ", " C ", " ", "F ", " G ", 1151 { " ", " A ", " B ", " C ", " ", "F ", " G ",
1152 "EEEE", " AA ", " BB ", "CCC ", " DD ", "FFF ", "GGG ", 1152 "EEEE", " AA ", " BB ", "CCC ", " DD ", "FFF ", "GGG ",
1153 " ", " A ", " B ", " ", " DD ", " ", " ", 1153 " ", " A ", " B ", " ", " DD ", " ", " ",
1154 " ", " ", " ", " ", " ", " ", " ", 1154 " ", " ", " ", " ", " ", " ", " ",
1155 " E ", " AA ", "BB ", " C ", " ", " FF ", " G ", 1155 " E ", " AA ", "BB ", " C ", " ", " FF ", " G ",
1156 " E ", "AA ", " BB ", " CC ", " DD ", " F ", " G ", 1156 " E ", "AA ", " BB ", " CC ", " DD ", " F ", " G ",
1157 " E ", " ", " ", " C ", " DD ", " F ", " GG ", 1157 " E ", " ", " ", " C ", " DD ", " F ", " GG ",
1158 " E ", " ", " ", " ", " ", " ", " ", 1158 " E ", " ", " ", " ", " ", " ", " ",
1159 " ", " A ", " B ", " ", " ", " ", " ", 1159 " ", " A ", " B ", " ", " ", " ", " ",
1160 "EEEE", " AA ", " BB ", "CCC ", " DD ", "FFF ", "GGG ", 1160 "EEEE", " AA ", " BB ", "CCC ", " DD ", "FFF ", "GGG ",
1161 " ", " A ", " B ", " C ", " DD ", " F ", "G ", 1161 " ", " A ", " B ", " C ", " DD ", " F ", "G ",
1162 " ", " ", " ", " ", " ", " ", " ", 1162 " ", " ", " ", " ", " ", " ", " ",
1163 " E ", " AA ", "BB ", " C ", " ", " F ", "GG ", 1163 " E ", " AA ", "BB ", " C ", " ", " F ", "GG ",
1164 " E ", "AA ", " BB ", "CC ", " DD ", " F ", " G ", 1164 " E ", "AA ", " BB ", "CC ", " DD ", " F ", " G ",
1165 " E ", " ", " ", " C ", " DD ", "FF ", " G ", 1165 " E ", " ", " ", " C ", " DD ", "FF ", " G ",
1166 " E ", " ", " ", " ", " ", " ", " " 1166 " E ", " ", " ", " ", " ", " ", " "
1167 }; 1167 };
1168 1168
1169 1169
1170 for (k=0;k<4;k++) 1170 for (k=0;k<4;k++)
1198 initTetGame(data); 1198 initTetGame(data);
1199 tetris_getNextShape(data); 1199 tetris_getNextShape(data);
1200 data->level = data->level+1; 1200 data->level = data->level+1;
1201 data->linesToGo = 5*(data->level+1); 1201 data->linesToGo = 5*(data->level+1);
1202 data->resetSpeed = 0; 1202 data->resetSpeed = 0;
1203 data->maxDropTime = (120-data->level*5); 1203 data->maxDropTime = (120-data->level*5);
1204 } 1204 }
1205 1205
1206 void initTetrisData( T_TETRIS *data ) 1206 void initTetrisData( T_TETRIS *data )
1207 { 1207 {
1208 data->level = 0; 1208 data->level = 0;
1218 1218
1219 void tetris_drawScreen( int allScreen, T_TETRIS *data) 1219 void tetris_drawScreen( int allScreen, T_TETRIS *data)
1220 { 1220 {
1221 int x1,y1,x2,y2; 1221 int x1,y1,x2,y2;
1222 int bCol; 1222 int bCol;
1223 int xOfs =5; 1223 int xOfs =5;
1224 int yOfs=10; 1224 int yOfs=10;
1225 int xOfs2=30; 1225 int xOfs2=30;
1226 int yOfs2=10; 1226 int yOfs2=10;
1227 int sx,sy; 1227 int sx,sy;
1228 int px,py; 1228 int px,py;
1229 // U32 oldfCol=0; // RAVI 1229 // U32 oldfCol=0; // RAVI
1230 // U32 oldbCol=0; // RAVI 1230 // U32 oldbCol=0; // RAVI
1231 int x = data->px; 1231 int x = data->px;
1232 int y = data->py; 1232 int y = data->py;
1233 1233
1234 // char dbg[80]; // RAVI 1234 // char dbg[80]; // RAVI
1235 1235
1236 1236
1237 #ifdef LSCREEN 1237 #ifdef LSCREEN
1238 //Calculate size based on the screen properties 1238 //Calculate size based on the screen properties
1239 sx = (SCREEN_SIZE_X-xOfs-xOfs2)/MAX_TET_X; 1239 sx = (SCREEN_SIZE_X-xOfs-xOfs2)/MAX_TET_X;
1240 sy = (SCREEN_SIZE_Y-yOfs-yOfs2-Mmi_layout_softkeyHeight())/MAX_TET_Y; 1240 sy = (SCREEN_SIZE_Y-yOfs-yOfs2-Mmi_layout_softkeyHeight())/MAX_TET_Y;
1241 #else 1241 #else
1257 { //redraw everything 1257 { //redraw everything
1258 x1 = 0; 1258 x1 = 0;
1259 y1 = 0; 1259 y1 = 0;
1260 x2 = MAX_TET_X; 1260 x2 = MAX_TET_X;
1261 y2 = MAX_TET_Y; 1261 y2 = MAX_TET_Y;
1262 1262
1263 } 1263 }
1264 else //just draw+1 box around current man 1264 else //just draw+1 box around current man
1265 { 1265 {
1266 x1 = x-1; 1266 x1 = x-1;
1267 y1 = y-1; 1267 y1 = y-1;
1270 if (x1<1)x1=1; 1270 if (x1<1)x1=1;
1271 if (y1<0)y1=0; 1271 if (y1<0)y1=0;
1272 if (x2>MAX_TET_X-1) x2=MAX_TET_X-1; 1272 if (x2>MAX_TET_X-1) x2=MAX_TET_X-1;
1273 if (y2>MAX_TET_Y-1) y2=MAX_TET_Y-1; 1273 if (y2>MAX_TET_Y-1) y2=MAX_TET_Y-1;
1274 } 1274 }
1275 1275
1276 #ifndef COLOURDISPLAY 1276 #ifndef COLOURDISPLAY
1277 dspl_Clear (xOfs+x1*sx,yOfs+y1*sy,xOfs+x2*sx-1,yOfs+y2*sy-1); 1277 dspl_Clear (xOfs+x1*sx,yOfs+y1*sy,xOfs+x2*sx-1,yOfs+y2*sy-1);
1278 #endif 1278 #endif
1279 for (px = x1;px<x2;px++) 1279 for (px = x1;px<x2;px++)
1280 { 1280 {
1281 for (py = y1;py<y2;py++) 1281 for (py = y1;py<y2;py++)
1282 { 1282 {
1283 char boardChr = data->tetrisScreen[px][py]; 1283 char boardChr = data->tetrisScreen[px][py];
1284 if ((px >= x ) && (px < x+4) && 1284 if ((px >= x ) && (px < x+4) &&
1285 (py >= y ) && (py < y+4)) 1285 (py >= y ) && (py < y+4))
1286 { 1286 {
1287 int shapeX,shapeY; 1287 int shapeX,shapeY;
1288 shapeX = px-x; 1288 shapeX = px-x;
1289 shapeY = py-y; 1289 shapeY = py-y;
1290 if (data->shapeStr[shapeX+shapeY*4] != ' ') 1290 if (data->shapeStr[shapeX+shapeY*4] != ' ')
1340 return(1); 1340 return(1);
1341 else 1341 else
1342 data->tetrisScreen[data->px+x][data->py+y] = data->shapeStr[x+y*4]; 1342 data->tetrisScreen[data->px+x][data->py+y] = data->shapeStr[x+y*4];
1343 } 1343 }
1344 return(0); 1344 return(0);
1345 1345
1346 } 1346 }
1347 1347
1348 int tetris_testForCompleteLines( T_TETRIS *data ) 1348 int tetris_testForCompleteLines( T_TETRIS *data )
1349 { 1349 {
1350 int nLines=0; 1350 int nLines=0;
1351 int x,y; 1351 int x,y;
1352 int blanks; 1352 int blanks;
1353 for (y=MAX_TET_Y-2;y>0;y--) 1353 for (y=MAX_TET_Y-2;y>0;y--)
1354 { 1354 {
1355 blanks = 0; 1355 blanks = 0;
1356 1356
1357 for (x=1;x<MAX_TET_X-1;x++) 1357 for (x=1;x<MAX_TET_X-1;x++)
1358 { 1358 {
1359 if (data->tetrisScreen[x][y] == ' ') 1359 if (data->tetrisScreen[x][y] == ' ')
1360 blanks++; 1360 blanks++;
1361 if (nLines >0) 1361 if (nLines >0)
1383 data->score = data->score + linesComplete*linesComplete; 1383 data->score = data->score + linesComplete*linesComplete;
1384 data->linesToGo = data->linesToGo - linesComplete; 1384 data->linesToGo = data->linesToGo - linesComplete;
1385 if (data->linesToGo <0) 1385 if (data->linesToGo <0)
1386 tetris_getNextLevel(data); 1386 tetris_getNextLevel(data);
1387 } 1387 }
1388 tetris_getNextShape(data); 1388 tetris_getNextShape(data);
1389 } 1389 }
1390 } 1390 }
1391 1391
1392 1392
1393 1393
1429 int MmiTetrisStart(void ) 1429 int MmiTetrisStart(void )
1430 { 1430 {
1431 MfwHnd hWin; 1431 MfwHnd hWin;
1432 1432
1433 MfwHnd hParentWin = mfwParent(mfwHeader()); 1433 MfwHnd hParentWin = mfwParent(mfwHeader());
1434 1434
1435 TRACE_FUNCTION ("TetrisStart()"); 1435 TRACE_FUNCTION ("TetrisStart()");
1436 1436
1437 hWin = TetrisCreate (hParentWin); 1437 hWin = TetrisCreate (hParentWin);
1438 1438
1439 if (hWin NEQ NULL) 1439 if (hWin NEQ NULL)
1440 { 1440 {
1441 SEND_EVENT (hWin, E_INIT, NULL, NULL); 1441 SEND_EVENT (hWin, E_INIT, NULL, NULL);
1442 } 1442 }
1443 1443
1444 return 1; 1444 return 1;
1445 } 1445 }
1446 1446
1447 void initTetrisData( T_TETRIS *data ); 1447 void initTetrisData( T_TETRIS *data );
1448 static MfwHnd TetrisCreate(MfwHnd hParentWin) 1448 static MfwHnd TetrisCreate(MfwHnd hParentWin)
1488 } 1488 }
1489 1489
1490 static int TetrisWinCb (MfwEvt uiE, MfwWin *psWin) 1490 static int TetrisWinCb (MfwEvt uiE, MfwWin *psWin)
1491 { 1491 {
1492 T_TETRIS *psData = (T_TETRIS *)psWin->user; 1492 T_TETRIS *psData = (T_TETRIS *)psWin->user;
1493 1493
1494 TRACE_FUNCTION ("TetrisWinCb()"); 1494 TRACE_FUNCTION ("TetrisWinCb()");
1495 1495
1496 switch (uiE) 1496 switch (uiE)
1497 { 1497 {
1498 case MfwWinVisible: 1498 case MfwWinVisible:
1499 dspl_ResetWindow(); 1499 dspl_ResetWindow();
1500 dspl_SetBgdColour(0x000000FF); 1500 dspl_SetBgdColour(0x000000FF);
1501 dspl_Clear(0,0,SCREEN_SIZE_X-1,SCREEN_SIZE_Y-1 ); 1501 dspl_Clear(0,0,SCREEN_SIZE_X-1,SCREEN_SIZE_Y-1 );
1502 tetris_drawScreen( 1, psData); 1502 tetris_drawScreen( 1, psData);
1503 1503
1504 break; 1504 break;
1505 1505
1506 case MfwWinFocussed: 1506 case MfwWinFocussed:
1507 case MfwWinDelete: 1507 case MfwWinDelete:
1508 default: 1508 default:
1509 return MFW_EVENT_REJECTED; 1509 return MFW_EVENT_REJECTED;
1510 } 1510 }
1511 TRACE_FUNCTION ("TetrisWinCb() - end"); 1511 TRACE_FUNCTION ("TetrisWinCb() - end");
1512 return MFW_EVENT_CONSUMED; 1512 return MFW_EVENT_CONSUMED;
1520 TRACE_FUNCTION ("TetrisExecCb()"); 1520 TRACE_FUNCTION ("TetrisExecCb()");
1521 1521
1522 switch (uiE) 1522 switch (uiE)
1523 { 1523 {
1524 case E_INIT: 1524 case E_INIT:
1525 1525
1526 psData->info_tim = timCreate(hWin, psData->timeStep, (MfwCb)tetris_tim_cb); 1526 psData->info_tim = timCreate(hWin, psData->timeStep, (MfwCb)tetris_tim_cb);
1527 psData->hKbd = kbdCreate(psData->win, KEY_ALL, (MfwCb)TetrisKbdCb); 1527 psData->hKbd = kbdCreate(psData->win, KEY_ALL, (MfwCb)TetrisKbdCb);
1528 timStart(psData->info_tim); 1528 timStart(psData->info_tim);
1529 1529
1530 /* */ 1530 /* */
1531 winShow(hWin); 1531 winShow(hWin);
1532 1532
1533 break; 1533 break;
1534 1534
1535 case E_EXIT: 1535 case E_EXIT:
1536 tetris_destroy(hWin); 1536 tetris_destroy(hWin);
1537 break; 1537 break;
1538 1538
1539 default: 1539 default:
1540 return; 1540 return;
1541 } 1541 }
1542 1542
1543 return; 1543 return;
1663 tetris_testGameOver( psData ); 1663 tetris_testGameOver( psData );
1664 break; 1664 break;
1665 case KEY_TET_DROPALL: 1665 case KEY_TET_DROPALL:
1666 while(tetris_moveDown(psData,&psData->px,&psData->py) ==0) 1666 while(tetris_moveDown(psData,&psData->px,&psData->py) ==0)
1667 { //loop until we hit the bottom 1667 { //loop until we hit the bottom
1668 1668
1669 } 1669 }
1670 cannotMove = 1; 1670 cannotMove = 1;
1671 tetris_testGameOver( psData ); 1671 tetris_testGameOver( psData );
1672 break; 1672 break;
1673 1673
1674 1674
1675 case KCD_RIGHT: 1675 case KCD_RIGHT:
1676 SEND_EVENT (hWin, E_EXIT, 0, 0); 1676 SEND_EVENT (hWin, E_EXIT, 0, 0);
1677 return MFW_EVENT_CONSUMED; 1677 return MFW_EVENT_CONSUMED;
1678 1678
1679 default: 1679 default:
1680 1680
1681 return MFW_EVENT_CONSUMED; 1681 return MFW_EVENT_CONSUMED;
1682 } 1682 }
1683 tetris_drawScreen(cannotMove, psData); 1683 tetris_drawScreen(cannotMove, psData);
1684 1684
1685 TRACE_FUNCTION ("TetrisKbdCb()-end"); 1685 TRACE_FUNCTION ("TetrisKbdCb()-end");
1686 return MFW_EVENT_CONSUMED; 1686 return MFW_EVENT_CONSUMED;
1687 } 1687 }
1688 1688
1689 static int tetris_tim_cb(MfwEvt e, MfwTim *t) 1689 static int tetris_tim_cb(MfwEvt e, MfwTim *t)
1709 data->dropTime = data->dropTime+75*10; 1709 data->dropTime = data->dropTime+75*10;
1710 else if (data->maxDropTime > 60) 1710 else if (data->maxDropTime > 60)
1711 data->dropTime = data->dropTime+(60+(data->maxDropTime-60)/2)*10; 1711 data->dropTime = data->dropTime+(60+(data->maxDropTime-60)/2)*10;
1712 else if (data->maxDropTime > 30) 1712 else if (data->maxDropTime > 30)
1713 data->dropTime = data->dropTime+data->maxDropTime*10; 1713 data->dropTime = data->dropTime+data->maxDropTime*10;
1714 else 1714 else
1715 data->dropTime = data->dropTime+(data->maxDropTime+90)/4*10; 1715 data->dropTime = data->dropTime+(data->maxDropTime+90)/4*10;
1716 1716
1717 if (data->dropTime < data->timeStep) 1717 if (data->dropTime < data->timeStep)
1718 data->dropTime = data->timeStep; 1718 data->dropTime = data->timeStep;
1719 else if (data->dropTime < data->timeStep) 1719 else if (data->dropTime < data->timeStep)
1720 data->dropTime = data->timeStep; 1720 data->dropTime = data->timeStep;
1721 1721
1722 resources_setColour(COLOUR_GAME); 1722 resources_setColour(COLOUR_GAME);
1723 sprintf(bfr,"%d ",data->score); 1723 sprintf(bfr,"%d ",data->score);
1724 dspl_TextOut(SCREEN_SIZE_X-30 ,10, 0, bfr); 1724 dspl_TextOut(SCREEN_SIZE_X-30 ,10, 0, bfr);
1725 sprintf(bfr,"%d ",data->linesToGo); 1725 sprintf(bfr,"%d ",data->linesToGo);
1726 dspl_TextOut(SCREEN_SIZE_X-30 ,12+Mmi_layout_line_height(), 0, bfr); 1726 dspl_TextOut(SCREEN_SIZE_X-30 ,12+Mmi_layout_line_height(), 0, bfr);
1727 resources_restoreColour(); 1727 resources_restoreColour();
1728 cannotMove = tetris_moveDown(data,&data->px,&data->py); 1728 cannotMove = tetris_moveDown(data,&data->px,&data->py);
1729 tetris_getNextShapeId( );//To randomize it 1729 tetris_getNextShapeId( );//To randomize it
1730 1730
1731 if (cannotMove) 1731 if (cannotMove)
1732 { 1732 {
1733 tetris_testGameOver( data ); 1733 tetris_testGameOver( data );
1734 } 1734 }
1735 tetris_drawScreen(cannotMove, data); 1735 tetris_drawScreen(cannotMove, data);
1736 } 1736 }
1737 1737
1738 timStart(data->info_tim); 1738 timStart(data->info_tim);
1739 TRACE_EVENT("tetris_tim_cb-end"); 1739 TRACE_EVENT("tetris_tim_cb-end");
1740 return 1; 1740 return 1;
1741 } 1741 }
1742 1742
1845 } 1845 }
1846 1846
1847 static void ShowInfoCB( T_MFW_HND win, USHORT Identifier,UBYTE reason) 1847 static void ShowInfoCB( T_MFW_HND win, USHORT Identifier,UBYTE reason)
1848 { 1848 {
1849 T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data; 1849 T_MFW_WIN *win_data = ( (T_MFW_HDR *) win )->data;
1850 tShowInfo*data = (tShowInfo*) win_data->user; 1850 tShowInfo*data = (tShowInfo*) win_data->user;
1851 1851
1852 1852
1853 TRACE_FUNCTION("ShowVerionCB()"); 1853 TRACE_FUNCTION("ShowVerionCB()");
1854 1854
1855 switch (reason ) 1855 switch (reason )
1856 { 1856 {
1857 case INFO_KCD_LEFT: 1857 case INFO_KCD_LEFT:
1867 /******************************************************************************* 1867 /*******************************************************************************
1868 1868
1869 $Function: showVersion_destroy 1869 $Function: showVersion_destroy
1870 1870
1871 $Description: Destroys the editor 1871 $Description: Destroys the editor
1872 1872
1873 $Returns: 1873 $Returns:
1874 1874
1875 $Arguments: 1875 $Arguments:
1876 1876
1877 *******************************************************************************/ 1877 *******************************************************************************/
1878 void showGameInfo_destroy(MfwHnd own_window) 1878 void showGameInfo_destroy(MfwHnd own_window)
1879 { 1879 {
1880 T_MFW_WIN * win_data; 1880 T_MFW_WIN * win_data;
1881 1881
1882 tShowInfo* data = NULL; 1882 tShowInfo* data = NULL;
1883 1883
1884 if (own_window == NULL) 1884 if (own_window == NULL)
1885 { 1885 {
1886 TRACE_EVENT ("Error : showGameInfo_destroy called with NULL Pointer"); 1886 TRACE_EVENT ("Error : showGameInfo_destroy called with NULL Pointer");