public Board CreateBoard() { String line = ""; String[] strValues; int[] intValues; StreamReader stmReader; Char delimitChar = ','; Board resultBoard; ui.UIDebug("Attempting to create board..."); try{ stmReader = new StreamReader(mBoardPath); resultBoard = new Board(); ui.UIDebug("Board stream initalized!"); for (int i = 1; i <= resultBoard.BoardSpaces.Length - 1; i++) { line = stmReader.ReadLine(); strValues = line.Split(delimitChar); intValues = new int[strValues.Length]; //create int array for int values such as rent, mortagage, etc for (int j = 0; j <= strValues.Length - 1; j++) { try { intValues[j] = int.Parse(strValues[j]); }//try catch (FormatException ex) { intValues[j] = 0; ex.GetType(); }//catch }//for //ugly switch, need to revise in the future switch (strValues[0]) { case "Property": Rent tempRent = new Rent(intValues[5], intValues[6], intValues[7], intValues[8], intValues[9], intValues[10]); Tiles.Property thisProp = new Tiles.Property(intValues[2], strValues[1], (PropertyColor)intValues[4], intValues[3], tempRent, intValues[11]); resultBoard.BoardSpaces[i] = thisProp; //add the property to the proper color group, see Enums for more details resultBoard.ColorGroups[(int)thisProp.Color].AddProperty(thisProp); break; case "Railroad": resultBoard.BoardSpaces[i] = new Tiles.Railroad(intValues[2], strValues[1]); break; case "Utility": resultBoard.BoardSpaces[i] = new Tiles.Utility(intValues[2], strValues[1]); break; case "LuxuryTax": resultBoard.BoardSpaces[i] = new Tiles.LuxuryTax(intValues[2], strValues[1]); break; case "IncomeTax": resultBoard.BoardSpaces[i] = new Tiles.IncomeTax(intValues[2], strValues[1]); break; case "CommunityChest": resultBoard.BoardSpaces[i] = new Tiles.CommunityChest(intValues[2], strValues[1]); break; case "Chance": resultBoard.BoardSpaces[i] = new Tiles.Chance(intValues[2], strValues[1]); break; case "Go": resultBoard.BoardSpaces[i] = new Tiles.Go(intValues[2], strValues[1]); break; case "GoToJail": resultBoard.BoardSpaces[i] = new Tiles.GoToJail(intValues[2], strValues[1]); break; case "Jail": resultBoard.BoardSpaces[i] = new Tiles.Jail(intValues[2], strValues[1]); break; case "FreeParking": resultBoard.BoardSpaces[i] = new Tiles.FreeParking(intValues[2], strValues[1]); break; default: ui.Error("The BoardReader was unable to determine space type!"); break; }//switch }//for }//try (open streamreader) catch (FileNotFoundException ex){ ui.Error("Stream couldn't be found.", ex); return null; }//catch FileNotFound (streamreader) return resultBoard; }
//used when pre-defining colorgroups public ColorGroup(PropertyColor groupColor, Tiles.Property prop1, Tiles.Property prop2) { this.GroupColor = groupColor; Tiles.Property[] props = new Tiles.Property[2] { prop1, prop2 }; AddPropertiesByArray(props); }
//used when pre-defining colorgroups public ColorGroup(PropertyColor propertyColor, Tiles.Property prop1, Tiles.Property prop2, Tiles.Property prop3) { this.GroupColor = propertyColor; Tiles.Property[] props = new Tiles.Property[3] { prop1, prop2, prop3 }; AddPropertiesByArray(props); }
public void TestNewPropClass() { Tiles.Property prop = new Tiles.Property(5, "testprop", PropertyColor.Brown, 5, new Rent(1, 2, 3, 4, 5, 6), 7); UI.UIDebug(prop.ToString()); Tiles.BuyableSpace buyablespace = prop; UI.UIDebug("buyspace cost: " + buyablespace.Cost); Tiles.BoardSpace boardspace = prop; UI.UIDebug("boardspace name: " + boardspace.Name); }