static void MoveCB(XtPointer client_data, XtIntervalId *id) { (void) id; // Use it XtIntervalId *timer = (XtIntervalId *)client_data; assert(*timer == *id); *timer = 0; autoMove(); repaint(); }
static void ResetTicTacToeCB(Widget, XtPointer, XtPointer) { static int tics = 0; initBoard(); if (tics++ % 2 == 0) autoMove(); repaint(); set_status("Welcome to Tic Tac Toe!"); }
void Card::moveToStack(Stack* s, bool autoMoving, bool pushUndo) { if (s == 0 || s == _stack) return; if (pushUndo) undoAddMove(_stack, s); _stack->popCard(); _stack = s; Card* top = _stack->topCard(); if (top != 0 && top->canBeParent(this)) parent(_stack->topCard()); else parent(0); _stack->pushCard(this); move(_stack->next_x(), _stack->next_y(), true); if (autoMoving && Option::autoPlay()) autoMove(); }
void UIDragPanel::moveByUpdate(float t) { float easeRate = 0.0f; switch (m_eMoveType) { case DRAGPANEL_MOVE_TYPE_AUTOMOVE: easeRate = m_fAutoMoveEaseRate; break; case DRAGPANEL_MOVE_TYPE_BOUNCE: easeRate = m_fBounceEaseRate; break; default: break; } t = powf(t, 1 / easeRate); CCPoint currentPos = m_pActionWidget->getPosition(); CCPoint diff = ccpSub(currentPos, m_previousPosition); m_startPosition = ccpAdd( m_startPosition, diff); CCPoint newPos = ccpAdd( m_startPosition, ccpMult(m_positionDelta, t) ); m_pActionWidget->setPosition(newPos); m_previousPosition = newPos; switch (m_eMoveType) { case DRAGPANEL_MOVE_TYPE_AUTOMOVE: autoMove(); break; default: break; } }
//play the game void Play::play(char test, int maxTurns, string tCase) { int curTurn = 0; bool ykmovesavailable = true; bool yTurn; //false = x, true = y bool compMove; char compPlayer; CurrentBoard board; LegalMoves checkmoves; ofstream myfile("gameResult.txt"); if (test == 'y') { //set the initial board setInitialBoard(myfile, board, test, tCase); //player x goes first yTurn = false; //take turns between players until checkmate, stalemate, or out of moves while (ykmovesavailable && curTurn < maxTurns) { cout << "Turn " << curTurn + 1 << '\n'; myfile << "Turn " << curTurn + 1 << '\n'; //get the next move autoMove(myfile, board, yTurn); if (curTurn < maxTurns) { //switch to other player if (yTurn) { yTurn = false; curTurn++; } else { yTurn = true; } } //check if y has moves available ykmovesavailable = checkYKingMoves(board); } //end while //call the function to check and print out the result checkResult(curTurn, maxTurns, board, myfile); } else { //set the initial board setInitialBoard(myfile, board, test, tCase); //if champion mode, find out if this computer is player x or y if (test == 'n') { cout << "Am I player X or Y: "; cin >> compPlayer; cout << '\n'; } //initial move setup if (test == 'n' && compPlayer == 'y') { compMove = false; yTurn = true; } else { compMove = true; yTurn = false; } //take turns between players until checkmate, stalemate, or out of moves while (ykmovesavailable && curTurn <= maxTurns) { cout << "Turn " << curTurn << '\n'; myfile << "Turn " << curTurn << '\n'; if (compMove) { //make an auto move autoMove(myfile, board, yTurn); if (test == 'y') { //test mode if (yTurn) { yTurn = false; curTurn++; } else { yTurn = true; } } else { compMove = false; } } else if (!compMove && compPlayer == 'y') { //champion mode, computer is y, ask for x championOpponentX(myfile, board); compMove = true; } else { //champion mode, computer is x, ask for y championOpponentY(myfile, board); curTurn++; compMove = true; } //check if y has moves available ykmovesavailable = checkYKingMoves(board); } //end while //call the function to check and print out the result checkResult(curTurn, maxTurns, board, myfile); }
/********************************************************** * DEBRIS GAME * DESCRIPTION: This is a game where you need to shoot blocks **********************************************************/ void Debris(void) { char xMoveStart = 1; char fireIndex = 0; char moveYStart = 0; char yPosStart = 1; char index = 0; char index2 = 0; char jetHitCheck = 1; char lastCheck = 0; char numShots = 0; char yStart = 1; unsigned int ballSpeed = DEBRIS_DEBRISMOVERATE; unsigned int health = 47; unsigned int ballsDestroyed = 0; unsigned int highScore = EEProm_Read_16(debrisHighScore_Addr); struct Solid balls[DEBRIS_MAXDEBRIS]; struct Fire ammo[DEBRIS_MAXPROJECTILES]; struct Jet jet; if (health == 0) { health = 47; } //Assign pointers to allocated objects for (index = 0; index < DEBRIS_MAXDEBRIS; index++) { balls[index].enabled = 0; //Balls start disabled } LcdClear(); //Initialize game objects constructJet(&jet, 15, 2); //Initialize balls reset(&balls[0], 80, 4, 1, 1, 1); reset(&balls[1], 60, 0, 3, 2, 1); reset(&balls[2], 70, 3, 1, 1, 1); reset(&balls[3], 60, 2, 3, 2, 1); reset(&balls[4], 80, 1, 1, 1, 1); display_jet(&jet, 0); DisplayHealth(health, 0); //Start Timers StartTimer(0, DEBRIS_USERMOVERATE_MS); //Move player timer StartTimer(1, DEBRIS_RATEOFFIRE_MS); //Fire timer StartTimer(2, DEBRIS_PROJECTILESPEED_MS); //Fire move timer StartTimer(3, ballSpeed); //Move balls //Enter game loop for (;;) { //Check user move button if (CheckTimer(0)) { if (GetEnterButton()) //User wants to pause the game { if (Pause(showJetScore, ballsDestroyed, health, highScore) == 1) { return; } display_jet(&jet, 0); DisplayHealth(health, 0); } else if (GetLeft()) //Left button is being pressed { jet_moveLeft(&jet, 0); } else if (GetRight()) { jet_moveRight(&jet, 0); } if (GetUp()) { jet_moveUp(&jet); } else if (GetDown()) { jet_moveDown(&jet); } StartTimer(0, DEBRIS_USERMOVERATE_MS); //Reset this timer } //Check fire buttons if (CheckTimer(1)) //Now we can fire { if (GetFire()) //User took the chance to fire { if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;} numShots++; startFire(&ammo[fireIndex], &jet, 0); StartTimer(1, DEBRIS_RATEOFFIRE_MS); //Restart the fire timer. fireIndex++; SendData(SOUND_FIRE_PROJECTILE); //Fire sound } else if (GetSecFire()) //Shockwave cannon { if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;} startFire(&ammo[fireIndex], &jet, 2); StartTimer(1, DEBRIS_RATEOFFIRE_MS + 300); //Restart the fire timer. numShots++; fireIndex++; SendData(SOUND_FIRE_PROJECTILE); //Fire sound } else if (GetRightFire()) //Fire Reverse { if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;} startFire(&ammo[fireIndex], &jet, 1); StartTimer(1, DEBRIS_RATEOFFIRE_MS); //Restart the fire timer. numShots++; fireIndex++; SendData(SOUND_FIRE_PROJECTILE); //Fire sound } else if (GetRightSecFire()) //Reverse Shockwave cannon { if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;} startFire(&ammo[fireIndex], &jet, 3); StartTimer(1, DEBRIS_RATEOFFIRE_MS + 300); numShots++; fireIndex++; SendData(SOUND_FIRE_PROJECTILE); //Fire sound } } //Moves the weapons fire if (CheckTimer(2)) { //Check each ammo value to see if it hit a ball for (index = 0; index < DEBRIS_MAXPROJECTILES; index++) { if (ammo[index].enabled == 1) //This gives the game a performance boost but can cause inconsistant ball speeds { if (autoMove(&ammo[index]) == 1) { } if (lastCheck == 0) { lastCheck = 1; //Check each bullet to see if it hit a ball for (index2 = 0; index2 < DEBRIS_MAXDEBRIS; index2++) { //If a ball is hit, reset it so it starts over again. if (fire_checkHit(&ammo[index], &balls[index2]) == 1)//ammo[index].fireOutput == 1) { SendData(SOUND_BLOCK_DESTROYED); //Block hit sound balls[index2].enabled = 0; displaySolid(&balls[index2], 1); if (ammo[index].weapon != 2 && ammo[index].weapon != 3) { ammo[index].enabled = 0; displayFire(&ammo[index], 1); } //Ball speed increases every time 3 balls are dispatched if (ballsDestroyed % 3 == 0 && ballSpeed > 15) { ballSpeed--; } changeBallStart(&balls[index2], &moveYStart, &yPosStart, &xMoveStart, &yStart); ballsDestroyed++; if (ballsDestroyed > highScore) { highScore = ballsDestroyed; EEProm_Write_16(debrisHighScore_Addr, highScore); } } } } else { lastCheck = 0; } } } StartTimer(2, DEBRIS_PROJECTILESPEED_MS); } //Move the balls if (CheckTimer(3)) { for (index = 0; index < DEBRIS_MAXDEBRIS; index++) { if (balls[index].enabled == 1) //Gives a small performance boost at the cost of ball speed consistancy { autoMoveSolid(&balls[index]); if (jetHitCheck == 0) { //Ball hits the jet jetHitCheck = 1; if (jet_checkHit(&jet, &balls[index]) != 0x00) { SendData(SOUND_BLOCK_DESTROYED); //Block hit sound balls[index].enabled = 0; displaySolid(&balls[index], 1); display_jet(&jet, 0); health--; DisplayHealth(health, 0); //Jet was destroyed if (health == 0) { display_jet(&jet, 1); constructJet(&jet, 15, 2); health = 47; ballsDestroyed = 0; display_jet(&jet, 0); } changeBallStart(&balls[index], &moveYStart, &yPosStart, &xMoveStart, &yStart); } } else { jetHitCheck = 0; } } } StartTimer(3, ballSpeed); } } }