/* * ChessDlgCommand: Handle WM_COMMAND messages in the main chess dialog. */ void ChessDlgCommand(HWND hDlg, int cmd_id, HWND hwndCtl, UINT codeNotify) { switch(cmd_id) { case IDC_RESIGN: if (!AreYouSure(hInst, hDlg, NO_BUTTON, IDS_ASKRESIGN)) break; if (b.color == WHITE) b.white_resigned = True; if (b.color == BLACK) b.black_resigned = True; ChessSendMove(); break; case IDC_RESTART_GAME: BoardInitialize(&b); ChessSendMove(); ChessRedrawBoard(); break; case IDC_RESETPLAYERS: RequestGameResetPlayers(game_obj); break; case IDOK: case IDCANCEL: ModuleExit(); break; } }
/* * ChessGotState: Got given board state from server. */ void ChessGotState(unsigned char *state) { // debug(("Chess got game state %s\n", state)); b.valid = True; // If game hasn't been initialized yet, set default board configuration if (state[0] == 0) BoardInitialize(&b); else if (!BoardDecode(state, &b)) debug(("HandleGameState got illegal state\n")); ChessRedrawBoard(); ChessDlgShowGameStatus(); ChessDlgShowMover(); }
int tetris_exec( int fdfb, int fdrc, int fdlcd, char *cfgfile ) { struct timeval tv; int x; int i; int fd; FILE *fp; char *line; char *p; if ( FBInitialize( 720, 576, 8, fdfb ) < 0 ) return -1; setup_colors(); if ( RcInitialize( fdrc ) < 0 ) return -1; /* load setup */ fp = fopen( CONFIGDIR "/games.cfg", "r" ); if ( fp ) { line=malloc(128); isalloc=1; #ifdef HAVE_CURL proxy_addr=0; proxy_user=0; #endif hscore=0; while( fgets( line, 128, fp ) ) { if ( *line == '#' ) continue; if ( *line == ';' ) continue; p=strchr(line,'\n'); if ( p ) *p=0; p=strchr(line,'='); if ( !p ) continue; *p=0; p++; #ifdef HAVE_CURL if ( !strcmp(line,"proxy") ) proxy_addr=strdup(p); else if ( !strcmp(line,"proxy_user") ) proxy_user=strdup(p); else if ( !strcmp(line,"hscore") ) hscore=strdup(p); #endif } fclose(fp); free(line); } fd = open( GAMESDIR "/tetris.hscore", O_RDONLY ); if ( fd == -1 ) { mkdir( GAMESDIR, 567 ); for( i=0; i < 8; i++ ) { strcpy(hsc[i].name,"nobody"); hsc[i].points=30; } } else { read( fd, hsc, sizeof(hsc) ); close(fd); } #ifdef HAVE_CURL if ( hscore ) { LoadHScore(); } #endif #if defined(HAVE_DBOX_HARDWARE) || defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE) Fx2ShowPig( 480, 400, 176, 144 ); #endif while( doexit != 3 ) { BoardInitialize(); DrawBoard( ); /* 0 = all */ NextItem(); #ifdef HAVE_DREAMBOX_HARDWARE Fx2ShowPig(480, 400, 176, 144 ); #endif doexit=0; while( !doexit ) { tv.tv_sec = 0; tv.tv_usec = 10000; x = select( 0, 0, 0, 0, &tv ); /* 10ms pause */ RcGetActCode( ); if ( doexit ) break; tv.tv_sec = 0; tv.tv_usec = 10000; x = select( 0, 0, 0, 0, &tv ); /* 10ms pause */ RcGetActCode( ); if ( doexit ) break; MoveSide(); if ( !FallDown() ) { RemoveCompl(); if ( !NextItem() ) doexit=1; } #if defined(USEX) || defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE) FBFlushGrafic(); #endif RcGetActCode( ); } if ( doexit != 3 ) { actcode=0xee; DrawGameOver(); #if defined(USEX) || defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE) FBFlushGrafic(); #endif doexit=0; SaveGame(); #ifdef HAVE_CURL if ( use_ihsc ) ShowIHScore(); #endif ShowHScore(hsc); Fx2PigPause(); #if defined(USEX) || defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE) FBFlushGrafic(); #endif i=0; actcode=0xee; while(( actcode != RC_OK ) && !doexit ) { tv.tv_sec = 0; tv.tv_usec = 100000; x = select( 0, 0, 0, 0, &tv ); /* 100ms pause */ RcGetActCode( ); i++; if ( i == 50 ) { FBDrawString( 190, 480, 48, "press OK for new game",GRAY,0); #if defined(USEX) || defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE) FBFlushGrafic(); #endif } } Fx2PigResume(); } } Fx2StopPig(); #if defined(HAVE_DBOX_HARDWARE) || defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE) /* fx2 */ /* buffer leeren, damit neutrino nicht rumspinnt */ realcode = RC_0; while( realcode != 0xee ) { tv.tv_sec = 0; tv.tv_usec = 300000; x = select( 0, 0, 0, 0, &tv ); /* 300ms pause */ RcGetActCode( ); } #endif RcClose(); FBClose(); /* save hscore */ fd = open( GAMESDIR "/tetris.hscore", O_CREAT|O_WRONLY, 438 ); if ( fd != -1 ) { write( fd, hsc, sizeof(hsc) ); close(fd); } if ( isalloc ) { #ifdef HAVE_CURL if ( proxy_addr ) free ( proxy_addr ); if ( proxy_user ) free ( proxy_user ); #endif if ( hscore ) free ( hscore ); } return 0; }
int mines_exec( int fdfb, int fdrc, int fdlcd, char *cfgfile ) { struct timeval tv; int x; if ( FBInitialize( 720, 576, 8, fdfb ) < 0 ) return -1; setup_colors(); if ( RcInitialize( fdrc ) < 0 ) return -1; while( doexit != 3 ) { BoardInitialize(); DrawBoard( 0 ); Fx2ShowPig( 470, 300, 176, 144 ); doexit=0; while( !doexit ) { tv.tv_sec = 0; tv.tv_usec = 10000; x = select( 0, 0, 0, 0, &tv ); /* 100ms pause */ RcGetActCode( ); MoveMouse(); #ifdef USEX FBFlushGrafic(); #endif } if ( doexit != 3 ) { actcode=0xee; if ( doexit ==2 ) DrawScore(); else DrawGameOver(); #ifdef USEX FBFlushGrafic(); #endif doexit=0; while(( actcode != RC_OK ) && !doexit ) { tv.tv_sec = 0; tv.tv_usec = 100000; x = select( 0, 0, 0, 0, &tv ); /* 100ms pause */ RcGetActCode( ); } } } Fx2StopPig(); /* fx2 */ /* buffer leeren, damit neutrino nicht rumspinnt */ realcode = RC_0; while( realcode != 0xee ) { tv.tv_sec = 0; tv.tv_usec = 300000; x = select( 0, 0, 0, 0, &tv ); /* 300ms pause */ RcGetActCode( ); } RcClose(); FBClose(); return 0; }
void MoveMouse() { static int locked = 0; int dx=0; int dy=0; char zug=' '; if ( locked ) { locked--; actcode=0xee; return; } switch( actcode ) { case RC_RIGHT : // Pinguin nach rechts if ( man_x+1 < MAZEW ) { dx = 1; dy = 0; zug = 'r'; locked=1; } break; case RC_LEFT : // Pinguin nach links if ( man_x > 1 ) { dx = -1; dy = 0; zug = 'l'; locked=1; } break; case RC_DOWN : // Pinguin nach unten if ( man_y+1 < MAZEH ) { dx = 0; dy = 1; zug = 'd'; locked=1; } break; case RC_UP : // Pinguin nach oben if ( man_y > 1 ) { dx = 0; dy = -1; zug = 'u'; locked=1; } break; case RC_MINUS : // letzte Züge rückgängig machen if (moves>0) { if (getField(man_x,man_y)=='@') { setField(man_x,man_y,' '); } else { setField(man_x,man_y,'.'); } if (Zuege[moves]=='r' || Zuege[moves]=='R') { man_x--; dx=1; } else if (Zuege[moves]=='l' || Zuege[moves]=='L') { man_x++; dx=-1; } else if (Zuege[moves]=='u' || Zuege[moves]=='U') { man_y++; dy=-1; } else if (Zuege[moves]=='d' || Zuege[moves]=='D') { man_y--; dy=1; } if (getField(man_x,man_y)==' ') { setField(man_x,man_y,'@'); } else { setField(man_x,man_y,'+'); } if (isupper(Zuege[moves])) { if (getField(man_x+2*dx,man_y+2*dy)=='$') { setField(man_x+2*dx,man_y+2*dy,' '); } else { setField(man_x+2*dx,man_y+2*dy,'.'); } if (getField(man_x+dx,man_y+dy)==' ') { setField(man_x+dx,man_y+dy,'$'); } else { setField(man_x+dx,man_y+dy,'*'); } pushes--; } moves--; dx=0; dy=0; DrawBoard(); DrawScore(); } locked=1; break; case RC_PLUS : // Rückgängig rückgängig machen if (Zuege[moves+1]!=' ') { if (Zuege[moves+1]=='r' || Zuege[moves+1]=='R') { dx=1; } else if (Zuege[moves+1]=='l' || Zuege[moves+1]=='L') { dx=-1; } else if (Zuege[moves+1]=='u' || Zuege[moves+1]=='U') { dy=-1; } else if (Zuege[moves+1]=='d' || Zuege[moves+1]=='D') { dy=1; } } locked=1; break; case RC_RED : // vorheriges Level - bei angefangenem Level nachfragen, ob wirklich sicher if (moves!=0) { FBFillRect( 160, 70, 400, 436, B ); FBDrawString( 160,75, 30, "Das Level ist noch nicht beendet!", WHITE, 0 ); FBDrawString( 160,110, 30, "ROT abbruch", WHITE, 0 ); FBDrawString( 160,140, 30, "OK naechstes Level", WHITE, 0 ); #ifdef USEX FBFlushGrafic(); #endif actcode=0xee; while( actcode != RC_OK && actcode != RC_RED ) { RcGetActCode(); } } if (actcode == RC_OK || moves==0) { if (level > 0) { level--; BoardInitialize(); } else { level = max_level-1; BoardInitialize(); } } else { FBFillRect( 0, 0, 720, 576, BLACK ); DrawBoard(); DrawScore(); } locked=1; break; case RC_GREEN : // naechstes Level - bei angefangenem Level nachfragen, ob wirklich sicher if (moves!=0) { FBFillRect( 160, 70, 400, 436, B ); FBDrawString( 160,75, 30, "Das Level ist noch nicht beendet!", WHITE, 0 ); FBDrawString( 160,110, 30, "ROT abbruch", WHITE, 0 ); FBDrawString( 160,140, 30, "OK vorheriges Level", WHITE, 0 ); #ifdef USEX FBFlushGrafic(); #endif actcode=0xee; while( actcode != RC_OK && actcode != RC_RED ) { RcGetActCode(); } } if (actcode == RC_OK || moves==0) { if (level+1 < max_level) { level++; BoardInitialize(); } else { level = 0; BoardInitialize(); } } else { FBFillRect( 0, 0, 720, 576, BLACK ); DrawBoard(); DrawScore(); } locked=1; break; case RC_YELLOW : // Randfelder ('a') aus-/einblenden if (Rand == 0) { Rand = 1; } else { Rand = 0; } locked=1; FBFillRect( 0, 0, 720, 576, BLACK ); DrawBoard(); DrawScore(); FBDrawString( 300, 510, 30, levelname[level], WHITE, 0 ); break; case RC_BLUE : // Level von vorne beginnen - bei angefangenem Level nachfragen, ob wirklich sicher if (moves!=0) { FBFillRect( 160, 70, 400, 436, B ); FBDrawString( 160,75, 30, "Das Level ist noch nicht beendet!", WHITE, 0 ); FBDrawString( 160,110, 30, "ROT abbruch", WHITE, 0 ); FBDrawString( 160,140, 30, "OK vorheriges Level", WHITE, 0 ); #ifdef USEX FBFlushGrafic(); #endif actcode=0xee; while( actcode != RC_OK && actcode != RC_RED ) { RcGetActCode(); } } if (actcode == RC_OK || moves==0) { BoardInitialize(); } else { FBFillRect( 0, 0, 720, 576, BLACK ); DrawBoard(); DrawScore(); } locked=1; break; case RC_HELP : // Hilfe anzeigen locked=1; FBFillRect( 160, 70, 400, 436, B ); FBDrawString( 160, 70, 30, "ROT vorheriges Level", WHITE, 0 ); FBDrawString( 160,100, 30, "GRUEN naechstes Level", WHITE, 0 ); FBDrawString( 160,130, 30, "GELB Rand ein/aus", WHITE, 0 ); FBDrawString( 160,160, 30, "BLAU Level neu starten", WHITE, 0 ); FBDrawString( 160,190, 30, "MINUS Zug zurueck", WHITE, 0 ); FBDrawString( 160,220, 30, "PLUS Zug vor", WHITE, 0 ); FBDrawString( 160,260, 30, "HOME Spiel beenden", WHITE, 0 ); FBDrawString( 160,290, 30, "STUMM Spiel aus-/einblenden", WHITE, 0 ); FBDrawString( 160,330, 30, "HILFE diese Hilfe", WHITE, 0 ); FBDrawString( 160,370, 30, "OK weiter", WHITE, 0 ); #ifdef USEX FBFlushGrafic(); #endif actcode=0xee; while( actcode != RC_OK ) { RcGetActCode( ); } FBFillRect( 0, 0, 720, 576, BLACK ); DrawBoard(); DrawScore(); FBDrawString( 300, 510, 30, levelname[level], WHITE, 0 ); break; } if (dx != 0 || dy != 0) // Soll Pinguin verschoben werden? { if (getField(man_x+dx, man_y+dy) == ' ') // Zug auf leeres Feld - keine Kiste vorhanden { if (getField(man_x,man_y)=='@') {setField(man_x,man_y,' ');} else {setField(man_x,man_y,'.');} DrawField(man_x, man_y); man_x += dx; dx = 0; man_y += dy; dy = 0; setField(man_x,man_y,'@'); DrawField(man_x, man_y); moves++; DrawScore(); } else if (getField(man_x+dx, man_y+dy) == '.') // Zug auf Zielfeld - keine Kiste vorhanden { if (getField(man_x,man_y)=='@') {setField(man_x,man_y,' ');} else {setField(man_x,man_y,'.');} DrawField(man_x, man_y); man_x += dx; dx = 0; man_y += dy; dy = 0; setField(man_x,man_y,'+'); DrawField(man_x, man_y); moves++; DrawScore(); } else if (getField(man_x+dx, man_y+dy) == '$' && getField(man_x+(2*dx), man_y+(2*dy)) == ' ') // Zug auf Feld mit Kiste - Kiste auf leeres Feld { setField(man_x+(2*dx), man_y+(2*dy),'$'); setField(man_x+dx, man_y+dy,' '); DrawField(man_x+(2*dx), man_y+(2*dy)); if (getField(man_x,man_y)=='@') {setField(man_x,man_y,' ');} else {setField(man_x,man_y,'.');} DrawField(man_x, man_y); man_x += dx; dx = 0; man_y += dy; dy = 0; setField(man_x,man_y,'@'); DrawField(man_x, man_y); moves++; pushes++; zug = toupper (zug); DrawScore(); } else if (getField(man_x+dx, man_y+dy) == '$' && getField(man_x+(2*dx), man_y+(2*dy)) == '.') // Zug auf Feld mit Kiste - Kiste auf Zielfeld { setField(man_x+(2*dx), man_y+(2*dy),'*'); setField(man_x+dx, man_y+dy,' '); DrawField(man_x+(2*dx), man_y+(2*dy)); if (getField(man_x,man_y)=='@') {setField(man_x,man_y,' ');} else {setField(man_x,man_y,'.');} DrawField(man_x, man_y); man_x += dx; dx = 0; man_y += dy; dy = 0; setField(man_x,man_y,'@'); DrawField(man_x, man_y); moves++; pushes++; zug = toupper (zug); DrawScore(); } else if (getField(man_x+dx, man_y+dy) == '*' && getField(man_x+(2*dx), man_y+(2*dy)) == ' ') // Zug auf Zielfeld mit Kiste - Kiste auf leeres Feld { setField(man_x+(2*dx), man_y+(2*dy),'$'); setField(man_x+dx, man_y+dy,'.'); DrawField(man_x+(2*dx), man_y+(2*dy)); if (getField(man_x,man_y)=='@') {setField(man_x,man_y,' ');} else {setField(man_x,man_y,'.');} DrawField(man_x, man_y); man_x += dx; dx = 0; man_y += dy; dy = 0; setField(man_x,man_y,'+'); DrawField(man_x, man_y); moves++; pushes++; zug = toupper (zug); DrawScore(); } else if (getField(man_x+dx, man_y+dy) == '*' && getField(man_x+(2*dx), man_y+(2*dy)) == '.') // Zug auf Zielfeld mit Kiste - Kiste auf Zielfeld { setField(man_x+(2*dx), man_y+(2*dy),'*'); setField(man_x+dx, man_y+dy,'.'); DrawField(man_x+(2*dx), man_y+(2*dy)); if (getField(man_x,man_y)=='@') {setField(man_x,man_y,' ');} else {setField(man_x,man_y,'.');} DrawField(man_x, man_y); man_x += dx; dx = 0; man_y += dy; dy = 0; setField(man_x,man_y,'+'); DrawField(man_x, man_y); moves++; pushes++; zug = toupper (zug); DrawScore(); } else { zug = ' '; } } if (zug !=' ') { Zuege[moves]=zug; } if (win() == 1) // durch letzten Zug gewonnen? { if (level+1 < max_level) { level++; } else { level = 0; } doexit=1; } #ifdef USEX FBFlushGrafic(); #endif return; }
int soko_exec( int fdfb, int fdrc, int fdlcd, char *cfgfile ) { struct timeval tv; int x; if ( FBInitialize( 720, 576, 8, fdfb ) < 0 ) return -1; setup_colors(); if ( RcInitialize( fdrc ) < 0 ) return -1; Fx2ShowPig( 540, 450, 120, 90 ); ladeVerzeichnis(); Startbildschirm(); while( doexit != 3 ) { doexit=0; BoardInitialize(); #ifdef USEX FBFlushGrafic(); #endif if ( doexit == 4 ) /* fx2 - install error: no level found */ { doexit=0; while(( actcode != RC_OK ) && !doexit ) { tv.tv_sec = 0; tv.tv_usec = 100000; x = select( 0, 0, 0, 0, &tv ); /* 100ms pause */ RcGetActCode( ); } break; } while( !doexit ) { tv.tv_sec = 0; tv.tv_usec = 10000; x = select( 0, 0, 0, 0, &tv ); /* 100ms pause */ RcGetActCode( ); MoveMouse(); } if ( doexit != 3 ) { actcode=0xee; if ( doexit ==2 ) DrawScore(); else DrawGameOver(); if (level+1 < max_level) { level++; } else { level = 0; } doexit=0; while(( actcode != RC_OK ) && !doexit ) { tv.tv_sec = 0; tv.tv_usec = 100000; x = select( 0, 0, 0, 0, &tv ); /* 100ms pause */ RcGetActCode( ); } } } Fx2StopPig(); /* fx2 */ /* buffer leeren, damit neutrino nicht rumspinnt */ realcode = RC_0; while( realcode != 0xee ) { tv.tv_sec = 0; tv.tv_usec = 300000; x = select( 0, 0, 0, 0, &tv ); /* 300ms pause */ RcGetActCode( ); } RcClose(); FBClose(); freeMem(); return 0; }