⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bricks.c

📁 一个操作系统源代码 用于嵌入式设备 在Vc++环境下仿真 成功移植到多款处理器上
💻 C
📖 第 1 页 / 共 2 页
字号:
	//   InitGame();
	DrawRec(hGC, GPC_BLACK, xPos-1, yPos-1, xWidth+xPos, yHeight+yPos, SOLID_LINE, REPLACE_STYLE);
	IsChangeScore = 1; //to print the initial score



}








void GenerateNew(U32 hGC)    //XXXXXXX need changed???????
{  
	U16 i,j;
	int temp = next_block;
	
	next_block = Random(7)+1;
	GenerateBlock(next_block);
	for (i=0; i<4; i++) 
	{
		for (j=0; j<2; j++) 
		{
			if (block[i][j] == 1)
				DrawSmallBrick(hGC, LCD_WIDTH*2/3 + i*sBricklen,30+j*sBricklen);
			else 
				DrawEmptyBrick(hGC, LCD_WIDTH*2/3 + i*sBricklen,30+j*sBricklen);
		}
	}
	GenerateBlock(temp);
	block_x = 3;   //tmp is on the map,while next_block is shown the next block which will drop  XXXXXXX
	block_y = 0;
	if (!CanPut()) 
	{
		if( MessageBox( 0,"Do you want to play again?","hello",MB_OKCANCEL) == IDCANCEL)
			QuitGame = 1;


		InitGame();
		ReSetGame(hGC);

		//XXXX   need  added
		/*
		text_mode(-1);
		textout_centre(screen, font, "G A M E", 202, 152, 42);
		textout_centre(screen, font, "G A M E", 200, 150, 15);
		textout_centre(screen, font, "O V E R", 202, 202, 42);
		textout_centre(screen, font, "O V E R", 200, 200, 15);
		textout_centre(screen, (FONT*)graphics[GAME_FONT].dat, "Press Enter to", 202, 252, 42);
		textout_centre(screen, (FONT*)graphics[GAME_FONT].dat, "to start a new game", 202, 277, 42);
		textout_centre(screen, (FONT*)graphics[GAME_FONT].dat, "Press Enter to", 200, 250, 15);
		textout_centre(screen, (FONT*)graphics[GAME_FONT].dat, "to start a new game", 200, 275, 15);
		sprintf(text, "%3d", score);
		textout_centre(screen, (FONT*)graphics[GAME_FONT].dat, text, 202, 302, 42);
		textout_centre(screen, (FONT*)graphics[GAME_FONT].dat, text, 200, 300, 15);
		clear_keybuf();

		do {
			if (key[KEY_ENTER]) break;
		   } while (1==1);
		clear_keybuf();
		*/
		//     NewGame(hGC);   //XXXXX?????
	}
}








void InitGame(void)
{
  //should take the timer in this functionXXXXX 
     Speed = 25;
 //  Speed = 4;
     Score = 0;
     Dels = 0;
     TimeNum = 0;



//    start_level = 0;   //XXXX  can change this var to set level and floors  ,need added  ???????
//    start_blocks = 0;

    //XXXX  added on 0716
    MustClearScreen = 0;
    IsChangeScore = 0;
}


