/// <summary> /// /// Initialises a board consisting of a mix of Ordinary Squares, /// Bad Investment Squares and Lottery Win Squares. /// The board has two 'non-board' squares: /// a start square; and /// a finish square. /// This is to comply with the Hare and Tortoise requirements. /// The start square is to be used for initialisation, play is not yet on the board. /// The finish square is to be used for termination, players cannot move past this square. /// Pre: none /// Post: board is constructed with each /// </summary> public static void SetUpBoard() { // Create the start square squares[START_SQUARE_NUMBER] = new Square(START_SQUARE_NUMBER, "Start"); // Create the 40 squares which make up the board // some of the squares will be LotteryWinSquares, // others will be BadInvestmentsSquares // with most bwing just ordinary squares for (int i = START_SQUARE_NUMBER + 1; i <= NUMBER_OF_SQUARES; i++) { squares[i] = new Square(i, "Ordinary"); if (i % 5 == 0 && i % 10 != 0) { squares[i] = new Square(i, "Bad Investment"); } else if (i % 10 == 0) { squares[i] = new Square(i, "Lottery Win"); } } //Create the finish square squares[FINISH_SQUARE_NUMBER] = new Square(FINISH_SQUARE_NUMBER, "Finish"); }
/// <summary> /// Constructor with initialising parameters. /// Pre: parameters square and players are both not null. /// Post: initialised object. /// </summary> /// <param name="square">The corresponding Square object, /// in the Board class of the SharedGameClasses.</param> /// <param name="players"The list of players,> /// in the Board class of the SharedGameClasses.</param> public SquareControl(Square square, BindingList<Player> players) { this.square = square; this.players = players; // Set GUI properties of the whole square. Size = new Size(SQUARE_SIZE, SQUARE_SIZE); Margin = new Padding(0); // No spacing around the cell. (Default is 3 pixels.) Dock = DockStyle.Fill; BorderStyle = BorderStyle.FixedSingle; BackColor = Color.CornflowerBlue; LoadImageWhenNeeded(); }
private Square[] squares = new Square[NUMBER_OF_SQUARES + 2]; // The array of squares. #endregion Fields #region Constructors /// <summary> /// Parameterless Constructor /// Initialises a board consisting of a mix of Ordinary Squares, /// Bad Investment Squares and Lottery Win Squares. /// The board has two 'non-board' squares: /// a start square; and /// a finish square. /// This is to comply with the Hare and Tortoise requirements. /// The start square is to be used for initialisation, play is not yet on the board. /// The finish square is to be used for termination, players cannot move past this square. /// Pre: none /// Post: board is constructed /// </summary> public Board() { //fill all squares for (int i = 0; i < squares.Length; i++) { Square square; if (i == START_SQUARE_NUMBER) { square = new Square(this,i,"Start"); } else if (i == FINISH_SQUARE_NUMBER) { square = new Square(this,i,"Finish"); } else { if (i % 10 == 0) //check squre is lotteryWinSquare { square = new LotteryWinSquare(this, i, (i + 1).ToString()); } else { if (i % 5 == 0) //check sqare is lose { square = new BadInvestmentSquare(this, i, (i + 1).ToString()); } else { square = new Square(this, i, (i + 1).ToString()); } } } squares[i] = square; } }
/// <summary> /// Creates each SquareControl and adds it to the boardTableLayoutPanel that displays the board. /// Pre: none. /// Post: the boardTableLayoutPanel contains all the SquareControl objects for displaying the board. /// </summary> private void SetupGameBoard() { // ########################### Code needs to be written to perform the following ############################################### /* * taking each Square of Baord separately create a SquareContol object containing that Square (look at the Constructor for SquareControl) * * when it is either the Start Square or the Finish Square set the BackColor of the SquareControl to BurlyWood * * DO NOT set the BackColor of any other Square Control * * Call MapSquareNumtoScreenRowAnd Column to determine the row and column position of the SquareControl on the TableLayoutPanel * * Add the Control to the TaleLayoutPanel * */ for (int i = Board.START_SQUARE_NUMBER; i <= Board.FINISH_SQUARE_NUMBER; i++) { Square square = new Square(Board.Squares[i].Number, Board.Squares[i].Name); SquareControl squareControl = new SquareControl(square, HareAndTortoiseGame.Players); if (square.Number == Board.START_SQUARE_NUMBER || square.Number == Board.FINISH_SQUARE_NUMBER) { squareControl.BackColor = Color.BurlyWood; } int row; int col; MapSquareNumToScreenRowAndColumn(i, out row, out col); boardTableLayoutPanel.Controls.Add(squareControl, col, row); } }
/// <summary> /// Constructor with initialising parameters. /// Pre: name to be used for this player. /// Post: this player object has all attributes initialised /// </summary> /// <param name="name">Name for this player</param> public Player(String name, Square initialLocation) { //######################### Code needs to be added here ########################################## this.name = name; this.location = initialLocation; }
/// <summary> /// Moves player the required number of squares forward /// Pre: the number of squares to move forward /// Post: the player is moved along the board. /// NOTE: Refer to Square.cs regarding the NextSquare property. /// </summary> /// <param name="numberOfSquares">the number of squares to move</param> private void Move(int numberOfSquares) { //######################### Code needs to be added here ##########################################3 for (int i = 0; i < numberOfSquares; i++) { if (location.Number < Board.FINISH_SQUARE_NUMBER) { location = location.NextSquare; } else { HareAndTortoiseGame.DetermineWinner(); } } }
} // end Player constructor /// <summary> /// Constructor with initialising parameters. /// Pre: name to be used for this player. /// Post: this player object has all attributes initialised /// </summary> /// <param name="name">Name for this player</param> public Player(String name, Square initialLocation) { //######################### Code needs to be added here ########################################## this.name = name; this.location = initialLocation; } // end Player constructor
/// <summary> /// Constructor with initialising parameters. /// Pre: name to be used for this player. /// Post: initialised object /// </summary> /// <param name="name">Name for this player</param> public Player(String name, Square initialLocation) { this.name = name; this.location = initialLocation; }
/// Sets the location of the player (mutator). /// Pre: a square to be used as the player's current location. /// Post: sets the player to a location on the board, /// if the location was 'start', the player's amount was also /// reset to the start amount. public void ResetToLocation(Square square) { location = square; }
/// <summary> /// Moves player the required number of squares forward /// Pre: the number of squares to move forward /// Post: the player is moved along the board. /// NOTE: Refer to Square.cs regarding the NextSquare property. /// </summary> /// <param name="numberOfSquares">the number of squares to move</param> public void Move(int numberOfSquares) { for (int i = 0; i < numberOfSquares; i++) { location = location.NextSquare; //stop move if current payer land on finish square if (location.Number == Board.FINISH_SQUARE_NUMBER) { return; } } }
/// <summary> /// Constructor with initialising parameters. /// Pre: name to be used for this player. /// Post: initialised object /// </summary> /// <param name="name">Name for this player</param> public Player(String name, Square initialLocation) { Name = name; Location = initialLocation; Money = INITIAL_AMOUNT; }
/// Sets the location of the player (mutator). /// Pre: a square to be used as the player's current location. /// Post: sets the player to a location on the board, /// if the location was 'start', the player's amount was also /// reset to the start amount. public void ResetToLocation(Square square) { }