Exemplo n.º 1
0
        public void GameOfCards_Dealer_Vs_Player_And_Player_ShouldWin()
        {
            var player = new Player();
            var dealer = new Dealer();

            var scoreboard = new ScoreBoard();

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

            var sut = new GameOfCards(scoreboard);

            var times = sut.CurrentDeck.Count;

            for (int i = 0; i < times; i++)
            {
                sut.DealTo(dealer);
                sut.DealTo(player);
                sut.DealTo(player);
                sut.DealTo(player);
            }

            Assert.IsFalse(sut.CanStillDeal);
            Assert.IsTrue(sut.CurrentDeck.Count is 24);
            Assert.IsTrue(scoreboard.IsGameOver is true);
            Assert.AreEqual(player, scoreboard.Winner);
        }
 public void AddPlayerScoreTest()
 {
     string playerName = "Pesho";
     int playerScore = 20;
     var scoreBoard = new ScoreBoard();
     scoreBoard.AddPlayer(playerName, playerScore);
     Assert.AreEqual(true, scoreBoard.scoreBoard.ContainsKey(playerScore));
 }
        public void AddZeroPlayerScoreTest()
        {
            string playerName = "Pesho";
            int playerScore = 0;

            var newScoreBoard = new ScoreBoard();
            newScoreBoard.AddPlayer(playerName, playerScore);
            Assert.AreEqual("0", newScoreBoard.scoreBoard.ContainsKey(playerScore).ToString());
        }
        public void AddNegativePlayerScoreTest()
        {
            string playerName = "Pesho";
            int playerScore = -1;

            var newScoreBoard = new ScoreBoard();
            newScoreBoard.AddPlayer(playerName, playerScore);
            Assert.AreEqual("Enter your name, please", newScoreBoard.scoreBoard.Contains(playerScore, playerName));
        }
Exemplo n.º 5
0
    void StartGame()
    {
        Debug.Log("Starting the game");
        view.enabled = false;
        GameObject player = SpawnPlayer();

        scoreBoard.enabled = true;
        scoreBoard.AddPlayer(view.MyName, player.networkView.owner.guid);

        string serializedData = scoreBoard.Serialize();

        //Debug.Log ("Sending data : " + serializedData);
        networkView.RPC("SetPlayerScores", RPCMode.Others, serializedData);
    }
        public void AddEmptyPlayerNameTest()
        {
            var output = new StringBuilder();
            var textWriter = new StringWriter(output);
            Console.SetOut(textWriter);

            string playerName = "";
            int playerScore = 20;
            var newScoreBoard = new ScoreBoard();
            newScoreBoard.AddPlayer(playerName, playerScore);

            string outputStr = output.ToString();

            Assert.AreEqual("Enter your name, please\r\n", outputStr);
        }
Exemplo n.º 7
0
        public void GameOfCards_CurrentDeck_ShouldRemoveSelectedCard1()
        {
            var sut = new ScoreBoard();

            sut.AddPlayer(new Player());
        }
        public void MakeMove(int row, int col)
        {
            if (playerMatrix[row, col] != Constants.Symbol)
            {
                renderer.WriteLine("Illegal move!");
                return;
            }

            if (matrix[row, col] == Constants.MinesSymbol)
            {
                for (int i = 0; i < matrix.GetLength(0); i++)
                {
                    for (int j = 0; j < matrix.GetLength(1); j++)
                    {
                        if (matrix[i, j] == Constants.MinesSymbol)
                        {
                            playerMatrix[i, j] = Constants.MinesSymbol;
                            continue;
                        }

                        if (playerMatrix[i, j] == Constants.Symbol)
                        {
                            playerMatrix[i, j] = Constants.EmptySymbol;
                        }
                    }
                }

                PrintMatrix(playerMatrix);
                gameInProgress = false;

                renderer.WriteLine("");
                renderer.WriteLine(String.Format("Booooom! You were killed by a mine. You revealed {0} cells without mines.", cellsOpened));

                if (scoreBoard.TopListCount() == 0)
                {
                    var newPlayer = new Player(String.Empty, new int());
                    scoreBoard.AddPlayer(newPlayer);
                    topList.Add(newPlayer);
                    emptyScoreboard = false;
                    //gameInProgress = true;
                }
                else
                {
                    var newPlayer = new Player(String.Empty, new int());
                    newPlayer.Place = topList.Count;
                    scoreBoard.AddPlayer(newPlayer);
                    emptyScoreboard = false;
                    topList.Add(newPlayer);

                    //player.Place++;
                }

                foreach (var player in topList)
                {
                    if (cellsOpened >= player.Score)
                    {
                        player.Score = cellsOpened;

                        renderer.Write("Please enter your name for the top scoreboard: ");
                        string playerName = Console.ReadLine();

                        player.Name = playerName;

                        if (emptyScoreboard || scoreBoard.TopListCount() == 6)
                        {
                            scoreBoard.RemovePlayer(scoreBoard.TopListCount() - 1);
                            emptyScoreboard = false;
                        }

                        playerAddedToScoreboard = true;
                        gameInProgress          = true;
                        break;
                    }
                }

                foreach (var player in topList)
                {
                    if (!playerAddedToScoreboard && player.Score < 5)
                    {
                        player.Score = cellsOpened;
                        renderer.Write("Please enter your name for the top scoreboard: ");
                        string playerName = Console.ReadLine();
                        player.Name = playerName;
                    }
                }

                playerAddedToScoreboard = false;
                scoreBoard.Print();
                Start();
            }
            else
            {
                cellsOpened++;
                if (cellsOpened == Constants.MaxScore)
                {
                    PrintMatrix(matrix);
                    renderer.WriteLine("Congratulations! You revealed all cells without mines!");

                    gameInProgress = false;

                    renderer.Write("Please enter your name for the top scoreboard: ");
                    string playerName = Console.ReadLine();
                    topList.Add(new Player(playerName, Constants.MaxScore));

                    if (scoreBoard.GetPlayers().Count == 6)
                    {
                        scoreBoard.RemovePlayer(5);
                    }

                    scoreBoard.Print();
                    Start();
                    return;
                }

                playerMatrix[row, col] = matrix[row, col];
                PrintMatrix(playerMatrix);
            }
        }
