public CombatEventArgs(Actor actor, BodyComponents attackedPart, int currentHP, Random randomGenerator) { this.actor = actor; this.attackedPart = attackedPart; this.currentHP = currentHP; this.randomGenerator = randomGenerator; }
public bool GetHit(BodyComponents attackedPart) { if ((Blocked & attackedPart) != 0) { return(false); } return(true); }
private void Attack(Actor attacker, Actor defender) { if (isFullRound == isPlayerTurn) { roundCount++; label_Round.Text = "Раунд " + roundCount; } BodyComponents attackedPart = BodyComponents.NONE; Array bodyParts = Enum.GetValues(typeof(BodyComponents)); if (attacker.Name == "Противник") { attackedPart = (BodyComponents)bodyParts.GetValue(randomGenerator.Next(1, 3)); if (radioButton_Head.Checked) { defender.SetBlock(BodyComponents.HEAD); } if (radioButton_Body.Checked) { defender.SetBlock(BodyComponents.BODY); } if (radioButton_Legs.Checked) { defender.SetBlock(BodyComponents.LEGS); } } else { if (radioButton_Head.Checked) { attackedPart = BodyComponents.HEAD; } if (radioButton_Body.Checked) { attackedPart = BodyComponents.BODY; } if (radioButton_Legs.Checked) { attackedPart = BodyComponents.LEGS; } defender.SetBlock((BodyComponents)bodyParts.GetValue(randomGenerator.Next(1, 3))); } isPlayerTurn = !isPlayerTurn; CombatEventArgs e = new CombatEventArgs(defender, attackedPart, 0, randomGenerator); defender.TryBlock(attackedPart, e); }
private string GetBodyPartString(BodyComponents component) { if ((component & BodyComponents.HEAD) != 0) { return("голову"); } if ((component & BodyComponents.BODY) != 0) { return("тело"); } if ((component & BodyComponents.LEGS) != 0) { return("ноги"); } return("Ничего"); }
public void TryBlock(BodyComponents attackedPart, CombatEventArgs e) { if (!GetHit(attackedPart)) { Block?.Invoke(this, e); } else { int damage = e.randomGenerator.Next(2, 20); e.currentHP = HP - damage; HP = e.currentHP; if (HP > 0) { Wound?.Invoke(this, e); } else { Death?.Invoke(this, e); } } }
public void SetBlock(BodyComponents blockedPart) { Blocked = blockedPart; }