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.

126 lines
2.7 KiB

  1. #include <iostream>
  2. #include <thread>
  3. #include <chrono>
  4. #include "components/Point.h"
  5. #include "components/Snack.h"
  6. #include "components/Snake.h"
  7. #include "game/Controller.h"
  8. #include "input-output/Graphics.h"
  9. void mainL01() {
  10. Graphics::get().init("Learners Helper");
  11. Point p(10,10,'X');
  12. p.print();
  13. Graphics::get().refreshScreen();
  14. std::this_thread::sleep_for(std::chrono::seconds(10));
  15. Graphics::get().finalize();
  16. std::cout << "Helper QUIT" << std::endl;
  17. }
  18. void mainL02() {
  19. Graphics::get().init("Learners Helper 02");
  20. Point p(10,10);
  21. generateSnack(&p);
  22. Graphics::get().refreshScreen();
  23. std::this_thread::sleep_for(std::chrono::seconds(10));
  24. Graphics::get().finalize();
  25. std::cout << "Helper QUIT" << std::endl;
  26. }
  27. void mainL03() {
  28. Graphics::get().init("Learners Helper 03");
  29. Point p(10,10);
  30. for (uint32_t i = 0; i < 100; i++) {
  31. p.moveDown();
  32. Graphics::get().refreshScreen();
  33. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  34. p.moveRight();
  35. Graphics::get().refreshScreen();
  36. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  37. }
  38. /*
  39. while(...) {
  40. // TODO: play with this
  41. }
  42. */
  43. /*
  44. do {
  45. // TODO: play with this
  46. } while (...)
  47. */
  48. Graphics::get().finalize();
  49. std::cout << "Helper QUIT" << std::endl;
  50. }
  51. void mainL04() {
  52. Graphics::get().init("Learners Helper 04");
  53. Snake snake;
  54. for (uint32_t i = 0; i < 100; i++) {
  55. snake.moveDown();
  56. Graphics::get().refreshScreen();
  57. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  58. snake.moveRight();
  59. Graphics::get().refreshScreen();
  60. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  61. }
  62. Graphics::get().finalize();
  63. std::cout << "Helper QUIT" << std::endl;
  64. }
  65. void mainL06() {
  66. Graphics::get().init("Learners Helper 06");
  67. Snake snake;
  68. // TODO: Now the snake will eventually crash into the lower wall which we detect and then abort
  69. // TODO: Figure out how to test the bit-itself and bit-snack functions yourself
  70. while(true) {
  71. snake.moveDown();
  72. Graphics::get().refreshScreen();
  73. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  74. if (snake.hasCrashedWall()) break;
  75. }
  76. Graphics::get().finalize();
  77. std::cout << "Helper QUIT" << std::endl;
  78. }
  79. void mainL08() {
  80. Graphics::get().init("Snake Game made by YOU");
  81. Controller controller;
  82. while(true) {
  83. controller.act();
  84. if (controller.wantsToQuit()) break;
  85. }
  86. Graphics::get().finalize();
  87. std::cout << "Final Score: " << controller.getScore() << std::endl;
  88. }
  89. int main() {
  90. mainL08();
  91. return 0;
  92. }