Example #1
0
        private Dice die = new Dice(); //Makes an object of the class 'Dice'

        #endregion

        public Game()
        {
            #if DEBUG
            Debug.WriteLine("DEBUGMODE");
            #endif

            Design.Clear(500);
            this.numberOfPlayers = SetNumberOfPlayers(); //Sets the number of players before the game begins
            CreatePlayers();                             //This method creates the players
            CreateField();                               //Creates the fields used in the game
            GetPlayers();
            Turn();                                      //Begins player one's turn
        }
Example #2
0
        private void CreatePlayers()
        {
            this.players = new Player[this.numberOfPlayers]; //Initializes the players array

            Console.WriteLine();
            for (int i = 0; i < this.numberOfPlayers; i++) //Runs until all users have names
            {
                Design.Clear(300);
                Console.Write("What is the name of player {0}: ", (i + 1)); //Asks for the players name
                string name = Console.ReadLine();                           //saves the name as a temporary variable called 'name'

                Token[] token = TokenAssign(i);                             //Assigns the tokens for the different users

                players[i] = new Player(name, (i + 1), token);              //Initalizes each player in the array

                PrintLog("Player " + i + " name: " + name);
            }
        }
Example #3
0
 //Each players turn
 private void Turn()
 {
     while (true)                                               //Checks if the game is on
     {
         Player turn = players[(playerTurn)];                   //Finds the player in the array
         Design.Clear(delay);
         Console.WriteLine("It is " + turn.Name + "'s turn\n"); //Some 'nice' output
         do
         {
             Console.Write("Press 'K' to roll the die: ");
         }while (Console.ReadKey().KeyChar != 'k');
         Console.WriteLine();
         Design.Clear(delay);
         Console.WriteLine("You got: " + die.ThrowDice());
         Console.WriteLine();
         CanMove(turn); //Checks if the player can move
     }
 }
Example #4
0
        private int SetNumberOfPlayers()
        {
            int numOfPlayers = 0;

            Console.Write("How many players?: ");                                          //Asks for how many players there will be in this game

            while (numOfPlayers < 2 || numOfPlayers > 4)                                   //Checks if there is less than 2 or more than 4
            {
                if (!int.TryParse(Console.ReadKey().KeyChar.ToString(), out numOfPlayers)) //Tries to save the input as 'this.numberOfPlayers'
                {
                    Console.WriteLine();                                                   //Makes a blank space
                    Design.Clear(160);
                    Console.Write("Unknown input, choose between 2 and 4 players: ");
                }
            }

            PrintLog("NumberOfPlayers: " + numOfPlayers);

            return(numOfPlayers);
        }
Example #5
0
        //OPTIMIZE CanMove
        //Checks if the player can move
        private void CanMove(Player turn)
        {
            Token[] tokens = turn.GetTokens();

            int choice = 0; //How many tokens can the player move
            int finish = 0;

            Console.WriteLine("Here are your pieces:");
            Design.WriteLine("", delay);
            foreach (Token tkn in tokens)                                               //Begins to write the tokens of the player
            {
                Console.Write("piece number: " + tkn.Id + " are placed: " + tkn.State); //Writes the id and state of each of the tokens
                switch (tkn.State)                                                      //Begins to check if the player can do anything with his/hers tokens
                {
                case TokenState.Home:
                    if (die.GetValue == 6)
                    {
                        Console.Write(" - Can move");
                        choice++;     //Can move this token AKA a choice
                        tkn.CanMove = true;
                    }
                    else
                    {
                        Console.Write(" - Can not move");
                        tkn.CanMove = false;
                    }
                    break;

                case TokenState.Finished:
                    Console.Write(" <- Is finished");
                    tkn.CanMove = false;
                    finish++;
                    break;

                default:
                    Console.Write(" <- Can move : " + tkn.Position + " ");
                    choice++;
                    tkn.CanMove = true;
                    break;
                }
                Design.WriteLine("", delay);
            }

            if (finish >= 4)
            {
                Finish(turn); //Finishes the game
            }

            Design.WriteLine("<------------------------------------------------>");
            Console.WriteLine(tokens[0].Color.ToString() + " have " + choice.ToString() + " options in this turn\n");

            tries++;

            if (tries < 3 && die.GetValue < 6 && choice == 0)
            {
                Turn();
            }

            tries = 0;

            if (choice == 0) //Cant do anything this turn skips the player
            {
                ChangeTurn();
            }
            else
            {
                MoveToField(players[playerTurn]);
                ChangeTurn();
            }
        }