-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsnakedef.cpp
More file actions
74 lines (70 loc) · 1.21 KB
/
snakedef.cpp
File metadata and controls
74 lines (70 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <stdlib.h>
#include <locale>
#include <thread>
#include <future>
using namespace std;
struct Partita {
int punti;
char matrix;
};
void riempiMatrice(string matrix[15][40])
{
for (int i = 1; i < 14; i++)
{
for (int j = 1; j < 39; j++)
matrix[i][j] = " ";
}
for (int i = 0; i < 15; i++)
{
matrix[i][0]="#";
matrix[i][39]="#";
}
for (int i = 0; i < 40; i++)
{
matrix[0][i]="#";
matrix[14][i]="#";
}
matrix [8][15]="█";
}
char inmossa()
{
char mossa;
cin>>mossa;
return mossa;
}
string movimento(string matrix[15][40], string mossa, int x, int y)
{
if(mossa=="w")
return matrix[x-1][y]="█";
if(mossa=="s")
return matrix[x+1][y]="█";
if(mossa=="a")
return matrix[x][y-1]="█";
if(mossa=="d")
return matrix[x][y+1]="█";
}
int main()
{
setlocale(LC_ALL,"");
string campo[15][40];
riempiMatrice(campo);
string s;
while(true)
{
using namespace std::literals;
auto input = std::async(std::launch::async, inmossa);
while (input.wait_for(0.1s) != std::future_status::ready)
{
for(int i=0; i<15; i++)
{
cout<<endl;
for(int j=0; j<40; j++)
cout<<campo[i][j];
}
s=inmossa();
system ("cls");
}
movimento(campo, s, 8, 15);
}
}