Power Grid Board Game Timer. Acts like a chess timer for 3-6 people. Uses an ADXL accelerometer to pause the timer and change players. Uses an LCD screen to prompt the players for input, read that input, and change between rounds.

Dependencies:   DmTouch_UniGraphic UniGraphic-forLdelaney17FinalProject mbed

game.cpp

Committer:
ldelaney17
Date:
2017-01-25
Revision:
3:22c644f16365
Parent:
2:e6788e73de54
Child:
4:e14c199c2466

File content as of revision 3:22c644f16365:

#include "game.h"

void game_setup(){
    init_num_players();
    set_player_order();
}

void init_num_players(){
    prompt(6, "Select the number of players\r\n"); //sets waiting_for_touch to true
    while(waiting_for_touch == true){ //until a valid input is read, spin our wheels here
        wait(0.1); // can busy wait during setup    
    }
    num_players = prompt_input_val; // set based on the circle touched
    stringstream ss;
    ss << "press 1 to confirm that " << num_players << " players is correct. Press 2 to select a different number";
    prompt(2, ss.str());
    while(waiting_for_touch == true){ //until a valid input is read
        wait(0.1); // can busy wait during setup    
    }
    int choice = prompt_input_val;
    switch(choice){
        case 1:
        return;
        break;
        case 2:
        init_num_players();
        return;
        break;
    }
}

//blocking wait function
void set_player_order(){
    player_order.clear();
    for (int i = 0; i <  num_players; i++){
        prompt(num_players, "select the player number with the most cities. \r\nIn case of a tie, the higher numbered power \r\nplant goes first\r\n");   
        while (waiting_for_touch){
           wait(0.05); //blocking busy wait 
        }
        player_order.push_back(prompt_input_val);
    }
    //TODO: if has duplicates, display message "invalid turn order" and call set_player_order
      
    stringstream ss;
    ss << "press 1 to confirm that player order is correct. \r\nPress 2 to change";
    ss << "\r\nPlayer Order:\t";
    for (int i = 0; i < num_players; i++){
        ss << player_order[i] << "\t";   
    }
    prompt(2, ss.str());
    while(waiting_for_touch == true){ //until a valid input is read
        wait(0.1); // can busy wait during setup    
    }
    int choice = prompt_input_val;
    switch(choice){
        case 1:
        return;
        break;
        case 2:
        set_player_order();
        return;
        break;
    }
}