Original Post
I was in the computer lab today with my english class, and I stumbled acrost a c++ compiler, so I wrote this, took about 45 min, including dodging looks from the teacher. Enjoy haha...
#include <stdlib.h>
#include <iostream.h>
#include <windows.h>
int world[100];
int mx = 0, my = 0;
int px = 5, py = 5;
bool running = true;
int block[3][3];
void resetworld()
{
memset(world,0,sizeof(int)*100);
for (int i = 0;i < 10; i++)
{
world = 1;
world[90+i] = 1;
world[i*10] = 1;
world[i*10+9] =1;
}
world[15] = 2;
world[35] = 2;
world[65] = 2;
block[0][0] = 3;
block[0][1] = 3;
block[0][2] = 1;
block[1][0] = 6;
block[1][1] = 7;
block[1][2] = 1;
block[2][0] = 7;
block[2][1] = 5;
block[2][2] = 1;
px = 5; py = 5;
}
void drawworld()
{
system("cls");
cout<<endl<<"With the O, push the #, into the @..."<<endl<<endl;
for(int y =0; y<10; y++)
{
for (int x =0; x< 10; x++)
{
if (x == px && y == py)
cout<<"O";
else if (block[0][0] ==x && block[0][1] == y)
cout<<"#";
else if (block[1][0] ==x && block[1][1] == y)
cout<<"#";
else if (block[2][0] ==x && block[2][1] == y)
cout<<"#";
else
if (world[x+y*10] == 1)
cout<<"#";
else if (world[x+y*10] == 2)
cout<<"@";
else
cout<<" ";
}
cout<<endl;
}
}
void getinput()
{
mx=0;
my = 0;
if (GetKeyState(VK_LEFT) < -100)
mx = -1;
if (GetKeyState(VK_RIGHT) < -100)
mx = 1;
if (GetKeyState(VK_UP) < -100)
my = -1;
if (GetKeyState(VK_DOWN) < -100)
my = 1;
if (GetKeyState(VK_ESCAPE) < -100)
running = false;
}
void wait(int ms)
{
long start = GetTickCount();
while (GetTickCount() - ms < start);
}
void process()
{
if (world[(px+mx)+(py+my)*10] ==1)
return; //wall
for(int i = 0; i < 3; i ++)
{
if (block[0] == px+mx && block[1] == py+my)
{
if (block[2] == 2)
return;
if (world[(block[0]+mx)+(block[1]+my)*10] ==1)
return; //wall
block[0] += mx;
block[1] += my;
if (world[(block[0])+(block[1])*10] ==2)
block[2] = 2;
}
}
px += mx;
py += my;
if (world[px+py*10] == 2)
{
system("cls");
cout<<"GOOD JOB YOU FELL IN A HOLE JERK!"<<endl<<endl;
system("pause");
resetworld();
}
if (block[0][2]==2 &█[1][2]==2 &█[2][2]==2 )
{
system("cls");
cout<<"YOU WIN!!!"<<endl<<endl;
system("pause");
resetworld();
}
}
void main()
{
resetworld();
while(running)
{
getinput();
process();
drawworld();
wait(100);
}
}