public void DealCards(Player p, int cards) { if (cards <= 0) return; Card[] drew = DrawDeck.Draw(cards, DiscardPile); p.Hand.Add(drew); string l = ""; foreach (Card c in drew) { l += " " + c.ToString(); } l = l.Substring(1); SendPriv(p.Nick, String.Format(Messages.DealCards, l)); }
private void InputWild(Player p, string line) { // Recognized commands: color string[] input = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (input.Length == 2 && (input[0] == "c" || input[0] == "color" || input[0] == "colour")) { CardColor color; try { color = Card.ParseColor(input[1]); } catch (FormatException) { return; } // Don't allow non-superuno colors if (!_super && (color == CardColor.Orange || color == CardColor.Purple)) return; if (color == CardColor.Wild) return; // Don't allow picking this color // Create a new top card and go to next turn _top = DispCard.Get(color, _top.Face); _inState = InputState.Turn; _state.Players.PushTurn(1); DisplayTurn(true); ResetTick(); } }
private void InputTurn(Player p, string line) { // Recognized commands: draw, pass, play string[] input = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (input.Length == 0) return; if (input.Length == 1 && (input[0] == "d" || input[0] == "draw")) { PlayerDrawCommand(p); } else if (input.Length == 1 && (input[0] == "s" || input[0] == "pass" || input[0] == "skip")) { // Next turn _disableDraw = false; _state.Players.PushTurn(1); DisplayTurn(true); ResetTick(); } else if (input[0] == "p" || input[0] == "play") { // Parse card and create a search object CardColor searchC; CardFace searchF; try { if (input.Length == 2) { searchC = CardColor.Wild; searchF = Card.ParseFace(input[1]); } else if (input.Length == 3) { searchC = Card.ParseColor(input[1]); searchF = Card.ParseFace(input[2]); } else { // not a valid command return; } } catch (FormatException) { return; } Card searchCard = DispCard.Get(searchC, searchF); PlayerPlayCommand(p, searchCard); } }
private void InputSwd4(Player p, string line) { // Recognized: player name Player victim = _state.Players[line]; if (victim == null) return; else if (victim == p) { SendOut(Messages.Swd4FailSelf); } else { SendOut(String.Format(Messages.DrawsFour, victim)); _state.DealCards(victim, 4); _disableDraw = false; _inState = InputState.Wild; DisplayTurn(false); ResetTick(); } }
private void SendCards(Player p) { SendOut(p.Nick, String.Format(Messages.DispCards, p.Hand)); }
private void PlayerPlayCommand(Player p, Card c) { if (!p.Hand.Contains(c)) { SendOut(p + ": " + Messages.PlayFailHand); return; } if (!c.Matches(_top)) { SendOut(p + ": " + Messages.PlayFailMatch); return; } // Card in parameter is a placeholder - get the actual object c = p.Hand.FirstOrDefault(hc => hc == c); p.Score += c.Score; p.Hand.Remove(c); // With some exceptions, make the card available again if (!(c.Face == CardFace._E || c.Face == CardFace._D || c.Face == CardFace.DH)) _state.DiscardPile.Add(c); // Check if player won if (HasPlayerWon(p)) return; // Move on to card processing PlayerPlayCardProcess(p, c, false); ResetTick(); }
private void PlayerPlayCardProcess(Player p, Card c, bool wtf) { bool showUno = p.Hand.Count != 1; // to avoid showing "__ has uno!" twice // Preparing to call play effect _state.NextInState = InputState.Turn; _state.NextTopCard = c; _state.NextTurnPush = 1; if (c is WtfCard) { Card wtfc; Random r = new Random(); int pick = r.Next(6); if (pick == 0) { // 1/48 chance (1/6 * 1/8) of the card becoming ASDF wtfc = AsdfCard.FromWtf(); if (wtfc == null) pick = r.Next(5) + 1; // Didn't happen - go for another card } if (pick == 1) wtfc = WildCard.FromWtf(); else if (pick == 2) wtfc = WildDrawFourCard.FromWtf(); else if (pick == 3) wtfc = WildMassDrawThreeCard.FromWtf(); else if (pick == 4) wtfc = SuperWildDrawFourCard.FromWtf(); else wtfc = ReverseWildDrawFourCard.FromWtf(); PlayerPlayCardProcess(p, wtfc, true); return; } else { c.OnPlay(_state, p); } // Check if player won if (HasPlayerWon(p, showUno)) return; // Check and apply results _inState = _state.NextInState; if (_state.NextTopCard != null) _top = _state.NextTopCard; if (_state.NextTurnPush > 0) { _disableDraw = false; _state.Players.PushTurn(_state.NextTurnPush); DisplayTurn(true); } }
private void PlayerDrawCommand(Player p) { if (_disableDraw) { SendOut(p + ": " + Messages.DrawFail); return; } _disableDraw = true; bool effect; Card c; // Determine which deck to draw from effect = ((new Random()).Next(_state.DrawDeck.Count + _state.DrawEffectDeck.Count) + 1) > _state.DrawDeck.Count; if (effect) { // Effect card c = _state.DrawEffectDeck.Draw(); } else { // Normal card c = _state.DrawDeck.Draw(1, _state.DiscardPile)[0]; } p.Hand.Add(c); // card may remove itself if it must if (!effect) SendOut(p.Nick, String.Format(Messages.DealCard, c)); else { // Preparing to call draw effect _state.NextInState = InputState.Turn; _state.NextTopCard = null; _state.NextTurnPush = 0; c.OnDraw(_state, p); // Check if player won if (HasPlayerWon(p)) return; // Check and apply results _inState = _state.NextInState; if (_state.NextTopCard != null) _top = _state.NextTopCard; if (_state.NextTurnPush > 0) { _disableDraw = false; _state.Players.PushTurn(_state.NextTurnPush); DisplayTurn(true); } } }
// Checks if the player has 1 or 0 cards remaining and displays the appropriate message private bool HasPlayerWon(Player p, bool showUno = true) { int count = p.Hand.Count; if (showUno && count == 1) { SendOut(String.Format(Messages.WinAlmost, p, Name)); } else if (count == 0) { SendOut(String.Format(Messages.Win, p, Name)); EndGame(); return true; } return false; }