예제 #1
0
//Update for GameLoop
void LevelTwo::update(float dt)
{
	playAudio();

	if (addPlatfroms == true)
	{
		createHiddenPlatforms();
		addPlatfroms = false;
	}

	if (player->getPhysicsBody()->getVelocity().y == 0 || playersColliding == true)
	{
		p1Jumped = false;
		//playersColliding = false;
	}
	else
		p1Jumped = true;

	if (player2->getPhysicsBody()->getVelocity().y == 0 || playersColliding == true)
	{
		p2Jumped = false;
	}
	else
		p2Jumped = true;

	if (playerOneDead == true)
	{
		player->respawnPoint(player, 2);
		playerOneDead = false;
	}

	if (playerTwoDead == true)
	{
		player2->respawnPoint(player2, 2);
		playerTwoDead = false;
	}

	if (playerOneEndGame == true && playerTwoEndGame == true)
	{
		showEndGame();
	}

	this->scheduleOnce(schedule_selector(LevelTwo::createFlames), 2.7f);
	//createFlames(checkCollision);
	//cameraTarget->setPosition(player->getPositionX(), player->getPositionY());
}
예제 #2
0
void ConsoleGame::handleMove(std::istringstream & iss)
{
  static std::map<char, int> columnMap, rowMap;

  if (columnMap.size() == 0) {
    columnMap['a'] = 0;
    columnMap['b'] = 1;
    columnMap['c'] = 2;
    columnMap['d'] = 3;
    columnMap['e'] = 4;
    columnMap['f'] = 5;
    columnMap['g'] = 6;
    columnMap['h'] = 7;

    rowMap['1'] = 0;
    rowMap['2'] = 1;
    rowMap['3'] = 2;
    rowMap['4'] = 3;
    rowMap['5'] = 4;
    rowMap['6'] = 5;
    rowMap['7'] = 6;
    rowMap['8'] = 7;

  }
  if (isGameOver()) {
    std::cout << "The game is over. Type new to start a new game\n";
    return;
  }

  std::string moveString;
  iss >> moveString;
  if (moveString.empty()) {
    std::cout << "A move string must be provided\n";
    return;
  }

  if (moveString.find_first_not_of("123456789abcdefghpnbrqkEcCNBRQ") != std::string::npos) {
    std::cout << "Invalid move string " << moveString << "\n";
    return;
  }

  if (moveString.length() < 4) {
    std::cout << "Invalid move string " << moveString << "\n";
    return;
  }

  int srcCol = columnMap[moveString.at(0)];
  int srcRow = rowMap[moveString.at(1)];
  int dstCol = columnMap[moveString.at(2)];
  int dstRow = rowMap[moveString.at(3)];

  uchar moveIndex = 0;
  bool moveFound = false;
  MoveList moveList;
  uchar totalMoves = mBoard->generateMoves(moveList);
  for (uchar i = 0; i < totalMoves; i++) {
    Move move = moveList[i];
    uchar sourceRow = move.sourceRow;
    uchar sourceCol = move.sourceCol;
    uchar destRow = move.destRow;
    uchar destCol = move.destCol;
    if (srcRow == sourceRow && dstRow == destRow && srcCol == sourceCol && dstCol == destCol) {
      moveIndex = i;
      moveFound = true;
      break;
    }
  }

  if (!moveFound) {
    std::cout << "Sorry " << moveString << " is not a valid move\n";
    for (uint i = 0; i < totalMoves; i++)
      std::cout << getSmithNotation(moveList[i]) << "\n";
    return;
  }

  doMove(moveList[moveIndex]);
  if (isGameOver()) {
    showEndGame();
    return;
  }

  bool doEngineMove = false;
//  if (gameType() == HumanVsComputer && !isWhiteToMove())
//    doEngineMove = true;
//  if (gameType() == ComputerVsHuman && isWhiteToMove())
//    doEngineMove = true;

  if (doEngineMove) {
    executeEngineMove();
    handlePrint();
    if (isGameOver()) {
      showEndGame();
    }
  }
}