/** @file game.c
 *  @author Tyler Cooper,& Blake tolmie
 *  @date 14 October 2024
 *  @brief runs each module in stages
 */
#include "system.h"
#include "player_setup.h"
#include "message.h"
#include <avr/io.h>
#include "pio.h"
#include "../fonts/font5x7_1.h"
#include "tinygl.h"
#include "win_lose_screen.h"


int main (void)
{
    /* initialise the system and variables used*/
    system_init ();
    tinygl_font_set (&font5x7_1);
    int8_t current_select = '2';
    char opponent_select = '3';
    uint16_t make_seconds = 1000;
    uint16_t duration = 5*make_seconds; //select how long to go before timing out 50 = 5s
    uint16_t homescreen_duration = 20*make_seconds;
    uint8_t state = 1; //select what module/part to run
    uint16_t stager = 0; // helps setup each module


    while (1)
    {
        if(state == 1) {
            //run star screen    
            message("Paper Scissors Rock!",true,homescreen_duration,&state,&stager);
        }

        if(state == 2) {
            player_selection(&current_select, &opponent_select, duration,&state,&stager);
        }
        if(state == 3) {
            /* run diffrent win lose screens depending on player and opennet selection*/
            if(current_select == opponent_select) {
                win_lose("Draw",true,duration,&state,&stager); 
            } else if (current_select == '1') {
                if (opponent_select == '2') {
                    win_lose("Winner",true,duration,&state,&stager);
                } else if (opponent_select == '3'){
                    win_lose("Loser",true,duration,&state,&stager);        
                } else{
                    win_lose("?",false,duration,&state,&stager);//result if error has occurred
                }
            } else if (current_select == '2') {
                if (opponent_select == '3') {
                    win_lose("Winner",true,duration,&state,&stager); 
                } else if( opponent_select == '1'){
                    win_lose("Loser",true,duration,&state,&stager);        
                } else{
                    win_lose("?",false,duration,&state,&stager);//result if error has occurred
                }
            } else if (current_select == '3') {
                if (opponent_select == '1') {
                    win_lose("Winner",true,duration,&state,&stager); 
                } else if (opponent_select == '2'){
                    win_lose("Loser",true,duration,&state,&stager);        
                } else{
                    win_lose("?",false,duration,&state,&stager);//result if error has occurred
                }
            }
        }
    }
}




