Esempio n. 1
0
        public void AddPlayerShouldAddThePlayerToThePlayersList()
        {
            this.scoreboardInstance = Scoreboard.Instance;
            player = new Player("pesho", 150);
            int scoreboardPlayersBeforeAddingNewOne = scoreboardInstance.GetPlayers().Count;

            scoreboardInstance.AddPlayer(player);
            Assert.AreEqual(scoreboardPlayersBeforeAddingNewOne + 1, scoreboardInstance.GetPlayers().Count);
        }
Esempio n. 2
0
 public void MaximumPlayersSizeMustBeFive()
 {
     this.scoreboardInstance = Scoreboard.Instance;
     player = new Player("pesho", 150);
     for (int i = 0; i < 20; i++)
     {
         scoreboardInstance.AddPlayer(player);
     }
     Assert.AreEqual(5, scoreboardInstance.GetPlayers().Count);
 }
    public void AddPlayerScore(GameObject player)
    {
        NetworkIdentity nId = player.GetComponent <NetworkIdentity>();

        Debug.LogWarning("Adding player " + player + ", " + nId.netId);
        if (scoreBoard != null && nId != null)
        {
            //NetworkInstanceId nIdScore = scoreBoard.SpawnPlayerScore ();
            //eventAddPlayer(playerNumber, nId.netId);
            scoreBoard.AddPlayer(playerNumber, nId.netId);
            scoreBoard.RpcAddPlayer(playerNumber, nId.netId);
        }
    }
Esempio n. 4
0
        public void PrintScoreboardTest()
        {
            //var currentConsoleOut = Console.Out;
            var    playerName = "Aashko";
            Player player     = new Player(playerName, 0);

            Scoreboard scoreboard = Scoreboard.Instance;

            scoreboard.AddPlayer(player);
            scoreboard.AddPlayer(player);

            var expected = new StringBuilder();

            expected.AppendLine("Scoreboard:\n1. Aashko --> 0 moves");

            using (var consoleOutput = new ConsoleOutput())
            {
                render.RenderScoreboard(scoreboard);
                bool containsString = consoleOutput.GetOuput().ToString().Contains(expected.ToString());
                Assert.AreEqual(true, containsString);
            }
        }
Esempio n. 5
0
        private void ProceedGameOver()
        {
            if (this.movesCount == 0)
            {
                Console.WriteLine(Messages.Lose);
            }
            else
            {
                Console.WriteLine(Messages.Win, this.movesCount);
                Console.Write(Messages.HighScore);

                string  playerName = Console.ReadLine();
                IPlayer player     = new Player(playerName, this.movesCount);
                Scoreboard.AddPlayer(player);
                Scoreboard.Save();
                Scoreboard.PrintScoreboard();
            }

            this.gameState      = State.Restart;
            this.isGameFinished = false;
            this.movesCount     = 0;
        }
        public void PrintScoreboardTest()
        {
            var    currentConsoleOut = Console.Out;
            var    playerName        = "Goshko";
            Player player            = new Player(playerName, 2);

            Scoreboard scoreboard = Scoreboard.Instance;

            scoreboard.AddPlayer(player);

            var expected = new StringBuilder();

            expected.AppendLine("Scoreboard:\n1. Goshko --> 2 moves");
            //expected.AppendLine("1. Goshko --> 2 moves");
            expected.AppendLine();

            using (var consoleOutput = new ConsoleOutput())
            {
                render.RenderScoreboard(scoreboard);
                Assert.AreEqual(expected.ToString(), consoleOutput.GetOuput());
            }

            Assert.AreEqual(currentConsoleOut, Console.Out);
        }
Esempio n. 7
0
 public void AddPlayerShouldThrowExceptionOnNullPassed()
 {
     this.scoreboardInstance = Scoreboard.Instance;
     scoreboardInstance.AddPlayer(null);
 }
