public async Task <int> DroppedCards(List <CardView> cards)
        {
            _totalCardsDropped += cards.Count;
            if (this.State == GameState.PlayerGiveToCrib)
            {
                _crib.AddRange(cards);

                if (_crib.Count == 4)
                {
                    await _view.OnSendCardsToCrib();

                    if (HandsFromService.SharedCard.Rank == 11)
                    {
                        await ScoreCutJack(HandsFromService.SharedCard.Index);
                    }
                    _game.SendAllCardsToCrib(_crib);
                    _totalCardsDropped = 0;
                    _crib.Clear();
                    SetStateAsync(GameState.Count);
                    return(0);
                }

                return(4 - _crib.Count);
            }

            if (this.State == GameState.PlayerCountCard)
            {
                CountingData data = _game.CountCard(PlayerType.Player, cards[0], Settings.Difficulty);
                _nPlayerCountingPoint += data.Score;
                _boardUi.AddScoreAsync(PlayerType.Player, data.Score);
                await _view.OnCountCard(cards[0], PlayerType.Player, data);

                _boardUi.Turn = data.NextPlayer;
                if (_game.GetCurrentScore(PlayerType.Player) > WINNING_SCORE)
                {
                    await SetState(GameState.GameOver);

                    return(8);
                }
                if (data.CardsCounted == 8)
                {
                    SetStateAsync(GameState.CountingEnded);
                    return(0);
                }
                else if (data.NextPlayerIsComputer)
                {
                    SetStateAsync(GameState.ComputerCountCard);
                    return(0);
                }
                else
                {
                    return(1);
                }
            }

            throw new Exception(String.Format("Unexpected state during user dropping card.  State is: {0}", _gameState));
        }
Esempio n. 2
0
        static void ReadAllFiles(string[] files, string checkValue)
        {
            string writePath = "output_" + checkValue + ".txt";

            foreach (var file in files)
            {
                using (StreamReader sr = new StreamReader(file, System.Text.Encoding.Default))
                {
                    string line;
                    using (StreamWriter sw = new StreamWriter(writePath, true, System.Text.Encoding.Default))
                    {   //true - the new data will be added at the end to the existing data.
                        while ((line = sr.ReadLine()) != null)
                        {
                            if (!line.Contains(checkValue))
                            {
                                sw.WriteLine(line);
                                CountingData.Counting(line);
                            }
                            else
                            {
                                logger.Info("\'" + line + "\' " + "contains " + checkValue);
                            }
                        }
                    }
                }
            }
            Console.WriteLine("Сombined file: " + Directory.GetCurrentDirectory() + "\\" + writePath);

            string stat = "statistic.txt";

            using (StreamWriter sw = new StreamWriter(stat, true, System.Text.Encoding.Default))
            {
                sw.WriteLine("Суммы всех чисел А из общего файла: " + CountingData.SumA.ToString());
                sw.WriteLine("Количество строк, где число Б находится в диапазоне 3.0-5.0: " + CountingData.CountB.ToString());
                sw.WriteLine("50 строк, содержащих самые большие числа А в порядке убывания: ");
                foreach (int top in CountingData.List)
                {
                    sw.WriteLine(top.ToString());
                }
                Console.WriteLine("Statistics: " + Directory.GetCurrentDirectory() + "\\" + stat);
            }
        }
Esempio n. 3
0
        public async Task OnCountCard(CardView card, PlayerType currentPlayer, CountingData countingData)
        {
            string message = "";

            if (countingData.Score > 0)
            {
                message = String.Format("{0} Scored Points\n\n{1}", currentPlayer == PlayerType.Player ? "You" : "The Computer", countingData.ScoreStory.Format());
                if (currentPlayer == PlayerType.Player)
                {
                    _pointsPlayerCountedThisTurn++;
                }
                else
                {
                    _pointsComputerCountedThisTurn++;
                }
            }
            if (currentPlayer == PlayerType.Computer)
            {
                //
                //  if it is the player, the card gets moved there via drag and drop
                await GridComputer.MoveCardToTarget(card, GridPlayedCards, MainPage.AnimationSpeeds.Medium);
            }


            if (card.Orientation == CardOrientation.FaceDown)
            {
                await card.SetOrientation(CardOrientation.FaceUp);
            }


            if (countingData.Score > 0)
            {
                await AddToScoreHistory(GridPlayedCards.Items, countingData.ScoreStory, currentPlayer);
            }


            UpdateCount(countingData.CurrentCount);


            if (countingData.ResetCount) // the card we just dropped hit 31 or a Go
            {
                UpdateCount(countingData.CountBeforeReset);
                await OnCountResetUpdateUi();
            }


            if (countingData.NextPlayer == PlayerType.Player)
            {
                GridPlayer.MaxSelected = 1;
                message += "Your Turn.\nDrag and drop one card into the middle window";
            }
            else
            {
                GridPlayer.MaxSelected = 0;
            }

            if (message != "")
            {
                ShowHintWindowAsync(true, false, message);
            }
        }