Jump to content
xisto Community
Sign in to follow this  
.hack//GU

Tetris Sourcode Making Tetris with C/C++

Recommended Posts

Please help me, I have an assignment to make a tetris-like game in C/C++.Anyone could help me with the source code?I've thought the algorithm to make a 2-D matrix, but in the end all I can make is only the one I've attached.So, please anyone who knows how to make this one to help me.Thank you in advance. :lol:(Attachment: Tetris2.TXT should be Tetris2.CPP to edit in C++)

TETRIS2.TXT

Edited by .hack//GU (see edit history)

Share this post


Link to post
Share on other sites

Woah. I couldn't even compile that one. (Probably because I don't have the identical headers to yours, I'm sure I even have a copy of dos.h) Mind commenting through the file? I mean, I'm probably one of the last people who should say this, but it's really necessary sometimes. Especially when you're talking to a public who has no clue what useX is used for or why it equals 41 instead of 42 :lol: So yeah, please comment through it. Otherwise it'd take us a lot longer than it should to find a problem and you'd get less people to help you.

Share this post


Link to post
Share on other sites

Woah. I couldn't even compile that one. (Probably because I don't have the identical headers to yours, I'm sure I even have a copy of dos.h) Mind commenting through the file? I mean, I'm probably one of the last people who should say this, but it's really necessary sometimes. Especially when you're talking to a public who has no clue what useX is used for or why it equals 41 instead of 42 :lol:
So yeah, please comment through it. Otherwise it'd take us a lot longer than it should to find a problem and you'd get less people to help you.


Well, I thought my code itself is a failure. I'll take another glimpse through the codes tonight. Anyway, I've acquired some tetris code but all of it are in graphics.h. Anyone know where I can get tetris code without graphics.h?

Share this post


Link to post
Share on other sites

I made a tetris game! It was part of a spoof i made of DOS in c++ feel free to use my source if you can find the tetris sourcecode inside the OS.

I looked through the file and found some lines of code that start with //START PONG and // END PONG so i think all the code is there. This should be all of it:

//START PONGvoid linecall(int line,int computerlocal,int plrlocal,int ballx,int bally){	int loopvar;	if(computerlocal+3>=line&&computerlocal<=line){	cout << "|";	}else{		cout << " ";	}if(bally==line){loopvar=1;while(loopvar<ballx){	cout << " ";	loopvar++;}cout << "O";while(loopvar<40){	cout << " ";	loopvar++;}}else{	cout << "										";}if(plrlocal+3>=line&&plrlocal<=line){	cout << "|";}cout << "\n";}void playpong(int diff){system("cls");//10 rows//paddles 4//40 cols//dwnleft-1//dwnright-2//upleft-3//upright-4int computerlocal=1;int plrlocal=1;int ballx=20;int bally=5;int balldir=1;int gamerun=1;int loopvar;while(gamerun==1){//linecall	loopvar=1;	while(loopvar<=10)	{linecall(loopvar,computerlocal,plrlocal,ballx,bally);loopvar++;	}	if(ballx>=41||ballx<=0)	{		if(ballx>=41)		{		gamerun=0;		cout << "You Lost!\n";		}else{		gamerun=0;		cout << "You Won!\n";		}	}else{		//computer ai		if((balldir==1)||(balldir==3))		{		if(((rand()%diff)*20)>(rand()%50))		{		if(computerlocal+2<bally)		{			computerlocal++;		}		if(computerlocal+2>bally)		{			computerlocal--;		}		}		}		if(computerlocal<1)		{			computerlocal=1;		}		if(computerlocal>7)		{			computerlocal=7;		}	//move ball		if(ballx==40&&plrlocal+3>=bally&&plrlocal<=bally)		{			if(balldir==2)			{				balldir=1;			}			if(balldir==4)			{				balldir=3;			}		}		if(ballx==1&&computerlocal+3>=bally&&computerlocal<=bally)		{			if(balldir==3)			{				balldir=4;			}			if(balldir==1)			{				balldir=2;			}		}	if(bally==0)	{		if(balldir==3)		{			balldir=1;		}		if(balldir==4)		{			balldir=2;		}	}	if(bally==10)	{		if(balldir==1)		{			balldir=3;		}		if(balldir==2)		{			balldir=4;		}	}	if(balldir==1)	{		bally++;		ballx--;	}	if(balldir==2)	{		bally++;		ballx++;	}	if(balldir==3)	{		bally--;		ballx--;	}	if(balldir==4)	{		bally--;		ballx++;	}clock_t endwait;endwait = clock () + .02 * CLK_TCK;while (clock() < endwait) {}	//key listen	int ch;	if(kbhit())	{  ch = getch();   if ( ch == 0 || ch == 224 )  {	ch = 256 + getch();  }  if(ch==328)  {	  plrlocal--;  }   if(ch==336)  {	  plrlocal++;  }  if(ch==27)  {system("cls");cout << "Pong game ended.\n";gamerun=0;  }  if(gamerun==1)  { 	 system("cls");  }	}else{			clock_t endwait; endwait = clock () + .02 * CLK_TCK; while (clock() < endwait) {} system("cls");	}		if(plrlocal<1)		{			plrlocal=1;		}		if(plrlocal>7)		{			plrlocal=7;		}}}}//END PONG

But this code might need the rest of the program to work.. I don't know, its been ages since ive looked at it. Good luck

OS.txt

Share this post


Link to post
Share on other sites

Um... My bad... I totaly confused tetris with pong there for a second... Wow... Sorry. Well if you want the code for a pong game, there it is... hehe

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.