/// <summary> /// Método que permite comserse una bolita a un jugador y obtener poder /// </summary> /// <param name="movement">Objeto de tipo LismanMovement</param> private void EatPowerPill(LismanMovement movement) { UpdateGameMap(movement.idGame, EMPTYBOX, movement.initialPositionX, movement.initialPositionY); UpdateGameMap(movement.idGame, movement.colorLisman, movement.finalPositionX, movement.finalPositionY); int scoreLisman = UpdateScore(movement.idGame, movement.colorLisman, POINTSPOWERPILL); string userName = multiplayerGameInformation[movement.idGame].lismanUsers[movement.colorLisman].userLisman; connectionGameService[userName].UpdateLismanSpeed(SPEEDPOWERFUL, true); foreach (KeyValuePair <int, InformationPlayer> player in multiplayerGameInformation[movement.idGame].lismanUsers) { if (player.Value.isLive) { try { connectionGameService[player.Value.userLisman].NotifyDisappearedPowerPill(movement.finalPositionX, movement.finalPositionY); connectionGameService[player.Value.userLisman].NotifyLismanMoved(movement.colorLisman, movement.finalPositionX, movement.finalPositionY, movement.goTo); connectionGameService[player.Value.userLisman].NotifyUpdateScore(movement.colorLisman, scoreLisman); } catch (CommunicationException e) { Console.WriteLine("Error en la conexión con el usuario:" + player.Value.userLisman + ". Error: " + e.Message); } } } }
/// <summary> /// Método que recibe un objeto de tipo Movement por parte de un cliente /// para solicitar se movido en el mapa /// </summary> /// <param name="movement">objeto de tipo Movement que tiene conocimiento del /// movimiento del jugador</param> public void MoveLisman(LismanMovement movement) { int valueBox = GetValueBox(movement.idGame, movement.finalPositionX, movement.finalPositionY); switch (valueBox) { case EMPTYBOX: MoveLismanToNewPosition(movement); break; case POWERPILL: EatPowerPill(movement); break; default: EatLismanEnemy(movement, valueBox); break; } }
/// <summary> /// Metodo que mueve a un jugador a una nueva posicion /// </summary> /// <param name="movement">Objeto de tipo LismanMovement</param> private void MoveLismanToNewPosition(LismanMovement movement) { UpdateGameMap(movement.idGame, EMPTYBOX, movement.initialPositionX, movement.initialPositionY); UpdateGameMap(movement.idGame, movement.colorLisman, movement.finalPositionX, movement.finalPositionY); foreach (KeyValuePair <int, InformationPlayer> player in multiplayerGameInformation[movement.idGame].lismanUsers) { if (player.Value.isLive && connectionGameService[player.Value.userLisman] != null) { try { connectionGameService[player.Value.userLisman].NotifyLismanMoved(movement.colorLisman, movement.finalPositionX, movement.finalPositionY, movement.goTo); } catch (CommunicationException e) { Console.WriteLine("Error en la conexión con el usuario:" + player.Value.userLisman + ". Error: " + e.Message); connectionGameService[player.Value.userLisman] = null; } } } }
/// <summary> /// Métdodo que termina el juego /// </summary> /// <param name="movement">Objeto de tipo Movement</param> /// <param name="colorLismanEnemy">Color del jugador enemigo</param> /// <param name="scoreLisman">Puntaje del jugador vivo</param> /// <param name="lifesLismanEnemy">Vidas del jugador enemigo</param> public void FinishGame(LismanMovement movement, int colorLismanEnemy, int scoreLisman, int lifesLismanEnemy) { String userLisman = multiplayerGameInformation[movement.idGame].lismanUsers[movement.colorLisman].userLisman; String userLismanEnemy = multiplayerGameInformation[movement.idGame].lismanUsers[colorLismanEnemy].userLisman; try { connectionGameService[userLisman].NotifyPlayerIsDead(colorLismanEnemy); connectionGameService[userLismanEnemy].NotifyPlayerIsDead(colorLismanEnemy); connectionGameService[userLisman].NotifyUpdateScore(movement.colorLisman, scoreLisman); connectionGameService[userLisman].NotifyUpdateLifes(colorLismanEnemy, lifesLismanEnemy); connectionGameService[userLisman].NotifyEndGame(movement.colorLisman); SaveGame(movement.idGame, userLisman); } catch (CommunicationException ex) { Logger.log.Error("FinishGame, " + ex); } }
/// <summary> /// Métdodo que permite matar a un jugador y avisar a todos los demás /// </summary> /// <param name="movement">objeto de tipo Movement</param> /// <param name="colorLismanEnemy">color del jugador que murio </param> /// <param name="scoreLisman">puntaje del jugador vivo</param> /// <param name="lifesLismanEnemy">vidas del jugador que morirá</param> public void KillLisman(LismanMovement movement, int colorLismanEnemy, int scoreLisman, int lifesLismanEnemy) { foreach (KeyValuePair <int, InformationPlayer> player in multiplayerGameInformation[movement.idGame].lismanUsers) { if (player.Value.isLive) { try { connectionGameService[player.Value.userLisman].NotifyPlayerIsDead(colorLismanEnemy); connectionGameService[player.Value.userLisman].NotifyLismanMoved(movement.colorLisman, movement.finalPositionX, movement.finalPositionY, movement.goTo); connectionGameService[player.Value.userLisman].NotifyUpdateScore(movement.colorLisman, scoreLisman); connectionGameService[player.Value.userLisman].NotifyUpdateLifes(colorLismanEnemy, lifesLismanEnemy); } catch (CommunicationException e) { Console.WriteLine("Error en la conexión con el usuario:" + player.Value.userLisman + ". Error: " + e.Message); } } } multiplayerGameInformation[movement.idGame].lismanUsers[colorLismanEnemy].isLive = false; }
/// <summary> /// Método que permite reaparecer a un jugador que ha sido comido /// </summary> /// <param name="movement">Objeto de tipo Movement</param> /// <param name="colorLismanEnemy">Color del jugador que ha sido comido</param> /// <param name="scoreLisman">Puntaje del jugador que comio </param> /// <param name="lifesLismanEnemy">Vidas del jugador que ha sido comido</param> public void RespawnLisman(LismanMovement movement, int colorLismanEnemy, int scoreLisman, int lifesLismanEnemy) { String userLismanEnemy = multiplayerGameInformation[movement.idGame].lismanUsers[colorLismanEnemy].userLisman; int[] positionInitialLismanEnemy = GetInitialPositionsLisman(colorLismanEnemy); UpdateGameMap(movement.idGame, colorLismanEnemy, positionInitialLismanEnemy[0], positionInitialLismanEnemy[1]); try { connectionGameService[userLismanEnemy].ReturnLismanToInitialPosition(colorLismanEnemy, positionInitialLismanEnemy[0], positionInitialLismanEnemy[1]); } catch (CommunicationException e) { Console.WriteLine("Error en la conexión con el usuario:" + userLismanEnemy + ". Error: " + e.Message); } String initialDirectionLismanEnemy = multiplayerGameInformation[movement.idGame].lismanUsers[colorLismanEnemy].initialDirecction; foreach (KeyValuePair <int, InformationPlayer> player in multiplayerGameInformation[movement.idGame].lismanUsers) { if (player.Value.isLive) { try { connectionGameService[player.Value.userLisman].NotifyLismanMoved(movement.colorLisman, movement.finalPositionX, movement.finalPositionY, movement.goTo); connectionGameService[player.Value.userLisman].NotifyLismanMoved(colorLismanEnemy, positionInitialLismanEnemy[0], positionInitialLismanEnemy[1], initialDirectionLismanEnemy); connectionGameService[player.Value.userLisman].NotifyUpdateScore(movement.colorLisman, scoreLisman); connectionGameService[player.Value.userLisman].NotifyUpdateLifes(colorLismanEnemy, lifesLismanEnemy); } catch (CommunicationException e) { Console.WriteLine("Error en la conexión con el usuario:" + player.Value.userLisman + ". Error: " + e.Message); } } } }
/// <summary> /// Método que permite comer a un jugador /// </summary> /// <param name="movement">Objeto de tipo Movement</param> /// <param name="colorLismanEnemy">Color del jugador el cual será comido</param> private void EatLismanEnemy(LismanMovement movement, int colorLismanEnemy) { int scoreLisman = UpdateScore(movement.idGame, movement.colorLisman, POINTSEATLISMAN); int lifesLismanEnemy = UpdateSubtractLifes(movement.idGame, colorLismanEnemy); UpdateGameMap(movement.idGame, EMPTYBOX, movement.initialPositionX, movement.initialPositionY); UpdateGameMap(movement.idGame, movement.colorLisman, movement.finalPositionX, movement.finalPositionY); if (PlayerWillDead(movement.idGame, colorLismanEnemy)) { if (GameWillEnd(movement.idGame)) { FinishGame(movement, colorLismanEnemy, scoreLisman, lifesLismanEnemy); } else { KillLisman(movement, colorLismanEnemy, scoreLisman, lifesLismanEnemy); } } else { RespawnLisman(movement, colorLismanEnemy, scoreLisman, lifesLismanEnemy); } }