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 }
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); } }
//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 } }
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); }