Exemplo n.º 9
0
    public void PlayMines()
    {
        ScoreBoard scoreBoard = new ScoreBoard();
        Random randomMines;
        string[,] minichki;
        int row;
        int col;
        int minesCounter;
        int revealedCellsCounter;
        bool isBoomed;
        // oxo glei glei
        // i go to si imam :)
        start:
        Zapochni(out minichki, out row, out col,
            out isBoomed,out minesCounter,out randomMines,out revealedCellsCounter);

        FillWithRandomMines(minichki, randomMines);

        PrintInitialMessage();

        while (true)
        {
            Display(minichki, isBoomed);
            enterRowCol:
            Console.Write("Enter row and column: ");
            string line = Console.ReadLine();
            line = line.Trim();

            if (IsMoveEntered(line))
            {
                string[] inputParams = line.Split();
                row = int.Parse(inputParams[0]);
                col = int.Parse(inputParams[1]);

                if ((row >= 0) && (row < minichki.GetLength(0)) && (col >= 0) && (col < minichki.GetLength(1)))
                {
                    bool hasBoomedMine = Boom(minichki, row, col);
                    if (hasBoomedMine)
                    {
                        isBoomed = true;
                        Display(minichki, isBoomed);
                        Console.Write("\nBooom! You are killed by a mine! ");
                        Console.WriteLine("You revealed {0} cells without mines.",revealedCellsCounter);

                        Console.Write("Please enter your name for the top scoreboard: ");
                        string currentPlayerName = Console.ReadLine();
                        scoreBoard.AddPlayer(currentPlayerName, revealedCellsCounter);

                        Console.WriteLine();
                        goto start;
                    }
                    bool winner = PichLiSi(minichki, minesCounter);
                    if (winner)
                    {
                        Console.WriteLine("Congratulations! You are the WINNER!\n");

                        Console.Write("Please enter your name for the top scoreboard: ");
                        string currentPlayerName = Console.ReadLine();
                        scoreBoard.AddPlayer(currentPlayerName, revealedCellsCounter);

                        Console.WriteLine();
                        goto start;
                    }
                    revealedCellsCounter++;
                }
                else
                {
                    Console.WriteLine("Enter valid Row/Col!\n");
                }
            }
            else if (proverka(line))
            {
                switch (line)
                {
                    case "top":
                        {
                            scoreBoard.PrintScoreBoard();
                            goto enterRowCol;
                        }
                    case "exit":
                        {
                            Console.WriteLine("\nGood bye!\n");
                            Environment.Exit(0);
                            break;
                        }
                    case "restart":
                        {
                            Console.WriteLine();
                            goto start;
                        }
                }
            }
            else
            {
                Console.WriteLine("Invalid Command!");
            }
        }
    }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            Console.Write("TiME tO pLaY!\r\n\r\nEnter your name: ");

            var username = Console.ReadLine();
            var player   = new Player(username);

            var dealer     = new Dealer("Dealer");
            var scoreboard = new ScoreBoard();

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

            Console.WriteLine("\r\nHello {0}" +
                              "\r\nRuLEs:" +
                              "\r\n* You only have 21 liVes." +
                              "\r\n* The Dealer only have 17 liVes." +
                              "\r\n* Game ends as soon as ones lives are done." +
                              "\r\n" +
                              "\r\n" +
                              "Play Directions:" +
                              "\r\no Press Y to play your turn." +
                              "\r\no Press D to give the Dealer a play turn.", username);

            Console.WriteLine("\r\n\r\nReaDy tO pLaY?\r\n> Press Y to start playing.\r\n> Press Enter to exit the game");
            var startGameKey = Console.ReadKey();

            if (startGameKey.Key == ConsoleKey.Y)
            {
                var game = new GameOfCards(scoreboard);

                game.DealTo(player);
                Console.WriteLine("\r\nYour score: {0}\r\nNumber of Plays: {1}", player.Score, player.Hand.Count);

                do
                {
                    Console.Write("\r\n\r\nPlay again? Y/D: ");

                    var hand      = player.Hand;
                    var playAgain = Console.ReadKey();
                    if (playAgain.Key == ConsoleKey.Y)
                    {
                        game.DealTo(player);
                        Console.WriteLine("\r\nYour score: {0}\r\nNumber of Plays: {1}", player.Score, hand.Count);
                    }
                    else if (playAgain.Key == ConsoleKey.D)
                    {
                        game.DealTo(dealer);
                        Console.WriteLine("\r\nDealer score: {0}\r\nNumber of Plays: {1}", dealer.Score, dealer.Hand.Count);
                    }
                } while (!scoreboard.IsGameOver);

                Console.WriteLine("\r\nGAmE OvEr!!!");

                if (scoreboard.Winner == player)
                {
                    Console.WriteLine("\r\n\r\nYoU wOn!!!\r\n\r\nYour score: {0}\r\nNumber of Plays: {1}", player.Score, player.Hand.Count);
                }
                else
                {
                    Console.WriteLine("DeAlEr wOn!!!\r\nDealer score: {0}\r\nNumber of Plays: {1}", dealer.Score, dealer.Hand.Count);
                }
                Console.ReadLine();
            }
            Console.WriteLine("See you again, sOOn!");
        }
