public void PlayerAttack() { if (GameEnd) { return; } if (CurrentMonster != null) { var damage = CurrentPlayer.Attack(); CurrentMonster.Lives -= damage; MonsterDead(); } CheckStatus(); }
public void Fight() { int foeIndex = 0; bool winner = false; while (!winner) { CurrentPlayer.Attack(Foes[foeIndex]); if (Foes[foeIndex].CurrentHealth <= 0) { Foes.RemoveAt(foeIndex); if (foeIndex >= Foes.Count) { winner = true; break; } } for (int i = 0; i < Foes.Count; i++) { Foes[i].Attack(CurrentPlayer); if (CurrentPlayer.CurrentHealth <= 0) { winner = true; break; } } } if (CurrentPlayer.CurrentHealth <= 0) { //code wordt wel bereikt, maar niet correct uitgevoerd? Zelfde code in CommandHandler wél! Game.Instance.CurrentPlayer = null; } else { Game.Instance.LevelUp(); LootItems(); } Game.Instance.CurrentBattle = null; }
private void OnCellClicked(Cell cell) { if (GameState != GameState.Running || _blockCells || cell.CellState != CellState.Empty) { return; } if (CurrentPlayer.PlayerType == PlayerType.Computer) { _blockCells = true; } PlaceMark(cell); if (CurrentPlayerWins(cell)) { Win(); CurrentPlayer.Sit(); if (CurrentPlayer == FirstPlayer) { SecondPlayer.Death(); } else { FirstPlayer.Death(); } return; } if (GameLogic.IsDraw(Cells, boardSize)) { Draw(); FirstPlayer.Sit(); SecondPlayer.Sit(); return; } CurrentPlayer.Attack(); ChangePlayer(); }
public void DoNextPhase(bool eraseActions = true) { if (GameEnded) { return; } if (eraseActions) { ClearActions(); } var troopsInStartupPhase = GetTroopsInStartupPhase(); var turnManager = GetTurnManager(CurrentPlayer); if (troopsInStartupPhase > 0) { TroopsToDeploy = troopsInStartupPhase; try { CurrentPlayer.Deploy(turnManager, troopsInStartupPhase); } catch (Exception e) { Log.AddException(e); } SetNextPlayer(); } else { if (CurrentPhase == EPhase.Deploy) { if (CurrentPlayer == startPlayer) { Turn++; if (Turn > MaximumAmountOfTurns) { var winner = GetPlayerWithMostCountries(); Log.AddMessage( string.Format("----- {0} has won the game with {1} countries, turn limit reached", winner.Name, turnManager.GetGameInfo().GetAllCountriesOwnedByPlayer(winner).Count)); statistics.AddCurrentGameResults(winner); GameEnded = true; return; } } var troopsToDeploy = new DeploymentCounter(CurrentPlayer, turnManager.GetGameInfo()).GetTroopsToDeploy(); Log.AddGameInfo(CurrentPhase, troopsToDeploy); TroopsToDeploy = troopsToDeploy; try { CurrentPlayer.Deploy(turnManager, troopsToDeploy); } catch (Exception e) { Log.AddException(e); } } else if (CurrentPhase == EPhase.Attack) { Log.AddGameInfo(CurrentPhase); try { CurrentPlayer.Attack(turnManager); } catch (Exception e) { Log.AddException(e); } if (PlayerHasWon()) { Log.AddMessage(string.Format("----- {0} has won the game with {1} countries", CurrentPlayer.Name, turnManager.GetGameInfo().GetAllCountriesOwnedByPlayer(CurrentPlayer).Count)); statistics.AddCurrentGameResults(CurrentPlayer); GameEnded = true; return; } } else if (CurrentPhase == EPhase.Move) { Log.AddGameInfo(CurrentPhase); TroopsToMove = 7; try { CurrentPlayer.Move(turnManager); } catch (Exception e) { Log.AddException(e); } SetNextPlayer(); } SetNextPhase(); } }