// Input: none // // Output: Prints a menu and returns user's choice. int roulMenu(){ int choice; // Print the starting menu printf("\n// Roulette Menu \\\\\n"); printf("Select an option from the menu below!\n"); printf("1. Play roulette!\n"); printf("2. How to play\n"); printf("3. View board\n"); printf("4. Back\n"); // Get user input choice = menuInput(choice, 1, 4); return choice; }
// Resets all player profiles of the game. void resetGame(){ printf("\nAre you sure you want to reset all profiles?\n"); printf("1. Yes\n"); printf("2. No\n"); int choice; choice = menuInput(choice, 1, 2); if(choice == 1){ FILE* ofp = fopen("playerdata.txt", "w"); int i; for(i = 0; i < 3; i++){ fprintf(ofp, "Empty\n0\n0\n0\n0\n"); } fclose(ofp); printf("\nGame successfully reset!\n"); } }
void game (gamedata &g){ SDL_Event event; quit = false; // Set first tick interval Uint32 next_time = SDL_GetTicks() + TICK_INTERVAL; while (!quit){ if(g.winner){ finish_game(g); setup_game(g); GameState = STATE_INTRO; CurrentMenu = MenuMainIntro; SelectedItem = menuSwitchItem(CurrentMenu, 0); demo = true; } else if (g.winner == 0){ Uint8 *keys = SDL_GetKeyState(NULL); if (SDL_PollEvent(&event) == 1){ switch (event.type){ case SDL_QUIT: { printf("Quit requested, quitting.\n"); quit = true; } break; } } if(GameState == STATE_INTRO || GameState == STATE_MENU) { menuInput(g); } else if(GameState == STATE_MENU_PLANE_SELECT) { menuPlanes(g); } else if(GameState == STATE_MENU_PLAYER_CONTROL_SELECT) { menuSelectPlayer(g); } else if(GameState == STATE_GAME) { if ((keys[SDLK_ESCAPE] == SDL_PRESSED) || (keys[51] == SDL_PRESSED)){ keys[SDLK_ESCAPE] = SDL_RELEASED; GameState = STATE_MENU; CurrentMenu = MenuMain; SelectedItem = menuSwitchItem(CurrentMenu, 0); //quit = true; } } // Go through each plane individually g.p.reset(); while (g.p.next()){ // Setup virtual joystick int jx = 0; int jy = 0; bool jb = false; if (g.p().state < 2){ control(g, keys, jx, jy, jb); controlJoy(g, jx, jy, jb); } // Then move the plane act(g, jx, jy, jb); // Remove expunged planes if (g.p().state == 4){ g.drakms.fighter[g.p().id-7] = false; g.drakms.fightersout--; g.dp.reset(); while(g.dp.next()){ if (g.dp().id == g.p().id) g.dp.kill(); } g.p.kill(); } } // Then do everything else all(g); drawall(g); // Delay for time remaining in TICK_INTERVAL SDL_Delay(time_left(next_time)); next_time = SDL_GetTicks() + TICK_INTERVAL; } } }
void InputEngine::controllerAxisMotion(SDL_Event e, GameState state) { if (state == GameState::PLAY || state == GameState::END) { if (inputs[e.cdevice.which] == nullptr || cameras[e.cdevice.which] == nullptr) return; if (e.caxis.axis == SDL_CONTROLLER_AXIS_LEFTX) { if (e.caxis.value < -deadzoneSize) { inputs[e.cdevice.which]->steer = (float)(e.caxis.value + deadzoneSize)/(MIN_AXIS_VALUE + deadzoneSize); } else if (e.caxis.value > deadzoneSize) { inputs[e.cdevice.which]->steer = -(float)(e.caxis.value - deadzoneSize)/(MAX_AXIS_VALUE - deadzoneSize); } else { inputs[e.cdevice.which]->steer = 0; } } else if (e.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT) { inputs[e.cdevice.which]->backward = (float)e.caxis.value/MAX_AXIS_VALUE; } else if (e.caxis.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) { inputs[e.cdevice.which]->forward = (float)e.caxis.value/MAX_AXIS_VALUE; } } else if (state == GameState::MENU) { if (e.caxis.axis == SDL_CONTROLLER_AXIS_LEFTY) { if (e.caxis.value >= MAX_AXIS_VALUE - 5) { menuInput(InputType::DOWN); } else if (e.caxis.value <= MIN_AXIS_VALUE + 5) { menuInput(InputType::UP); } } else if (e.caxis.axis == SDL_CONTROLLER_AXIS_LEFTX) { if (e.caxis.value >= MAX_AXIS_VALUE - 5) { menuInput(InputType::RIGHT); } else if (e.caxis.value <= MIN_AXIS_VALUE + 5) { menuInput(InputType::LEFT); } } } else if (state == GameState::PAUSE) { if (e.caxis.axis == SDL_CONTROLLER_AXIS_LEFTY) { if (e.caxis.value >= MAX_AXIS_VALUE - 5) { pauseInput(InputType::DOWN); } else if (e.caxis.value <= MIN_AXIS_VALUE + 5) { pauseInput(InputType::UP); } } } }
void InputEngine::controllerButtonDown(SDL_Event e, GameState state) { if (state == GameState::PLAY || state == GameState::END) { if (inputs[e.cdevice.which] == nullptr || cameras[e.cdevice.which] == nullptr) return; if (e.cbutton.button == SDL_CONTROLLER_BUTTON_X) { inputs[e.cdevice.which]->shootPizza = true; } else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_A) { inputs[e.cdevice.which]->handBrake = true; } else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_B) { cameras[e.cdevice.which]->setReverseCam(true); } else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_RIGHTSTICK) { //unFucker(); } else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_Y) { inputs[e.cdevice.which]->jump = true; } else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_START) { if (isCheatCode(e.cdevice.which)) { space(); } (state == GameState::PLAY) ? setGameState(GameState::PAUSE) : setGameState(GameState::BACK_TO_MENU); } pastInputs[e.cdevice.which][pastInputsIndex[e.cdevice.which]] = e.cbutton.button; pastInputsIndex[e.cdevice.which] = (pastInputsIndex[e.cdevice.which] + 1) % BUFFER_SIZE; } else if (state == GameState::MENU) { if (e.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_UP) { menuInput(InputType::UP); } else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) { menuInput(InputType::DOWN); } else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) { menuInput(InputType::LEFT); } else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) { menuInput(InputType::RIGHT); } else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_A) { menuInput(InputType::ENTER); } else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_B) { menuInput(InputType::BACK); } } else if (state == GameState::PAUSE) { if (e.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_UP) { pauseInput(InputType::UP); } else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) { pauseInput(InputType::DOWN); } else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_A) { pauseInput(InputType::ENTER); } else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_B) { pauseInput(InputType::BACK); } else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_START) { pauseInput(InputType::BACK); } } }
// Input: initialized bet array, player array, current player number // // Output: gets and verifies the user's desired bet, returns the number of // bets made. int rGetBet(struct rBet bets[], struct player player[], int playerNumber){ int num_bets = 0; //To keep track of the num of bets int flag = 0; //Flag if user wants to quit before max bets while(!flag && num_bets < 10){ printf("\nWhat type of bet would you like to place?\n"); printf("1. Inside Bet\n"); printf("2. Outside Bet\n"); int choice; int bet; choice = menuInput(choice, 1, 2); // For inside bets if(choice == 1){ int valid = 0; while(!valid){ // Check if player's balance is less than the minimum bet if(player[playerNumber].balance <= 5){ printf("\nLooks like you don't have enough money to make a bet!\n"); printf("Here's some to help you out!\n"); player[playerNumber].balance += 500; } printf("\nYour current balance is: $%d.\n", player[playerNumber].balance); printf("How much would you like to bet? (min bet: $5, max: $100)\n"); int tempBet = menuInput(bet, 5, 100); // Check the bet isn't greater than the player's balance. if(player[playerNumber].balance - tempBet < 0){ printf("Sorry, you don't have enough money to make that bet.\n"); } else{ valid = 1; bets[num_bets].bet = tempBet; // Store the bet player[playerNumber].balance -= tempBet; insideBets(bets, num_bets); // Get the specific type of bet } } } // For outside bets else if(choice == 2){ int valid = 0; while(!valid){ if(player[playerNumber].balance <= 5){ printf("\nLooks like you don't have enough money to make a bet!\n"); printf("Here's some to help you out!\n"); player[playerNumber].balance += 500; } printf("\nYour current balance is: $%d.\n", player[playerNumber].balance); printf("How much would you like to bet? (min bet: $5, max: $1000)\n"); int tempBet = menuInput(bet, 5, 1000); if(player[playerNumber].balance - tempBet <= 0){ printf("Sorry, you don't have enough money to make that bet.\n"); } else{ valid = 1; bets[num_bets].bet = tempBet; // Store the bet player[playerNumber].balance -= tempBet; outsideBets(bets, num_bets); // Get the specifc type of bet } } } // Print out a summary of the bet. printf("\nBet %d:\n", num_bets+1); printf("Amount: %d\n", bets[num_bets].bet); printf("Type: %s\n", bets[num_bets].type); printf("Winning Numbers: "); int i; for(i = 0; i < MAXNUMWIN; i++){ if(bets[num_bets].win_nums[i] > -1) printf("%d ", bets[num_bets].win_nums[i]); } printf("\n"); // Check the number of bets is not ten. num_bets++; if(num_bets == 10) flag = 1; else{ int cont; printf("\nWould you like to place another bet?\n"); printf("1. Yes\n"); printf("2. No\n"); flag = menuInput(cont, 1, 2) - 1; } } return num_bets; }
// Input: the bet array, the current bet. // // Output: stores the user's bet in the bet array. void outsideBets(struct rBet bets[], int num_bets){ /*Outside Bets *Red or Black 1-1 (bet * 2) *Odd or Even (bet * 2) 1-1 (bet * 2) *1 - 18/ 19- 36 1-1 (bet * 2) *Dozens 2-1 (bet * 3) *Columns 2-1 (bet *3) */ int choice; int k; for(k = 0; k < MAXNUMWIN; k++) bets[num_bets].win_nums[k] = -1; printf("\nWhat type of outside bet would you like to make?\n"); printf("1. Red or Black\n"); printf("2. Odd or Even\n"); printf("3. 1-18/19-36\n"); printf("4. Dozens\n"); printf("5. Columns\n"); choice = menuInput(choice, 1, 5); // Each of the options below validate the desired bet, and store // the winning numbers and multiplier for that bet. // Bet Type: Red/Black if(choice == 1){ int numb; printf("\nWould you like to bet on red or black? (Enter 1 for red, 2 for black)\n"); int redWin[18] = {2,4,6,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35}; int blkWin[18] = {1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36}; numb = menuInput(numb, 1, 2); if(numb == 1){ int i; for(i = 0; i < 18; i++){ bets[num_bets].win_nums[i] = redWin[i]; printf("%d ", bets[num_bets].win_nums[i]); } strcpy(bets[num_bets].type, "Red"); } else if(numb == 2){ int i; for(i = 0; i < 18; i++){ bets[num_bets].win_nums[i] = blkWin[i]; printf("%d ", bets[num_bets].win_nums[i]); } strcpy(bets[num_bets].type, "Black"); } bets[num_bets].mult = 2; } // Bet Type: Odd/Even else if(choice == 2){ int numb; printf("\nWould you like to bet on odd or even? (Enter 1 for odd, 2 for even)\n"); numb = menuInput(numb, 1, 2); // Odds if(numb == 1){ int i; for(i = 0; i < MAXNUMWIN; i++){ bets[num_bets].win_nums[i] = (i*2)+1; } strcpy(bets[num_bets].type, "Odds"); } // Evens else if(numb == 2){ int i; for(i = 0; i < MAXNUMWIN; i++){ bets[num_bets].win_nums[i] = (i*2)+2; } strcpy(bets[num_bets].type, "Evens"); } bets[num_bets].mult = 2; } // Bet Type: 1-18/19-36 else if(choice == 3){ int numb; printf("\nWould you like to bet on 1-18, or 19-36? (Enter 1 for 1-18, 2 for 19-36)\n"); numb = menuInput(numb, 1, 2); if(numb == 1){ int i; for(i = 0; i < MAXNUMWIN; i++) bets[num_bets].win_nums[i] = i+1; strcpy(bets[num_bets].type, "1-18"); } else if(numb == 2){ int i; for(i = 0; i < MAXNUMWIN; i++) bets[num_bets].win_nums[i] = i+19; strcpy(bets[num_bets].type, "19-36"); } bets[num_bets].mult = 2; } // Bet Type: Dozens else if(choice == 4){ int num; printf("\nWhich of the three dozens would you like to bet on? (1 for 1-12, 2 for 13-24, 3 for 25-36)\n"); num = menuInput(num, 1,3); if(num == 1){ int i; for(i = 0; i < 12; i++) bets[num_bets].win_nums[i] = i+1; strcpy(bets[num_bets].type, "1st Dozen"); } else if(num == 2){ int i; for(i = 0; i < 12; i++) bets[num_bets].win_nums[i] = i+13; strcpy(bets[num_bets].type, "2nd Dozen"); } else if(num == 3){ int i; for(i = 0; i < 12; i++) bets[num_bets].win_nums[i] = i+25; strcpy(bets[num_bets].type, "3rd Dozen"); } bets[num_bets].mult = 3; } // Bet Type: Columns else if(choice == 5){ int num; printf("\nWhich of the three columns would you like to bet on? (1, 2, or 3)\n"); num = menuInput(num, 1,3); if(num == 1){ int i; for(i = 0; i < 12; i++) bets[num_bets].win_nums[i] = (i*3)+num; strcpy(bets[num_bets].type, "1st Column"); } else if(num == 2){ int i; for(i = 0; i < 12; i++) bets[num_bets].win_nums[i] = (i*3)+num; strcpy(bets[num_bets].type, "2nd Column"); } else if(num == 3){ int i; for(i = 0; i < 12; i++) bets[num_bets].win_nums[i] = (i*3)+num; strcpy(bets[num_bets].type, "3rd Column"); } bets[num_bets].mult = 3; } }
// Input: the bet array, the current bet. // // Output: stores the user's bet in the bet array. void insideBets(struct rBet bets[], int num_bets){ /*Inside Bets *Single number 35-1 (bet * 36) *Split(2 adjacent numbers) 17-1 (bet * 18) *Street(Row) 13-1 (bet * 14) *Corner(4 adj numbers) 8-1 (bet * 9) *Double street 5-1 (bet *6) */ int choice; // Initialize the bet array to a none winning value. int k; for(k = 0; k < MAXNUMWIN; k++) bets[num_bets].win_nums[k] = -1; printf("\nWhat type of inside bet would you like to make?\n"); printf("1. Single Number\n"); printf("2. Split\n"); printf("3. Street\n"); printf("4. Corner\n"); printf("5. Double Street\n"); choice = menuInput(choice, 1, 5); // Each of the options below validate the desired bet, and store // the winning numbers and multiplier for that bet. // Bet Type: Single Number if(choice == 1){ int numb; printf("\nEnter the number you want to bet on.\n"); bets[num_bets].win_nums[0] = menuInput(numb, 0, 36); bets[num_bets].mult = 36; strcpy(bets[num_bets].type, "Single Num"); } // Bet Type: Split else if(choice == 2){ int numb1, numb2; printf("\nEnter the two consecutive numbers you would like to bet on:\n"); int valid = 0; while(!valid){ printf(">> "); scanf("%d %d", &numb1, &numb2); // Swap numbers so numb1 is smaller if(numb1 > numb2){ int temp = numb2; numb1 = numb2; numb2 = temp; } if(numb1 % 3 == 0) printf("Sorry, this is not a valid split. Try again.\n"); else if(numb2 - numb1 != 1) printf("Sorry, these numbers are not consecutive. Try again.\n"); else valid = 1; } bets[num_bets].win_nums[0] = numb1; bets[num_bets].win_nums[1] = numb2; bets[num_bets].mult = 18; strcpy(bets[num_bets].type, "Split"); } // Bet Type: Street else if(choice == 3){ int num; printf("\nEnter the first number of the street (row) you would like to bet on:\n"); int valid = 0; while(!valid){ printf(">> "); scanf("%d", &num); if((num % 3 != 1) || (num > 34)){ printf("Sorry, that is not the first number of a street. Try again.\n"); } else valid = 1; } int i; for(i = 0; i < 3; i++) bets[num_bets].win_nums[i] = num+i; bets[num_bets].mult = 14; strcpy(bets[num_bets].type, "Street"); } // Bet Type: Corner else if(choice == 4){ int num; printf("\nEnter the number in the top left of the four numbers sharing the corners:\n"); int valid = 0; while(!valid){ printf(">> "); scanf("%d", &num); if(num % 3 == 0) printf("Sorry, that is not the top left part of a corner. Try again.\n"); else if(num < 1 || num > 32) printf("Sorry, that is not the top left part of a corner. Try again.\n"); else valid = 1; } bets[num_bets].win_nums[0] = num; bets[num_bets].win_nums[1] = num+1; bets[num_bets].win_nums[2] = num+3; bets[num_bets].win_nums[3] = num+4; bets[num_bets].mult = 6; strcpy(bets[num_bets].type, "Corner"); } // Bet Type: Double Street else if(choice == 5){ int num; printf("\nEnter the first number of the top street in your double street:\n"); int valid = 0; while(!valid){ printf(">> "); scanf("%d", &num); if((num % 3 != 1) || (num > 31)){ printf("Sorry, that is not the first number of a double street. Try again.\n"); } else valid = 1; } int i; for(i = 0; i < 6; i++) bets[num_bets].win_nums[i] = num+i; bets[num_bets].mult = 6; strcpy(bets[num_bets].type, "Double Street"); } }
int main(int argc, char *argv[]){ char esc,tmp,strInputs[8] = {'I','T','L','F','C','U','E','O'}; int i,j,activeStructures[8]; Init(); while(1){ char c,c2; if(MainMenu.buttons[0].clicked){//PLAY button gameInit(); gameRun(); MainMenu.buttons[0].clicked = 0; } else if(MainMenu.buttons[1].clicked){//BEST SCORE button printf("Name : %s Best Score : %d",HighScore.name,HighScore.score); getch(); MainMenu.buttons[1].clicked = 0; } else if(MainMenu.buttons[2].clicked){//SETTINGS button if(SettingsMenu.buttons[0].clicked){//MATRIXSIZE button printf("Current Matrix Size : %d",Board.settings.matrixSize); printf("\nPress Enter To Change..."); c2 = getch(); if(c2 == 13) { printf("\nNew Size : "); scanf("%d",&Board.settings.matrixSize); if(Board.settings.matrixSize > BOARD_MAX_SIZE)Board.settings.matrixSize = BOARD_MAX_SIZE; else if(Board.settings.matrixSize < 5)Board.settings.matrixSize = 5; printf("Current Matrix Size : %d",Board.settings.matrixSize); getch(); } SettingsMenu.buttons[0].clicked = 0; } else if(SettingsMenu.buttons[1].clicked){//RANGE button printf("Number Range : %d , %d",Board.settings.range[0],Board.settings.range[1]); printf("\n(Difference must be greater then 2 <2,10>)\nPress Enter To Change..."); c2 = getch(); if(c2 == 13) { printf("\nRange Begin : "); scanf("%d",&Board.settings.range[0]); if(Board.settings.range[0] < 2)Board.settings.range[0] = 2; printf("Range End : "); scanf("%d",&Board.settings.range[1]); if(Board.settings.range[1] > 10)Board.settings.range[1] = 10; if(Board.settings.range[0] > Board.settings.range[1] - 2){ Board.settings.range[0] = 2; Board.settings.range[1] = 10; } printf("\nNew Number Range : %d , %d",Board.settings.range[0],Board.settings.range[1]); getch(); } SettingsMenu.buttons[1].clicked = 0; } else if(SettingsMenu.buttons[2].clicked){//STRUCTURE button printf("Active Structures : "); for(i = 0;i < Board.settings.numberOfStructures;i++)printf(" %c ",Board.settings.structures[i].name); printf("\nAvaliable Structures : I T L C E F O U"); printf("\nPress Enter To Change..."); c2 = getch(); if(c2 == 13) { printf("\n\nThe characters you used will be saved up till you use different ones\n\n");//ingilizceye çevir i = 0; esc = 0; while(i < 8 && !esc){ j = 0; printf("Enter Structure : "); scanf(" %c",&tmp); while(j < 8 && strInputs[j] != tmp && strInputs[j] != (tmp-'a'+'A') )j++; if(j < 8)activeStructures[i] = j; else esc = 1; i++; } if(i > 1){ if(!esc)MYS_Settings_CreateStructures(&Board.settings,activeStructures,i); else MYS_Settings_CreateStructures(&Board.settings,activeStructures,i-1); } printf("Active Structures : "); for(i = 0;i < Board.settings.numberOfStructures;i++)printf(" %c ",Board.settings.structures[i].name); getch(); } SettingsMenu.buttons[2].clicked = 0; } else if(SettingsMenu.buttons[3].clicked){//PLAYER NAME button char name[32]; printf("Current Name : %s",Board.settings.player.name); printf("\n(Name Length must be greater then 2)\nPress Enter To Change..."); c2 = getch(); if(c2 == 13) { printf("\nNew Name : "); gets(name); if(strlen(name) > 2) strcpy(Board.settings.player.name,name); printf("Current Name : %s",Board.settings.player.name); SaveScore(); getch(); } SettingsMenu.buttons[3].clicked = 0; } else if(SettingsMenu.buttons[4].clicked){//BACK button SettingsMenu.buttons[4].clicked = 0; MainMenu.buttons[2].clicked = 0; MainMenu.focusedButtonIndex = 0; } else{ drawMenu(&SettingsMenu); c = getch(); if(c == 27){//BACK button SettingsMenu.buttons[4].clicked = 0; MainMenu.buttons[2].clicked = 0; MainMenu.focusedButtonIndex = 0; } else menuInput(&SettingsMenu,c); } } else if(MainMenu.buttons[3].clicked){//EXIT button printf("CODED BY EMRE KUL"); getch(); return; } else {//w s enter key drawMenu(&MainMenu); c = getch(); menuInput(&MainMenu,c); } system("cls"); } return 0; }