private void attack_Click(object sender, EventArgs e) { var move = new Random().Next(3); if (compHero.currentHealth < 2) { move = new Random().Next(1, 3); } if (move == 0) { compHero.Run(false); playerHero.Attack(compHero); player_move.Text = $@"{playerHero.name} атакует"; comp_move.Text = $@"{compHero.name} убегает"; } if (move == 1) { playerHero.Attack(compHero); player_move.Text = $@"{playerHero.name} атакует"; comp_move.Text = $@"{compHero.name} защищается"; } if (move == 2) { var i = 0; if (Math.Abs(playerHero.currentHealth - compHero.currentHealth) < 0.1) { i = new Random().Next(-1, 2); } if (playerHero.currentHealth + i > compHero.currentHealth) { playerHero.Attack(compHero); player_move.Text = $@"{playerHero.name} атакует"; comp_move.Text = $@"{compHero.name} защищается, так как у него меньше очков"; } else { compHero.Attack(playerHero); player_move.Text = $@"{playerHero.name} защищается так как у него меньше очков"; comp_move.Text = $@"{compHero.name} атакует"; } } UpdateLabels(); CheckEndGame(); }
private void defend_Click(object sender, EventArgs e) { var move = new Random().Next(3); if (move == 1) { player_move.Text = $@"{playerHero.name} защищается"; comp_move.Text = $@"{compHero.name} защищается"; return; } if (move == 0) { compHero.Run(true); player_move.Text = $@"{playerHero.name} защищается"; comp_move.Text = $@"{compHero.name} убегает"; return; } compHero.Attack(playerHero); player_move.Text = $@"{playerHero.name} защищается"; comp_move.Text = $@"{compHero.name} атакует"; UpdateLabels(); CheckEndGame(); }