/// <summary> /// Simulates that the user's board broke in a competition . If a board breaks it gets removed from the storage . /// </summary> /// <param name="competitor"></param> public void BrokeBoard(Skateboard competitor) { var rand = new Random(); if (rand.Next(0, 5) == 0) { TimeSpan ts = new TimeSpan(0, 0, 3); UI.Printer($"Your board just broke into a million pieces. RIP {competitor.name}"); Thread.Sleep(ts); DeleteSkateboard(competitor.name); Save(); } }
/// <summary> /// Loads the user created skateboards from an xml. /// </summary> /// <param name="fileName"></param> public void LoadXML(string fileName = "inventory.xml") { XElement element = XElement.Load(fileName); var partNodes = element.Elements("Skateboard"); foreach (var node in partNodes) { var skateboard = new Skateboard(); var wheel = new Hardware.Wheels(); var truck = new Hardware.Truck(); var griptape = new Hardware.Griptape(); var deck = new Hardware.Deck(); var bearings = new Hardware.Bearings(); skateboard.name = node.Element("name").Value; var wheelNode = new XElement(node.Element("wheel")); wheel.brand = wheelNode.Element("brand").Value; wheel.size = Convert.ToInt32(wheelNode.Element("size").Value); wheel.hardness = wheelNode.Element("hardness").Value; var truckNode = new XElement(node.Element("truck")); truck.brand = truckNode.Element("brand").Value; truck.size = float.Parse(truckNode.Element("size").Value, CultureInfo.InvariantCulture.NumberFormat); var griptapeNode = new XElement(node.Element("griptape")); griptape.brand = griptapeNode.Element("brand").Value; var deckNode = new XElement(node.Element("deck")); deck.brand = deckNode.Element("brand").Value; deck.width = float.Parse(deckNode.Element("width").Value, CultureInfo.InvariantCulture.NumberFormat); deck.length = float.Parse(deckNode.Element("length").Value, CultureInfo.InvariantCulture.NumberFormat); var bearingsNode = new XElement(node.Element("bearings")); bearings.brand = bearingsNode.Element("brand").Value; bearings.type = bearingsNode.Element("type").Value; skateboard.wheel = wheel; skateboard.truck = truck; skateboard.griptape = griptape; skateboard.deck = deck; skateboard.bearings = bearings; Skateboards.Add(skateboard); } }
/// <summary> /// Simulates a competition . Returns true if the competitor won. /// </summary> /// <param name="storage"></param> /// <param name="competitor"></param> /// <returns></returns> public abstract bool Race(Storage storage, Skateboard competitor);
/// <summary> /// Creates a new skateboard instance, with parts chosen by the user /// </summary> /// <returns></returns> public Skateboard SkateboardAssembly() { Console.Clear(); CsvReader store = new CsvReader(); //Loads hardware from the csv file store.LoadEverything(); Skateboard skateboard = new Skateboard(); //Checks if the given name already exists in the storage. Throws exception if it does. string name; while (true) { try { name = CheckIfBoardNameExists(UI.GetNameOfBoard()); break; } catch (Exceptions.NameExistsException) { UI.PrintErrorMessage("This name already exists."); } } skateboard.name = name; while (true) { Console.Clear(); Hardware.Deck deck = DeckForAssembly(store); try { //Gets the chosen deck from the store and puts it in deckReturnable . Hardware.Deck deckReturnable = (Hardware.Deck)skateboard.PartInStore(store, deck); if (!deckReturnable.Equals(null)) { skateboard.deck = deckReturnable; break; } } catch (NullReferenceException) { UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!"); } } while (true) { Console.Clear(); Hardware.Griptape griptape = GriptapeForAssembly(store); try { Hardware.Griptape griptapeReturnable = (Hardware.Griptape)skateboard.PartInStore(store, griptape); if (!griptapeReturnable.Equals(null)) { skateboard.griptape = griptapeReturnable; break; } } catch (NullReferenceException) { UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!"); } } while (true) { Console.Clear(); Hardware.Truck truck = TruckForAssembly(store); try { Hardware.Truck truckReturnable = (Hardware.Truck)skateboard.PartInStore(store, truck); if (!truckReturnable.Equals(null)) { skateboard.truck = truckReturnable; break; } } catch (NullReferenceException) { UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!"); } } while (true) { Console.Clear(); Hardware.Wheels wheels = WheelsForAssembly(store); try { Hardware.Wheels wheelsReturnable = (Hardware.Wheels)skateboard.PartInStore(store, wheels); if (!wheelsReturnable.Equals(null)) { skateboard.wheel = wheelsReturnable; break; } } catch (NullReferenceException) { UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!"); } } while (true) { Console.Clear(); Hardware.Bearings bearings = BearingsForAssembly(store); try { Hardware.Bearings bearingsReturnable = (Hardware.Bearings)skateboard.PartInStore(store, bearings); if (!bearingsReturnable.Equals(null)) { skateboard.bearings = bearingsReturnable; break; } } catch (NullReferenceException) { UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!"); } } return(skateboard); }
/// <summary> /// Checks if a board is eligible for a competition . Returns true if its eligible. /// </summary> /// <param name="competitor"></param> /// <returns></returns> public abstract bool EligibleForCompetition(Skateboard competitor);