#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte ROWS = 4; // počet řádků na klávesnici
const byte COLS = 4; // počet sloupců na klávesnici
byte rowPins[ROWS] = {9, 8, 7, 6}; // připojené k pinům pro řádky
byte colPins[COLS] = {5, 4, 3, 2}; // připojené k pinům pro sloupce
char keys[ROWS][COLS] = {
{'1','2','3','+'},
{'4','5','6','-'},
{'7','8','9','*'},
{'D','0','=','/'}
};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
int plrY = 0;
int obsYpos[2][4] = {
{'1', '0', '1', '0'},
{'0', '1', '0', '1'},
};
int x = random(1,3);
int obsX[4] = {15,15,15,15};
int obsY[4] = {0,0,0,0};
char obs = '#';
int actObs = 0;
char plr = 'N';
char plrList[4] = {'N', '0', '*', 'U'};
int plrNum = 0;
String win = "menu";
bool gameStart = true;
String language = "English";
void setup() {
if (x == 1) {
for (int i = 0; i < 3; i++) {
obsY[i] = obsYpos[0][i];
}
} else {
for (int i = 0; i < 3; i++) {
obsY[i] = obsYpos[1][i];
}
}
obstInit();
lcd.init();
lcd.backlight();
// put your setup code here, to run once:
if (win == "menu") {
showMenuChar();
menu();
} else if (win == "game") {
game();
}
Serial.begin(9600);
}
void obstInit() {
obsY[0] = randomNumGen();
obsY[1] = randomNumGen();
obsY[2] = randomNumGen();
obsY[3] = randomNumGen();
}
void showData(){
lcd.clear();
lcd.setCursor(obsX[actObs], obsY[actObs]);
lcd.print(obs);
lcd.setCursor(0, plrY);
lcd.print(plr);
Serial.println(obsY[0]);
Serial.println(obsY[2]);
Serial.println(obsY[3]);
Serial.println(obsY[4]);
}
int randomNumGen() {
int num = random(1,101);
if (num <= 50) {
return 1;
} else if (num > 50) {
return 0;
}
}
void game() {
obstInit();
}
void loop() {
// put your main code here, to run repeatedly:
char key = keypad.getKey();
if (key) {
if (key == '+') {
plrY = 0;
} else if (key == '-') {
plrY = 1;
}
}
obsX[actObs] -=1;
if (obsX[actObs] == -1) {
obsX[actObs] = 15;
actObs += 1;
if (actObs == 4) {
actObs = 0;
}
}
showData();
delay(50);
}
void menu() {
while (win == "menu") {
char key = keypad.getKey();
if (key) {
if (key == '+') {
plrNum += 1;
if (plrNum == 4) {
plrNum = 0;
}
showMenuChar();
} else if (key == '-') {
plrNum -= 1;
if (plrNum == -1) {
plrNum = 3;
}
showMenuChar();
} else if (key == '=') {
plr = plrList[plrNum];
win = "game";
}
}
}
}
void showMenuChar() {
lcd.clear();
lcd.setCursor(0,0);
if (language == "English") {
lcd.print("Choose character:");
} else if (language == "Cesky") {
lcd.print("Vyberte postavu:");
} else if (language == "Bahasa Indonesia") {
lcd.print("Vyber id");
}
lcd.setCursor(0,1);
lcd.print(plrList[plrNum]);
}