#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int btn = 2;
int btnState;
int col;
int pRow = 0;
int oRow;
bool Running = true;
int score = 0; // Variable to keep track of the score
void setup() {
pinMode(btn, INPUT);
lcd.init();
lcd.backlight();
randomSeed(analogRead(0));
lcd.setCursor(0, 0);
lcd.print("Score: 0");
}
void loop() {
score = 0;
Running = true;
while (Running) {
for (col = 15; col >= 0; col--) {
lcd.clear();
lcd.setCursor(col, oRow);
lcd.print("(o)");
lcd.setCursor(1, pRow);
lcd.print("8===D");
btnState = digitalRead(btn);
player();
delay(100);
if (col == 1 && oRow == pRow) {
Running = false;
break;
}
}
if (col < 0) {
oRow = random(0, 2);
}
score++;
}
displayScore();
while (true);
}
void player() {
if (btnState == HIGH) {
pRow = (pRow == 0) ? 1 : 0;
delay(100);
}
if (col == 1 && oRow == pRow) {
Running = false;
}
}
void displayScore() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("BUNTIS KA NA!");
lcd.setCursor(0, 1);
lcd.print("Score: ");
lcd.print(score);
}