/// <summary> /// Adds a piece to the grid, with ownership given by <paramref name="belongsToPlayer1"/>, type <paramref name="typeOfPiece"/> and location <paramref name="location"/> /// </summary> /// <param name="belongsToPlayer1">Ownership bool, true for player1</param> /// <param name="typeOfPiece">Type of piece</param> /// <param name="location">Location of piece</param> public void AddPiece(bool belongsToPlayer1, string typeOfPiece, int location) { ///sets the piece to the correct type given by typeOfPiece Piece newPiece; if (typeOfPiece == "Baron") { newPiece = new BaronPiece(belongsToPlayer1); } else if (typeOfPiece == "LESS") { newPiece = new LESSPiece(belongsToPlayer1); } else if (typeOfPiece == "PBDS") { newPiece = new PBDSPiece(belongsToPlayer1); } else { newPiece = new Piece(belongsToPlayer1); } //adds to pieces and set tile pieces.Add(newPiece); tiles[location].SetPiece(newPiece); }
/// <summary> /// Executes an upgrade command given by <paramref name="items"/> /// </summary> /// <param name="items">Command</param> /// <param name="lumberAvailable">Lumber available</param> /// <returns>Int representing lumber cost, -1 for invalid</returns> private int ExecuteUpgradeCommand(List <string> items, int lumberAvailable) { //gets the tile, checks if it's valid, more than 5 lumber available and piece is either pbds or less int tileToUse = Convert.ToInt32(items[2]); if (!CheckPieceAndTileAreValid(tileToUse) || lumberAvailable < 5 || !(items[1] == "pbds" || items[1] == "less")) { return(-1); } else { //fetches piece from grid Piece thePiece = tiles[tileToUse].GetPieceInTile(); //if piece isn't "S", invalid if (thePiece.GetPieceType().ToUpper() != "S") { return(-1); } //destroy the piece and create a new one given by second command item thePiece.DestroyPiece(); if (items[1] == "pbds") { thePiece = new PBDSPiece(player1Turn); } else { thePiece = new LESSPiece(player1Turn); } //add the new piece, and set the tile to it pieces.Add(thePiece); tiles[tileToUse].SetPiece(thePiece); //return 5 - for lumber cost return(5); } }