alsoijw,
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <termios.h>
#include <sys/select.h>
using namespace std;
int a[24][19];
int nado_sobrat=0;
int x; int y;
void print_a()
{
for (int i=0; i<24; i++)
{
for (int m=0; m<19; m++)
{
if (a[i][m]==0 || a[i][m]==3) cout<<" ";
if (a[i][m]==2) cout<<"╠╣";
if (a[i][m]==4) cout<<"••";
}
cout<<endl;
}
}
void nonblock(int state)
{
struct termios ttystate;
tcgetattr(STDIN_FILENO, &ttystate);
if (state == 1)
{
ttystate.c_lflag &= ~ICANON;
ttystate.c_cc[VMIN] = 1;
}
else if (state == 0)
{
ttystate.c_lflag |= ICANON;
}
tcsetattr(0, TCSANOW, &ttystate);
}
int getch()
{
nonblock(1);
return fgetc(stdin);
nonblock(0);
}
int win()
{
if (nado_sobrat==0) return 1;
else return 0;
}
void motion()
{
a[x][y] = 0;
char m;
m = getch();
switch (m)
{
case 65 :
case 'w' : x--; break;
case 66 :
case 's' : x++; break;
case 68 :
case 'a' : y--; break;
case 67 :
case 'd' : y++; break;
}
if (a[x][y]==4) nado_sobrat--;
if (a[x][y]==0 || a[x][y]==3 || a[x][y]==4) a[x][y] = 2;
else
{
switch (m)
{
case 65 :
case 'w' : x++; break;
case 66 :
case 's' : x--; break;
case 68 :
case 'a' : y++; break;
case 67 :
case 'd' : y--; break;
}
a[x][y] = 2;
}
}
void clear_scr()
{
cout<<"\033[H\033[J\033[m";
}
int main()
{
ifstream fin("test.txt");
for (int m=0; m<24; m++)
{
for (int n=0; n<19; n++)
{
fin >> a[m][n];
if (a[m][n]==4) nado_sobrat++;
}
}
fin >> x;
fin >> y;
while (win()==0)
{
print_a();
motion();
clear_scr();
}
cout<<"Молодца";
return 0;
}