Ejemplo n.º 1
0
        public Player()
        {
            Players++;
            switch (Players)
            {
            case 1:
                color = Color.Red;
                break;

            case 2:
                color = Color.Yellow;
                break;

            case 3:
                color = Color.Green;
                break;

            case 4:
                color = Color.Blue;
                break;

            case 5:
                throw new Exception("Too many players. Only 4 allowed");
            }
            Dice d = new Dice();

            startValue = d.Roll();
            Pawn Pawn1 = new Pawn();

            Pawns.Add(Pawn1);
            Pawn Pawn2 = new Pawn();

            Pawns.Add(Pawn2);
            Pawn Pawn3 = new Pawn();

            Pawns.Add(Pawn3);
            Pawn Pawn4 = new Pawn();

            Pawns.Add(Pawn4);
        }
Ejemplo n.º 2
0
        static Player DetermineStarter(List <Player> playerList)
        {
            // Sort the Players list by startValue in descending order
            playerList.Sort((p1, p2) => {
                return(p2.StartValue - p1.StartValue);
            });

            if (playerList[0].StartValue == playerList[1].StartValue)
            {
                List <Player> rePlayers = new List <Player>()
                {
                    playerList[0],
                    playerList[1]
                };
                if (playerList.Count > 2)
                {
                    if (playerList[1].StartValue == playerList[2].StartValue)
                    {
                        rePlayers.Add(playerList[2]);

                        if (playerList.Count > 3)
                        {
                            if (playerList[2].StartValue == playerList[3].StartValue)
                            {
                                rePlayers.Add(playerList[3]);
                            }
                        }
                    }
                }
                Dice d = new Dice();
                foreach (Player p in rePlayers)
                {
                    p.StartValue = d.Roll();
                }

                return(DetermineStarter(rePlayers));
            }
            return(playerList[0]);
        }
Ejemplo n.º 3
0
        private void Turn()
        {
            int    throwCounter  = 0;
            string diceResult    = "";
            Player currentPlayer = players[TurnCounter % players.Count];
            bool   extraThrow    = false;

            SetColour(currentPlayer);
            Console.WriteLine(string.Format("Current player is the {0} player", currentPlayer.color));
            writeCurrentPosition(currentPlayer);

            /*&& diceResult != "Globe" && diceResult != "6" &&*/
            /*&& diceResult != "Globe" && diceResult != "6" &&*/
            if (TokensInPlay(currentPlayer) < 1)
            {
                while (TokensInPlay(currentPlayer) < 1 && throwCounter < 3) //|| diceResult != "Globe" && diceResult != "6" && throwCounter < 1)
                {
                    Console.WriteLine("Press any button to throw the dice");
                    Console.ReadKey(true);
                    diceResult = dice.Roll();
                    Console.WriteLine(string.Format("you rolled a '{0}' ", diceResult));
                    if (diceResult == "Globe" || diceResult == "6")
                    {
                        Console.WriteLine("Which token would you like to move(use the 1, 2, 3 or 4 key)");
                        switch (Console.ReadKey(true).KeyChar)
                        {
                        case '1':
                            currentPlayer.tokens[0].Move(diceResult, board);
                            break;

                        case '2':
                            currentPlayer.tokens[1].Move(diceResult, board);
                            break;

                        case '3':
                            currentPlayer.tokens[2].Move(diceResult, board);
                            break;

                        case '4':
                            currentPlayer.tokens[3].Move(diceResult, board);
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("no possible moves, throw again");
                    }

                    throwCounter++;
                    if (diceResult == "Globe" || diceResult == "6")
                    {
                        writeCurrentPosition(currentPlayer);
                    }
                }
            }
            else if (TokensInPlay(currentPlayer) >= 1)
            {
                while (throwCounter < 1)
                {
                    Console.WriteLine("Press any button to throw the dice");
                    Console.ReadKey(true);
                    diceResult = dice.Roll();
                    Console.WriteLine(string.Format("you rolled a '{0}' ", diceResult));
                    Console.WriteLine("Which token would you like to move(use the 1, 2, 3 or 4 key)");

                    switch (Console.ReadKey(true).KeyChar)
                    {
                    case '1':
                        currentPlayer.tokens[0].Move(diceResult, board);
                        break;

                    case '2':
                        currentPlayer.tokens[1].Move(diceResult, board);
                        break;

                    case '3':
                        currentPlayer.tokens[2].Move(diceResult, board);
                        break;

                    case '4':
                        currentPlayer.tokens[3].Move(diceResult, board);
                        break;
                    }
                    if (diceResult == "Globe" || diceResult == "6")
                    {
                        extraThrow = true;
                    }
                    switch (extraThrow)
                    {
                    case true:
                        throwCounter = 0;
                        break;

                    case false:
                        throwCounter++;
                        break;
                    }
                    writeCurrentPosition(currentPlayer);
                }
            }

            TurnCounter++;
            Console.WriteLine("press a key to end your turn");
            Console.ReadKey(true);
            Console.ForegroundColor = ConsoleColor.White;
        }