Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
3.6 kB
3
Indexable
Never
#include <xc.h>
#include <libpic30.h>
#include <stdio.h>
#include <string.h>
#include "lcd.h"
#include "buttons.h"

#define TOTAL_TIME (15)  

volatile unsigned int seconds = TOTAL_TIME;

int main(void) {
    char buffer[32];
    LCD_Initialize();
    unsigned int remainingSecondsWhite = seconds;
    unsigned int remainingSecondsBlack = seconds;
    int gamePhase = 3;  

    while (true) {
        // Obsługa przycisku resetu S6
        if (BUTTON_IsPressed(BUTTON_S6) == true) { 
            gamePhase = 3; 
            remainingSecondsWhite = seconds;
            remainingSecondsBlack = seconds;
        }

        switch (gamePhase) {
            case 0:  // Koniec czasu - resetowanie zegarów i powrót do ekranu startowego
                LCD_ClearScreen();
                if (remainingSecondsWhite < 1) {
                    LCD_PutString("Biale przegrywaja", strlen("Biale przegrywaja")); 
                } else {
                    LCD_PutString("Czarne przegrywaja", strlen("Czarne przegrywaja")); 
                }
                __delay_ms(4000); 
                remainingSecondsWhite = seconds;
                remainingSecondsBlack = seconds;
                gamePhase = 3;  
                break;

            case 1:  // Tura białych
                // Obsługa przycisku zmiany tury S3
                if (BUTTON_IsPressed(BUTTON_S3) == true) { 
                    gamePhase = 2;
                    break;
                }

                sprintf(buffer, "%02u:%02u biale", remainingSecondsWhite / 60, remainingSecondsWhite % 60);
                LCD_ClearScreen();
                LCD_PutString(buffer, strlen(buffer));
                LCD_PutString("\n", 1); 
                sprintf(buffer, "%02u:%02u czarne", remainingSecondsBlack / 60, remainingSecondsBlack % 60);
                LCD_PutString(buffer, strlen(buffer));
                __delay_ms(1000); 
                remainingSecondsWhite--;

                if (remainingSecondsWhite < 1) {
                    gamePhase = 0;
                }
                break;

            case 2:  // Tura czarnych
                // Obsługa przycisku zmiany tury S4
                if (BUTTON_IsPressed(BUTTON_S4) == true) { 
                    gamePhase = 1;
                    break;
                }

                sprintf(buffer, "%02u:%02u czarne", remainingSecondsBlack / 60, remainingSecondsBlack % 60);
                LCD_ClearScreen();
                LCD_PutString(buffer, strlen(buffer));
                LCD_PutString("\n", 1); 
                sprintf(buffer, "%02u:%02u biale", remainingSecondsWhite / 60, remainingSecondsWhite % 60);
                LCD_PutString(buffer, strlen(buffer));
                __delay_ms(1000);
                remainingSecondsBlack--;
                if (remainingSecondsBlack < 1) {
                    gamePhase = 0;
                }
                break;

            case 3: // Kto zaczyna?
                LCD_PutString("Kto zaczyna?\n s3=biale s4=czarne", 32);
                __delay_ms(4000); 
                LCD_ClearScreen();
                if (BUTTON_IsPressed(BUTTON_S3) == true) {
                    gamePhase = 1; 
                    break;
                }
                if (BUTTON_IsPressed(BUTTON_S4) == true) {
                    gamePhase = 2; 
                    break;
                }
                break; // Dodanie break dla case 3

            default:
                break;
        }
    }
    return 0;
}
Leave a Comment