public AutoBattleState Battle(Player player, Player opponent) { _player = player; _opponent = opponent; State = AutoBattleState.IsRunning; bool lastRoundPlayerFirst = true; for (int round = 0; round < MaxRounds; round++) { // Do rounds 0 to 4 OnRoundStart(); CheckPrematureEnd(); if (IsPlayerFaster(round, lastRoundPlayerFirst)) { // Player starts round DoRound(round, _player, _opponent); lastRoundPlayerFirst = true; } else { // Opponent starts round DoRound(round, _opponent, _player); lastRoundPlayerFirst = false; } if (State != AutoBattleState.IsRunning) { // Premature End break; } } return(State = GetBattleResult()); }
// // Called every frame. 'delta' is the elapsed time since the previous frame. // public override void _Process(float delta) // { // // } private void _on_Button_pressed() { AutoBattleState result = _battle.Battle(); _battleLabel.Text = result.ToString(); _playerLabel.Text = $"{_player.Name} ({_player.Health})"; _opponentLabel.Text = $"{_battle.Opponent.Name} ({_battle.Opponent.Health})"; Console.WriteLine($"Battle Result: \n\t{result}\n"); Console.WriteLine($"Player: \n\t{_player}\n"); Console.WriteLine($"Opponent: \n\t{_battle.Opponent}\n"); }
/// <summary> /// Checks if any player's health is zero or below /// Sets Battle State accordingly to draw, lost, won. /// </summary> private void CheckPrematureEnd() { if (_player.Health <= 0 && _opponent.Health <= 0) { State = AutoBattleState.Draw; } else if (_player.Health <= 0) { State = AutoBattleState.Lost; } else if (_opponent.Health <= 0) { State = AutoBattleState.Won; } }