private async Task DealAnimation(HandsFromServer hfs, double duration = Double.MaxValue) { if (duration == Double.MaxValue) { duration = MainPage.AnimationSpeeds.Medium; } CardView card; List <Task <Object> > tasks = new List <Task <object> >(); for (int i = 0; i < 6; i++) { card = hfs.PlayerCards[i]; card.BoostZindex(); card.Owner = Owner.Player; GridDeck.MoveCardToTarget(card, GridPlayer, tasks, duration, true); card = hfs.ComputerCards[i]; card.Owner = Owner.Computer; card.BoostZindex(); GridDeck.MoveCardToTarget(card, GridComputer, tasks, duration, true); } await Task.WhenAll(tasks); await GridPlayer.FlipAllCards(CardOrientation.FaceUp, duration); for (int i = 0; i < 6; i++) { GridPlayer.Items[i].ResetZIndex(); GridComputer.Items[i].ResetZIndex(); } hfs.SharedCard.BoostZindex(ZIndexBoost.SmallBoost); }
private async Task DealAnimation(HandsFromServer hfs) { CardView card; List <Task <Object> > tasks = new List <Task <object> >(); for (int i = 0; i < 6; i++) { card = hfs.PlayerCards[i]; card.BoostZindex(); card.Owner = Owner.Player; _gridDeck.MoveCardToTarget(card, _gridPlayer, tasks, MainPage.AnimationSpeeds.Medium, true); card = hfs.ComputerCards[i]; card.Owner = Owner.Computer; card.BoostZindex(); _gridDeck.MoveCardToTarget(card, _gridComputer, tasks, MainPage.AnimationSpeeds.Medium, true); } await Task.WhenAll(tasks); await _gridPlayer.FlipAllCards(CardOrientation.FaceUp); for (int i = 0; i < 6; i++) { _gridPlayer.Items[i].ResetZIndex(); _gridComputer.Items[i].ResetZIndex(); } hfs.SharedCard.BoostZindex(ZIndexBoost.SmallBoost); }
public async Task OnDeal(HandsFromServer hfs, double duration = Double.MaxValue) { GridDeck.Items.Remove(hfs.SharedCard); GridDeck.Items.Insert(0, hfs.SharedCard); hfs.PlayerCards.Sort(CardView.CompareCardsByRank); Hfs = hfs; await DealAnimation(hfs, duration); }
//private bool DoesPointContainElement(Point hitTestPoint, FrameworkElement element) //{ // GeneralTransform gt = this.TransformToVisual(element); // Point localPoint = gt.TransformPoint(hitTestPoint); // if (localPoint.X < 0 || localPoint.Y < 0 || localPoint.X > element.ActualWidth || localPoint.Y > element.ActualHeight) // return false; // return true; //} private async Task TestDealAnimation() { HandsFromServer hfs = new HandsFromServer(); hfs.ComputerCards = new List <CardView>(); hfs.PlayerCards = new List <CardView>(); for (int i = 0; i < 6; i++) { hfs.PlayerCards.Add(_gridDeck.Items[i]); hfs.ComputerCards.Add(_gridDeck.Items[i + 20]); } hfs.SharedCard = _gridDeck.Items[30]; await DealAnimation(hfs); }
private Task StartGame(HandsFromServer hfs) { throw new NotImplementedException(); //LocalGame game = new LocalGame(); //game.NewGame(PlayerType.Computer, Deck); //hfs = game.ShuffleAndReturnAllCards(hfs); //List<CardView> crib = game.GetSuggestedCrib(PlayerType.Player, GameDifficulty.Hard); //game.SendToCrib(PlayerType.Computer, crib); //hfs.PlayerCards.Remove(crib[0]); //hfs.PlayerCards.Remove(crib[1]); //int scoreGuess = game.GetScore(PlayerType.Player, HandType.Regular); //ScoreCollection scores = game.UpdateScore(PlayerType.Player, HandType.Regular, scoreGuess, GameDifficulty.Hard, MugginsSettings.None); //List<CardView> cards = new List<CardView>(hfs.PlayerCards); //_gridDeck.Items.Remove(hfs.SharedCard); //_gridDeck.Items.Insert(0, hfs.SharedCard); //await _view.AddToScoreHistory(cards, scores, PlayerType.Computer); }
private async Task AddScoreCollectionToHistory() { LocalGame game = new LocalGame(); game.NewGame(PlayerType.Computer, MainPage.Current.Deck); HandsFromServer hfs = game.ShuffleAndReturnAllCards(); List <CardView> crib = game.GetSuggestedCrib(PlayerType.Player, GameDifficulty.Hard); game.SendToCrib(PlayerType.Computer, crib); hfs.PlayerCards.Remove(crib[0]); hfs.PlayerCards.Remove(crib[1]); int scoreGuess = game.GetScore(PlayerType.Player, HandType.Regular); ScoreCollection scores = game.UpdateScore(PlayerType.Player, HandType.Regular, scoreGuess, GameDifficulty.Hard); List <CardView> cards = new List <CardView>(hfs.PlayerCards); _gridDeck.Items.Remove(hfs.SharedCard); _gridDeck.Items.Insert(0, hfs.SharedCard); await _view.AddToScoreHistory(cards, scores, PlayerType.Player); }
async Task IShowInstructionsUi.InsertEndOfHandSummary(PlayerType dealer, int cribScore, List <CardView> crib, int nComputerCountingPoint, int nPlayerCountingPoint, int ComputerPointsThisTurn, int PlayerPointsThisTurn, HandsFromServer hfs) { RemoveScoreDetails(); OneHandHistoryCtrl view = new OneHandHistoryCtrl(); await view.SetPlayerCards(hfs.PlayerCards); await view.SetComputerHand(hfs.ComputerCards); await view.SetSharedCard(hfs.SharedCard); await view.SetCribHand(crib, dealer); view.SetCountScores(nPlayerCountingPoint, nComputerCountingPoint); view.SetCribScore(cribScore); view.SetComputerHandScore(ComputerPointsThisTurn); view.SetPlayerHandScore(PlayerPointsThisTurn); view.Width = _listHistory.ActualWidth - SCROLLBAR_WIDTH; view.Height = (view.Width * HEIGHT_WIDTH_RATIO_HAND_SUMMARY); _scoreHistoryList.Insert(0, view); // // Counting stats MainPage.Current.StatsView.Stats.Stat(StatName.CountingMostPoints).UpdateStatistic(PlayerType.Player, nPlayerCountingPoint); MainPage.Current.StatsView.Stats.Stat(StatName.CountingMostPoints).UpdateStatistic(PlayerType.Computer, nComputerCountingPoint); MainPage.Current.StatsView.Stats.Stat(StatName.CountingTotalPoints).UpdateStatistic(PlayerType.Player, nPlayerCountingPoint); MainPage.Current.StatsView.Stats.Stat(StatName.CountingTotalPoints).UpdateStatistic(PlayerType.Computer, nComputerCountingPoint); // // Hand Stats MainPage.Current.StatsView.Stats.Stat(StatName.HandMostPoints).UpdateStatistic(PlayerType.Player, PlayerPointsThisTurn); MainPage.Current.StatsView.Stats.Stat(StatName.HandMostPoints).UpdateStatistic(PlayerType.Computer, ComputerPointsThisTurn); MainPage.Current.StatsView.Stats.Stat(StatName.HandTotalPoints).UpdateStatistic(PlayerType.Player, PlayerPointsThisTurn); MainPage.Current.StatsView.Stats.Stat(StatName.HandTotalPoints).UpdateStatistic(PlayerType.Computer, ComputerPointsThisTurn); MainPage.Current.StatsView.Stats.Stat(StatName.HandAveragePoints).UpdateStatistic(PlayerType.Player, 0); MainPage.Current.StatsView.Stats.Stat(StatName.HandAveragePoints).UpdateStatistic(PlayerType.Computer, 0); // // Crib stats MainPage.Current.StatsView.Stats.Stat(StatName.CribMostPoints).UpdateStatistic(dealer, cribScore); MainPage.Current.StatsView.Stats.Stat(StatName.CribTotalPoints).UpdateStatistic(dealer, cribScore); MainPage.Current.StatsView.Stats.Stat(StatName.CribAveragePoints).UpdateStatistic(dealer, 0); if (cribScore == 0) { MainPage.Current.StatsView.Stats.Stat(StatName.Crib0Points).UpdateStatistic(dealer, 1); } // // keeping track of 0's if (PlayerPointsThisTurn == 0) { MainPage.Current.StatsView.Stats.Stat(StatName.Hand0Points).UpdateStatistic(PlayerType.Player, 1); } if (ComputerPointsThisTurn == 0) { MainPage.Current.StatsView.Stats.Stat(StatName.Hand0Points).UpdateStatistic(PlayerType.Computer, 1); } if (nComputerCountingPoint == 0) { MainPage.Current.StatsView.Stats.Stat(StatName.Counting0Points).UpdateStatistic(PlayerType.Computer, 1); } if (nPlayerCountingPoint == 0) { MainPage.Current.StatsView.Stats.Stat(StatName.Counting0Points).UpdateStatistic(PlayerType.Player, 1); } }
Task IShowInstructionsAndHistoryController.InsertEndOfHandSummary(PlayerType dealer, int cribScore, List <CardView> list, int nComputerCountingPoint, int nPlayerCountingPoint, int ComputerPointsThisTurn, int PlayerPointsThisTurn, HandsFromServer Hfs) { return(ShowInstructionsUi.InsertEndOfHandSummary(dealer, cribScore, list, nComputerCountingPoint, nPlayerCountingPoint, ComputerPointsThisTurn, PlayerPointsThisTurn, Hfs)); }
public async Task <Dictionary <string, string> > Load(string s) { if (s == "") { return(null); } Dictionary <string, string> sections = StaticHelpers.GetSections(s); if (_game.Deserialize(sections, _view.Deck) == false) { return(null); } Dictionary <string, string> game = StaticHelpers.DeserializeDictionary(sections["State"]); if (sections == null) { return(null); } if (game["Version"] != SERIALIZATION_VERSION) { return(null); } _gameState = (GameState)Enum.Parse(typeof(GameState), game["GameState"]); _dealer = (PlayerType)Enum.Parse(typeof(PlayerType), game["Dealer"]); _totalCardsDropped = Convert.ToInt32(game["TotalCardsDropped"]); _nPlayerCountingPoint = Convert.ToInt32(game["PlayerCountingPoints"]); _nPlayerPointsThisTurn = Convert.ToInt32(game["PlayerPointsThisTurn"]); _nComputerCountingPoint = Convert.ToInt32(game["ComputerCountingPoints"]); _nComputerPointsThisTurn = Convert.ToInt32(game["ComputerPointsThisTurn"]); _nCribPointsThisTurn = Convert.ToInt32(game["CribPointsThisTurn"]); int playerScore = Convert.ToInt32(game["PlayerScore"]); int computerScore = Convert.ToInt32(game["ComputerScore"]); _hfs = _game.GetHfs(); _view.Hfs = _hfs; Dictionary <string, string> grids = StaticHelpers.DeserializeDictionary(sections["Grids"]); List <CardView> PlayerCards = StaticHelpers.DeserializeToList(grids["Player"], _view.Deck); List <CardView> ComputerCards = StaticHelpers.DeserializeToList(grids["Computer"], _view.Deck); List <CardView> cribCards = StaticHelpers.DeserializeToList(grids["Crib"], _view.Deck); CardView SharedCard = StaticHelpers.CardFromString(grids["SharedCard"], _view.Deck); List <CardView> playedCards = StaticHelpers.DeserializeToList(grids["Played"], _view.Deck); List <Task <object> > taskList = new List <Task <object> >(); _view.MoveCards(taskList, playedCards, _view.GridPlayedCards); _view.MoveCards(taskList, cribCards, _view.GridCrib); _view.MoveCards(taskList, PlayerCards, _view.GridPlayer); _view.MoveCards(taskList, ComputerCards, _view.GridComputer); if (_gameState == GameState.PlayerGiveToCrib) { _crib.AddRange(playedCards); } await Task.WhenAll(taskList); SharedCard.BoostZindex(ZIndexBoost.SmallBoost); _game.UpdateScoreDirect(PlayerType.Player, ScoreType.Saved, playerScore); // give the points to the player _game.UpdateScoreDirect(PlayerType.Computer, ScoreType.Saved, computerScore); // give the points to the player await UiState.AddScore(PlayerType.Player, playerScore); await UiState.AddScore(PlayerType.Computer, computerScore); _view.CountControl.Count = _game.CurrentCount; await FixUpUiState(); string scoreHistory = ""; if (sections.TryGetValue("Score History", out scoreHistory)) { await _view.Load(scoreHistory); } if (_gameState == GameState.PlayerScoreHand) { // // if we saved in the state where the player is supposed to score the hard, we need to drive the state machine // through the completion of the GameState.ScoreHand states if (_dealer == PlayerType.Player) { await SetState(GameState.PlayerScoreHand); await SetState(GameState.ShowCrib); await SetState(GameState.PlayerScoreCrib); _gameState = GameState.EndOfHand; } else { _gameState = GameState.ScoreHands; } } else if (_gameState == GameState.PlayerScoreCrib) { await SetState(GameState.PlayerScoreCrib); _gameState = GameState.EndOfHand; } SetStateAsync(_gameState); return(sections); }
public void TransferState() { HandsFromServer hfs = _game.GetHfs(); // _view.TransferCards(hfs); switch (_gameState) { case GameState.Start: case GameState.PickCard: SetStateAsync(_gameState); break; case GameState.Deal: break; case GameState.GiveToCrib: break; case GameState.PlayerGiveToCrib: break; case GameState.ComputerGiveToCrib: break; case GameState.Count: break; case GameState.ComputerCountCard: break; case GameState.PlayerCountCard: break; case GameState.CountingEnded: break; case GameState.ScoreHands: break; case GameState.PlayerScoreHand: break; case GameState.PlayerScoreCrib: break; case GameState.ComputerScoreHand: break; case GameState.ComputerScoreCrib: break; case GameState.ShowCrib: break; case GameState.EndOfHand: break; case GameState.GameOver: break; case GameState.None: break; default: break; } { } }
public async Task TransferCards(HandsFromServer hfs) { await AnimateAllCardsBackToDeck(); await OnDeal(hfs); }