static void Main(string[] args) { ISort sort = new VeryGoodSort(); var dealer = new CardDealer(); var cards = dealer.DealInfinitely().Take(10000).ToList(); Card.ResetComparisonCount(); Card previous = null; var sortedCards = sort.Sort(cards); foreach (var current in sortedCards) { //Console.WriteLine(current); if (!object.ReferenceEquals(previous, null) && previous > current) { Console.WriteLine($"{previous} is stricly greater than {current} ! Bad sorting!"); break; } previous = current; } Console.WriteLine($"it took me only {Card.ComparisonCount} comparisons!"); Console.ReadLine(); }
public LeagueOrganizer(IEnumerable <IPlayer> players, CardDealer dealer, ILogger logger) { _dealer = dealer; _logger = logger; _players = players; GamesNumberPerTournament = 100; }
public void Restart() { winText.gameObject.SetActive(false); loseText.gameObject.SetActive(false); tieText.gameObject.SetActive(false); restartButton.gameObject.SetActive(false); playButtons.gameObject.SetActive(false); betButtons.gameObject.SetActive(true); dealerScoreText.text = "Dealer: " + 0; dealerScoreText.color = Color.white; playerScoreText.text = "Player: " + 0; playerScoreText.color = Color.white; betValue = 0; betText.text = "" + betValue; playValue.text = Constants.PotMoneyText + betValue; deckManager.DiscardCards(); CardDealer.StartRoutine(); var clones = GameObject.FindGameObjectsWithTag("clone"); foreach (var clone in clones) { Destroy(clone); } Destroy(GameObject.FindGameObjectWithTag("backCard")); }
public void CanDealMultipleCards() { var cardDealer = new CardDealer(); testDeal(cardDealer, -1); testDeal(cardDealer, 2); testDeal(cardDealer, 5); }
public Game(CardDealer dealer, List <IPlayer> players, int handSize, ILogger logger) { _players = players; _handSize = handSize; _dealer = dealer; _logger = logger; _scores = new List <int>(players.Select(p => 0)); _hands = new List <Card> [PlayersCount]; }
public TournamentOrganiser(IEnumerable <IPlayer> players, CardDealer dealer, ILogger logger) { _players = players.ToList(); _dealer = dealer; _logger = logger; _scores = new List <int>(players.Select(p => 0)); HandSize = 5; GamesNumber = 1000; }
void RpcMatchStart() { Debug.Log("Match has started"); matchStarted = true; Destroy(buttonGO); players = GameObject.FindGameObjectsWithTag("Player"); CardDealer.dealCards(players, 2); CardDealer.distributeCards(players, playerHands, cardPrefab); }
void Start() { starOnSprite = Resources.Load <Sprite>("StarSprites/star_on"); starOffSprite = Resources.Load <Sprite>("StarSprites/star_off"); touchController = GameObject.Find("TouchController").GetComponent <TouchController>(); cardDealer = GameObject.Find("CardDealer").GetComponent <CardDealer>(); scoreDirector = GameObject.Find("ScoreDirector").GetComponent <ScoreDirector>(); adDirector = GameObject.Find("AdDirector").GetComponent <AdDirector>(); }
/// <summary> /// 通知发牌器给该卡牌槽位发牌 /// </summary> /// <returns></returns> public bool DealCard() { lock ( SyncRoot ) { if (HasCard) { return(false); } Card = CardDealer.DealCard(); return(true); } }
public void CannotDealNegativeCards() { var cardDealer = new CardDealer(); Assert.Throws <ArgumentOutOfRangeException>(() => cardDealer.Deal(-1, Suit.Clubs)); Assert.Throws <ArgumentOutOfRangeException>(() => cardDealer.Deal(-1, Suit.Spades)); Assert.Throws <ArgumentOutOfRangeException>(() => cardDealer.Deal(-1, Suit.Hearts)); Assert.Throws <ArgumentOutOfRangeException>(() => cardDealer.Deal(-1, Suit.Diamonds)); Assert.Throws <ArgumentOutOfRangeException>(() => cardDealer.Deal(-5, Suit.Clubs)); Assert.Throws <ArgumentOutOfRangeException>(() => cardDealer.Deal(-5, Suit.Spades)); Assert.Throws <ArgumentOutOfRangeException>(() => cardDealer.Deal(-5, Suit.Hearts)); Assert.Throws <ArgumentOutOfRangeException>(() => cardDealer.Deal(-5, Suit.Diamonds)); }
public void Constructor_CorrectValue() { Card cardOne = new Card(1, 1); Card cardTwo = new Card(2, 1); Card cardThree = new Card(3, 1); List <Card> cardList = new List <Card> { cardOne, cardTwo, cardThree }; CardDealer dealer = new CardDealer(cardList); Assert.AreEqual(cardOne, dealer.GetCard()); Assert.AreEqual(cardTwo, dealer.GetCard()); Assert.AreEqual(cardThree, dealer.GetCard()); }
[Test] public void Test_Deal_Decreases_Deck_Size() { IDeck deck = new Deck(); IShuffleCard shuffleCard = new ShuffleCard(deck); deck = shuffleCard.Shuffle(); ICardDealer cardDealer = new CardDealer(deck); Card first = cardDealer.Deal(); Assert.That(cardDealer.CardsRemaining(), Is.EqualTo(51)); }
private void testDeal(CardDealer cardDealer, int numCards) { var suits = Enum.GetValues(typeof(Suit)).Cast <Suit>(); foreach (Suit suit in suits) { Card[] cards = cardDealer.Deal(numCards, suit); Assert.That(cards.Length, Is.EqualTo(numCards)); for (int c = 0; c < numCards; ++c) { Assert.That(cards[c].Suit, Is.EqualTo(suit)); } } }
public void ScrambleDeck_ShuffleValues() { Card cardOne = new Card(1, 1); Card cardTwo = new Card(2, 1); Card cardThree = new Card(3, 1); List <Card> cardList = new List <Card> { cardOne, cardTwo, cardThree }; CardDealer dealer = new CardDealer(cardList, randSeed: 2); dealer.ScrambleDeck(); Assert.AreEqual(cardThree, dealer.GetCard()); Assert.AreEqual(cardOne, dealer.GetCard()); Assert.AreEqual(cardTwo, dealer.GetCard()); }
public void Shuffle_And_Deal_Returns_Different_Card() { IDeck deck = new Deck(); IShuffleCard shuffleCard = new ShuffleCard(deck); deck = shuffleCard.Shuffle(); ICardDealer cardDealer = new CardDealer(deck); Card first = cardDealer.Deal(); Card second = cardDealer.Deal(); Assert.That(first, Is.Not.EqualTo(second)); }
public PlayViewModel() { Model = new TabModel(); CardDealer dealer = new CardDealer(); SystemCard sensor = dealer.ChooseRandomSensor(); List <Card> cards = dealer.DealCardsForSensor(sensor); this.Items = new ObservableCollection <CardBaseViewModel>(); this.Items.Add(new CardBaseViewModel(cards[0].Name)); this.Items.Add(new CardBaseViewModel(cards[1].Name)); this.Items.Add(new CardBaseViewModel(cards[2].Name)); this.OtherItems = new ObservableCollection <SystemBaseViewModel>(); this.OtherItems.Add(new SystemBaseViewModel(sensor.Name)); SelectLeftCommand = new ButtonCommand(this.CheckLeft, true); SelectMiddleCommand = new ButtonCommand(this.CheckMiddle, true); SelectRightCommand = new ButtonCommand(this.CheckRight, true); }
// Start is called before the first frame update void Start() { deckManager = deck.gameObject.GetComponent <CardDealer>(); dealerBlackStack = new Stack <GameObject>(); dealerGreenStack = new Stack <GameObject>(); dealerBlueStack = new Stack <GameObject>(); dealerRedStack = new Stack <GameObject>(); dealerWhiteStack = new Stack <GameObject>(); playerBlackStack = new Stack <GameObject>(); playerGreenStack = new Stack <GameObject>(); playerBlueStack = new Stack <GameObject>(); playerRedStack = new Stack <GameObject>(); playerWhiteStack = new Stack <GameObject>(); doubleDown.gameObject.SetActive(false); restartButton.gameObject.SetActive(false); winText.gameObject.SetActive(false); loseText.gameObject.SetActive(false); tieText.gameObject.SetActive(false); playButtons.gameObject.SetActive(false); betButtons.gameObject.SetActive(true); betValue = 0; playValue.text = Constants.PotMoneyText + betValue; dealerScoreText.text = "Dealer: " + 0; playerScoreText.text = "Player: " + 0; betText.text = "" + betValue; playerMoney = Constants.playerIntialMoney; moneyText.text = Constants.PlayerMoneyText + playerMoney; win = false; manageDealerCoins(Constants.dealerInitialBlacks, Constants.dealerInitialGreens, Constants.dealerInitialBlues, Constants.dealerInitialReds, Constants.dealerInitialWhites, false); managePlayerCoins(Constants.playerInitialBlacks, Constants.playerInitialGreens, Constants.playerInitialBlues, Constants.playerInitialReds, Constants.playerInitialWhites, true); UpdateDealerMoney(); }
/// <summary> /// Loads the main form /// </summary> public DurakUI() { InitializeComponent(); // opens the settings form SettingForm settings = new SettingForm(); settings.ShowDialog(); dealer = new CardDealer(numberOfCards); // set the number of cards for the dealer lblCardsRemaining.Text = (dealer.NumberOfCards).ToString(); // set the label test to the number of cards Card.trumpsExist = true; // sets trump to true playerAttacking = true; // sets the player to attacking noCardsRemainingNotification = false; // sets the no cards notication to false currentPlayer = 1; // sets the first player as playing WriteToFile(log_file_path, START_GAME_STRING + DateTime.Now.ToString()); }
private void SetAllPlayerCards() { CardDealer cardDealer = new CardDealer(); List <int> playerscardlist = cardDealer.GetTheAllPlayersCard(); AllPlayersCard.Add(new List <int>()); for (int i = 0; i < playerscardlist.Count; i++) { DebugManager.Log(i + " " + playerscardlist[i]); //int value = playerscardlist[i] % 13 != 0 ? playerscardlist[i] % 13 : 1; int value = playerscardlist[i]; AllPlayersCard[AllPlayersCard.Count - 1].Add(value); if ((i + 1) % 13 == 0) { AllPlayersCard.Add(new List <int>()); } } }
public void Deal_All_Cards() { IDeck deck = new Deck(); IShuffleCard shuffleCard = new ShuffleCard(deck); deck = shuffleCard.Shuffle(); ICardDealer cardDealer = new CardDealer(deck); int cardsLeft = deck.Cards.Length; while (cardsLeft > 0) { Card card = cardDealer.Deal(); cardsLeft--; Assert.That(cardsLeft, Is.EqualTo(cardDealer.CardsRemaining())); } }
public ViewDeckViewModel() { //**THIS CODE BELONGS HERE**// CardDealer dealer = new CardDealer(); List <Card> cards = dealer.ListAllCards(); ////**THIS CODE BELONGS IN THE PLAYDECK**// //CardDealer dealer = new CardDealer(); //SystemCard sensor = dealer.ChooseRandomSensor(); //List<Card> cards = dealer.DealCardsForSensor(sensor); // The text for the cards can be found in cards[n].Name // The text for the sensor can be found in sensor.Name this.Items = new ObservableCollection <CardBaseViewModel>(); this.Items.Add(new CardBaseViewModel(cards[0].Name)); this.Items.Add(new CardBaseViewModel(cards[1].Name)); this.Items.Add(new CardBaseViewModel(cards[2].Name)); this.Items.Add(new CardBaseViewModel(cards[3].Name)); this.Items.Add(new CardBaseViewModel(cards[4].Name)); this.Items.Add(new CardBaseViewModel(cards[5].Name)); }
static void Main(string[] args) { TextReader inputReader = Console.In; IGameInterface gameInterface = new GameInterface(NUMBER_OF_CARDS_IN_HAND); ICardShuffler shuffler = new CardShuffler(); ICardDealer cardDealer = new CardDealer(NUMBER_OF_CARDS_IN_DECK, shuffler); ICardMapper cardMapper = new CardMapper(); ICardMapperForUI cardMapperForUI = new CardMapperForUI(); Hand hand = new Hand(NUMBER_OF_CARDS_IN_HAND); IEvaluator evaluator = new Evaluator(cardMapper); CombinationNameAndPayoutMapper resultMapper = new CombinationNameAndPayoutMapper(); Game game = new Game( inputReader, gameInterface, cardDealer, cardMapper, cardMapperForUI, hand, evaluator, resultMapper); game.PlayGame(); }
public Form1() { InitializeComponent(); dealer = new CardDealer(timer1); }
public PlayerData(CardDealer d, CardHandController h, SelfHider hider) { CardDealer = d; CardHandController = h; SelfHider = hider; }
static void Main(string[] args) { // Choose Test Console.WriteLine("account or gameElements?"); string response1 = Console.ReadLine(); // Test Accounts if (response1 == "account") { Console.WriteLine("read or write?"); string response2 = Console.ReadLine(); // Test Writing a New Account if (response2 == "write") { Console.WriteLine("Beginning Write Test..."); AccountRecord testRecord = new AccountRecord(); AccountDatabase database = new AccountDatabase(); database.OpenConnection(); //request dummy data Console.WriteLine("Please provide a username:"******"Please provide a password:"******"A duplicate exists. No account was created. Try a different name."); } database.CloseConnection(); } // Test Reading an Existing Account else { Console.WriteLine("Beginning Read Test..."); AccountRecord testRecord = new AccountRecord(); AccountDatabase database = new AccountDatabase(); database.OpenConnection(); //request dummy data Console.WriteLine("Please provide a username:"******"Please provide a password:"******"Hello {testRecord.Username}!"); Console.WriteLine(testRecord.ErrorString); database.CloseConnection(); } } // Test Other Database Activity else { Console.WriteLine("Beginning Other Database Test..."); CardDatabase database = new CardDatabase(); List <string> names = new List <string>(); database.OpenConnection(); // Test Pull All String Names names = database.RequestAllGameElementNames(); foreach (string name in names) { Console.WriteLine(name); } Console.WriteLine("Test 1 Complete."); CardDealer dealer = new CardDealer(); List <Card> cards1 = dealer.ListAllCards(); // Test Pull All Card Records List <Card> moreCards = new List <Card>(); foreach (Card card2 in cards1) { Console.WriteLine(card2.Name); } Console.WriteLine("Test 2 Complete."); // Test Pull a Specific Card Record SystemCard sensor = dealer.ChooseRandomSensor(); List <Card> cards6 = dealer.DealCardsForSensor(sensor); foreach (Card carde in cards6) { Console.WriteLine(carde.Name); } Console.WriteLine(sensor.Name); Console.WriteLine("Please Provide the name of one of the cards above (type exactly):"); CardRecord card = database.RequestCardByName(Console.ReadLine()); Console.WriteLine($"{card.Name},{card.ADCType},{card.IsMultiplexed},{card.SignalConditioning}"); database.CloseConnection(); } Console.WriteLine("Nothing went wrong in this tests"); Console.ReadLine(); }
void Start() { mainCamera = Camera.main; cardDealer = GameObject.Find("CardDealer").GetComponent <CardDealer>(); }
private void Awake() { DealRound = DealRoundEnum.Zero; _transform = transform; _instance = this; CardDictionary.Clear(); CardValueDictionary.Add("Club_2", 2); CardValueDictionary.Add("Club_3", 3); CardValueDictionary.Add("Club_4", 4); CardValueDictionary.Add("Club_5", 5); CardValueDictionary.Add("Club_6", 6); CardValueDictionary.Add("Club_7", 7); CardValueDictionary.Add("Club_8", 8); CardValueDictionary.Add("Club_9", 9); CardValueDictionary.Add("Club_10", 10); CardValueDictionary.Add("Club_J", 11); CardValueDictionary.Add("Club_Q", 12); CardValueDictionary.Add("Club_K", 13); CardValueDictionary.Add("Club_A", 14); CardValueDictionary.Add("Diamond_2", 2); CardValueDictionary.Add("Diamond_3", 3); CardValueDictionary.Add("Diamond_4", 4); CardValueDictionary.Add("Diamond_5", 5); CardValueDictionary.Add("Diamond_6", 6); CardValueDictionary.Add("Diamond_7", 7); CardValueDictionary.Add("Diamond_8", 8); CardValueDictionary.Add("Diamond_9", 9); CardValueDictionary.Add("Diamond_10", 10); CardValueDictionary.Add("Diamond_J", 11); CardValueDictionary.Add("Diamond_Q", 12); CardValueDictionary.Add("Diamond_K", 13); CardValueDictionary.Add("Diamond_A", 14); CardValueDictionary.Add("Spade_2", 2); CardValueDictionary.Add("Spade_3", 3); CardValueDictionary.Add("Spade_4", 4); CardValueDictionary.Add("Spade_5", 5); CardValueDictionary.Add("Spade_6", 6); CardValueDictionary.Add("Spade_7", 7); CardValueDictionary.Add("Spade_8", 8); CardValueDictionary.Add("Spade_9", 9); CardValueDictionary.Add("Spade_10", 10); CardValueDictionary.Add("Spade_J", 11); CardValueDictionary.Add("Spade_Q", 12); CardValueDictionary.Add("Spade_K", 13); CardValueDictionary.Add("Spade_A", 14); CardValueDictionary.Add("Heart_2", 2); CardValueDictionary.Add("Heart_3", 3); CardValueDictionary.Add("Heart_4", 4); CardValueDictionary.Add("Heart_5", 5); CardValueDictionary.Add("Heart_6", 6); CardValueDictionary.Add("Heart_7", 7); CardValueDictionary.Add("Heart_8", 8); CardValueDictionary.Add("Heart_9", 9); CardValueDictionary.Add("Heart_10", 10); CardValueDictionary.Add("Heart_J", 11); CardValueDictionary.Add("Heart_Q", 12); CardValueDictionary.Add("Heart_K", 13); CardValueDictionary.Add("Heart_A", 14); }
public async Task CallHalfSuit(string halfsuit, string callstring) { callstring = callstring.Trim(); halfsuit = halfsuit.ToUpperInvariant(); if (variables[Context.Guild].RedScore + variables[Context.Guild].BlueScore == 9) { await ReplyAsync( ":checkered_flag: The game has ended! Use the `.reset` command to play again! :checkered_flag:"); return; } if (!variables[Context.Guild].GameInProgress) { await ReplyAsync($":x: Game is not in progress yet! :x:"); return; } // make sure game is in progress if (!CardDealer.HalfSuitNames.Contains(halfsuit)) { await ReplyAsync($":x: `{halfsuit}` is not a valid halfsuit! :x:"); return; } // make sure that the halfsuit called is valid if (variables[Context.Guild].CalledHalfSuits.Contains(halfsuit)) { await ReplyAsync($":x: `{halfsuit}` was already called! :x:"); return; } // make sure that the halfsuit has not already been called var seperatedCallString = callstring.Split(" "); var claimedCards = new List <string>(); var allClaimed = new List <string>(); var cuser = ""; var authorName = ""; foreach (var authorUserPair in variables[Context.Guild].AuthorUsers) { if (authorUserPair.Value == Context.Message.Author) { authorName = authorUserPair.Key; } } var works = true; foreach (string strSeg in seperatedCallString) { string editedSeg = strSeg.Replace("@", "").Replace("<", "").Replace(">", "").Replace("!", ""); if (editedSeg == "") { continue; } if (!CardDealer.CardNames.Contains(editedSeg) && !variables[Context.Guild].Players.Contains(editedSeg)) { await ReplyAsync( $":x: `{editedSeg}` not recognized as a card or a player! :x:"); // if a strSeg in the callString is not a player nor a card then it's invalid return; } if (variables[Context.Guild].Players.Contains(editedSeg)) // if this part of the segStr is a player { foreach (string card in claimedCards) { if (!variables[Context.Guild].PlayerCards[cuser].Contains(CardDealer.GetCardByName(card.ToUpperInvariant()))) { works = false; } } cuser = editedSeg; if (variables[Context.Guild].TeamDict[cuser] != variables[Context.Guild].TeamDict[authorName]) { await ReplyAsync($":x: callString included players not on your team! :x:"); return; } claimedCards = new List <string>(); } else { if (CardDealer.CardNames.Contains(editedSeg)) { claimedCards.Add(editedSeg); allClaimed.Add(editedSeg); } } } foreach (string card in claimedCards) { if (!variables[Context.Guild].PlayerCards[cuser].Contains(CardDealer.GetCardByName(card))) { works = false; } } int hsindex = CardDealer.HalfSuitNames.IndexOf(halfsuit); foreach (string _ in allClaimed) { for (var i = 0; i < 6; i++) { if (!allClaimed.Contains(CardDealer.CardNames[hsindex * 6 + i])) { await ReplyAsync(":x: Cards do not match up with the halfsuit :x:"); return; } } } for (var i = 0; i < 6; i++) // cards { foreach (string t in variables[Context.Guild].Players) { variables[Context.Guild].PlayerCards[t] .Remove(CardDealer.GetCardByName(CardDealer.CardNames[hsindex * 6 + i])); } } var username = ""; foreach (var player in variables[Context.Guild].AuthorUsers) { if (player.Value == Context.User) { username = player.Key; } } await CardDealer.SendCards(Context.Guild); string team = variables[Context.Guild].TeamDict[username]; var builder = new EmbedBuilder { Title = ":telephone_receiver: HalfSuit Call :telephone_receiver:" }; if (works) { variables[Context.Guild].AlgebraicNotation += $"callhs {username} {halfsuit} {callstring} hit;"; builder.Color = Color.Green; builder.Description = $":boom: <@{username}> **hit** the `{halfsuit}`! :boom:"; if (team == "red") { variables[Context.Guild].RedScore++; } else { variables[Context.Guild].BlueScore++; } } else { variables[Context.Guild].AlgebraicNotation += $"callhs {username} {halfsuit} {callstring} miss;"; builder.Color = Color.DarkRed; builder.Description = $":thinking: <@{username}> **missed** the `{halfsuit}`! :thinking:"; if (team == "red") { variables[Context.Guild].BlueScore++; } else { variables[Context.Guild].RedScore++; } } variables[Context.Guild].CalledHalfSuits.Add(halfsuit); builder.AddField("Score Update", $"Blue Team: {variables[Context.Guild].BlueScore}\n Red Team: {variables[Context.Guild].RedScore}"); await ReplyAsync("", false, builder.Build()); if (variables[Context.Guild].RedScore + variables[Context.Guild].BlueScore >= 9) { // maybe refactor this and combine with the one in gamemodule var builder2 = new EmbedBuilder { Title = "Game Result!" }; if (variables[Context.Guild].RedScore > variables[Context.Guild].BlueScore) { builder2.Color = Color.Red; builder2.Description = ":red_circle: Red team wins! :red_circle:"; } else { builder2.Color = Color.Blue; builder2.Description = ":large_blue_circle: Blue team wins! :large_blue_circle:"; } builder2.AddField("Final Scores", $"Blue Team: {variables[Context.Guild].BlueScore}\n Red Team: {variables[Context.Guild].RedScore}"); await ReplyAsync("", false, builder2.Build()); await ReplyAsync(":checkered_flag: The game has ended! Use the `.reset` command to play again! :checkered_flag:"); File.WriteAllText("afn.txt", variables[Context.Guild].AlgebraicNotation); // end of that upper comment thing } else { if (variables[Context.Guild].RedScore >= 5) { await ReplyAsync("Red Team has clinched the game!! Use `.reset` to stop the game now, or continue playing!"); variables[Context.Guild].GameClinch = true; } else if (variables[Context.Guild].BlueScore >= 5) { await ReplyAsync("Blue Team has clinched the game!! Use `.reset` to stop the game now, or continue playing!"); variables[Context.Guild].GameClinch = true; } } if (CheckPlayerTurnHandEmpty() && variables[Context.Guild].GameInProgress) { string newPlayerID = ""; if (variables[Context.Guild].TeamDict[variables[Context.Guild].PlayerTurn] == "red") { // red team int playerIndex = variables[Context.Guild].RedTeam.FindIndex(a => a == variables[Context.Guild].PlayerTurn); newPlayerID = variables[Context.Guild].RedTeam[(playerIndex + 1) % variables[Context.Guild].RedTeam.Count]; } else if (variables[Context.Guild].TeamDict[variables[Context.Guild].PlayerTurn] == "blue") { // blue team int playerIndex = variables[Context.Guild].BlueTeam.FindIndex(a => a == variables[Context.Guild].PlayerTurn); newPlayerID = variables[Context.Guild].BlueTeam[(playerIndex + 1) % variables[Context.Guild].BlueTeam.Count]; } await ReplyAsync($":open_mouth: <@{variables[Context.Guild].PlayerTurn}> is out of cards! Turn will move to <@{newPlayerID}> :open_mouth:"); //await ReplyAsync($":open_mouth: {variables[Context.Guild].PlayerTurn} is out of cards! Use the `.designate` command to select the next player! :open_mouth:"); //variables[Context.Guild].NeedsDesignatedPlayer = true; //variables[Context.Guild].Designator = variables[Context.Guild].PlayerTurn.Replace("@", "").Replace("<", "").Replace(">", "").Replace("!", ""); } }
public async Task Start() { if (variables[Context.Guild].GameInProgress) // check if the game is in progress { if (variables[Context.Guild].RedScore + variables[Context.Guild].BlueScore == 9) { await ReplyAsync( ":checkered_flag: The game has ended! Use the `.reset` command to play again! :checkered_flag:"); return; } await ReplyAsync(":trophy: Game is already in progess! :trophy:"); return; } if (variables[Context.Guild].Players.Count == 0) { await ReplyAsync(":x: There are not enough players!! :x:"); return; } //if (variables[Context.Guild].RedTeam.Count != variables[Context.Guild].BlueTeam.Count) // make sure the teams are even //{ // await ReplyAsync($"Teams are not even! Check teams using the `.team list` command"); // return; //} foreach (string player in variables[Context.Guild].Players) // make sure that each username is attached to a IUser { if (variables[Context.Guild].AuthorUsers.ContainsKey(player)) { continue; } await ReplyAsync($":x: <@{player}> is not attached to a SocketUser! :x:"); return; } variables[Context.Guild].GameInProgress = true; variables[Context.Guild].CalledHalfSuits.Clear(); //Create AFN header variables[Context.Guild].AlgebraicNotation += variables[Context.Guild].Players.Count + ";"; variables[Context.Guild].AlgebraicNotation += variables[Context.Guild].RedTeam.Count + ";"; variables[Context.Guild].AlgebraicNotation += variables[Context.Guild].BlueTeam.Count + ";"; foreach (string redPlayer in variables[Context.Guild].RedTeam) { variables[Context.Guild].AlgebraicNotation += redPlayer + ":" + variables[Context.Guild].AuthorUsers[redPlayer] + ";"; } foreach (string bluePlayer in variables[Context.Guild].BlueTeam) { variables[Context.Guild].AlgebraicNotation += bluePlayer + ":" + variables[Context.Guild].AuthorUsers[bluePlayer] + ";"; } // Starting game await ReplyAsync(":trophy: `Starting Game...` :weary:"); variables[Context.Guild].PlayerTurn = variables[Context.Guild] .Players[new Random().Next(variables[Context.Guild].Players.Count)]; // get random player to start variables[Context.Guild].AlgebraicNotation += variables[Context.Guild].PlayerTurn + ";"; // add first player to afn variables[Context.Guild].GameStart = true; await CardDealer.DealCards(Context.Guild); await ReplyAsync($":game_die: It's <@{variables[Context.Guild].PlayerTurn}>'s turn!"); }
public async Task Call(string target, string requestedCard) { target = target.Replace("@", "").Replace("<", "").Replace(">", "").Replace("!", ""); requestedCard = requestedCard.ToUpperInvariant(); if (variables[Context.Guild].RedScore + variables[Context.Guild].BlueScore == 9) { await ReplyAsync( ":checkered_flag: The game has ended! Use the `.reset` command to play again! :checkered_flag:"); return; } if (!variables[Context.Guild].GameInProgress) { await ReplyAsync($":x: Game is not in progress yet! :x:"); await Context.Message.DeleteAsync(); return; } // make sure the game is in progress if (variables[Context.Guild].AuthorUsers[variables[Context.Guild].PlayerTurn] != Context.Message.Author) { await Context.Message.DeleteAsync(); return; } // make sure only the person's whose turn it is can call if (variables[Context.Guild].TeamDict[target] == variables[Context.Guild].TeamDict[variables[Context.Guild].PlayerTurn]) { await ReplyAsync($":x: Cannot call cards from someone on your team! :x:"); await Context.Message.DeleteAsync(); return; } // make sure they call someone on the opposite team if (variables[Context.Guild].PlayerCards[target].Count == 0) { await ReplyAsync($":x: Cannot call a player with no cards! :x:"); await Context.Message.DeleteAsync(); return; } // delete previous call info var rawMessages = Context.Channel.GetMessagesAsync().FlattenAsync(); foreach (var msg in rawMessages.Result) { if (msg.Author.Id == Context.Client.CurrentUser.Id && msg.Content.Contains("*TEMPORARY*")) // everything marked with *TEMPORARY* { await msg.DeleteAsync(); } } var req = CardDealer.GetCardByName(requestedCard.ToUpperInvariant()); if (!variables[Context.Guild].Players.Contains(target)) // make sure the target is a valid player { await ReplyAsync($":x: `{target}` is not a player! :x:"); await Context.Message.DeleteAsync(); return; } if (!CardDealer.CardNames.Contains(requestedCard)) // make sure requestedCard is a valid card { await ReplyAsync($":x: `{requestedCard}` is not a valid card! :x:"); await Context.Message.DeleteAsync(); return; } var builder = new EmbedBuilder { Title = "Call Result", ImageUrl = "https://raw.githubusercontent.com/jonathanh8686/DiscordFishBot/master/cards/" + req.CardName + ".png" }; int cardIndex = CardDealer.CardNames.IndexOf(requestedCard); int hsIndex = cardIndex / 6; // get index of halfsuit var hasHalfSuit = false; for (var i = 0; i < 6; i++) // loop through halfsuit and see if they have something in the same hs { if (variables[Context.Guild].PlayerCards[variables[Context.Guild].PlayerTurn] .Contains(CardDealer.GetCardByName(CardDealer.CardNames[6 * hsIndex + i]))) { hasHalfSuit = true; } } // handing illegal moves if (variables[Context.Guild].PlayerCards[variables[Context.Guild].PlayerTurn].Contains(req) || !hasHalfSuit) // player already has the card or they don't have something in the halfsuit { await Context.Message.DeleteAsync(); return; //variables[Context.Guild].AlgebraicNotation += $"call {target} {requestedCard} illegal;"; //builder.Color = Color.Magenta; //builder.Description = ":oncoming_police_car: ILLEGAL CALL! :oncoming_police_car:"; //builder.AddField("Info", // $"<@{variables[Context.Guild].PlayerTurn}> called the `{requestedCard}` from <@{target}> but it was **illegal**!\n It is now <@{target}>'s turn."); //variables[Context.Guild].PlayerTurn = target; //await ReplyAsync("*TEMPORARY*", false, builder.Build()); //await Context.Message.DeleteAsync(); //return; } if (variables[Context.Guild].PlayerCards[target].Contains(req)) { // hit variables[Context.Guild].AlgebraicNotation += $"call {target} {requestedCard} hit;"; builder.Color = Color.Green; builder.Description = ":boom: Call was a hit! :boom:"; builder.ThumbnailUrl = "https://raw.githubusercontent.com/jonathanh8686/DiscordFishBot/master/cards/hit.png"; builder.AddField("Info", $"<@{variables[Context.Guild].PlayerTurn}> called the `{requestedCard}` from <@{target}> and it was a **hit**!\n It is now <@{variables[Context.Guild].PlayerTurn}>'s turn."); variables[Context.Guild].PlayerCards[target].Remove(req); variables[Context.Guild].PlayerCards[variables[Context.Guild].PlayerTurn].Add(req); } else { // miss variables[Context.Guild].AlgebraicNotation += $"call {target} {requestedCard} miss;"; builder.Color = Color.DarkRed; builder.Description = ":thinking: Call was a miss! :thinking:"; builder.ThumbnailUrl = "https://raw.githubusercontent.com/jonathanh8686/DiscordFishBot/master/cards/miss.png"; builder.AddField("Info", $"<@{variables[Context.Guild].PlayerTurn}> called the `{requestedCard}` from <@{target}> and it was a **miss**!\n It is now <@{target}>'s turn."); variables[Context.Guild].PlayerTurn = target; } await Context.Message.DeleteAsync(); await ReplyAsync("*TEMPORARY*", false, builder.Build()); await CardDealer.SendCards(Context.Guild); if (CheckPlayerTurnHandEmpty()) { await ReplyAsync( "not sure how this can ever get called but ill leave this here for a few games and see if this text ever shows up and if it doesn't i guess ill delete it xd"); await ReplyAsync( $"<@{variables[Context.Guild].PlayerTurn}> is out of cards! Use the `.designate` command to select the next player!"); variables[Context.Guild].NeedsDesignatedPlayer = true; } }