void SearchRussianBlock(U32 hGC)
{
	MSG 	msg;
	U32		mainwin;
	//	U32		  hGC;
	U8		  quit = 0;
	U32        timeslot;

	U8       isstart = 0;  //added on 0716


	U32    leftbt,rightbt,startbt,downbt,rotatbt;

	U32    scoreout,speedout,floorout;







	/* 创建主窗口 */
	mainwin = CreateWindow(	WNDCLASS_WIN,			//窗口类型(主窗口)
						"俄罗斯方块",			//窗口标题
						WS_OVERLAPPEDWINDOW,	//窗口风格(主窗口风格的宏定义参见头文件asixwin.h)
						0,0,					//窗口左上角在逻辑屏幕中的坐标
						PHY_LCD_W,PHY_LCD_H,	//窗口的宽度和高度
						0,						//窗口的父窗口(主窗口没有父窗口)
						0,						//窗口的附加参数(主窗口没有附加参数)
						NULL);					//窗口的附加数据(主窗口没有附加数据)

	leftbt = CreateWindow( WNDCLASS_BUTTON,
					"左",
					WS_CHILD | BS_REGULAR,
					LCD_WIDTH*2/3 , LCD_HEIGHT*7/12,
					LCD_WIDTH/8,LCD_HEIGHT/12,
					mainwin,
					0x00180018,
					NULL);

	rightbt = CreateWindow( WNDCLASS_BUTTON,
					"右",
					WS_CHILD | BS_REGULAR,
					LCD_WIDTH*2/3 + LCD_WIDTH/8, LCD_HEIGHT*7/12,		//6 is the distance between two blocks
				//      125,160,
					LCD_WIDTH/8,LCD_HEIGHT/12,
					mainwin,
					0x00180018,
					NULL);

	startbt = CreateWindow( WNDCLASS_BUTTON,
					"暂停",
					WS_CHILD | BS_REGULAR,
					LCD_WIDTH*2/3,LCD_HEIGHT*3/4,
					2*LCD_WIDTH/8,LCD_HEIGHT/12,
					mainwin,
					0,
					NULL);

	downbt = CreateWindow( WNDCLASS_BUTTON,
					"下",
					WS_CHILD | BS_REGULAR,
					LCD_WIDTH*2/3 + LCD_WIDTH/16,LCD_HEIGHT*2/3,
					LCD_WIDTH/8,LCD_HEIGHT/12,
					mainwin,
					0,
					NULL);
	rotatbt= CreateWindow( WNDCLASS_BUTTON,
					"旋转",
					WS_CHILD | BS_REGULAR,
					LCD_WIDTH*2/3 , LCD_HEIGHT*1/2,
					2*LCD_WIDTH/8 ,LCD_HEIGHT/12,
					mainwin,
					0,
					NULL);






	sprintf(text, "得分:\n%-4d",Score);

	scoreout = CreateWindow(WNDCLASS_STATIC, 
					text,
					WS_CHILD|SS_TEXT|SS_MULTILINE|SS_LEFT,
					LCD_WIDTH*2/3,LCD_HEIGHT*1/3 ,
					LCD_WIDTH/3,LCD_HEIGHT/9,
					mainwin,
					0,
					NULL);

	sprintf(text,"速度:%d",start_level);
	speedout = CreateWindow(WNDCLASS_STATIC, 
					text,
					WS_CHILD|SS_TEXT|SS_LEFT,
					LCD_WIDTH*2/3,LCD_HEIGHT*4/15,
					LCD_WIDTH/3,LCD_HEIGHT/15,
					mainwin,
					0,
					NULL);

	sprintf(text,"高度:%d",start_blocks);
	floorout = CreateWindow(WNDCLASS_STATIC, 
					text,
					WS_CHILD|SS_TEXT|SS_LEFT,
					LCD_WIDTH*2/3,LCD_HEIGHT/5 ,
					LCD_WIDTH/3,LCD_HEIGHT/15,
					mainwin,
					0,
					NULL);


	/* 用户可以在此绘图,但该图形不会被保存 */


	DrawRec(hGC, GPC_BLACK, xPos-1, yPos-1, xWidth+xPos, yHeight+yPos, SOLID_LINE, REPLACE_STYLE);
	
	//timeslot should moodified  XXXXX and should take these functoions into initial
	CreateTimer( &timeslot, 10, NULL, NULL, CYC_MODE|AUTO_START_MODE );
	StartTimer( timeslot);

	InitGame();
	NewGame(hGC);

	QuitGame = 0;

	while(!quit)
	{
		ASIXGetMessage(&msg, NULL, 0, 0);
		switch(msg.message)
		{ 
			case WM_COMMAND:
				if (msg.lparam == leftbt)
				{
					//XXXX
					ClearLastBrick(hGC);
					block_x--; 
					if (!CanPut())
						block_x++;
					//                  	   SetWindowText(leftbt, NULL, (char *)rightpoint);//XXXXADDED BY RSH ON 0816
				}else
				if (msg.lparam == rightbt)
				{
					ClearLastBrick(hGC);
					block_x++;
					if (!CanPut()) 
						block_x--;

				}else
				if (msg.lparam == startbt)
				{
					if ((isstart%2) == 0 )
					{
						SetWindowText(startbt, "开始", NULL);
						StopTimer(timeslot);
					}
					else
					{
						SetWindowText(startbt, "暂停", NULL);
						StartTimer( timeslot);
					}
					isstart ++;	

				}else
				if (msg.lparam == downbt)
				{ 
					ClearLastBrick(hGC);
					while (CanPut()) 
					{
						// ClearLastBrick(hGC);   
						// DrawMap(hGC); //it need check XXXX
						block_y++;
					};
					block_y--;
				}else
				if (msg.lparam == rotatbt)
				{  
					//XXXX
					ClearLastBrick(hGC);
					RotateBlock();
				}

				DrawMap(hGC);
				break;
			case   WM_TIMER:
				TimeNum++;
				if (TimeNum > Speed)
				{

					ClearLastBrick(hGC);
					block_y++;
					if (!CanPut()) 
					{
						block_y --; 

						PutBlock(); 
						GenerateNew(hGC);
						quit = QuitGame;
					}
					DrawMap(hGC);
					if (IsChangeScore == 1)
					{
						sprintf(text, "得分:\n%-4d",Score);
						SetWindowText(scoreout, text, NULL);
						sprintf(text,"速度:%d",start_level);
						SetWindowText(speedout, text, NULL);
						sprintf(text,"高度:%d",start_blocks);
						SetWindowText(floorout, text, NULL);
						IsChangeScore = 0;
					}
					TimeNum = 0;                             
				}                         

				break;
			case WM_QUIT:
				quit = 1;
				break;
		}
		DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam); 



	}

	DestroyWindow( mainwin );

	StopTimer( timeslot );
	FreeTimer( timeslot);

	//	EndofTask();
}