Esempio n. 8
0
        /// <summary>Starts new game.</summary>
        public void StartNewGame()
        {
            IMatrixGenerator matrixGenerator = new MatrixGenerator(CommonConstants.GAME_BOARD_SIZE, this.numberGenerator);

            int[,] currentMatrix = matrixGenerator.GenerateMatrix();
            IEqualMatrixChecker         equalMatrixChecker = new EqualMatrixChecker();
            MatrixEmptyCellRandomizator matrixRandomizator = new MatrixEmptyCellRandomizator();
            Point   emptyPoint = matrixRandomizator.Randomize(currentMatrix);
            Command currentCommand;

            this.renderer.PrintWelcome();

            // main algorithm
            int playerMoves = 0;

            gameEnd = false;
            string inputString = "";

            while (!gameEnd)
            {
                this.renderer.RenderMatrix(currentMatrix);
                if (equalMatrixChecker.IsSorted(currentMatrix))  // IsGameWon check
                {
                    this.renderer.PrintGameWon(playerMoves);

                    this.renderer.Print(CommonConstants.PLAYER_NAME);
                    string playerName = "";
                    while (true)
                    {
                        playerName = this.inputReader.Read();
                        if (!string.IsNullOrEmpty(playerName))
                        {
                            break;
                        }
                        this.renderer.Print(CommonConstants.NON_EMPTY_PLAYER_NAME);
                    }

                    Player currentPlayer = new Player(playerName, playerMoves);
                    scoreboard.AddPlayer(currentPlayer);

                    this.renderer.RenderScoreboard(scoreboard);
                    return;
                }

                this.renderer.Print(CommonConstants.NUMBER_TO_MOVE);
                inputString = this.inputReader.Read();

                switch (inputString)
                {
                case "exit":
                    currentCommand = new ExitCommand(this.renderer, this);
                    break;

                case "restart":
                    currentCommand = new RestartCommand(this);
                    break;

                case "top":
                    currentCommand = new ShowScoreboardCommand(this.renderer, scoreboard);
                    break;

                default:
                    currentCommand = new DefaultCommand(currentMatrix, this.renderer, emptyPoint, inputString);
                    break;
                }

                currentCommand.Execute();

                if (currentCommand is DefaultCommand && (currentCommand as DefaultCommand).IsPlayerMoved)
                {
                    playerMoves++;
                }
            }
        }
        /// <summary>
        /// Main method of the program.
        /// </summary>
        public static void Main()
        {
            List <Tile> tilesMatrix    = new List <Tile>();
            int         movesCount     = 0;
            string      currentCommand = "restart";
            bool        isMatrixSolved = false;

            while (currentCommand != "exit")
            {
                if (!isMatrixSolved)
                {
                    switch (currentCommand)
                    {
                    case "restart":
                    {
                        string welcomeMessage = "Welcome to the game “15”. Please try to arrange the numbers sequentially." +
                                                "\nUse 'top' to view the top scoreboard, 'restart' to start a new game and 'exit'\nto quit the game.";
                        Console.WriteLine();
                        Console.WriteLine(welcomeMessage);
                        tilesMatrix    = MatrixGenerator.GenerateMatrix();
                        tilesMatrix    = MatrixGenerator.ShuffleMatrix(tilesMatrix);
                        isMatrixSolved = Gameplay.IsMatrixSolved(tilesMatrix);
                        Console.WriteLine(Gameplay.GetMatrixAsString(tilesMatrix));
                        break;
                    }

                    case "top":
                    {
                        Console.WriteLine(Scoreboard.PrintScoreboard());
                        break;
                    }
                    }

                    Console.Write("Enter a number to move: ");
                    currentCommand = Console.ReadLine();

                    int  tileLabel;
                    bool isMovingCommand = int.TryParse(currentCommand, out tileLabel);

                    if (isMovingCommand)
                    {
                        try
                        {
                            Gameplay.MoveTiles(tilesMatrix, tileLabel);
                            movesCount++;
                            Console.WriteLine(Gameplay.GetMatrixAsString(tilesMatrix));
                            isMatrixSolved = Gameplay.IsMatrixSolved(tilesMatrix);
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine(exception.Message);
                        }
                    }
                    else
                    {
                        currentCommand = currentCommand.ToLower();
                        if (!Enum.GetNames(typeof(Command)).Any(x => x.ToLower().Equals(currentCommand)))
                        {
                            Console.WriteLine("Invalid command");
                        }
                    }
                }
                else
                {
                    if (movesCount == 0)
                    {
                        Console.WriteLine("Your matrix was solved by default :) Come on - NEXT try");
                    }
                    else
                    {
                        Console.WriteLine("Congratulations! You won the game in {0} moves.", movesCount);
                        if (Scoreboard.CheckPlayerScores(movesCount))
                        {
                            Console.Write("Please enter your name for the top scoreboard: ");
                            string playerName = Console.ReadLine();
                            Player player     = new Player(playerName, movesCount);
                            Scoreboard.AddPlayer(player);
                        }
                        else
                        {
                            Console.WriteLine("Your scores are not at top five.");
                        }

                        Console.WriteLine(Scoreboard.PrintScoreboard());
                    }

                    currentCommand = "restart";
                    isMatrixSolved = false;
                    movesCount     = 0;
                }
            }
        }