Пример #1
0
void IMob::processGUImsg(const Message2 &msg)
{
    if (msg.type != MessageType::ORDINARY)
    {
        return;
    }

    QJsonObject obj = Network2::ParseJson(msg);

    if (Network2::IsKey(obj, Input::MOVE_UP))
    {
        checkMove(D_UP);
    }
    else if (Network2::IsKey(obj, Input::MOVE_DOWN))
    {
        checkMove(D_DOWN);
    }
    else if (Network2::IsKey(obj, Input::MOVE_LEFT))
    {
        checkMove(D_LEFT);
    }
    else if (Network2::IsKey(obj, Input::MOVE_RIGHT))
    {
        checkMove(D_RIGHT);
    }
}
Пример #2
0
// Find a next legal move
bool findNextMove() {
  bool foundMove = false;
  for (int x=0; x < BOARD_PIECES_X; ++x) {
    for (int y=0; y < BOARD_PIECES_Y; ++y) {
      if (y < BOARD_PIECES_Y - 1) {
        s_switch.first = GPoint(x,y);
        s_switch.second = GPoint(x,y+1);
        foundMove = checkMove();
        if (foundMove == true) break;
      }
      if (x < BOARD_PIECES_X - 1) {
        s_switch.first = GPoint(x,y);
        s_switch.second = GPoint(x+1,y);
        foundMove = checkMove();
        if (foundMove == true) break;
      }
    }
    if (foundMove == true) break;
  }
  if (foundMove == true) { // There is a legal move somewhere on the board, we'll take note of it in case the user is dumb and can't find it on their own
    s_availableMove = s_switch.first;
    s_gameState = kIdle;
    #ifdef AUTO_MODE
    s_gameState = kCheckMove; // This ONE line lets the pebble play automatically, love that
    #endif
    s_hintTimer = app_timer_register(HINT_TIMER, enableHint, NULL); // Pops up a hint in the future
  } else { // Oh dear, there are no legal swaps left on the board. Hope the user has some lives left!
    s_availableMove = GPoint(-1,-1);
    s_gameState = kCheckLives;
  }
  return false; // don't redraw
}
Пример #3
0
Файл: GB.cpp Проект: Kionte/2048
void GB::changeGB() {
    switch (command) {
        case 9:
            leftGB();
            if(checkMove()) {
                randomInput();
            }
            outputGB();
            break;
        case 8:
            rightGB();
            if(checkMove()) {
                randomInput();
            }
            outputGB();
            break;
        case 7:
            upGB();
            if(checkMove()) {
                randomInput();
            }
            outputGB();
            break;
        case 6:
            downGB();
            if(checkMove()) {
                randomInput();
            }
            outputGB();
            break;
        default:
            //non valid move
            break;
    }
}
Пример #4
0
int Board::numMovesLeft(){
	int movesLeft = 0;
	for(int x = 0; x < 8; x ++){
		for(int y = 0; y < 8; y ++){
			Move * move = new Move(x, y);
			if(checkMove(move, BLACK) or checkMove(move, WHITE)){
				movesLeft ++;
			}
			delete move;
		}
	}
	return movesLeft;
}
Пример #5
0
/**
 * One frame of logic for this behavior
 */
