Untitled

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

#define TOTAL_TIME (2500)  // Czas dla obu graczy

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) {
        switch(gamePhase) {

            if (BUTTON_IsPressed ( BUTTON_S6 ) == true) { // Reset gry przytrzymaniem przycisku S6
                gamePhase = 3; 
                remainingSecondsWhite = seconds;
                remainingSecondsBlack = seconds;
            }

            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")); 
                }
                __delay32(4000000); // Czekamy 10 sekund
                remainingSecondsWhite = seconds; // Reset czasu białych
                remainingSecondsBlack = seconds;  // Reset czasu czarnych
                gamePhase = 3;  

            case 1:  // Tura białych
                if (BUTTON_IsPressed(BUTTON_S4) == 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));
                __delay32(4000000); // Czekamy sekundę (zamiast __delay32(4000000))
                remainingSecondsWhite--;
                if(remainingSecondsWhite < 1) {
                    gamePhase = 0;
                }
                break;

            case 2:  // Tura czarnych
                if (BUTTON_IsPressed ( BUTTON_S3 ) == 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));
                __delay32(4000000); // Czekamy sekundę (zamiast __delay32(4000000))
                remainingSecondsBlack--;
                if(remainingSecondsBlack < 1) {
                    gamePhase = 0;
                }
                break;


            case 3: // Kto zaczyna?
                LCD_PutString("Kto zaczyna?\n s3=b s4=cz",32);
                __delay32(4000000);
                LCD_ClearScreen();
                if (BUTTON_IsPressed ( BUTTON_S3 ) == true) {
                    gamePhase = 2;
                    break;
                }
                if (BUTTON_IsPressed ( BUTTON_S4 ) == true) {
                    gamePhase = 1; 
                    break;
                }

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