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; }
//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; } }
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; }
void movePlayer(PLAYER (*ppp)[], int i, int dir) { PLAYER *p = &(*ppp)[i]; POSITION oldPosition = (*p).obj.pos; POSITION newPosition = getNewPosition(oldPosition, dir); if (isPositionValid(newPosition, dir)) { // save move if not yet finished: if ((*p).finished != 1) { saveMove(p, dir); } // if player crossed the line, finished flag is set to true: if (crossedTheLine(oldPosition, dir)) { (*p).finished = 1; } int symbol = getSymbolOnTheTrack(oldPosition); erasePlayer(p); // if player was on the finish line, draw finish line: if (symbol == '|') { printChar('|', oldPosition); } (*p).obj.pos = newPosition; // so that if two were on the same spot both get printed: printAllPlayers(ppp); // so that it if two are on the same spot the last that arrived gets printed: printPlayer(p); } }
/*! */ bool TextPrinter::handleShow( const int, const rcsc::rcg::ShowInfoT & show ) { if ( ! M_init_written ) { M_init_written = true; M_os << "(Init)" << "\n"; } M_os << "(Info "; printState( M_os, show.time_ ); // ball M_os << " (ball " << show.ball_.x_ << ' ' << show.ball_.y_ << ' ' << show.ball_.vx_ << ' ' << show.ball_.vy_ << ')'; // players for ( int i = 0; i < rcsc::MAX_PLAYER*2; ++i ) { rcsc::rcg::player_t p; rcsc::rcg::Serializer::convert( show.player_[i], p ); printPlayer( M_os, show.player_[i].side(), show.player_[i].unum_, M_command_count[i], p ); M_command_count[i].update( show.player_[i] ); } M_os << ")\n"; return true; }
void RenewGame() { gamedone = 0; LCDclear(); player = initPlayer(); printPlayer(player); }
void ModelPainter::paint(sf::RenderWindow& window) { model::ObjectPtr playerObj = modelFacade_->getPlayerObject(); maps::IMapContainer& currentMap = modelFacade_->getCurrentMap(); printMap(window, currentMap); printPlayer(window, playerObj); setCamera(window, playerObj); updateViewportArea(currentMap, playerObj); }
int main(void) { WDTCTL = WDTPW | WDTHOLD; player = initPlayer(); initSPI(); LCDinit(); LCDclear(); RenewGame(); printPlayer(player); init_timer(); init_buttons(); __enable_interrupt(); while(1) { if (player==0xC7) { TACTL &= ~TAIE; LCDclear(); cursorToLineOne(); writeString("YOU"); cursorToLineTwo(); writeString("WON!"); gamedone = 1; _delay_cycles(1000000); } if (CountTimer >=4) { TACTL &= ~TAIE; LCDclear(); cursorToLineOne(); writeString("Game"); cursorToLineTwo(); writeString("Over"); gamedone = 1; _delay_cycles(1000000); } } return 0; }
void* displayOnScreen(void* screen_void){ ScreenInfo* screen = (ScreenInfo*) screen_void; Process* process = screen->process; while(*screen->isClosed == false){ int i; if(process->player->position[0] != -1){ printMap(screen->win, process->map, *screen->selectedItem, process->player); printInventory(screen->win, *screen->selectedItem, process->player); printPlayer(screen->win, (NB_LIGNE / 2), (NB_COLONNE / 2)); for(i = 0; i < process->nbPlayers - 1; i++){ printPlayer(screen->win, process->players[i].x - process->player->position[0] + (NB_LIGNE / 2), process->players[i].y - process->player->position[1] + (NB_COLONNE / 2)); } SDL_UpdateWindowSurface(screen->win); } usleep(1000000/30); } pthread_exit(NULL); }
int main() { int numberOfPlayer=sizeof(player)/sizeof(tableTennis_t); printf(" Original data\n"); printPlayer(player,numberOfPlayer); sortName(player,numberOfPlayer); printf("\n Title order\n"); printPlayer(player,numberOfPlayer); sortHeight(player,numberOfPlayer); printf("\n Height order\n"); printPlayer(player,numberOfPlayer); sortWeight(player,numberOfPlayer); printf("\n Weight order\n"); printPlayer(player,numberOfPlayer); sortYear(player,numberOfPlayer); printf("\n Year order\n"); printPlayer(player,numberOfPlayer); return 0; }
void Reset(char buttonToTest){ if(buttonToTest &P2IFG){ if(buttonToTest & P2IES){ gameover=0; LCDclear(); player=initPlayer(); printPlayer(player); clearTimer(); TACTL|= TAIE; } else{ debounce(); } P2IES ^= buttonToTest; P2IFG &= ~buttonToTest; } }
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; } }
/*! */ bool TextPrinter::handleShowInfo( const rcsc::rcg::showinfo_t & show ) { if ( ! M_init_written ) { M_init_written = true; M_os << "(Init)" << "\n"; } handlePlayMode( show.pmode ); handleTeamInfo( show.team[0], show.team[1] ); M_os << "(Info"; M_os << ' '; printState( M_os, static_cast< long >( static_cast< short >( ntohs( show.time ) ) ) ); M_os << ' '; printBall( M_os, show.pos[0] ); for ( int i = 1; i < rcsc::MAX_PLAYER * 2 + 1; ++i ) { if ( ntohs( show.pos[i].enable ) == 0 ) { // player is not connected continue; } int unum = ( i <= rcsc::MAX_PLAYER ? i : i - rcsc::MAX_PLAYER ); //const std::string & teamname = ( i <= rcsc::MAX_PLAYER //? M_left_team_name //: M_right_team_name ); M_os << ' '; printPlayer( M_os, //teamname, ( i <= rcsc::MAX_PLAYER ? rcsc::LEFT : rcsc::RIGHT ), unum, show.pos[i] ); } M_os << ")" << std::endl; return true; }
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); }
int main(void) { WDTCTL = (WDTPW|WDTHOLD); player = initPlayer(); //debugging: had player defined twice, caused * to jump around alot initSPI(); LCDinit(); LCDclear(); printPlayer(player); init_timer(); init_buttons(); __enable_interrupt(); while(1) { if(player == 0xC7){ TACTL &= ~TAIE; LCDclear(); cursorToLineOne(); writeString("YOU"); cursorToLineTwo(); writeString("WON!"); gameover = 1; _delay_cycles(100000); } if(timerCount >= 4){ TACTL &= ~TAIE; LCDclear(); cursorToLineOne(); writeString("Game"); cursorToLineTwo(); writeString("Over!"); gameover = 1; _delay_cycles(100000); } } return 0; }
/*! */ bool TextPrinter::handleShortShowInfo2( const rcsc::rcg::short_showinfo_t2 & show ) { if ( ! M_init_written ) { M_init_written = true; M_os << "(Init)" << "\n"; } M_os << "(Info "; printState( M_os, static_cast< long >( static_cast< short >( ntohs( show.time ) ) ) ); M_os << " "; printBall( M_os, show.ball ); for ( int i = 0; i < rcsc::MAX_PLAYER * 2; ++i ) { if ( ntohs( show.pos[i].mode ) == 0 ) { // player is not connected continue; } int unum = ( i < rcsc::MAX_PLAYER ? i + 1 : i + 1 - rcsc::MAX_PLAYER ); //const std::string & teamname = ( i < rcsc::MAX_PLAYER //? M_left_team_name //: M_right_team_name ); M_os << " "; printPlayer( M_os, //teamname, ( i < rcsc::MAX_PLAYER ? rcsc::LEFT : rcsc::RIGHT ), unum, M_command_count[i], show.pos[i] ); M_command_count[i].update( show.pos[i] ); } M_os << ")" << std::endl; return true; }
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; }
void printAllPlayers(PLAYER (*ppp)[]) { int i; for (i = 0; i < numOfPlayers; i++) { printPlayer(&((*ppp)[i])); } }
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) { } } }
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; }
static void printTeam( const team_s *team ) { printf( "{\"name\":\"%s\"", team->name ); printf( ",\"location\":\"%s\"", team->location ); printf( ",\"abbreviation\":\"%s\"", team->abbreviation ); if ( team->stats != NULL ) { printf( ",\"stats\":" ); printf( "{\"wins\":%d", team->stats->wins ); printf( ",\"losses\":%d", team->stats->losses ); printf( ",\"ties\":%d", team->stats->ties ); printf( ",\"points_scored\":%d", team->stats->points_scored ); printf( ",\"points_allowed\":%d", team->stats->points_allowed ); printf( "}" ); } if ( team->offense_stats != NULL ) { printf( ",\"offense_stats\":" ); printf( "{\"pass_attempts\":%d", team->offense_stats->pass_attempts ); printf( ",\"completions\":%d", team->offense_stats->completions ); printf( ",\"interceptions\":%d", team->offense_stats->interceptions ); printf( ",\"pass_yards\":%d", team->offense_stats->pass_yards ); printf( ",\"pass_touchdowns\":%d", team->offense_stats->pass_touchdowns ); printf( ",\"rush_attempts\":%d", team->offense_stats->rush_attempts ); printf( ",\"rush_yards\":%d", team->offense_stats->rush_yards ); printf( ",\"rush_touchdowns\":%d", team->offense_stats->rush_touchdowns ); printf( "}" ); } if ( team->defense_stats != NULL ) { printf( ",\"defense_stats\":" ); printf( "{\"sacks\":%d", team->defense_stats->sacks ); printf( ",\"interceptions\":%d", team->defense_stats->interceptions ); printf( ",\"return_yards\":%d", team->defense_stats->return_yards ); printf( ",\"return_touchdowns\":%d", team->defense_stats->return_touchdowns ); printf( "}" ); } if ( team->kicking_stats != NULL ) { printf( ",\"kicking_stats\":" ); printf( "{\"extra_point_attempts\":%d", team->kicking_stats->extra_point_attempts ); printf( ",\"extra_points_made\":%d", team->kicking_stats->extra_points_made ); printf( ",\"field_goal_attempts\":%d", team->kicking_stats->field_goal_attempts ); printf( ",\"field_goals_made\":%d", team->kicking_stats->field_goals_made ); printf( ",\"punts\":%d", team->kicking_stats->punts ); printf( ",\"punt_yards\":%d", team->kicking_stats->punt_yards ); printf( ",\"kick_returns\":%d", team->kicking_stats->kick_returns ); printf( ",\"kick_return_yards\":%d", team->kicking_stats->kick_return_yards ); printf( ",\"kick_return_touchdowns\":%d", team->kicking_stats->kick_return_touchdowns ); printf( ",\"punt_returns\":%d", team->kicking_stats->punt_returns ); printf( ",\"punt_return_yards\":%d", team->kicking_stats->punt_return_yards ); printf( ",\"punt_return_touchdowns\":%d", team->kicking_stats->punt_return_touchdowns ); printf( "}" ); } if ( team->players != NULL ) { printf( ",\"players\":[" ); for ( int i = 0; team->players[i].player != NULL; ++i ) { if ( i > 0 ) printf( "," ); printPlayer( team->players[i].player ); } printf( "]" ); } printf( "}" ); }
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); } } }
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); } } }