Exemple #1
0
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

    initSPI();

    LCDinit();

    LCDclear();

    unsigned char player = initPlayer();

    init_timer();
    init_buttons();
    __enable_interrupt();
   	printPlayer(player);
    while(1)
    {

    	player = movementCheck(player);
    	if(LOSE == 1){
    		LCDclear();
    		print("GAME");
    		secondLine();
    		print("OVER");
    		firstLine();
    		GAMEOVER = 1;
    		waitForP1ButtonRelease(BIT1|BIT2|BIT3|BIT4);
    		debounce();
    	}
    	if(didPlayerWin(player)){
    		LCDclear();
    		print("YOU");
    		secondLine();
    		print("WON");
    		firstLine();
    		GAMEOVER = 1;
    		waitForP1ButtonRelease(BIT1|BIT2|BIT3|BIT4);
    		debounce();
    	}
    	if(GAMEOVER){
    		char buttonsToPoll[4] = {BIT1, BIT2, BIT3, BIT4};
    		while(!pollP1Buttons(buttonsToPoll, 4)){
    			//poll until something is pressed
    		}
    		TAR = 0;
    		LOSE = 0;
    		TIMER = 0;
    		GAMEOVER = 0;
    		LCDclear();
    		player = initPlayer();
    		printPlayer(player);
    	}
    }

    return 0;
}
Exemple #2
0
int main(void) {
	WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
	char * endMessageTop = "You am  ";
	char * endMessageBottomLose = "lose    ";
	char * endMessageBottomWin = "Not lose";
	char * deadMessage = "Dead    ";
	unsigned char player;
	unsigned char mines[NUM_MINES];

	while (1) {
		timer = 0;
		button = 0;
		player = initPlayer();
		initProgram();
		printPlayer(player);
		generateMines(mines);

		//run while none of the end-game situations have occurred
		while ((timer < 4) && !didPlayerWin(player)
				&& !didPlayerHitMine(player, mines)) {

			if (button) {
				switch (button) {
				case BIT0:
					player = movePlayer(player, RIGHT);
					break;
				case BIT1:
					player = movePlayer(player, LEFT);
					break;
				case BIT2:
					player = movePlayer(player, UP);
					break;
				case BIT3:
					player = movePlayer(player, DOWN);
					break;
				}
				button = 0;
			}
		}

		//if the timer hits 2 seconds, or if the player hits a mine, the game is over
		if (timer == 4 || didPlayerHitMine(player, mines)) {

			//displays a special message if the player lost due to hitting a mine
			if (didPlayerHitMine(player, mines)) {
				cursorToLineOne();
				writeString(deadMessage, 8);
				_delay_cycles(500000);
			}
			button = 0;

			//displays game over message
			cursorToLineOne();
			writeString(endMessageTop, 8);
			cursorToLineTwo();
			writeString(endMessageBottomLose, 8);
		}
		//if the player hits 0xC7 they win, display the win message
		else if (didPlayerWin(player)) {
			button = 0;
			cursorToLineOne();
			writeString(endMessageTop, 8);
			cursorToLineTwo();
			writeString(endMessageBottomWin, 8);
		}

		// Waits for a button input and then resets the game
		while (button != 0) {
		}
	}
}
Exemple #3
0
unsigned char movePlayer(unsigned char player, unsigned char direction)
{


	switch (direction) {
		//
		// update player position based on direction of movement
		//
	case BIT1:		//UP

		clearScreen();
		clearPlayer(player);
		if (player == 0xc7)
				{
					player = 0x80;
				}
		else if (0xc0<=player<=0xc7)
			{
				player = 0x80+(player&0x0f);
			}
				debounce();
				printPlayer(player);

		break;

	case BIT2:		//DOWN

		clearScreen();
		clearPlayer(player);
		if (player == 0xc7)
				{
					player = 0x80;
				}
		else if (0x80<=player<=0x87)
			{
				player = 0xC0+(player&0x0f);
				didPlayerWin(player);
			}

		debounce();
		printPlayer(player);

		break;

	case BIT3:		//LEFT

		clearScreen();
		clearPlayer(player);

		if (player == 0xc7)
				{
					player = 0x80;
				}

		else if(player == 0xc0)
		{
			player = 0x87;
		}
		else if (player == 0x80)
		{
			player = 0x80;
		}else
			player = player-0x01;

		debounce();
		printPlayer(player);
		break;

	case BIT4:		//RIGHT

		clearScreen();
		clearPlayer(player);

		if (player == 0xc7)
				{
					player = 0x80;
				}

		else if (player == 0x87)
				{
					player = 0xc0;
				}
		else if(player == 0xc7)
		{
			player =0xc7;
		}else
			player = player + 0x01;
			didPlayerWin(player);

		debounce();
		printPlayer(player);

	}

	return player;
}
Exemple #4
0
void main(void) {
	WDTCTL = (WDTPW | WDTHOLD);

	initSPI();

	LCDinit();

	LCDclear();

	//unsigned char player = initPlayer();

	init_timer();
	init_buttons();

	LCDclear();
	player = initPlayer();
	clearTimer();
	WIN = 0;
	printPlayer(player);

	__enable_interrupt();
	while (1) {



		if (didPlayerWin(player) == 1) {

			LCDclear();
			writeString("You");
			cursorToLineTwo();
			writeString("Win");

			reset = 0;
			while(reset == 0){

			}
			LCDclear();
			player = initPlayer();
			clearTimer();
			WIN = 0;
			printPlayer(player);
		} else if (WIN == 1) {

			LCDclear();
			writeString("Game");
			cursorToLineTwo();
			writeString("Over");

			reset = 0;
			while(reset == 0){

			}
			LCDclear();
			player = initPlayer();
			clearTimer();
			WIN = 0;
			printPlayer(player);
		}



	}

}