private string GetCardType(Card.CardTypes cardType) { return(cardType switch { Card.CardTypes.Card => "story-card", _ => throw new Exception($"Card type {cardType} not mapped.") });
public bool PlayConfirmed(Card tmp, Card.CardTypes trump, List <Card> board, List <Card> hand) { _board = board; _hand = hand; _trump = trump; return(HandleMissPlay(tmp)); }
private static string GetCardType(Card.CardTypes cardType) { switch (cardType) { case Card.CardTypes.Card: return("story-card"); default: throw new Exception($"Card type {cardType} not mapped."); } }
public StoryResult(int id, string content, string ctaText, string ctaLink, string image, string posterUrl, Card.CardTypes cardType) { Id = id; Content = content; CtaText = ctaText; CtaLink = ctaLink; Image = image; PosterUrl = posterUrl; Type = GetCardType(cardType); }
private bool HasHigherCard(bool isTrump, Card highestCard, Card.CardTypes type) { foreach (var it in _hand) { if (isTrump) { if (it.Trumpvalue > highestCard.Trumpvalue && it.Color == type) { return(true); } } else if (it.NonTrumpvalue > highestCard.NonTrumpvalue && it.Color == type) { return(true); } } return(false); }
public string ConvertCardTypeIntToString(Card.CardTypes cardType) { switch (cardType) { case Card.CardTypes.Club: return("Club"); case Card.CardTypes.Diamond: return("Diamond"); case Card.CardTypes.Spade: return("Spade"); case Card.CardTypes.Heart: return("Heart"); default: return("UNKNOWN"); } }
public void Treatmsg(Protocol tmp) { if (_contract) { try { _num = int.Parse(tmp.Msg); } catch { var range = new Protocol { Msg = "Please choose a number in range", state = Protocol.State.Play }; _handler.SendToOne(_playerList[_index].GetCon(), range); return; } if (_num > 0 && _num < _maxrange) { if (!_ruler.PlayConfirmed(_playerList[_index].Hand[_num - 1], _trump, _rulesCheck, _playerList[_index].Hand)) { _handler.SendToOne(_playerList[_index].GetCon(), new Protocol() { Msg = "You can't play this one please respect the belotte rules !", state = Protocol.State.Play }); return; } _nbPlay += 1; var card = new Protocol { Msg = "Player " + (_index + 1) + " play " + _playerList[_index].Hand[_num - 1].Value + " Of " + _playerList[_index].Hand[_num - 1].Color }; _handler.SendToAll(card); _board.Add(_index, _playerList[_index].Hand[_num - 1]); _rulesCheck.Add(_playerList[_index].Hand[_num - 1]); _playerList[_index].Hand.RemoveAt(_num - 1); _index = _index + 1 > 3 ? 0 : _index + 1; if (_nbPlay == 5) { _turnDown += 1; if (_turnDown == 9) { EndofGame(); } CountTurn(); return; } LoopGame(); } else { var range = new Protocol { Msg = "Please choose a number in range", state = Protocol.State.Play }; _handler.SendToOne(_playerList[_index].GetCon(), range); } } else if (!_contract) { if (tmp.Msg.Equals("Pass")) { var pass = new Protocol { Msg = "Player " + (_index + 1) + " pass." }; _index = _index + 1 > 3 ? 0 : _index + 1; _count += 1; _handler.SendToAll(pass); switch (_count) { case 5: var second = new Protocol(); second.Msg = "Second contract, distribution of the deck in progress ..."; _handler.SendToAll(second); ContinuDistrib(); break; case 9: ReDistribution(); return; } Contract(); } else if (_doColor && tmp.Msg.Equals("Spade") || tmp.Msg.Equals("Heart") || tmp.Msg.Equals("Club") || tmp.Msg.Equals("Diamond")) { _contract = true; _trump = _deck.ConvertStringToCardType(tmp.Msg); var trump = new Protocol { Msg = "Player " + (_index + 1) + " choose " + _trump + " as trump color\nPlayer " + (_index + 1) + " start the round " + _turnDown, state = Protocol.State.Wait, }; _handler.SendToAll(trump); LoopGame(); } else if (tmp.Msg.Equals("Take") && !_doColor) { if (_count < 5) { _contract = true; _trump = _deck._deck[20].Color; var trump = new Protocol { Msg = "Player " + (_index + 1) + " take the card. The color as trump is " + _trump, state = Protocol.State.Wait, }; _handler.SendToAll(trump); ContinuDistrib(); var game = new Protocol { Msg = "Player " + (_index + 1) + " start the round " + _turnDown, state = Protocol.State.Wait }; _handler.SendToAll(game); LoopGame(); } else if (_count >= 5) { WhatColor(); _doColor = true; } } else { _doColor = false; var doTake = new Protocol { Msg = "Please choose Take or Pass.", state = Protocol.State.Play }; _handler.SendToOne(_playerList[_index].GetCon(), doTake); } } }