Exemplo n.º 11
0
    public void PlayMines()
    {
        ScoreBoard scoreBoard = new ScoreBoard();
        Random     randomMines;

        string[,] minichki;
        int  row;
        int  col;
        int  minesCounter;
        int  revealedCellsCounter;
        bool isBoomed;

        // oxo glei glei
        // i go to si imam :)
start:
        Zapochni(out minichki, out row, out col,
                 out isBoomed, out minesCounter, out randomMines, out revealedCellsCounter);

        FillWithRandomMines(minichki, randomMines);

        PrintInitialMessage();

        while (true)
        {
            Display(minichki, isBoomed);
enterRowCol:
            Console.Write("Enter row and column: ");
            string line = Console.ReadLine();
            line = line.Trim();

            if (IsMoveEntered(line))
            {
                string[] inputParams = line.Split();
                row = int.Parse(inputParams[0]);
                col = int.Parse(inputParams[1]);

                if ((row >= 0) && (row < minichki.GetLength(0)) && (col >= 0) && (col < minichki.GetLength(1)))
                {
                    bool hasBoomedMine = Boom(minichki, row, col);
                    if (hasBoomedMine)
                    {
                        isBoomed = true;
                        Display(minichki, isBoomed);
                        Console.Write("\nBooom! You are killed by a mine! ");
                        Console.WriteLine("You revealed {0} cells without mines.", revealedCellsCounter);

                        Console.Write("Please enter your name for the top scoreboard: ");
                        string currentPlayerName = Console.ReadLine();
                        scoreBoard.AddPlayer(currentPlayerName, revealedCellsCounter);

                        Console.WriteLine();
                        goto start;
                    }
                    bool winner = PichLiSi(minichki, minesCounter);
                    if (winner)
                    {
                        Console.WriteLine("Congratulations! You are the WINNER!\n");

                        Console.Write("Please enter your name for the top scoreboard: ");
                        string currentPlayerName = Console.ReadLine();
                        scoreBoard.AddPlayer(currentPlayerName, revealedCellsCounter);

                        Console.WriteLine();
                        goto start;
                    }
                    revealedCellsCounter++;
                }
                else
                {
                    Console.WriteLine("Enter valid Row/Col!\n");
                }
            }
            else if (proverka(line))
            {
                switch (line)
                {
                case "top":
                {
                    scoreBoard.PrintScoreBoard();
                    goto enterRowCol;
                }

                case "exit":
                {
                    Console.WriteLine("\nGood bye!\n");
                    Environment.Exit(0);
                    break;
                }

                case "restart":
                {
                    Console.WriteLine();
                    goto start;
                }
                }
            }
            else
            {
                Console.WriteLine("Invalid Command!");
            }
        }
    }