void BehaviorStandard::logic() {

	// skip all logic if the enemy is dead and no longer animating
	if (e->stats.corpse) {
		if (e->stats.corpse_ticks > 0)
			e->stats.corpse_ticks--;
		return;
	}

	if (!e->stats.hero_ally) {
		if (calcDist(e->stats.pos, pc->stats.pos) <= ENCOUNTER_DIST)
			e->stats.encountered = true;

		if (!e->stats.encountered)
			return;
	}

	doUpkeep();
	findTarget();
	checkPower();
	checkMove();
	updateState();

	fleeing = false;
}
Пример #6
0
void Chomp::handle(const char& c){
  /**
   * Cette fonction vérifie les touches tapées au clavier
   * par les joueurs.
   * @param c représente le caractère taper au clavier
   */
  if(checkMove(c) ){
    return;
  }
  
  // si le joueur veut quitter le jeux
  if (c == 'x') {
    Game::getInstance()->mainMenu();
    return;
  }

  // si le joueur veux executer une action, ici joueur une piece
  if (c == 'p' || c == MARK) {
    /* vérifie si b est en position gagnante 
     * avec le coup jouer */
    if( isNext(mPointer, mSuccessors) ){
      mBoard.at(mPointer.fst(), mPointer.snd()) = mCurrentPlayer->getColor(); 
      fillcolor(mPointer.fst(), mPointer.snd());
      mCurrentPlayer = opponent();
    }
  }
}
Пример #7
0
bool QAbstractKineticScrollerPrivate::handleMouseMove(QMouseEvent *e)
{
    Q_Q(QAbstractKineticScroller);
    qKSDebug() << "MM: pos: " << e->globalPos() << " - time: " << QTime::currentTime().msec();
    if (!(e->buttons() & Qt::LeftButton))
        return false;
    if ((state != QAbstractKineticScroller::MousePressed) &&
        (state != QAbstractKineticScroller::Pushing) &&
        (state != QAbstractKineticScroller::AutoScrolling))
        return false;
    if (moved && !lastTime.elapsed())
        return true;
    if (lastType == QEvent::MouseButtonPress)
        firstDrag = true;

    QPoint delta = e->globalPos() - pos;

    if (!moved) {
        checkMove(e, delta);
    }

    if (moved) {
        if (state != QAbstractKineticScroller::Pushing) {
            q->cancelLeftMouseButtonPress(ipos);

            changeState(QAbstractKineticScroller::Pushing);
        }
        handleMove(e, delta);
    }
    lastTime.restart();
    lastType = e->type();

    qKSDebug("MM: end %d", moved);
    return moved;
}
Пример #8
0
Файл: term.c Проект: gto76/race
int main(void) {
	setEnvironment();
	setOutput();
	setScoreboard();

	while(1) {
		setRaceMode();
		PLAYER ppp[numOfPlayers];
		setPlayer(&ppp, 0, STARTING_POSITION_X, 18, '1', 65, 66, 67, 68);
		setPlayer(&ppp, 1, STARTING_POSITION_X, 20, '2', 119, 115, 100, 97);
		players = &ppp;

		redrawScreen();
		splashScreen();
		countdown();

		setStartTime(&ppp); 
		char c;
		while (!weHaveAWinner(&ppp)) { 
			c = getc(stdin);
			checkMove(c, &ppp);
		}
		printWins();
		checkeredFlag();
		waitForEnter();
	}

	return EXIT_SUCCESS;
}	
Пример #9
0
int play(int *score, Tetromino *tetromino)
{
  int col;
  Tetromino tempTetromino;

  tempTetromino = *tetromino;
  tempTetromino.location += 38;
  printTetromino(tetromino, ' ');

  if(checkMove(&tempTetromino)) // can move
  {
    *tetromino = tempTetromino;  
    printTetromino(tetromino, 'X');
  }  // if can move
  else // cannot move
  {
    printTetromino(tetromino, 'X');
    checkLines(score);

    for(col = 1; col <= 10; col++)
      if(crt[1][col] != ' ')
        return 0;  // X on the second row  so game over.

    startTetromino(tetromino); 
  }  // else cannot move

  return 1;
}  // play()
Пример #10
0
/*******************************************************************************
* function updateData (void)
*
* This function is called every time the player makes a move, it updates
* the board, the mask, the missiles fired, the missiles remaining, the score,
* the previous move and makes the current move
*
*            char board[] - Stores where the ships are located
*             char mask[] - Stores the board that is shown to the player
*     int * missilesFired - Stores how many missiles were already fired
* int * missilesRemaining - Stores how many missiles the player still has
*             int * score - Stores the player's score
*     char previousMove[] - Stores what was the previous move the player made
*     char  currentMove[] - Stores what is the current move the player made
*/
void updateData ( char board[], char mask[], int  * missilesFired,
                  int  * missilesRemaining , int  * score,
                  char previousMove[]      , char currentMove[] )
{

  int currentMoveNumeric = checkMove ( currentMove );

  // Checking if the player hasn't made this move (if it is not water)
  if ( mask [currentMoveNumeric] == ' ')
  {
    *missilesFired = *missilesFired + 1;
    *missilesRemaining = *missilesRemaining - 1;

    // Checking what the player hit
    // Water
    if ( board [currentMoveNumeric] == ' ')
    {
      mask [currentMoveNumeric] = '~';
      strcpy (previousMove, "MISS on ");
    }
    // A ship
    else
    {
      mask [currentMoveNumeric] = board [currentMoveNumeric];
      strcpy (previousMove, "HIT on ");
      *score += 5;
    }

    strncat (previousMove, currentMove, 2);
  }
}
Пример #11
0
void solveProblem()
{
	int index, result;
	while(true)
	{
		for(index = 0; index < numMoves; index++)
		{
			result = checkMove(index);
			
			if(result <= 1)
				break;
		}
		
		if(result == 0)
		{
			printf("You are cheating!\n");
			return;
		}

		if(index != numMoves)
			continue;

		printf("%d", guess[0]);
		for(index=1; index < numPins; index++)
			printf(" %d", guess[index]);
		printf("\n");
		return;
	}
}
Пример #12
0
//mouse event detection
void DrawingManager::mouseDrag(double x, double y){
    if (mode == DRAW_M); //addPoint(x,y);
    else if (mode == ELLIPSE_M || mode== LINE_M || mode==RECT_M) sizeShape(x,y);
    else if (mode == SELECT_M) checkMove(x,y);
    else if (mode == DIRECT_M) checkDMove(x,y);
    else if (mode == SCALE_M) checkScale(x,y);
    
}
Пример #13
0
bool GameState::executeMove(int who, int fieldIndex) {
  Move m;
  if(!checkMove(who,fieldIndex,m)) {
    return false;
  }
  doMove(who,m);
  return true;
}
Пример #14
0
void Core::handleKey()
{
  if (this->_key == 4)
    {
      this->_isRunning = false;
    }
  else
    checkMove();
}
Пример #15
0
/**
 * One frame of logic for this behavior
 */
