/// <summary> /// Player draws card from the deck. /// If player doesn't have any card in the deck, player Bleeds Out. /// And if player's health reaches at zero, PlayerHealthBelowZero event is triggered /// /// If player has any card in the deck, a random card is retrieved from the deck. /// If player has maximum amount of card in the hand, that drawn card would discarded immediately. /// Otherwise, player adds drawn card to hand. /// </summary> public void DrawCard() { if (Deck.Count == 0) { Console.WriteLine($"{Name} doesn't have any card in deck. {Name} is bleeding out."); Health -= 1; if (Health <= 0) { PlayerHealthBelowZeroEventArgs args = new PlayerHealthBelowZeroEventArgs() { LoserPlayer = this, }; OnPlayerHealthBelowZero(args); } } else { int nextCardIndex = random.Next(Deck.Count - 1); Card drawedCard = Deck[nextCardIndex]; Deck.RemoveAt(nextCardIndex); Console.WriteLine($"{Name} draws a card"); if (Hand.Count < PlayerConstants.MAX_HAND_SIZE) { Hand.Add(drawedCard); } else { Console.WriteLine($"{Name} reached the hand limit. {drawedCard.Point} is discarded."); } } }
private void Player_HealthBelowZero(object sender, PlayerHealthBelowZeroEventArgs e) { IsGameFinished = true; var loserPlayer = e.LoserPlayer; WinnerPlayer = PlayerList.Where((x) => x.Id != loserPlayer.Id).First(); Console.WriteLine(); Console.WriteLine($"Game is over! Winner is {WinnerPlayer.Name} and {loserPlayer.Name} has lost the game."); Console.WriteLine($"Game lasted for {TurnCount} turns"); }
/// <summary> /// Player's health drops by damage points. /// If player's health goes below zero, PlayerHealthBelowZeroEvent is triggered /// </summary> /// <param name="damage">Amount of damage</param> public void InflictDamage(int damage) { Health -= damage; if (Health <= 0) { PlayerHealthBelowZeroEventArgs args = new PlayerHealthBelowZeroEventArgs() { LoserPlayer = this, }; OnPlayerHealthBelowZero(args); } }
/// <summary> /// When player's health goes below zero, HealthHandler event is triggered /// </summary> /// <param name="e">Event arguments</param> private void OnPlayerHealthBelowZero(PlayerHealthBelowZeroEventArgs e) { HealthHandler?.Invoke(this, e); }