AirsoftTimer software based on mbed
Dependencies: mbed TextLCD keypad
Revision 12:22e9ef610ea2, committed 2015-05-23
- Comitter:
- sillevl
- Date:
- Sat May 23 15:28:55 2015 +0000
- Parent:
- 11:50572814f73e
- Child:
- 13:ece97a1108cc
- Commit message:
- Showbuzzer game only
Changed in this revision
--- a/Airsofttimer.cpp Wed Dec 31 15:27:43 2014 +0000 +++ b/Airsofttimer.cpp Sat May 23 15:28:55 2015 +0000 @@ -37,6 +37,7 @@ // first we need to select a game from the available games list int game_number = select_game(); Game* game = Game::create_game(board, game_number); + game->setup(); game->run(); delete game; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/games/CatchItKeepIt.cpp Sat May 23 15:28:55 2015 +0000 @@ -0,0 +1,34 @@ + +#include "CatchItKeepIt.h" + + +static const char* NAME = "ShowBuzzer"; + +CatchItKeepIt::CatchItKeepIt(Board* board) : Game(board){ + Settings settings; + settings.activation_code[0] = 1397; + settings.activation_code[1] = 2684; + settings.activation_code[2] = 1597; + settings.activation_code[3] = 3579; + settings.timeout = 60; // 1 minute + settings.decrease_timeout = 0; // decrease with 0% + settings.beep_interval = 1; // beep every second + settings.team_count = 2; // start with 2 teams +} + +void CatchItKeepIt::setup(){ + // number of teams + // set timer + // set beep interval + // set decrease timer interval + // uses custom codes? +} + +void CatchItKeepIt::run(){ + while(true){ + // wait for code input + // count down + // beep + // don't return from this function yet (only if the game ends); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/games/CatchItKeepIt.h Sat May 23 15:28:55 2015 +0000 @@ -0,0 +1,37 @@ + +#ifndef CATCHITKEEPIT_H +#define CATCHITKEEPIT_H + +#include "Game.h" + +class CatchItKeepIt : public Game{ + + public: + CatchItKeepIt(Board* board); + virtual void setup(); + virtual void run(); + + protected: + enum Team {ALPHA, BRAVO, CHARLY, DELTA}; + + struct Settings{ + int team_count; + int activation_code[4]; + int timeout; + int beep_interval; + int decrease_timeout; + }; + + static const int MIN_TEAMS = 2; + static const int MAX_TEAMS = 4; + static const int MIN_TIMEOUT = 60; // 1 minute + static const int MAX_TIMEOUT = 60*60; // 1 hour + static const int MIN_BEEP_INTERVAL = 0; + static const int MAX_BEEP_INTERVAL = 10; + static const int MIN_DECREASE_TIMEOUT = 0; + static const int MAX_DECREASE_TIMEOUT = 75; + +}; + + +#endif \ No newline at end of file
--- a/games/Game.cpp Wed Dec 31 15:27:43 2014 +0000 +++ b/games/Game.cpp Sat May 23 15:28:55 2015 +0000 @@ -4,6 +4,16 @@ Game::Game(Board* board){ this->board = board; + lcd = board->lcd; + leds = board->leds; + key = board->key; + button = board->button; + keyboard = board->keyboard; + buzzer = board->buzzer; + + //keyboard->attach(this,&Game::keyEvent); + //keyboard->start(); + leds->off(Leds::ALL); } Game* Game::create_game(Board* board, int choice){ @@ -11,3 +21,8 @@ return game; } +void Game::keyEvent(char key){ + // play key pressed sound ? + // do nothing by default +} +
--- a/games/Game.h Wed Dec 31 15:27:43 2014 +0000 +++ b/games/Game.h Sat May 23 15:28:55 2015 +0000 @@ -9,11 +9,21 @@ static const char* NAME; static Game* create_game(Board* board, int choice); //factory method + virtual void setup() = 0; virtual void run() = 0; protected: Board* board; + LCD* lcd; + Leds* leds; + Key* key; + Button* button; + Keyboard* keyboard; + Buzzer* buzzer; + + void keyEvent(char key); + };
--- a/games/ShowBuzzer.cpp Wed Dec 31 15:27:43 2014 +0000 +++ b/games/ShowBuzzer.cpp Sat May 23 15:28:55 2015 +0000 @@ -5,13 +5,17 @@ static const char* NAME = "ShowBuzzer"; ShowBuzzer::ShowBuzzer(Board* board) : Game(board){ - board->keyboard->attach(this,&ShowBuzzer::keyPressed); - board->keyboard->start(); - board->leds->off(Leds::ALL); + keyboard->attach(this,&ShowBuzzer::keyPressed); + keyboard->start(); + leds->off(Leds::ALL); +} + +void ShowBuzzer::setup(){ + //no setup required for this game } void ShowBuzzer::run(){ - board->lcd->printf("ShowBuzzer"); + lcd->printf("ShowBuzzer"); newRound(); while(true){ @@ -33,20 +37,20 @@ } void ShowBuzzer::newRound(){ - board->buzzer->playNote(200,50); - board->leds->off(Leds::ALL); - board->lcd->cls(); - board->lcd->printf("*** WAITING ***"); + buzzer->playNote(200,50); + leds->off(Leds::ALL); + lcd->cls(); + lcd->printf("*** WAITING ***"); } ShowBuzzer::Team ShowBuzzer::waitForButtonPress(){ Team team; while(true){ - if(board->button->read() == 0){ + if(button->read() == 0){ team = TEAM_B; break; } - if(board->key->read() == 0){ + if(key->read() == 0){ team = TEAM_A; break; } @@ -57,10 +61,10 @@ void ShowBuzzer::setLeds(Team team){ switch(team){ case TEAM_A: - board->leds->on(Leds::LEFT); + leds->on(Leds::LEFT); break; case TEAM_B: - board->leds->on(Leds::RIGHT); + leds->on(Leds::RIGHT); break; default: break; @@ -68,14 +72,14 @@ } void ShowBuzzer::setDisplay(Team team){ - board->lcd->locate(0,0); - board->lcd->cls(); + lcd->locate(0,0); + lcd->cls(); switch(team){ case TEAM_A: - board->lcd->printf("Team A"); + lcd->printf("Team A"); break; case TEAM_B: - board->lcd->printf("Team B"); + lcd->printf("Team B"); break; default: break; @@ -83,27 +87,27 @@ } void ShowBuzzer::playSound(){ - board->buzzer->playNote(698, 50); - board->buzzer->playNote(783, 50); - board->buzzer->playNote(880, 50); - board->buzzer->playNote(987, 50); - board->buzzer->playNote(1108, 50); - board->buzzer->playNote(1244, 50); - board->buzzer->playNote(1396, 50); - board->buzzer->playNote(1567, 50); - board->buzzer->playNote(1760, 50); - board->buzzer->playNote(1975, 50); + buzzer->playNote(698, 50); + buzzer->playNote(783, 50); + buzzer->playNote(880, 50); + buzzer->playNote(987, 50); + buzzer->playNote(1108, 50); + buzzer->playNote(1244, 50); + buzzer->playNote(1396, 50); + buzzer->playNote(1567, 50); + buzzer->playNote(1760, 50); + buzzer->playNote(1975, 50); } void ShowBuzzer::playCorrect(){ - board->buzzer->playNote(2093, 100); - board->buzzer->playNote(2637, 100); - board->buzzer->playNote(3165, 100); - board->buzzer->playNote(3951, 100); + buzzer->playNote(2093, 100); + buzzer->playNote(2637, 100); + buzzer->playNote(3165, 100); + buzzer->playNote(3951, 100); } void ShowBuzzer::playWrong(){ - board->buzzer->playNote(440, 1000); + buzzer->playNote(440, 1000); } uint32_t ShowBuzzer::keyPressed(uint32_t key){
--- a/games/ShowBuzzer.h Wed Dec 31 15:27:43 2014 +0000 +++ b/games/ShowBuzzer.h Sat May 23 15:28:55 2015 +0000 @@ -8,6 +8,7 @@ public: ShowBuzzer(Board* board); + virtual void setup(); virtual void run(); private:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/games/settings/Setting.h Sat May 23 15:28:55 2015 +0000 @@ -0,0 +1,16 @@ +#ifndef SETTING_H +#define SETTING_H + +class Setting{ + public: + Setting(); + + private: + string title; + //printable on lcd + +} + + + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/games/settings/SettingsMenu.h Sat May 23 15:28:55 2015 +0000 @@ -0,0 +1,27 @@ +#ifndef SETTINGSMENU_H +#define SETTINGSMENU_H + +#include "../../board/Board.h" + +class GameSelector{ + Board* board; + void print_up_down_arrows(); + void print_selection_arrow(); + void print_list(); + + void go_down(); + void go_up(); + + int start_position; + int current_selection; + int total_selections; + + //char* titles[7]; + Vector<Setting> settings; + + public: + GameSelector(Board* board); + void run(); +}; + +#endif \ No newline at end of file