void ClearSelect()
{
	start_blocks = 0;
	start_level   = 0;
}


void RussianBlock(void)
{
	MSG 	msg;
 	U32		mainwin;
	U32		  hGC;
 	U8		  quit=0;
 	U32    selheight,selspeed,startbt,showselect;
	U32		tskbar;	// 任务栏

 	

 struct	MENU_ITEM speedmenu[]= 
	{
			1, 1, "  1   ",
			1, 1, "  2   ",
			1, 1, "  3   ",
			1, 1, "  4   ",
			1, 1, "  5   ",
			1, 1, "  6   ",
			1, 1, "  7   ",
			1, 1, "  8   ",
			1, 1, "  9   ",
			1, 1, "  10  ",
			0, 0, NULL,
	};


 
 struct	MENU_ITEM floormenu[]= 
	{
			1, 1, "   1   ",
			1, 1, "   2   ",
			1, 1, "   3   ",
			1, 1, "   4   ",
			1, 1, "   5   ",
			1, 1, "   6   ",
			1, 1, "   7   ",
			1, 1, "   8   ",
			1, 1, "   9   ",
			1, 1, "   10  ",
			0, 0, NULL,
	};


	/* 创建主窗口 */
 	mainwin = CreateWindow(	WNDCLASS_WIN,			//窗口类型(主窗口)
							"俄罗斯方块",			//窗口标题
							WS_OVERLAPPEDWINDOW,	//窗口风格(主窗口风格的宏定义参见头文件asixwin.h)
							0,0,					//窗口左上角在逻辑屏幕中的坐标
							PHY_LCD_W,PHY_LCD_H,	//窗口的宽度和高度
							0,						//窗口的父窗口(主窗口没有父窗口)
							0,						//窗口的附加参数(主窗口没有附加参数)
							NULL);	
	tskbar = CreateWindow(WNDCLASS_TSKBAR, NULL, WS_CHILD|TBS_TYPICAL, 0, 0, 0, 0,mainwin, 0, NULL);


    selheight = CreateWindow( WNDCLASS_MENU,
							"高度",
							WS_CHILD | MNS_MID,
							30,100,
							42,20,
							mainwin,
							0,
							(void *)floormenu);


    selspeed = CreateWindow( WNDCLASS_MENU,
							"速度",
							WS_CHILD | MNS_MID,
							30,125,
							42,20,
							mainwin,
							0,
							(void *)speedmenu); 

    startbt = CreateWindow( WNDCLASS_BUTTON,
							"开始",
							WS_CHILD | BS_REGULAR,
							30,55,
							42,20,
							mainwin,
							0,
							NULL);

	sprintf(text,"速度已选:  %d\n\n高度已选:  %d",start_level,start_blocks);
	showselect = CreateWindow(WNDCLASS_STATIC, 
							text,
							WS_CHILD|SS_TEXT|SS_MULTILINE,
							30,165,
							100,40,
							mainwin,
							0,
							NULL);

	hGC = GetGC();

	while(!quit)
	{
		ASIXGetMessage(&msg, NULL, 0, 0);
		switch(msg.message)
		{
			// 在此用户加入自己的消息处理
			case  WM_COMMAND:
				if (msg.lparam == startbt)    
				{
					SearchRussianBlock(hGC);
					ClearSelect();
					sprintf(text,"速度已选:  %d\n\n高度已选:  %d",start_level,start_blocks);
					SetWindowText(showselect, text, NULL);
				} 
				if (msg.lparam == selspeed)	
				{
					start_level = msg.wparam + 1;
					sprintf(text,"速度已选:  %d\n\n高度已选:  %d",start_level,start_blocks);
					SetWindowText(showselect, text, NULL);
				}
				if (msg.lparam == selheight)	
				{
					start_blocks = msg.wparam + 1;
					sprintf(text,"速度已选:  %d\n\n高度已选:  %d",start_level,start_blocks);
					SetWindowText(showselect, text, NULL);
				}
				break;
			case WM_QUIT:
				quit = 1;
				break;
			default:
				break;	
		}
		DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam); 
	}

	DestroyWindow( mainwin );

	EndofTask();
}

    
 




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -