Advertisement
SIKER_98

2

Apr 27th, 2020
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <unistd.h>
  3. //#include <ostream>
  4.  
  5. using namespace std;
  6.  
  7. class Snake {
  8. public:
  9. int x, y;
  10. Snake *next;
  11. };
  12.  
  13. class Game {
  14. private:
  15. int board[10][10][1];
  16. int szerokosc, dlugosc;
  17. int points;
  18. int direction;
  19. Snake head;
  20.  
  21. public:
  22. Game(int szerokosc, int dlugosc) {
  23. this->szerokosc = szerokosc;
  24. this->dlugosc = dlugosc;
  25. this->points = 0;
  26. Snake *head = new Snake();
  27. head->x = 5;
  28. head->y = 5;
  29. }
  30.  
  31. void pressUp() {
  32. this->direction = 0;
  33. }
  34.  
  35. void pressDown() {
  36. this->direction = 1;
  37. }
  38.  
  39. void pressLeft() {
  40. this->direction = 2;
  41. }
  42.  
  43. void pressRight() {
  44. this->direction = 4;
  45. }
  46.  
  47. void chodzenie() {
  48. for (int i = 0; i < 10; i++)
  49. for (int j = 0; j < 10; j++)
  50. board[i][j][0] = 0;
  51.  
  52. Snake tmp = head;
  53. while (head.next != null) {
  54. board[tmp.x][tmp.y][0] = 1;
  55. tmp = *tmp.next;
  56. }
  57. board[tmp.x][tmp.y][0] = 1;
  58. }
  59.  
  60. void step() {
  61.  
  62. }
  63.  
  64. int getPoints() {
  65. return this->points;
  66. }
  67.  
  68. void show() {
  69.  
  70. }
  71.  
  72. void setDirection(int direction) {
  73. switch (direction) {
  74. case 0:
  75. pressUp();
  76. break;
  77. case 1:
  78. pressDown();
  79. break;
  80. case 2:
  81. pressLeft();
  82. break;
  83. case 4:
  84. pressRight();
  85. break;
  86. }
  87. }
  88.  
  89. void testSnake() {
  90. int steps = 50;
  91. Game *g = new Game(10, 10);
  92. g->show();
  93. int a[] = {5, 2, 5, 5, 5, 1, 5, 5, 5, 3, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 2, 5, 5, 5, 5, 5, 1, 5, 5, 5, 3, 5,
  94. 5, 5, 0};
  95. for (int i = 0; i < steps; i++) {
  96. usleep(500000);
  97. int r = a[i % (sizeof(a) / sizeof(*a))];
  98. system("clear");
  99. cout << "Punkty:" << g->getPoints() << endl;
  100. if (r < 4) {
  101. g->setDirection(r);
  102. }
  103. g->step();
  104. g->show();
  105. cout << flush;
  106. }
  107. }
  108.  
  109. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement