Răspuns :
Ok. am facut si eu un joculet de tip Snake(scuze ca are comentarii in engleza, dar asa m-am obisnuit.)
Nu ma lasa brainly sa-l postez. Il poti gasi aici
https://sourceb.in/q9tGembQtv
#include <windows.h>
#include <iostream>
#include <cstdlib>
#include <conio.h>
class Joc {
public:
static void start() {
for (;;) {
if (pos[0] == rnd[0] && pos[1] == rnd[1])
gen_rnd();
system("cls");
print();
switch (getch()) {
case 119: // tasta w
if (pos[0])
--pos[0];
break;
case 100: // a
if (pos[1] < 17)
++pos[1];
break;
case 115: // s
if (pos[0] < 19)
++pos[0];
break;
case 97: // d
if (pos[1])
--pos[1];
break;
case 27: // esc
return;
}
Sleep(50);
}
}
private:
static size_t pos[2], rnd[2], p;
static void print() {
size_t j, i;
for (i = 0; i < 20; ++i)
std::cout << '#';
std::cout << '\n';
for (i = 0; i < 20; ++i) {
std::cout << '#';
for (j = 0; j < 18; ++j) {
std::cout << (i == pos[0] && j == pos[1] ? 'X' : i == rnd[0] && j == rnd[1] ? '%'
: ' ');
}
std::cout << "#\n";
}
for (i = 0; i < 20; ++i)
std::cout << '#';
std::cout << "\n\nPuncte: " << p;
}
static void gen_rnd() {
++p;
rnd[0] = rand() % 20;
rnd[1] = rand() % 18;
}
};
size_t Joc::pos[2], Joc::rnd[2], Joc::p = SIZE_MAX;
int main() {
Joc::start();
}