You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB

  1. #include "Controller.h"
  2. #include <string>
  3. #include <iostream>
  4. Controller::Controller()
  5. : input_{0}, score_{0}, snack_{Point(0,0,0)}
  6. {
  7. generateSnack(&snack_);
  8. }
  9. void Controller::printScore(uint32_t score) const {
  10. const std::string str = "Score: " + std::to_string(score);
  11. // locate message at (-1,-1) because otherwise it'll be printed inside the game box
  12. Graphics::get().printMsg(-1, -1, str);
  13. }
  14. int Controller::act() {
  15. readInput();
  16. if (snake_.hasBitSnack(snack_.getY(), snack_.getX())) {
  17. score_ += 10;
  18. snake_.incSize();
  19. generateSnack(&snack_);
  20. Graphics::get().advanceDifficulty();
  21. printScore(score_);
  22. }
  23. // TODO: perform action depending on value of input_ - see "Snake::updateHead" for some guidance
  24. Graphics::get().refreshScreen();
  25. // TODO: handle bit-itself and crashed-wall case by returning DEFEAT
  26. return 0;
  27. }
  28. void Controller::readInput() {
  29. input_ = Graphics::get().readInpt();
  30. }
  31. bool Controller::wantsToQuit() const {
  32. return input_ == EXIT_GAME;
  33. }
  34. uint32_t Controller::getScore() const {
  35. return score_;
  36. }