#include "Arduino.h"
#include "config.h"
#include "GameDisplay.h"

GameDisplay::GameDisplay(const int pinRs, const int pinEn, const int pinD4, const int pinD5, const int pinD6, const int pinD7, const int rows, const int cols)
  : m_lcd(pinRs, pinEn, pinD4, pinD5, pinD6, pinD7), m_rows(rows), m_cols(cols) { }


void GameDisplay::printCenter(String str, int col) {
  m_lcd.setCursor(((m_rows - (int) str.length()) / 2), col);
  m_lcd.print(str);
}


void GameDisplay::init(void) {
  m_lcd.begin(m_rows, m_cols);
  m_lcd.clear();
}

void GameDisplay::showScoreScreen(int score, int highScore) {
  String strHighscore = "Highscore: ";
  String strScore = "Score: ";

  strHighscore.concat(highScore);
  strScore.concat(score);
  
  m_lcd.clear();
  printCenter(strHighscore, 0);
  printCenter(strScore, 1);
}

void GameDisplay::showHitScreen(int score, bool full) {
  String strScore = "Score: ";

  strScore.concat(score);
  m_lcd.clear();

  printCenter((full ? ">>FULL HIT<<" : ">>HALF HIT<<"), 0);
  printCenter(strScore, 1);
}

void GameDisplay::showHealthScreen(int health) {
  String strHealth = "Health: ";
  strHealth.concat(health);

  m_lcd.clear();
  printCenter(">> MISS <<", 0);
  printCenter(strHealth, 1);
}

void GameDisplay::showGameOverScreen(int score) {
  String strScore = "Score: ";
  strScore.concat(score);

  m_lcd.clear();
  printCenter(">> GAME OVER <<", 0);
  printCenter(strScore, 1);
}

void GameDisplay::showResetScreen(void) {
  m_lcd.clear();
  printCenter(">> HIGHSCORE <<", 0);
  printCenter(">>  CLEARED  <<", 1);
}