#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define BUTTON_NO 2
#define BUTTON_YES 3
#define BUZZER 4

int currentMenu = 0;

void setup() {
  pinMode(BUTTON_NO, INPUT_PULLUP);
  pinMode(BUTTON_YES, INPUT_PULLUP);
  pinMode(BUZZER, OUTPUT);

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    for (;;);
  }
  display.clearDisplay();
  display.display();

  showMenu();
}

void loop() {
  if (digitalRead(BUTTON_NO) == LOW) {
    handleNo();
    delay(200);
  }
  if (digitalRead(BUTTON_YES) == LOW) {
    handleYes();
    delay(200);
  }
}

void showMenu() {
  display.clearDisplay();
  switch (currentMenu) {
    case 0:
      display.setCursor(0, 0);
      display.setTextSize(1);
      display.setTextColor(SSD1306_WHITE);
      display.println("Do you want to play?");
      display.setCursor(0, 30);
      display.println("<- No         Yes ->");
      break;
    case 1:
      display.setCursor(0, 0);
      display.println("Do you like apple?");
      display.setCursor(0, 30);
      display.println("<- No         Yes ->");
      break;
    case 2:
      display.setCursor(0, 0);
      display.println("Do you like your brother?");
      display.setCursor(0, 30);
      display.println("<- No         Yes ->");
      break;
    case 3:
      display.setCursor(0, 0);
      display.println("Do you like a wall?");
      display.setCursor(0, 30);
      display.println("<- No         Yes ->");
      break;
    case 4:
      display.setCursor(0, 0);
      display.println("Do you like your family?");
      display.setCursor(0, 30);
      display.println("<- No         Yes ->");
      break;
    case 5:
      display.setCursor(0, 0);
      display.println("Do you kill yourself?");
      display.setCursor(0, 30);
      display.println("<- No         Yes ->");
      break;
    case 6:
      display.setCursor(0, 0);
      display.println("Yes, you do.");
      break;
  }
  display.display();
}

void handleNo() {
  if (currentMenu == 6) return;

  digitalWrite(BUZZER, HIGH);
  delay(100);
  digitalWrite(BUZZER, LOW);

  if (currentMenu == 3) {
    currentMenu++;
  } else {
    showMenu();
  }
}

void handleYes() {
  if (currentMenu == 6) {
    digitalWrite(BUZZER, HIGH);
    delay(5000);
    digitalWrite(BUZZER, LOW);
    currentMenu = 0;
  } else {
    currentMenu++;
  }
  showMenu();
}