Ejemplo n.º 1
0
        private static bool EndCurrentTurn()
        {
            // Get all placed pieces
            var placedPieces = HandController.HandSlots.Where(s => s.IsPlaced).ToList();

            if (PiecePlacementIsValid(placedPieces) == false)
            {
                return(false);
            }

            if (placedPieces.Any())
            {
                var words = GetNewWords(placedPieces);
                if (WordsAreValid(words) == false)
                {
                    Game.Current.TurnErrors.Add(Constants.InvalidTurnReason.InvalidWord);
                    return(false);
                }

                Game.Current.TurnsWithoutPlacement = 0;
                Game.Current.CurrentPlayer.TurnsPlayed++;

                var turnPoints = CalculatePoints(placedPieces);
                Game.Current.CurrentPlayer.Score += turnPoints;

                if (Game.Current.CurrentPlayer.IsAI == false && turnPoints >= Constants.ScreenshotMinimumPoints)
                {
                    // TODO: Save points in a highscore board as well
                    Util.CaptureScreenshot(Program.MainView, 0, Game.Current.Players.Sum(p => p.TurnsPlayed));
                }

                HandController.ConfirmAll();
                SidebarController.RenderWords();

                HandController.SaveHand(Game.Current.CurrentPlayer);
            }
            else
            {
                Game.Current.TurnsWithoutPlacement++;
                Game.Current.CurrentPlayer.TurnsPlayed++;
                if (Game.Current.TurnsWithoutPlacement == 2 * Game.Current.Players.Count)
                {
                    EndGame(Constants.GameEndReason.NoMoreTurns);
                    return(false);
                }
            }

            return(true);
        }