#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
int buttons[] = {35, 37, 41, 39};
int LEDs[] = {23, 25, 27, 29, 31, 53, 51, 49, 47, 45};
void setup() {
Serial.begin(9600);
randomSeed(analogRead(0));
lcd.begin(16, 2);
random(2, 9);
for(int i = 0; i < 10; i++) pinMode(LEDs[i], OUTPUT);
lcd.print(" Select P1");
}
void wait_sec(double sec){
unsigned long startTime = millis();
while (millis() - startTime < sec*1000){}
}
String center(String text){
return text;
}
int* select_bullets(int n=0){
if(n==0) n = random(2, 9);
int* bullets = new int[8];
for(int i = 0; i < n; i++) bullets[i] = random(1, 3);
return bullets;
}
String concat_bullets(int bullets[]){
String text = "";
for(int i = 0; i < 8; i++){
switch(bullets[i]){
case 0: text += "_"; break;
case 1: text += "8"; break;
case 2: text += "u"; break;
}
}
return text;
}
void show_bullets(int bullets[]){
lcd.clear();
lcd.setCursor(4, 0);
lcd.print(concat_bullets(bullets));
wait_sec(1);
lcd.clear();
}
bool started = false;
int P1self;
int P1other;
int P2self;
int P2other;
int P1health;
int P2health;
int* P1LEDs = new int[5];
int* P2LEDs = new int[5];
bool P1turn = true;
void loop() {
if(!started){
while(!(digitalRead(buttons[0]) || digitalRead(buttons[1]) || digitalRead(buttons[2]) || digitalRead(buttons[3]))){}
if(digitalRead(buttons[0]) || digitalRead(buttons[1])) {
P1self = buttons[0];
P1other = buttons[1];
P2other = buttons[3];
P2self = buttons[2];
for(int i = 0; i < 5; i++){
P1LEDs[i] = LEDs[i];
P2LEDs[i] = LEDs[i+5];
}
}
else {
P2self = buttons[0];
P2other = buttons[1];
P1other = buttons[3];
P1self = buttons[2];
for(int i = 0; i < 5; i++){
P2LEDs[i] = LEDs[i];
P1LEDs[i] = LEDs[i+5];
}
}
lcd.clear();
for(int i = 0; i < 5; i++){
digitalWrite(P1LEDs[i], HIGH);
digitalWrite(P2LEDs[i], HIGH);
wait_sec(0.5);
}
P1health = 5;
P2health = 5;
wait_sec(1);
int* bullets = select_bullets();
show_bullets(bullets);
started = true;
}
else{
}
}