Multi-game multiplayer arcade gaming system meant for the blue O when playing Super Tic-Tac-Toe.
Dependencies: 4DGL-uLCD-SE PinDetect SDFileSystem mbed wave_player
Diff: main.cpp
- Revision:
- 2:da0f01fbd25c
- Parent:
- 1:2a7e2f5aeda4
--- a/main.cpp Sat Nov 28 21:57:03 2015 +0000 +++ b/main.cpp Fri Dec 04 23:00:42 2015 +0000 @@ -1,3 +1,21 @@ +/******************************************************* + * This main program simulates a multi-game multiplayer + * arcade gaming system. The program allows the player + * to choose from four different games: + * + * 1) Simon + * 2) Super Tic-Tac-Toe (second player, the blue O) + * 3) Pac-Man + * 4) Rock, Paper, Scissors, Lizard, Spock + * + * All games except Pac-Man communicate with another + * gaming system via an XBee module to simulate + * multiplayer. Pac-Man is multiplayer as well, but the + * characters in the game are controlled using the three + * tactile switches on one board. + *******************************************************/ + + #include "mbed.h" #include "PinDetect.h" #include "SDFileSystem.h" @@ -5,18 +23,14 @@ #include "wave_player.h" #include <mpr121.h> #include "RGBLED.h" -#include "SimonSays.h" -#include "SuperTicTacToe.h" +#include "BlueO.h" +#include "Simon.h" #include "Stage.h" #include "Pacman.h" #include "Ghost.h" #include "RPSLK.h" -/* -------------------------------------------------------------------------------------------- - --------------------Global components used in all games with no overlap--------------------- - --------------------------------------------------------------------------------------------*/ - // Speaker AnalogOut DACout(p18); wave_player waver(&DACout); @@ -32,29 +46,15 @@ uLCD_4DGL uLCD(p28, p27, p30); -/* -------------------------------------------------------------------------------------------- - -----------------Variables and functions prototypes used in multiple games------------------ - --------------------------------------------------------------------------------------------*/ - // Select game to play int selectGame(); -/* -------------------------------------------------------------------------------------------- - ----------Rock, Paper, Scissors, Lizard, Spock variables and function prototypes------------ - --------------------------------------------------------------------------------------------*/ - - -/* -------------------------------------------------------------------------------------------- - --------------------------------------Main function----------------------------------------- - --------------------------------------------------------------------------------------------*/ - int main() { - start: - int game = selectGame(); + int gameNumber = selectGame(); // Play Simon Says - if (game == 0) { + if (gameNumber == 0) { // Analog noise AnalogIn noise(p15); @@ -64,22 +64,22 @@ PinDetect button3(p20); PinDetect button4(p16); - SimonSays simon = SimonSays(noise, button1, button2, button3, button4, sd, uLCD, waver); - simon.playSimonSays(); + Simon simon = Simon(noise, reset, button1, button2, button3, button4, sd, XBee, uLCD, waver); + simon.playSimon(); // Play Super Tic-Tac-Toe - } else if (game == 1) { + } else if (gameNumber == 1) { // Touch keypad InterruptIn input(p21); I2C i2c(p9, p10); Mpr121 MPR121(&i2c, Mpr121::ADD_VSS); - + // RGB LED RGBLED RGB(p25, p23, p22); - SuperTicTacToe super = SuperTicTacToe(input, MPR121, RGB, sd, uLCD, waver); - super.playSuperTicTacToe(); + BlueO player = BlueO(reset, input, MPR121, RGB, sd, XBee, uLCD, waver); + player.playSuperTicTacToe(); // Play Pac-Man - } else if (game == 2) { + } else if (gameNumber == 2) { // Pac-Man controller PinDetect PacmanRight(p9); PinDetect PacmanDown(p10); @@ -106,19 +106,18 @@ stage.initialize(); // Set up Pac-Man - Pacman pacman(PacmanRight, PacmanDown, PacmanLeft, PacmanUp, stage, uLCD); + Pacman pacman(PacmanRight, PacmanDown, PacmanLeft, PacmanUp, stage, uLCD, waver); pacman.initialize(); // Set up the red ghost Ghost redGhost(RED, pacman, redGhostRight, redGhostDown, redGhostLeft, redGhostUp, stage, uLCD); redGhost.initialize(60, 60, FACELEFT); - + // Set up the yellow ghost Ghost yellowGhost(YELLOW, pacman, yellowGhostRight, yellowGhostDown, yellowGhostLeft, yellowGhostUp, stage, uLCD); yellowGhost.initialize(68, 60, FACERIGHT); - - // Wait 3 seconds - wait(3); + + pacman.playSound(THEME); // Checks to see whether the game is over bool gameOver; @@ -152,18 +151,18 @@ RPSLK rpslk = RPSLK(reset, rock, paper, scissors, lizard, spock, sd, XBee, uLCD, waver); rpslk.playRPSLK(); } - - wait(3); - goto start; } -/* -------------------------------------------------------------------------------------------- - ------------------------Functions used in multiple games------------------------------------ - --------------------------------------------------------------------------------------------*/ - // Select game to play int selectGame() { + // Set up XBee + reset = 0; + wait(0.001); + reset = 1; + wait(0.001); + + selection: DigitalIn button1(p17); DigitalIn button2(p19); DigitalIn button3(p20); @@ -208,7 +207,38 @@ gameNumber = 3; break; } - } + } + + uLCD.cls(); + XBee.putc(gameNumber); + int otherGame = -1; + bool print = true; + + if ((gameNumber == 0) || (gameNumber == 1) || (gameNumber == 3)) { + while (otherGame == -1) { + if (XBee.readable() == true) { + otherGame = XBee.getc(); + print = false; + } + + if (print == true) { + uLCD.printf("Waiting for other player..."); + print = false; + } + } + + if (otherGame != gameNumber) { + uLCD.cls(); + uLCD.printf("Sorry, but the "); + uLCD.printf("other player chose"); + uLCD.printf("a different game. "); + uLCD.printf("Returning to game "); + uLCD.printf("selection menu."); + wait(2); + uLCD.cls(); + goto selection; + } + } uLCD.cls(); return gameNumber;