public void DealCards() { // Reset the board GameHelper.ResetImages(Player, Computer); GameHelper.ResetGame(Player, Computer); View.ResetResult(); View.SplitDeck(Player, false); BetPlaced = true; int cardOne = Random.Next(2, 12); int cardTwo = Random.Next(2, 12); GameHelper.AddAces(Player, cardOne); GameHelper.AddAces(Player, cardTwo); Player.Images[0].Source = ImagesHelper.RandomColorCard(CardImages.First(x => x.Key == cardOne).Value); Player.Images[1].Source = ImagesHelper.RandomColorCard(CardImages.First(x => x.Key == cardTwo).Value); Player.Score = cardOne + cardTwo; View.DisplayPoints(Player); if (cardOne == cardTwo) { DoubleCards = true; } if (Player.Score > 21) { GameHelper.HasAces(Player); View.DisplayPoints(Player); } }
public void Stand(bool isSplit) { int cardOne = Random.Next(2, 12); int cardTwo = Random.Next(2, 12); GameHelper.AddAces(Computer, cardOne); GameHelper.AddAces(Computer, cardTwo); Computer.Images[0].Source = ImagesHelper.RandomColorCard(CardImages.First(x => x.Key == cardOne).Value); Computer.Images[1].Source = ImagesHelper.RandomColorCard(CardImages.First(x => x.Key == cardTwo).Value); Computer.Score = cardOne + cardTwo; View.DisplayPoints(Computer); if (Computer.Score < 17 || (Computer.Score > 21 && GameHelper.HasAces(Computer))) { TaskFactory = new TaskFactory(TaskScheduler.FromCurrentSynchronizationContext()); new Thread(() => HitCardComputer(isSplit)).Start(); } else { End(isSplit); } BetPlaced = false; }
public void HitCard() { int card = Random.Next(2, 12); GameHelper.AddAces(Player, card); Player.Images[Player.CurrentImage].Source = ImagesHelper.RandomColorCard(CardImages.First(x => x.Key == card).Value); Player.CurrentImage++; Player.Score += card; if (Player.Score > 21 && !GameHelper.HasAces(Player)) { BetPlaced = false; End(false); } View.DisplayPoints(Player); }
public void HitCardComputer(bool isSplit) { TaskFactory.StartNew(() => View.DealButton(false)); while (Computer.Score < 17 && Computer.CurrentImage < Computer.Images.Count()) { // Pretend to be thinking Thread.Sleep(1000); int card = Random.Next(2, 12); GameHelper.AddAces(Computer, card); Computer.Score += card; TaskFactory.StartNew((() => DisplayCard(card))); if (Computer.Score > 21) { GameHelper.HasAces(Computer); } } TaskFactory.StartNew(() => End(isSplit)); TaskFactory.StartNew(() => View.DealButton(true)); Thread.Yield(); }