Skip to main content
gamedev.net
🔒 Locked

English Lab Program

Started by bzroom Jun 29, 2006 at 1:19 PM 3 replies 600+ views
Original Post
bzroom
bzroom
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);
	}
}



Ravuya
Ravuya
I'm not a jerk! It's the jerk!
twystidmynd
twystidmynd
Cute game ;)

There's a small bug in it, though, with the winning condition. With one of the # if I push it into a hole, I win, even if no other #s are in the hole.

I suspect the bug has something to do with this segment of code you've got
if (block[0][2]==2 &█[0][2]==2 &█[0][2]==2 )

in there, but - and I admit I didn't read the code that thoroughly to see exactly what the bug is - isn't there a bit of redundance in that if statement =P
bzroom
bzroom
haha, yes your right, soon after i posted that I further tested the game, and if you look in my post again you will see that I corrected it, another small problem which may or may not be a bug depending on the "story" of the game, is that you can push all the blocks into the same hole if you want...
Adams555
Adams555
Yeah.. The one thing that I notice, is that the '#'s can be pushed together (and then of course you can never seperate them) Just make sure the #s can never overlap, which would fix both my problem, and the problem of letting all of them go into the same hole.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.