console game

Hey i'm new in c++ and i have this simple console game. In which i can't make the bot move, when i'm not moving.

#include <iostream>
using namespace std;
#include <windows.h>
int main()
{
char level[14][14];
int a, b, c, j, k, x, y, y1, m, o, t, p, px, py, py1, l;
string s;
cout<<"controls 8 5 4 6";
Sleep(3000);
system("cls");
for(a=0;a<15;a++)
{
for(b=0;b<15;b++)
{
level[a][b]=' ';
}
}
for(c=0;c<15;c++)
{
level[c][0]=219;
}
px= 12;
py= 2;
py1= 1;
x=1;
y=12;
y1=11;
j=1;
t=0;
m = 2;
o= 10;

do{
level[px][py]=31;
level[px][py1]=2;
level[x][y]=31;
level[x][y1]=1;
for(b=0;b<15;b++)
{
for(a=0;a<15;a++)
{
cout<<level[a][b];
}
cout<<"\n";
}
if(x == px && y == py || x == px && y1 == py || x == px && y == py1)
{
cout<<"your dead\n";
j=0;
l=0;
break;
}
if(x == m && y == o || x == m && y1 == o)
{
t = t + 10;
m= rand() % 12;
o= rand() % 11 + 1;
if(t==100)
{
j=0;
l=1;
break;
}
}
cout<<"your money: "<<t<<"\n";
cin>>k;
switch(k)
{
case 4:
level[x][y1]=' ';
level[x][y]=' ';
if(x > 0)
{
x=x-1;
}
level[x][y]=31;
level[x][y1]=1;
break;
case 6:
level[x][y1]=' ';
level[x][y]=' ';
if(x < 28)
{
x=x+1;
}
level[x][y]=31;
level[x][y1]=1;
break;
case 8:
level[x][y1]=' ';
level[x][y]=' ';
if(y > 2)
{
y=y-1;
y1=y1-1;
}
level[x][y]=31;
level[x][y1]=1;
break;
case 5:
level[x][y1]=' ';
level[x][y]=' ';
if(y < 12)
{
y=y+1;
y1=y1+1;
}
level[x][y]=31;
level[x][y1]=1;
break;
}
p= rand() % 4;
switch(p)
{
case 0:
level[px][py1]=' ';
level[px][py]=' ';
if(px > 0)
{
px=px-1;
}
level[px][py]=31;
level[px][py1]=2;
break;
case 1:
level[px][py1]=' ';
level[px][py]=' ';
if(px < 12)
{
px=px+1;
}
level[px][py]=31;
level[px][py1]=2;
break;
case 2:
level[px][py1]=' ';
level[px][py]=' ';
if(py > 2)
{
py=py-1;
py1=py1-1;
}
level[px][py]=31;
level[px][py1]=2;
break;
case 3:
level[px][py1]=' ';
level[px][py]=' ';
if(py < 12)
{
py=py+1;
py1=py1+1;
}
level[px][py]=31;
level[px][py1]=2;
break;
}
if(a=2)
{
level[m][o]= 36;
}
system("cls");
}while(j=1);
system("cls");
if(l==1)
{
cout<<"Congratulations you won";
Sleep(4000);
system("cls");
}
else
{
cout<<"goodluck next time";
Sleep(4000);
system("cls");
}
system("pause");
}
Please put tags around your code:

[code]
// Your code here
[/code]

becomes:

 
// Your code here 

you may use threads
The console is a terrible medium for games. Getting this to work how you want would be more trouble than it would be to just get a library that is designed to make games.

Get this: http://www.sfml-dev.org/
Topic archived. No new replies allowed.