예제 #1
0
파일: main.c 프로젝트: JennaeN/Lab05_Game
//Function used to determine which button has been pushed without polling
void testAndRespondToButtonPush(char buttonToTest) {
	if (buttonToTest & P1IFG) {

		if (buttonToTest & P1IES) {

			if (flag == 5) {
				LCDclr();
				location = initPlayer();
				printPlayer(location);
				flag = 0;
			}

			else {
				//This code is used to prevent the player (*) from moving outside of the game bounds.
				int mod = 0;
				mod = movePlayerInResponseToButtonPush(buttonToTest);
				clearPlayer(location);
				location += mod;
				location = movePlayer(location, mod);
				clearTimer();
			}

			//Debounces the button
		} else {
			debounce();
		}

		//Toggles between reading rising and falling edge
		P1IES ^= buttonToTest;
		P1IFG &= ~buttonToTest;
	}

}
예제 #2
0
파일: game.c 프로젝트: alexstrom/LAB5
unsigned char movePlayer(unsigned char player, unsigned char direction){
	clearPlayer(player);
	LCDclear();

	if(direction == BIT1){
		if(player != 0x87 && player != 0xc7){
			player++;
		}        }
	else if(direction == BIT2){
		if(player != 0x80 && player != 0xc0){
			player--;
		}
	}
	else if(direction == BIT3){
		if(player < 0x88){
			player+=0x40;
		}
		if(player> 0xdf){
			player+=0xc0;
		}
	}
	else if(direction == BIT4){
		player &= ~ROW_MASK;}
	return player;

}
예제 #3
0
파일: game.c 프로젝트: sleeprocking/Lab5
unsigned char movePlayer(unsigned char player, unsigned char direction)
{			clearPlayer(player);
        switch (direction) {

        	case UP:
        		if (player>= 0xc0){		//if player is on line 2
        			player -=0x40;
        		}
        		break;

        	case DOWN:
        		if(player<=0x87){		//if player is on line 1
        			player+=0x40;
        		}
        		break;

        	case LEFT:
        		if((player & 0x0f)>0){		//checks if 1's place is zero
        			player--;
        		}
        		break;

        	case RIGHT:
        		if (player < 0x87 || player >= 0xC0){ //makes sure player doesn't go off screen
        			player++;
        		}
        		break;

        }

        printPlayer(player);
        return player;
}
예제 #4
0
파일: game.c 프로젝트: csbaltar/Lab5_Game
unsigned char gameOver(unsigned char  player)
{
	clearPlayer(player);
	cursorToLineOne();
	writeString(game);
	cursorToLineTwo();
	writeString(over);
	return initPlayer();
}
예제 #5
0
파일: game.c 프로젝트: csbaltar/Lab5_Game
unsigned char youWon(unsigned char player)
{
	clearPlayer(player);
	cursorToLineOne();
	writeString(you);
	cursorToLineTwo();
	writeString(won);

	return initPlayer();
}
예제 #6
0
void recvPlayerLeft(NETQUEUE queue)
{
	uint32_t playerIndex = 0;

	NETbeginDecode(queue, GAME_PLAYER_LEFT);
		NETuint32_t(&playerIndex);
	NETend();

	turnOffMultiMsg(true);
	clearPlayer(playerIndex, false);  // don't do it quietly
	turnOffMultiMsg(false);
}
예제 #7
0
// ////////////////////////////////////////////////////////////////////////////
// A remote player has left the game
bool MultiPlayerLeave(UDWORD playerIndex)
{
	char	buf[255];

	if (playerIndex >= MAX_PLAYERS)
	{
		ASSERT(false, "Bad player number");
		return false;
	}

	NETlogEntry("Player leaving game", SYNC_FLAG, playerIndex);
	debug(LOG_NET,"** Player %u [%s], has left the game at game time %u.", playerIndex, getPlayerName(playerIndex), gameTime);

	ssprintf(buf, _("%s has Left the Game"), getPlayerName(playerIndex));

	if (ingame.localJoiningInProgress)
	{
		clearPlayer(playerIndex, false);
	}
	else if (NetPlay.isHost)  // If hosting, and game has started (not in pre-game lobby screen, that is).
	{
		sendPlayerLeft(playerIndex);
	}
	game.skDiff[playerIndex] = 0;

	addConsoleMessage(buf, DEFAULT_JUSTIFY, SYSTEM_MESSAGE);

	if (NetPlay.players[playerIndex].wzFile.isSending)
	{
		char buf[256];

		ssprintf(buf, _("File transfer has been aborted for %d.") , playerIndex);
		addConsoleMessage(buf, DEFAULT_JUSTIFY, SYSTEM_MESSAGE);
		debug(LOG_INFO, "=== File has been aborted for %d ===", playerIndex);
		NetPlay.players[playerIndex].wzFile.isSending = false;
		NetPlay.players[playerIndex].needFile = false;
	}
	NetPlay.players[playerIndex].kick = true;  // Don't wait for GAME_GAME_TIME messages from them.

	if (widgGetFromID(psWScreen, IDRET_FORM))
	{
		audio_QueueTrack(ID_CLAN_EXIT);
	}

	// fire script callback to reassign skirmish players.
	CBPlayerLeft = playerIndex;
	eventFireCallbackTrigger((TRIGGER_TYPE)CALL_PLAYERLEFT);

	netPlayersUpdated = true;
	return true;
}
예제 #8
0
// ////////////////////////////////////////////////////////////////////////////
static BOOL gameInit(void)
{
    UDWORD			player;

    scriptInit();

    // If this is from a savegame, stop here!
    if (getSaveGameType() == GTYPE_SAVE_START || getSaveGameType() == GTYPE_SAVE_MIDMISSION)
    {
        // these two lines are the biggest hack in the world.
        // the reticule seems to get detached from 'reticuleup'
        // this forces it back in sync...
        intRemoveReticule();
        intAddReticule();

        return true;
    }

    for(player = 0; player<game.maxPlayers; player++)			// clean up only to the player limit for this map..
    {
        cleanMap(player);
    }

    for (player = 1; player < MAX_PLAYERS; player++)
    {
        // we want to remove disabled AI & all the other players that don't belong
        if ((game.skDiff[player] == 0 || player >= game.maxPlayers) && (!game.scavengers || player != 7))
        {
            clearPlayer(player, true);			// do this quietly
            debug(LOG_NET, "removing disabled AI (%d) from map.", player);
        }
    }

    if (game.scavengers)	// FIXME - not sure if we still need this hack - Per
    {
        // ugly hack for now
        game.skDiff[7] = DIFF_SLIDER_STOPS / 2;
    }

    if (NetPlay.isHost)	// add oil drums
    {
        addOilDrum(NetPlay.playercount * 2);
    }

    playerResponding();			// say howdy!

    return true;
}
예제 #9
0
파일: main.c 프로젝트: ntaormina/Lab5
void testAndRespondToButtonPush(char buttonToTest) {
	if (buttonToTest & P1IFG) {
		if (buttonToTest & P1IES) {
			clearPlayer(player);
			player = movePlayer(player, buttonToTest);
			printPlayer(player);
			clearTimer();
			reset = 1;

		} else {
			debounce();
		}

		P1IES ^= buttonToTest;
		P1IFG &= ~buttonToTest;
	}
}
예제 #10
0
// ////////////////////////////////////////////////////////////////////////////
static bool gameInit(void)
{
    UDWORD			player;

    // If this is from a savegame, stop here!
    if (getSaveGameType() == GTYPE_SAVE_START || getSaveGameType() == GTYPE_SAVE_MIDMISSION)
    {
        // these two lines are the biggest hack in the world.
        // the reticule seems to get detached from 'reticuleup'
        // this forces it back in sync...
        intRemoveReticule();
        intAddReticule();

        return true;
    }

    for (player = 1; player < MAX_PLAYERS; player++)
    {
        // we want to remove disabled AI & all the other players that don't belong
        if ((game.skDiff[player] == 0 || player >= game.maxPlayers) && player != scavengerPlayer())
        {
            clearPlayer(player, true);			// do this quietly
            debug(LOG_NET, "removing disabled AI (%d) from map.", player);
        }
    }

    if (game.scavengers)	// FIXME - not sure if we still need this hack - Per
    {
        // ugly hack for now
        game.skDiff[scavengerPlayer()] = DIFF_SLIDER_STOPS / 2;
    }

    unsigned playerCount = 0;
    for (int index = 0; index < game.maxPlayers; ++index)
    {
        playerCount += NetPlay.players[index].ai >= 0 || NetPlay.players[index].allocated;
    }
    addOilDrum(playerCount * 2);  // Calculating playerCount instead of using NetPlay.playercount, since the latter seems to be 0 for non-hosts.

    playerResponding();			// say howdy!

    return true;
}
예제 #11
0
파일: main.c 프로젝트: ryanlamo/lab5
void movecursor(char buttonToTest)
{
	clearPlayer(player);
	ClearTimer();
	switch(buttonToTest){
		case BIT1:
			player = movePlayer(player,RIGHT);
			break;
		case BIT2:
			player = movePlayer(player,LEFT);
			break;
		case BIT3:
			player = movePlayer(player,UP);
			break;
		case BIT4:
			player = movePlayer(player,DOWN);
			break;
	}
	printPlayer(player);
}
예제 #12
0
unsigned char movePlayer(unsigned char player, unsigned char direction)
{                clearPlayer(player);
        switch (direction) {
        case UP:
                     player &= ~BIT6;
                     break;
             case DOWN:
                     player |= BIT6;
                     break;
             case RIGHT:
                     if (player < 0x87 || player >= 0xC0){
                             player++;
                                  }
                     break;
             case LEFT:
                     if ((player & 0x0f)>0)
                             player--;

     }
     printPlayer(player);
        return player;
}
예제 #13
0
void recvPlayerLeft(NETQUEUE queue)
{
	uint32_t playerIndex = 0;
	NETbeginDecode(queue, GAME_PLAYER_LEFT);
	NETuint32_t(&playerIndex);
	NETend();

	addConsolePlayerLeftMessage(playerIndex);

	if (whosResponsible(playerIndex) != queue.index)
	{
		return;
	}

	turnOffMultiMsg(true);
	clearPlayer(playerIndex, false);  // don't do it quietly
	turnOffMultiMsg(false);
	NetPlay.players[playerIndex].allocated = false;

	NETsetPlayerConnectionStatus(CONNECTIONSTATUS_PLAYER_DROPPED, playerIndex);

	debug(LOG_INFO, "** player %u has dropped, in-game!", playerIndex);
}
예제 #14
0
void recvPlayerLeft(NETQUEUE queue)
{
	uint32_t playerIndex = 0;
	NETbeginDecode(queue, GAME_PLAYER_LEFT);
		NETuint32_t(&playerIndex);
	NETend();
	if (whosResponsible(playerIndex) != queue.index)
	{
		return;
	}

	turnOffMultiMsg(true);
	clearPlayer(playerIndex, false);  // don't do it quietly
	turnOffMultiMsg(false);
	NetPlay.players[playerIndex].allocated = false;

	char buf[256];
	ssprintf(buf, _("%s has Left the Game"), getPlayerName(playerIndex));
	addConsoleMessage(buf, DEFAULT_JUSTIFY, SYSTEM_MESSAGE);
	NETsetPlayerConnectionStatus(CONNECTIONSTATUS_PLAYER_DROPPED, playerIndex);

	debug(LOG_INFO, "** player %u has dropped, in-game!", playerIndex);
}
예제 #15
0
파일: main.c 프로젝트: JennaeN/Lab05_Game
int main(void) {
	WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

	//Use seed to create a random number
	static const char seed = 1234;

	//Define all of the strings that will be used in the program
	char * you = "YOU     ";
	char * win = "WIN!    ";
	char * game = "GAME    ";
	char * over = "OVER!   ";
	char * boom = "BOOM!   ";
	char * space = "        ";

	//Initialize the timer
	init_timer();

	//Initialize the buttons
	init_buttons();

	//Enable the interrupt
	__enable_interrupt();

	//SPI initialization function
	initSPI();

	// LCD initialization function
	LCDinit();

	//Clear the LCD screen
	LCDclr();

	//Place the player at the starting location
	printPlayer(location);

	//Create random mine placement
	char random = prand(seed);
	random = prand(random);
	char mine1Location = 0x81 + random % 7;
	random = prand(random);
	char mine2Location = 0xC0 + random % 7;

	//print the first mine, and check to make sure the second mine is printed in a place that the user can still win the game
	printMine(mine1Location);
	while (mine2Location == mine1Location
			|| mine2Location == (mine1Location + 0x40)
			|| mine2Location == (mine1Location + 0x41)
			|| mine2Location == (mine1Location + 0x3F)) {
		random = prand(random);
		mine2Location = 0xC0 + random % 7;
	}
	printMine(mine2Location);

	//during the rest of the game
	while (1) {

		//This is the end of the level - player wins!
		if (location == 0xC7) {
			print2LineMessage(you, win);
			//Set flag and increment to a value above 4 so that 'game over' is not printed
			flag = 5;
			increment = 5;

			//Reset the game for the next level
			while (flag > 4) {
			}
			LCDclr();
			location = initPlayer();
			printPlayer(location);
			mine1Location = 0x81 + random % 7;
			printMine(mine1Location);
			while (mine2Location == mine1Location
					|| mine2Location == (mine1Location + 0x40)
					|| mine2Location == (mine1Location + 0x41)
					|| mine2Location == (mine1Location + 0x3F)) {
				random = prand(random);
				mine2Location = 0xC0 + random % 7;
			}
			printMine(mine2Location);
			increment = 0;
		}

		//The game is over if the player hits a mine
		if (location == mine1Location || location == mine2Location) {
			flag = 4;
			print2LineMessage(boom, space);
			__delay_cycles(444444);
		}

		//If two seconds have passed, increment the mines to move in the opposite directions of each other
		if (increment == 4) {
			clearPlayer(mine1Location);
			clearPlayer(mine2Location);
			mine1Location--;
			mine2Location++;
			printMine(mine1Location);
			printMine(mine2Location);
			increment = 0;
		}

		//If the player loses, print 'game over'
		if (flag == 4) {
			print2LineMessage(game, over);
			flag = 5;
			increment = 5;

			//Reset the game for a new level
			while (flag > 4) {
			}
			LCDclr();
			location = initPlayer();
			printPlayer(location);
			flag = 0;
			increment = 0;
			mine1Location = 0x81 + random % 7;
			printMine(mine1Location);
			while (mine2Location == mine1Location
					|| mine2Location == (mine1Location + 0x40)
					|| mine2Location == (mine1Location + 0x41)
					|| mine2Location == (mine1Location + 0x3F)) {
				random = prand(random);
				mine2Location = 0xC0 + random % 7;
			}
			printMine(mine2Location);
		}
	}

}
예제 #16
0
파일: game.c 프로젝트: csbaltar/Lab5_Game
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;
}