示例#1
0
文件: ge.cpp 项目: wbovela/zztpp
//=============================================================================
// Function: RunGame
//		gets control from the main program and runs the main zzt++ loop.
// Parameters:
//		none.
// Returns:
//    nothing
//=============================================================================
void GameEngine::RunGame(void)
{

	char xit=0;			// exit game, false by default.
	char shift='\0'; 	// shift pressed, false by default.
	char x,y;			// temporary storage for player coordinates
	char currentboard;// current boad number during play
	int c;				// used to store character read from keyboard.
	int mod;				// used to store keyboard modifier status.

	// We're playing a new game, so we go to the first board.
	BM.SetCurrentBoard(1);
	currentboard=BM.GetCurrentBoard();

	// Draw the current board. The player gets drawn automatically.
	BM.DrawBoard(BM.GetCurrentBoard());

	// Get the modifiers from the keyboard
	mod=MM.ReadKeyboardModifiers();
	// check whether left or right shift was pressed
	shift=((mod & KMOD_LFT) || (mod & KMOD_RGT));

	// Set initial game speed.
	SetSpeed(5);

	// Draw game menu
	MM.DrawMenu(GAMEMENU);

	// start the main loop
	while (!xit)
	{
		// Set counter at 0 at beginning of loop.
		// this is declared in timerisr.hpp as global.
		CycleCount=0;

		// Store current player position on current (title screen) board
		x=BM.BRDOBJ[currentboard][0].XPos;
		y=BM.BRDOBJ[currentboard][0].YPos;

		// Read a character from the keyboard buffer.
		// This method of MM does not wait for user input.
		c=MM.ReadKeyboard();

		// Get the modifiers from the keyboard
		mod=MM.ReadKeyboardModifiers();
		// check whether left or right shift was pressed
		shift=((mod & KMOD_LFT) || (mod & KMOD_RGT));

		// now, interpret the command.
		switch (c)
		{

			// Escape or Quit was pressed.
			case 'q':
			case 'Q':
			case ESC: xit=Quit(); break;

			// Player movement
			// Player goes up
			case UP:
				if (shift)
				{
					// FIRE UP
				}
				else
				{
					 y-=BM.Try(x,y-1)?1:0; BM.MovePlayer(x,y);
				}
				break;

			// Player goes down
			case DOWN:
				if (shift)
				{
					// FIRE DOWN
				}
				else
				{
					 y+=BM.Try(x,y+1)?1:0; BM.MovePlayer(x,y); break;
				}
				break;

			// Player goes left
			case LEFT:
				if (shift)
				{
					// FIRE LEFT
				}
				else
				{
					 x-=BM.Try(x-1,y)?1:0; BM.MovePlayer(x,y); break;
				}
				break;

			// Player goes right
			case RIGHT:
				if (shift)
				{
					// FIRE RIGHT
				}
				else
				{
					 x+=BM.Try(x+1,y)?1:0; BM.MovePlayer(x,y); break;
				}
				break;

			default: break;
		}; // end of switch(c)

		// wait if we were too fast.
		while (CycleCount < (GetSpeed()-1)*8) {/* do nothing here */};

	}// end of while(!xit)
}