void BehaviorStandard::logic() {

	doUpkeep();
	findTarget();
	checkPower();
	checkMove();
	updateState();

}
Пример #16
0
int GameState::firstMove( int who, Move &m ) {
  for(int i = 1; i < ARRAYSIZE(fs); i++) {
    if(checkMove(who,i,m)) {
      return i;
    }
  }
  m.fieldIndex = MOVE_PASS;
  return MOVE_PASS;
}
Пример #17
0
/*
 * Returns true if there are legal moves for the given side.
 */
bool Board::hasMoves(Side side) {
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
            Move move(i, j);
            if (checkMove(&move, side)) return true;
        }
    }
    return false;
}
Пример #18
0
void towers(int n, char first, char last, char mid){
  
  // If only 1 disk, make the move and return
  if(n==1){ printf("\nDisk 1 from peg %c to %c",first,last);
    checkMove(first,last);
    return;
  }
  
  // Move top n-1 disks from A to B, using C as auxiliary
  towers(n-1,first,mid,last);

  // Move remaining disks from A to C 
  printf("\nMove disk %d from peg %c to peg %c",n,first,last);
  checkMove(first,last);

  // Move n-1 disks from B to C using A as auxiliary
  towers(n-1,mid,last,first);
}
Пример #19
0
int GameState::nextMove( int who, Move &m  ) {
  if(m.fieldIndex != MOVE_PASS) {
    for(int i = m.fieldIndex + 1; i < ARRAYSIZE(fs); i++) {
      if(checkMove(who,i,m)) {
        return i;
      }
    }
  }
  return -1;
}
Пример #20
0
//Make a move if it is valid
bool Piece::move(ChessBoard &board, int fromRow, int fromCol, int toRow, int toCol) {
	if(checkMove(board, fromRow, fromCol, toRow,toCol)) {
		board.getPiece(toRow, toCol)->setCaptured();
		board.swap(fromRow, fromCol, toRow, toCol);
		hasMoved = true;
		return true;
	} else {
		//Invalid move
		return false;
	}
}
Пример #21
0
bool ConnectFour::Board::testMove(const Move& move) const
{
    if(!isInBounds(move))
        return false;

    unsigned int x = move.column();
    // The move comes in on top of the column, so its (size - 1) + 1
    unsigned int y = (unsigned int)m_board[x].size();

    return checkMove({x, y}, move.player());
}
Пример #22
0
Morris::MoveResult Morris::move(MorrisState::Player player, int piece, int x, int y)
{
	// エラー処理
	MoveResult res = checkMove(player, piece, x, y);
	if (res != ok) {
		return res;
	}

	// コマを置く/動かす
	for (int i = 0; i < 3; ++i) {
		s.pieces[player][i].prevX = -1;
		s.pieces[player][i].prevY = -1;
	}
	MorrisState::Piece &p = s.pieces[player][piece];
	p.prevX = p.x;
	p.prevY = p.y;
	p.x = x;
	p.y = y;

	// 決着判定
	bool t[3][3] = { false };
	if (s.pieces[player][0].x >= 0 && s.pieces[player][1].x >= 0 && s.pieces[player][2].x >= 0) {
		for (int i = 0; i < 3; ++i) {
			t[s.pieces[player][i].x][s.pieces[player][i].y] = true;
		}
	}
	if ((t[0][0] && t[0][1] && t[0][2])
		|| (t[1][0] && t[1][1] && t[1][2])
		|| (t[2][0] && t[2][1] && t[2][2])
		|| (t[0][0] && t[1][0] && t[2][0])
		|| (t[0][1] && t[1][1] && t[2][1])
		|| (t[0][2] && t[1][2] && t[2][2])
		|| (t[0][0] && t[1][1] && t[2][2])
		|| (t[2][0] && t[1][1] && t[0][2])
		) {
		s.finished = true;
		return ok;
	}

	// 全部置き終わったら動かすフェーズに入る
	if (s.phase == MorrisState::put) {
		if (s.pieces[MorrisState::second][0].x >= 0 && s.pieces[MorrisState::second][1].x >= 0 && s.pieces[MorrisState::second][2].x >= 0) {
			s.phase = MorrisState::move;
		}
	}

	// プレイヤーの番を交代
	s.playing = (player == MorrisState::first) ? MorrisState::second : MorrisState::first;

	return ok;
}
Пример #23
0
std::vector<Move*> Board::getMoves(Side side) {
	std::vector<Move*> valid_moves;
	for (int i = 0; i < 8; i++) {
		 for (int j = 0; j < 8; j++) {
			Move * move = new Move(i, j);
			if (checkMove(move, side)) {
				valid_moves.push_back(move);
			}
			else {
				delete move;
			}
		}
	}
	return valid_moves;
}
Пример #24
0
/**
 * One frame of logic for this behavior
 */
