public void Pass(PlayerType player) { // There can be two types of situation // First: when that is player's party and player's turn // In this case we just clear the DescPairs and hand out remaining cards from deck // // Second: when that is enemy's party and enemy's turn // In this case we make the same thing // // In other cases we just refuse action if (IsBlocked) { return; } switch (GameState) { case GameState.Ready: GameState = GameState.Playing; break; case GameState.Finished: return; case GameState.Playing: break; default: return; } if (DescPairs.Count == 0) { if (OnActionRefused != null) { OnActionRefused(GameAction.Pass, GameError.Warning, "You cant't say pass"); } return; } if (WhoseParty == PlayerType.Player) { if (player != PlayerType.Player) { if (OnActionRefused != null) { OnActionRefused(GameAction.Pass, GameError.Warning, "You cant't say pass"); } return; } DescPairs.Clear(); WhoseParty = PlayerType.Enemy; if (OnPass != null) { OnPass(player); } HandOutCards(); WhoseTurn = PlayerType.Enemy; CheckGameState(); return; } if (WhoseParty == PlayerType.Enemy) { if (player != PlayerType.Enemy) { if (OnActionRefused != null) { OnActionRefused(GameAction.Pass, GameError.Warning, "You cant't say pass"); } return; } DescPairs.Clear(); WhoseParty = PlayerType.Player; if (OnPass != null) { OnPass(player); } HandOutCards(); WhoseTurn = PlayerType.Player; CheckGameState(); return; } }
public void GetAll(PlayerType player) { // There can be two types of situation // First: when that is player's party and enemy's turn // In this case we extend player's list of cards with list of cards from desc. Thern we clear desc. // // Second: when that is enemy's party and player's turn // In this case we make the same thing // // In other cases we just refuse action if (IsBlocked) { return; } switch (GameState) { case GameState.Ready: GameState = GameState.Playing; break; case GameState.Finished: return; case GameState.Playing: break; default: return; } if (DescPairs.Count == 0) { if (OnActionRefused != null) { OnActionRefused(GameAction.Pass, GameError.Warning, "You cant't say get all"); } return; } if (WhoseParty == PlayerType.Player) { if (player != PlayerType.Enemy) { if (OnActionRefused != null) { OnActionRefused(GameAction.GetAll, GameError.Warning, "You cant't say get all"); } return; } foreach (var cardPair in DescPairs) { EnemyCards.Add(cardPair.LowerCard); if (cardPair.UpperCard != null) { EnemyCards.Add((Card)cardPair.UpperCard); } } DescPairs.Clear(); if (OnGetAll != null) { OnGetAll(player); } HandOutCards(); WhoseTurn = PlayerType.Player; CheckGameState(); return; } if (WhoseParty == PlayerType.Enemy) { if (player != PlayerType.Player) { if (OnActionRefused != null) { OnActionRefused(GameAction.GetAll, GameError.Warning, "You cant't say get all"); } return; } foreach (var cardPair in DescPairs) { PlayerCards.Add(cardPair.LowerCard); if (cardPair.UpperCard != null) { PlayerCards.Add((Card)cardPair.UpperCard); } } DescPairs.Clear(); if (OnGetAll != null) { OnGetAll(player); } HandOutCards(); WhoseTurn = PlayerType.Enemy; CheckGameState(); return; } }
public void ThrowCard(PlayerType player, Card card) { // There are 4 possible variations and 2 types of rules // // First (1'st type): when that is player's party and player's throw. // In this case we shall see for equivalent cards on desc and allow only these, // which are equal by type with cards already thrown. // // Second (1'st type): when that is enemy's party and enemy's throw. // In this case we shall see for equivalent cards on desc and allow only these, // which are equal by type with cards already thrown. // // Third (2'nd type): when that is player's party and enemy's throw. // In this case we shall find out, could the thrown card beat the card, which was // thrown by player. Otherwise we refuse throwing. // // Fourth (2'nd type): when that is enemy's party and player's throw. // In this case we shall find out, could the thrown card beat the card, which was // thrown by player. Otherwise we refuse throwing. if (IsBlocked) { return; } switch (GameState) { case GameState.Ready: GameState = GameState.Playing; break; case GameState.Finished: return; case GameState.Playing: break; default: return; } if (player == PlayerType.Player && WhoseParty == PlayerType.Player) { if (!PlayerCards.Contains(card)) { if (OnActionRefused != null) { OnActionRefused(GameAction.Throw, GameError.Warning, "You has no such card"); } return; } if (!ThrowWhenOwnParty(card)) { if (OnActionRefused != null) { OnActionRefused(GameAction.Throw, GameError.ActionRefused, "You can't throw that card"); } return; } else { PlayerCards.Remove(card); DescPairs.Add(new CardPair { LowerCard = card }); if (OnThrowCard != null) { OnThrowCard(player, card); } WhoseTurn = PlayerType.Enemy; CheckGameState(); return; } } if (player == PlayerType.Enemy && WhoseParty == PlayerType.Enemy) { if (!EnemyCards.Contains(card)) { if (OnActionRefused != null) { OnActionRefused(GameAction.Throw, GameError.Warning, "You has no such card"); } return; } if (!ThrowWhenOwnParty(card)) { if (OnActionRefused != null) { OnActionRefused(GameAction.Throw, GameError.ActionRefused, "You can't throw that card"); } return; } else { EnemyCards.Remove(card); DescPairs.Add(new CardPair { LowerCard = card }); if (OnThrowCard != null) { OnThrowCard(player, card); } WhoseTurn = PlayerType.Player; CheckGameState(); return; } } if (player == PlayerType.Player && WhoseParty == PlayerType.Enemy) { if (!PlayerCards.Contains(card)) { if (OnActionRefused != null) { OnActionRefused(GameAction.Throw, GameError.Warning, "You has no such card"); } return; } if (!ThrowWhenNotOwnParty(card)) { if (OnActionRefused != null) { OnActionRefused(GameAction.Throw, GameError.ActionRefused, "You can't throw that card"); } return; } else { PlayerCards.Remove(card); DescPairs[DescPairs.Count - 1].UpperCard = card; if (OnThrowCard != null) { OnThrowCard(player, card); } WhoseTurn = PlayerType.Enemy; CheckGameState(); return; } } if (player == PlayerType.Enemy && WhoseParty == PlayerType.Player) { if (!EnemyCards.Contains(card)) { if (OnActionRefused != null) { OnActionRefused(GameAction.Throw, GameError.Warning, "You has no such card"); } return; } if (!ThrowWhenNotOwnParty(card)) { if (OnActionRefused != null) { OnActionRefused(GameAction.Throw, GameError.ActionRefused, "You can't throw that card"); } return; } else { EnemyCards.Remove(card); DescPairs[DescPairs.Count - 1].UpperCard = card; if (OnThrowCard != null) { OnThrowCard(player, card); } WhoseTurn = PlayerType.Player; CheckGameState(); return; } } }