State onNewGame(Game* game) { int choice = 0; assert(game); /* new game has started */ game->setting->gameCreated = 1; /* print menu for user preferences */ game->color = 'w'; gameOptions(game); /* TODO * Player should be able to choose whether to go first or not. * This function is not fully implemented. Added by Cesar... White will always go first, player can choose white or black and in that way choose to go first or not */ if(game->setting->gameMode == 0) { if(game->color == 'w') return TurnPlayer; else if(game->color == 'b') return TurnAI; } else if(game->setting->gameMode == 1) return TurnPlayer; /* if(game->setting->gameMode == 2) left this condition out because there was not last condition stated */ return TurnAI; }
State onPlayersTurn(Game* game) { /* added clear screen -Cesar 1/27 */ char cmd[255]; char choice = 0; char userInput[255]; char promotionChoice; char maxTurnUserInput; int result; int ox, oy, dx, dy; clearScreen(); assert(game); printBoard(game); printf("Turn number: %d, ", game->turn+1); if(game->turn%2 == 0) printf("WHITE's turn\n"); else printf("BLACK's turn\n"); printUserMenu(game); getGameInput(cmd); choice = cmd[0]; if(check500Turns(game)) return MainMenu; /* added by Cesar 1/26 */ switch(choice) { case '0': return MainMenu; case '1': printHints(game); return TurnPlayer; case '2': redo(game); return TurnPlayer; case '3': printLog(game); return TurnPlayer; case '4': replay(game); return TurnPlayer; case '5': printf("Enter the file name you want to save \n"); scanf("%s", userInput); saveLog(game, userInput); fseek(stdin,0,SEEK_END); return TurnPlayer; case '6': printf("Enter the file name you want to save: "); scanf("%s", userInput); printf("\n"); fseek(stdin,0,SEEK_END); saveGame(game, userInput); return TurnPlayer; case '7': gameOptions(game); return TurnPlayer; default: break; } ox = cmd[0] - 97; oy = cmd[1] - 49; dx = cmd[2] - 97; dy = cmd[3] - 49; if((!checkBoarder(ox, oy))||(!checkBoarder(dx, dy)) || (isValidMove(game, ox, oy, dx, dy) <= 0)) { printf("INVALID MOVE DETECTED"); if(game->setting->allowIllegalMove == 1) { printf(", TRY AGAIN\n\n"); return TurnPlayer; } else { printf(", GAME OVER!\n\n"); return MainMenu; } } result = gameLogic(game, cmd); if(result == 9 || result == 10) { promotionChoice = ' '; while(promotionChoice != 'Q' && promotionChoice != 'R' && promotionChoice != 'N' && promotionChoice != 'B') { printf("Pawn promotion, enter the promotion choice (char to represent piece): "); scanf("%c", &promotionChoice); fseek(stdin,0,SEEK_END); if(promotionChoice=='q') promotionChoice='Q'; else if(promotionChoice=='r') promotionChoice='R'; else if(promotionChoice=='n') promotionChoice='N'; else if(promotionChoice=='b') promotionChoice='B'; printf("%c\n",promotionChoice); if(promotionChoice != 'Q' && promotionChoice != 'R' && promotionChoice != 'N' && promotionChoice != 'B') printf("Invalid input, try again.\n"); } result = promotion(game, cmd, promotionChoice); } if(result == 7) { printf("CHECKMATE\n"); getchar(); return MainMenu; } else if(result == 8) { printf("STALEMATE\n"); getchar(); return MainMenu; } if(game->setting->gameMode == 0) return TurnAI; else if(game->setting->gameMode == 1) return TurnPlayer; else return MainMenu; /* game logic returns 0 meaning the game is end */ }
void toMenu() { BITMAP *menuBuffer = NULL; menuBuffer = create_bitmap(1024,768); //Create an empty bitmap. BITMAP *menuBackground = NULL; menuBackground = load_bitmap("Menu Background.bmp", NULL); // Load our picture BITMAP *highlighter = NULL; highlighter = load_bitmap("Menu Highlighter.bmp", NULL); // Load our picture BITMAP *smoke = NULL; smoke = load_bitmap("Menu Smoke.bmp", NULL); // Load our picture MIDI *menuMusic = NULL; menuMusic = load_midi("Soundtrack1.mid"); SAMPLE *menuClick = load_sample("Click.wav"); clear_bitmap(menuBuffer); // Clear the contents of the buffer bitmap int highlightedOption = 1; int inMenu = 1; int smokePosition = 1024; int smokePosition2 = 1024; draw_sprite(menuBuffer, menuBackground, 0, 0); draw_sprite(menuBuffer, highlighter, 6, 186); blit(menuBuffer, screen, 0,0,0,0,1024,768);//Draw the buffer to the screen play_midi(menuMusic, 1); while (inMenu == 1) { draw_sprite(menuBuffer, menuBackground, 0, 0); smokePosition --; smokePosition2 -= 3; if (smokePosition <= -1024) { smokePosition = 0; } readkey(); if(key[KEY_UP]) { play_sample(menuClick, 155, 0, 2000, 0); highlightedOption--; if (highlightedOption <= 0) { highlightedOption = 5; } } else if(key[KEY_DOWN]) { play_sample(menuClick, 155, 0, 2000, 0); highlightedOption++; if (highlightedOption >= 6) { highlightedOption = 1; } } else if(key[KEY_ENTER]) { play_sample(menuClick, 155, 0, 4000, 0); switch (highlightedOption) { case 1: isXenoPatriots = selectRace(); newGame(); startGame(); play_midi(menuMusic, 1); break; case 2: loadGame(); break; case 3: gameOptions(); break; case 4: break; case 5: quitGame(); inMenu ^= 0; return; break; } } switch (highlightedOption) { case 1: draw_sprite(menuBuffer, highlighter, 6, 186); break; case 2: draw_sprite(menuBuffer, highlighter, 6, 278); break; case 3: draw_sprite(menuBuffer, highlighter, 6, 373); break; case 4: draw_sprite(menuBuffer, highlighter, 6, 465); break; case 5: draw_sprite(menuBuffer, highlighter, 6, 629); break; } /*draw_sprite(menuBuffer, smoke, smokePosition, 0); draw_sprite(menuBuffer, smoke, smokePosition + 1024, 0); draw_sprite(menuBuffer, smoke, smokePosition2, 0); draw_sprite(menuBuffer, smoke, smokePosition2 + 1024, 0);*/ blit(menuBuffer, screen, 0,0,0,0,1024,768);//Draw the buffer to the screen } }