void BehaviorStandard::logic() {

	// skip all logic if the enemy is dead and no longer animating
	if (e->stats.corpse) {
		if (e->stats.corpse_ticks > 0)
			e->stats.corpse_ticks--;
		return;
	}
	doUpkeep();
	findTarget();
	checkPower();
	checkMove();
	updateState();

}
/* 
* Returns vector of all legal moves for a given side
*/
vector<Move *> Board::getLegalMoves(Side side){
    vector<Move *> possibleMoves;
    Move* m = new Move(0, 0);
    for (int i = 0; i < 8; i++){
        m->setX(i);
        for (int j = 0; j < 8; j++){
            m->setY(j);
            if (checkMove(m, side) == true){

                Move* good = new Move(i, j);
                possibleMoves.push_back(good);
            }
        }   
    }
    return possibleMoves;
}
Пример #26
0
void IMovable::ProcessForce()
{

    Dir step = VDirToDir(force_);

    checkMove(step);

    if (!NonZero(force_))
        return;

    // qDebug() << "Process force: " << GetId();
    // qDebug() << force_.x;
    // qDebug() << force_.y;

    VDir vstep = DirToVDir[step];
    force_.x -= (vstep.x * Friction::CombinedFriction(GetTurf())) / Friction::BASE_FRICTION;
    force_.y -= (vstep.y * Friction::CombinedFriction(GetTurf())) / Friction::BASE_FRICTION;
    force_.z -= (vstep.z * Friction::CombinedFriction(GetTurf())) / Friction::BASE_FRICTION;
}
Пример #27
0
void playBattleship(void) {

	char board[SIZE], mask[SIZE];
	char previousMove[] = "N/A";
	int missilesFired = 0, score = 0, missilesRemaining = 100;
	char coord[] = "N/A";
	char c = 0;

	initGame(board, mask);
	
	do {
		
		drawGame(board, missilesFired, missilesRemaining, score, previousMove);
		printf("Missles Fired:%d  Missles Remaining:%d\n", missilesFired, missilesRemaining);
		printf("Current Score %d  \n", score);
		checkMove(coord);
		updateData(board, mask, &missilesFired, &missilesRemaining, &score, previousMove, coord);
	} while (missilesRemaining > 0 && score != 110);
	getchar();
}
Пример #28
0
void changeTetromino(Tetromino *tetromino, char key)
{
  Tetromino tempTetromino;
  tempTetromino = *tetromino;
  
  switch(key)
  {
    case UP : tempTetromino.rotation = (tempTetromino.rotation + 1) % 4; break;
    case DOWN : tempTetromino.location += 38; break;
    case RIGHT : tempTetromino.location += 1; break;
    case LEFT : tempTetromino.location -= 1; break;
  } // switch

  printTetromino(tetromino, ' ');

  if(checkMove(&tempTetromino))
    *tetromino = tempTetromino;

  printTetromino(tetromino, 'X');
  
  
} // changeTetromino()
Пример #29
0
void gameLoop(void* data) {
  if (++s_frame == ANIM_FPS) s_frame = 0; // Note we may not draw every frame
  #ifdef DEBUG_MODE
  ++s_FPS;
  #endif

  bool requestRedraw = false;

  switch (s_gameState) {
    case kIdle: break;
    case kAwaitingDirection: requestRedraw = awaitingDirection(); break;
    case kCheckMove: requestRedraw = checkMove(); break;
    case kNudgeAnimate: requestRedraw = nudgeAnimate(); break;
    case kSwapAnimate: requestRedraw = swapAnimate(); break;
    case kFindMatches: requestRedraw = findMatches(); break;
    case kFlashRemoved: requestRedraw = flashRemoved(); break;
    case kRemoveAndReplace: requestRedraw = removeAndReplace(); break;
    case kSettleBoard: requestRedraw = settleBoard(); break;
    case kFindNextMove: requestRedraw = findNextMove(); break;
    case kCheckLives: requestRedraw = checkLives(); break;
    case kGameOver: requestRedraw = gameOver(); break;
    default: break;
  }

  switch (s_scoreState) {
    case kWait: requestRedraw |= checkScoreBuffer(); break;
    case kApplyPoints: requestRedraw |= applyPoints(); break;
    case kCheckNewLevel: requestRedraw |= checkNewLevel(); break;
    default: break;
  }

  // only if taking acceleromiter data do we ALWAY redraw
  if (s_tiltMode > 0 || requestRedraw == true) {
    redraw();
  }

  s_gameLoopTime = app_timer_register(ANIM_DELAY, gameLoop, NULL);
}
Пример #30
0
bool Model::checkPosition(MoveRule moveRule, const Figure& figure, Move& move, int movetype, bool needCheck) const {

    if (myBoard(move.pos2.myX, move.pos2.myY) == -1) {
        return false;
    }
    Position curPos = move.pos2;
    bool accepted = false;

    move.figureId = figure.id;

    if ((movetype & MOVE) && myBoard(move.pos2.myX, move.pos2.myY) == 0 && (moveRule.moveType & MOVE)) {
        accepted = checkMove(moveRule, figure, move);
    } else if ((movetype & CAPTURE) && myBoard(curPos.myX, curPos.myY) > 0 && (moveRule.moveType & CAPTURE)) {
        accepted = checkCapture(moveRule, figure, move);
    } else if ((movetype & CAPTURE) && myBoard(curPos.myX, curPos.myY) == 0 && (moveRule.moveType == INPASSING)) {
        accepted = checkInpassing(moveRule, figure, move);
    }
    if (accepted == true && needCheck == true) {
        accepted = !checkIfCheck(moveRule, figure, move);
    }

    return accepted;
}