я по видео создаю. и все как на видео до середины второй части. вроде как, пересматривал неоднократно, код такой же как и у него на С++.
проблемка в том, что когда нажимаю А, например, то буква S должна переместиться влево. как в AWSD управлении. Почему, оно стоит на месте? скажи пожалуйста
#include<conio.h>
#include <cstdlib>
#include<iostream>
using namespace std;
bool GameOver;
const int width = 20;
const int height = 20;
int x, y, FruitX, FruitY, score;
enum eDirection { STOP = 0, LEFT, RIGHT, UP, DOWN }; // тип enum с именем eDirection
eDirection dir; // переменная dir типа eDirection, может принимать любое из значений, определенных в перечислении
void Setup() { //setting parameters
GameOver = false;
dir = STOP;
x = width / 2;
y = height / 2;
FruitX = rand() % width;
FruitY = rand() % height;
score = 0; // score at the begging = 0
}
void Draw() { //setting location
system("cls"); //очищает терминал каждый раз когда вызываем функцию Draw
for (int i = 0; i < width+1; i++)
cout << "#";
cout << endl;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (j == 0 || j == width - 1) {
cout << "#";
}
if (i == x && j == y)
cout << "S";//snake
else if (i == FruitX && j == FruitY)
cout << "F";
else {
cout << " ";
}
}
cout << endl;
}
for (int i = 0; i < width+1; i++)
cout << "#";
}
void Input() { //react on user's actions and manipulations
if(_kbhit()) { //define if was there any stroke
switch (_getch()) { //reads characters by using console without using a buffer
case 'a':
dir = LEFT;
break;
case 'd':
dir = RIGHT;
break;
case 'w':
dir = UP;
break;
case 's':
dir = DOWN;
break;
case 27: //ASCII-код для клавиши "esc"
GameOver = true;
break;
}
}
}
void Logic() {
switch (dir) {
case LEFT:
x--;
break;
case RIGHT:
x++;
break;
case UP:
y++;
break;
case DOWN:
y--;
break;
}
}
int main() {
Setup();
while (!GameOver) {
Draw();
Input();
Logic();
}
return 0;
}