Archived

This topic is now archived and is closed to further replies.

for loop crashing game

This topic is 5018 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok im trying to create my first tetris game... im using an array to hold int corresponding to a block color ex: 1=red, 2=green, etc... the array is called screen[160][480] or 16 pixel blocks 10x30 for the grid the program seems to crash in this nested for loop
int fn_RefreshScreen_ar()
{
	int color = 0;

	for(int cntrY = DefaultScreenY; cntrY <= 30; (cntrY + BlockSize))
	{
		for(int cntrX = DefaultScreenX; cntrX <= 10; (cntrX + BlockSize))
		{
			if(ar_Screen[cntrX][cntrY]!=0)
			{
				color = ar_Screen[cntrX][cntrY];

				switch(color)
				{

				case 1:
					fn_DrawBlock(cntrX,cntrY,255,0,0,1);
					break;
				case 2:
					fn_DrawBlock(cntrX,cntrY,0,255,0,2);
					break;
				case 3:
					fn_DrawBlock(cntrX,cntrY,0,0,255,3);
					break;
				case 4:
					fn_DrawBlock(cntrX,cntrY,100,100,100,4);
					break;
				case 5:	
					fn_DrawBlock(cntrX,cntrY,100,200,200,5);
					break;
				case 6:
					fn_DrawBlock(cntrX,cntrY,200,200,100,6);
					break;

					return 0;
				}
			}

			else 
			{
				//MessageBox(hwnd, "You must enter the correct password! (""GameTutorials"")", "Error!", MB_OK);

				//return 0;

			}
		

		}
	}
	return 0;
}/source

i think that is coded correctly, i think it's something i did wrong in design time... and i know i can put things in the code box but i don't know the syntax yet will edit when i learn...

<SPAN CLASS=editedby>[edited by - Mad One on March 20, 2004 6:41:34 PM]</SPAN>

<SPAN CLASS=editedby>[edited by - Mad One on March 20, 2004 6:45:24 PM]</SPAN>

Share this post


Link to post
Share on other sites

for(int cntrY = DefaultScreenY; cntrY <= 30; (cntrY + BlockSize))
{
for(int cntrX = DefaultScreenX; cntrX <= 10; (cntrX + BlockSize))
{


Should the last calculations of the lines above increase cntrY and cntrX?

Because right now they are not really doing anything, to get them increase they should look like:

(cntrY += BlockSize) or (cntrY = cntrY + BlockSize)

And

(cntrX += BlockSize) or (cntrX = cntrX + BlockSize)


"and i know i can put things in the code box but i don't know the syntax yet will edit when i learn..."

Put source inside [] these to start and /source to stop.


[edited by - Mkk on March 20, 2004 6:37:38 PM]

Share this post


Link to post
Share on other sites