public string StartRace(string raceName) { IRace race = this.races.GetByName(raceName); if (race == null) { string msg1 = String.Format(ExceptionMessages.RaceNotFound, raceName); throw new InvalidOperationException(msg1); } if (race.Drivers.Count < 3) { string msg1 = String.Format(ExceptionMessages.RaceInvalid, raceName, 3); throw new InvalidOperationException(msg1); } List <IDriver> drivers = race.Drivers.OrderByDescending(d => d.Car.CalculateRacePoints(race.Laps)).ToList(); StringBuilder sb = new StringBuilder(); sb.AppendLine($"Driver {drivers[0].Name} wins {raceName} race."); sb.AppendLine($"Driver {drivers[1].Name} is second in {raceName} race."); sb.AppendLine($"Driver {drivers[2].Name} is third in {raceName} race."); return(sb.ToString().Trim()); }
public override double CalculateRaceSpeed(IRace race) { var weight = this.Weight + this.CargoWeight; var result = (this.Engine.Output - weight) + (race.OceanCurrentSpeed / 2); return(result); }
public override double CalculateRaceSpeed(IRace race) { var weight = this.Weight + this.CargoWeight; var result = (this.Engine.Output - weight) + (race.OceanCurrentSpeed / 2); return result; }
public static void ValidateRaceIsSet(IRace race) { if (race == null) { throw new NoSetRaceException(Constants.NoSetRaceMessage); } }
public static IRace CreateRaceConfig() { RaceType raceType = (RaceType)Enum.Parse(typeof(RaceType), IRacTypeConfig); IRace iRace = null; switch (raceType) { case RaceType.Human: iRace = new Human(); break; case RaceType.Undead: iRace = new Undead(); break; case RaceType.ORC: iRace = new ORC(); break; case RaceType.NE: iRace = new NE(); break; default: throw new Exception("wrong raceType"); } return(iRace); }
public static void ValidateRaceIsEmpty(IRace race) { if (race != null) { throw new RaceAlreadyExistsException(Constants.RaceAlreadyExistsMessage); } }
static void Main(string[] args) { Console.WriteLine("欢迎大家来到软谋教育.net高级班公开课程"); Human human2 = new Human(); human2.ShowKing(); //IRace human1 = new Human(); IFactoryMethod humanFactory = new HumanFactory(); IRace human = humanFactory.CreateInstance(); human.ShowKing(); //Five five = new Five(); IFactoryMethod fiveFactory = new FiveFactory(); IRace five = fiveFactory.CreateInstance(); five.ShowKing(); Console.Read(); }
public double GetAverageFuelConsumption(IRace Race) { var averageFuelConsumption = 0.0; for (int i=0; i< Race.Waypoints.Count(); i++) { // Check Instruction if not null in case value sent from Unit testing var instruction = Race.Waypoints.ElementAt(i).Instruction ?? WayPointInstructionsHelper.GetWayPointInstruction(Race.Waypoints.ElementAt(i), Race.Waypoints.ToList()); SetCurrentSpeed(instruction); var distance = 0.0; // no need for calculate distance in last wayoint assuming that last point is Race end point if(i != Race.Waypoints.Count() - 1) distance = Race.GetDistanceForLeg(Race.Waypoints.ElementAt(i).Position, Race.Waypoints.ElementAt(i + 1).Position); // What If current Speed not in low or high range How to calculate Consumption ?? if (LowSpeedConsumption.Range.IsWithinRange(this.CurrentSpeed)) averageFuelConsumption += LowSpeedConsumption.Consumption * distance; else if (HighSpeedConsumption.Range.IsWithinRange(this.CurrentSpeed)) averageFuelConsumption += HighSpeedConsumption.Consumption * distance; } return averageFuelConsumption; }
public override double CalculateRaceSpeed(IRace race) { double output = this.Engines.Sum(e => e.Output); double result = (output - this.Weight) + (race.OceanCurrentSpeed / (double)Factor); return result; }
public string StartRace(string raceName) { IRace race = this.raceRepository.GetByName(raceName); if (race == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } if (race.Riders.Count < MinParticipants) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, raceName, MinParticipants)); } List <IRider> fastestRiders = race.Riders .OrderByDescending(x => x.Motorcycle.CalculateRacePoints(race.Laps)) .Take(3) .ToList(); IRider winner = fastestRiders.First(); winner.WinRace(); StringBuilder result = new StringBuilder(); result.AppendLine(string.Format(OutputMessages.RiderFirstPosition, winner.Name, raceName)); result.AppendLine(string.Format(OutputMessages.RiderSecondPosition, fastestRiders[1].Name, raceName)); result.AppendLine(string.Format(OutputMessages.RiderThirdPosition, fastestRiders[2].Name, raceName)); this.raceRepository.Remove(race); return(result.ToString().TrimEnd()); }
public override double CalculateRaceSpeed(IRace race) { var efficiancyFactor = this.sailEfficiency / (double)Factor; var result = ((race.WindSpeed * efficiancyFactor) - this.Weight) + (race.OceanCurrentSpeed / 2.0); return(result); }
public string CreateRace(string name, int laps) { //Creates a race with the given name and laps and adds it to the race repository. IRace race = this.raceRepository .GetByName(name); //If the race with the given name already exists, throw an InvalidOperationException with message: //• "Race {name} is already created." if (race != null) { throw new InvalidOperationException( string.Format( ExceptionMessages.RaceExists, name)); } //If everything is successful you should return the following message: race = this.raceFactory .CreateRace(name, laps); this.raceRepository.Add(race); string result = string.Format( OutputMessages.RaceCreated, name); return(result); }
/// <summary> /// 通过传递参数创建实例类型 /// </summary> /// <param name="raceType"></param> /// <returns></returns> public static IRace GetRace(RaceType raceType) { IRace race = null; switch (raceType) { case RaceType.Human: race = new Human(); break; case RaceType.NE: race = new NE(); break; case RaceType.ORC: race = new ORC(); break; case RaceType.Undead: race = new Undead(); break; default: throw new Exception($"种族{raceType}不存在"); } return(race); }
public string StartRace(string raceName) { StringBuilder sb = new StringBuilder(); IRace race = this.raceRepository.GetByName(raceName); this.raceRepository.Remove(race); if (race == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } if (race.Riders.Count < 3) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, raceName, 3)); } List <IRider> topThreeRiders = race.Riders.OrderByDescending(r => r.Motorcycle.CalculateRacePoints(race.Laps)) .ToList(); sb.AppendLine(string.Format(OutputMessages.RiderFirstPosition, topThreeRiders[0].Name, raceName)); sb.AppendLine(string.Format(OutputMessages.RiderSecondPosition, topThreeRiders[1].Name, raceName)); sb.AppendLine(string.Format(OutputMessages.RiderThirdPosition, topThreeRiders[2].Name, raceName)); topThreeRiders[0].WinRace(); return(sb.ToString().TrimEnd()); }
public void SetRace(ISubrace value) { Race = value; Ability += value.AbilityModifier; Speed = value.Speed; Size = value.Size; }
// overload so we can pass in a race or not? public ICivilization GenerateSingle(IRace race) { // TODO: needs shit like "Kingdom" or "Empire" and whatnot to prepend onto these names string civName = ""; switch (race.GetType().Name.ToLower()) { case "humans": civName = Names.SingleName(CoreEnums.Word.HumanMale); break; case "elves": civName = Names.SingleName(CoreEnums.Word.ElfPlace); break; case "dwarves": default: civName = Names.SingleName(CoreEnums.Word.DwarfFemale); break; } ICivilization civilization = new Civilization { Id = Random.Next(0, 676786760), // TODO: this is database related shit Name = civName, Description = "CIVDESCRIPTION", Race = race, RegionsOwned = new List<IRegion>(), PopulationCenters = new List<IPopulationCenters>(), TotalPopulation = new List<IPerson>() }; return civilization; }
private void SetDiceThrowLabel(ICaste caste, IRace race, string propertyName, Label label) { var casteAttributes = caste.GetCustomAttributes(propertyName); var diceThrow = AttributeUtils.GetAttribute <DiceThrowAttribute>(casteAttributes); var diceThrowModifier = AttributeUtils.GetAttribute <DiceThrowModifierAttribute>(casteAttributes); var specialTrainingAttribute = AttributeUtils.GetAttribute <SpecialTrainingAttribute>(casteAttributes); label.Text = Lng.Elem(EnumUtils.GetDescription(diceThrow.DiceThrowType)); if (diceThrowModifier != null) { label.Text += $" + {diceThrowModifier.Modifier}"; } if (specialTrainingAttribute != null) { label.Text += $" + {Lng.Elem("St")}"; } if (diceThrow.DiceThrowType.ToString().EndsWith("2_Times")) { label.Text += " (2x)"; } var raceModifier = race.GetPropertyShortValue(propertyName); if (raceModifier != 0) { label.Text += raceModifier < 0 ? $" - {Math.Abs(raceModifier)}" : $" + {raceModifier}"; } }
public string StartRace(string raceName) { IRace race = raceRepository.GetByName(raceName); if (race == null) { throw new InvalidOperationException($"Race {raceName} could not be found."); } if (race.Drivers.Count < 3) { throw new InvalidOperationException($"Race {raceName} cannot start with less than 3 participants."); } var sortedDrivers = race.Drivers.OrderByDescending(x => x.Car.CalculateRacePoints(race.Laps)).ToArray(); StringBuilder sb = new StringBuilder(); sb.AppendLine($"Driver {sortedDrivers[0].Name} wins {raceName} race."); sb.AppendLine($"Driver {sortedDrivers[1].Name} is second in {raceName} race."); sb.AppendLine($"Driver {sortedDrivers[2].Name} is third in {raceName} race."); this.raceRepository.Remove(race); return(sb.ToString().Trim()); }
public Player(string name, IRace race) : base(race.Health) { Name = name; Race = race; Inventory = new Inventory(); _maxHealth = race.Health; }
public string StartRace(string raceName) { if (!races.Any(x => x.Name == raceName)) { string exeption = string.Format(ExceptionMessages.RaceNotFound, raceName); throw new InvalidOperationException(exeption); } IRace race = races.FirstOrDefault(x => x.Name == raceName); if (race.Drivers.Count < minPaticipants) { string exeption = string.Format(ExceptionMessages.RaceInvalid, raceName, minPaticipants); throw new InvalidOperationException(exeption); } List <IDriver> drivers = race.Drivers.OrderByDescending(x => x.Car.CalculateRacePoints(race.Laps)).Take(3).ToList(); races.Remove(race); StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format(OutputMessages.DriverFirstPosition, drivers[0].Name, race.Name)); sb.AppendLine(string.Format(OutputMessages.DriverSecondPosition, drivers[1].Name, race.Name)); sb.AppendLine(string.Format(OutputMessages.DriverThirdPosition, drivers[2].Name, race.Name)); return(sb.ToString().TrimEnd()); }
public string StartRace(string raceName) { IRace race = this.raceRepository.GetByName(raceName); if (race == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } if (race.Drivers.Count < MinParticipants) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, raceName, MinParticipants)); } var winners = race.Drivers .OrderByDescending(d => d.Car.CalculateRacePoints(race.Laps)) .Take(3) .ToArray(); this.raceRepository.Remove(race); return(string.Format(OutputMessages.DriverFirstPosition, winners[0].Name, race.Name) + Environment.NewLine + string.Format(OutputMessages.DriverSecondPosition, winners[1].Name, race.Name) + Environment.NewLine + string.Format(OutputMessages.DriverThirdPosition, winners[2].Name, race.Name)); }
private void OnRaceChanged(object sender, SelectionChangedEventArgs e) { IRace race = this.RaceComboBox.SelectedItem as IRace; if (race.Race == AnAppearance.Races.Hrothgar) { this.Appearance.Gender = AnAppearance.Genders.Masculine; } if (race.Race == AnAppearance.Races.Viera) { this.Appearance.Gender = AnAppearance.Genders.Feminine; } if (this.Race == race) { return; } this.Race = race; this.Appearance.Race = this.Race.Race; this.TribeComboBox.ItemsSource = this.Race.Tribes; this.Tribe = this.Race.Tribes.First(); this.TribeComboBox.SelectedItem = this.Tribe; this.UpdateRaceAndTribe(); }
public string StartRace(string raceName) { IRace race = this.races.GetByName(raceName); if (race == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } else if (race.Riders.Count < 3) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, race.Name, 3)); } List <IRider> winners = new List <IRider>(); foreach (IRider rider in race.Riders.OrderByDescending(r => r.Motorcycle.CalculateRacePoints(race.Laps)).Take(3)) { winners.Add(rider); } StringBuilder sb = new StringBuilder(); IRider first = winners[0]; IRider second = winners[1]; IRider third = winners[2]; sb.AppendLine(string.Format(OutputMessages.RiderFirstPosition, first.Name, race.Name)); sb.AppendLine(string.Format(OutputMessages.RiderSecondPosition, second.Name, race.Name)); sb.AppendLine(string.Format(OutputMessages.RiderThirdPosition, third.Name, race.Name)); this.races.Remove(race); return(sb.ToString().TrimEnd()); }
public string StartRace(string raceName) { if (!this.raceRepository.GetAll().Any(r => r.Name == raceName)) { string msg = String.Format(ExceptionMessages.RaceNotFound, raceName); throw new InvalidOperationException(msg); } IRace race = this.raceRepository.GetAll().First(r => r.Name == raceName); if (race.Drivers.Count < MinParticipants) { string msg = String.Format(ExceptionMessages.RaceInvalid, race.Name, MinParticipants); throw new InvalidOperationException(msg); } var topThreeRacers = race.Drivers.ToList().OrderByDescending(d => d.Car.CalculateRacePoints(race.Laps)).Take(3).ToList(); this.raceRepository.Remove(race); var sb = new StringBuilder(); sb .AppendLine(String.Format(OutputMessages.DriverFirstPosition, topThreeRacers[0].Name, race.Name)) .AppendLine(String.Format(OutputMessages.DriverSecondPosition, topThreeRacers[1].Name, race.Name)) .AppendLine(String.Format(OutputMessages.DriverThirdPosition, topThreeRacers[2].Name, race.Name)); return(sb.ToString().Trim()); }
public string StartRace(string raceName) { //If everything is valid, you should arrange all riders and then return the three fastest riders. //To do this you should sort all riders in descending order by the result of CalculateRacePoints //method in the motorcycle object. At the end, if everything is valid remove this race from race repository. IRace race = this.raceRepository .GetByName(raceName); //If the race does not exist in race repository, throw an InvalidOperationException with message: //• "Race {name} could not be found." if (race == null) { throw new InvalidOperationException( string.Format( ExceptionMessages.RaceNotFound, raceName)); } //If the participants in the race are less than 3, throw an InvalidOperationException with message: //• "Race {race name} cannot start with less than 3 participants." if (race.Riders.Count < 3) { throw new InvalidOperationException( string.Format( ExceptionMessages.RaceInvalid, raceName, 3)); } //If everything is successful, you should return the following message: //• "Rider {first rider name} wins {race name} race." //"Rider {second rider name} is second in {race name} race." //"Rider {third rider name} is third in {race name} race." var sortRiders = race.Riders .OrderByDescending(r => r.Motorcycle.CalculateRacePoints(race.Laps)) .Take(3) .ToList(); StringBuilder builder = new StringBuilder(); builder.AppendLine( string.Format( OutputMessages.RiderFirstPosition, sortRiders[0].Name, raceName)); builder.AppendLine( string.Format( OutputMessages.RiderSecondPosition, sortRiders[1].Name, raceName)); builder.AppendLine( string.Format( OutputMessages.RiderThirdPosition, sortRiders[2].Name, raceName)); this.raceRepository.Remove(race); return(builder.ToString().TrimEnd()); }
public string StartRace(string raceName) { StringBuilder sb = new StringBuilder(); IRace race = this.raceRepo.GetByName(raceName); if (race == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } if (race.Drivers.Count < 3) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, raceName, 3)); } this.raceRepo.Remove(race); List <IDriver> drivers = race.Drivers.OrderByDescending(d => d.Car.CalculateRacePoints(race.Laps)).Take(3).ToList(); IDriver first = drivers.FirstOrDefault(); IDriver second = drivers.Skip(1).FirstOrDefault(); IDriver third = drivers.Skip(2).FirstOrDefault(); first.WinRace(); sb.AppendLine(string.Format(OutputMessages.DriverFirstPosition, first.Name, race.Name)); sb.AppendLine(string.Format(OutputMessages.DriverSecondPosition, second.Name, race.Name)); sb.AppendLine(string.Format(OutputMessages.DriverThirdPosition, third.Name, race.Name)); return(sb.ToString().TrimEnd()); }
/// <summary> /// 细节没有消失 只是转移 /// 转移了矛盾,并没有消除矛盾 /// /// 集中了矛盾 /// </summary> /// <param name="raceType"></param> /// <returns></returns> public static IRace CreateRace(RaceType raceType) { IRace iRace = null; switch (raceType) { case RaceType.Human: iRace = new Human(); break; case RaceType.Undead: iRace = new Undead(); break; case RaceType.ORC: iRace = new ORC(); break; case RaceType.NE: iRace = new NE(); break; //增加一个分支 default: throw new Exception("wrong raceType"); } return(iRace); }
public string StartRace(string raceName) { IRace race = raceRepository.Models.FirstOrDefault(r => r.Name == raceName); if (race == null) { throw new InvalidOperationException(String.Format(ExceptionMessages.RaceNotFound, raceName)); } if (race.Riders.Count < 3) { throw new InvalidOperationException(String.Format(ExceptionMessages.RaceInvalid, raceName, 3)); } riders = race.Riders.ToList(); Ordering(r => r.Motorcycle.CalculateRacePoints(race.Laps)); string first = riders.First().Name; string sec = riders.Skip(1).First().Name; string third = riders.Skip(2).First().Name; StringBuilder sb = new StringBuilder(); sb.AppendLine(String.Format(OutputMessages.RiderFirstPosition, first, race.Name)) .AppendLine(String.Format(OutputMessages.RiderSecondPosition, sec, race.Name)) .AppendLine(String.Format(OutputMessages.RiderThirdPosition, third, race.Name)); raceRepository.Remove(race); return(sb.ToString().TrimEnd()); }
public static IRace CreateInstance(RaceType raceType) { IRace race = null; switch (raceType) { case RaceType.Human: race = new Human(); break; case RaceType.NE: race = new NE(); break; case RaceType.ORC: race = new ORC(); break; case RaceType.Undead: race = new Undead(); break; default: throw new Exception("wrong raceType"); } return(race); }
public void ShowRace(IRace race) { int turn = 0; this.drawTrack(race, turn, "Press any key to start the race..."); Console.ReadKey(true); using (Timer timer = new System.Threading.Timer( (o) => { turn++; this.drawTrack(race, turn, "(Press any key to skip)"); } )) { timer.Change(this.speed, this.speed); while (turn < race.TurnCount - 1 && !Console.KeyAvailable) ; // check if race is finished or if there's anything in the input buffer while (Console.KeyAvailable) { Console.ReadKey(true); // clear the input buffer } timer.Dispose(); } this.drawTrack(race, race.TurnCount - 1, string.Format("The winner is {0}\n\n", race.Winner.Name) + this.leftMargin + "Press any key to continue..."); Console.ReadKey(true); }
public string StartRace(string raceName) { IRace race = this.raceRepository.GetByName(raceName); if (race == null) { throw new InvalidOperationException (string.Format(ExceptionMessages.RaceNotFound, raceName)); } if (race.Drivers.Count < minRaceParticipants) { throw new InvalidOperationException (string.Format(ExceptionMessages.RaceInvalid, raceName, minRaceParticipants)); } var winners = race.Drivers .OrderByDescending (first => first.Car.CalculateRacePoints(race.Laps)) .Take(3) .ToArray(); this.raceRepository.Remove(race); var firstWinner = winners[0]; var secondWinner = winners[1]; var thirdWinner = winners[2]; var text = new StringBuilder(); text.AppendLine(string.Format(OutputMessages.DriverFirstPosition, firstWinner, raceName)); text.AppendLine(string.Format(OutputMessages.DriverSecondPosition, secondWinner, raceName)); text.AppendLine(string.Format(OutputMessages.DriverThirdPosition, thirdWinner, raceName)); return(text.ToString().TrimEnd()); }
static void Main(string[] args) {//make a list of cars Car bigBlue = new Car("Big Blue", 102.40); Car herby = new Car("Herby", 40); Car delorian = new Car("Delorian", 88); Car mysteryMachine = new Car("Mystery Machine", 102.5); Person Alson = new Person("Alison", 100); Person Mary = new Person("Mary", 70); List <IRace> racers = new List <IRace>(); racers.Add(bigBlue); racers.Add(herby); racers.Add(delorian); racers.Add(mysteryMachine); racers.Add(Alson); racers.Add(Mary); foreach (IRace r1 in racers) { foreach (IRace r2 in racers) { IRace winner = race(r1, r2); Console.WriteLine("{0} vs {1} = {2}", r1, r2, winner); } } }
public void PayWinnings(IPlayer player, IRace raceResults) { if (this.Bet.PickToWin == raceResults.Winner) { player.Money += this.Bet.WagerAmount * raceResults.Positions.Count(); } }
public string StartRace(string raceName) { IRace race = this.raceRepository .GetByName(raceName); if (race is null) { throw new InvalidOperationException( $"Race {raceName} could not be found."); } if (race.Riders.Count < 3) { throw new InvalidOperationException( $"Race {raceName} cannot start with less than 3 participants."); } var sortedRiders = race .Riders .OrderByDescending(r => r.Motorcycle.CalculateRacePoints(race.Laps)) .Take(3) .ToList(); StringBuilder builder = new StringBuilder(); builder.AppendLine($"Rider {sortedRiders[0].Name} wins {raceName} race."); builder.AppendLine($"Rider {sortedRiders[1].Name} is second in {raceName} race."); builder.AppendLine($"Rider {sortedRiders[2].Name} is third in {raceName} race."); this.raceRepository.Remove(race); return(builder.ToString().TrimEnd()); }
public override double CalculateRaceSpeed(IRace race) { var efficiancyFactor = this.sailEfficiency / (double)Factor; var result = ((race.WindSpeed * efficiancyFactor) - this.Weight) + (race.OceanCurrentSpeed / 2.0); return result; }
public string CreateRace(string name, int laps) { bool isExistRace = this.raceRepository .GetAll() .Any(r => r.Name == name); if (isExistRace) { throw new InvalidOperationException( string.Format( ExceptionMessages.RaceExists, name)); } IRace race = this.raceFactory .CreateRace(name, laps); this.raceRepository.Add(race); string result = string.Format( OutputMessages.RaceCreated, name); return(result); }
public string StartRace(string raceName) { if (raceRepository.GetByName(raceName) == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } IRace race = raceRepository.GetByName(raceName); List <IRider> bestRiders = race.Riders.OrderByDescending(x => x.Motorcycle.CalculateRacePoints(raceRepository.GetByName(raceName).Laps)).ToList(); if (bestRiders.Count() < 3) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, raceName, 3)); } StringBuilder sb = new StringBuilder(); sb.AppendLine($"Rider {bestRiders.ElementAt(0).Name} wins {raceRepository.GetByName(raceName).Name} race.") .AppendLine($"Rider {bestRiders.ElementAt(1).Name} is second in {raceRepository.GetByName(raceName).Name} race.") .AppendLine($"Rider {bestRiders.ElementAt(2).Name} is third in {raceRepository.GetByName(raceName).Name} race."); raceRepository.Remove(raceRepository.GetByName(raceName)); return(sb.ToString().TrimEnd()); }
private IRace RandomRace() { var random = new Random(); int index = random.Next(IRace.allRaces.Count); return(IRace.FactoryMethod(IRace.allRaces[index].Name)); }
public string StartRace(string raceName) { IRace race = raceRepository.GetByName(raceName); if (race == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName)); } if (race.Drivers.Count < 3) { throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, raceName, 3)); } IDriver[] sortedDrivers = race.Drivers.OrderByDescending(d => d.Car.CalculateRacePoints(race.Laps)).Take(3).ToArray(); raceRepository.Remove(race); IDriver firstDriver = sortedDrivers[0]; IDriver secondDriver = sortedDrivers[1]; IDriver thirdDriver = sortedDrivers[2]; StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format(OutputMessages.DriverFirstPosition, firstDriver.Name, raceName)); sb.AppendLine(string.Format(OutputMessages.DriverSecondPosition, secondDriver.Name, raceName)); sb.AppendLine(string.Format(OutputMessages.DriverThirdPosition, thirdDriver.Name, raceName)); return(sb.ToString().TrimEnd()); }
public MapLoader() { this._friendRace = this.ChoseRandomFriendRace(); this._enemyRace = this.ChoseRandomEnemyRace(); this.Enemies = new List<Enemy>(); this.ItemToCollect = new List<CollectableItem>(); this.Maze = new List<MazeItem>(); }
public virtual void SetRace(IRace race) { if (race == null) { throw new ArgumentNullException(nameof(race), "You can not assign a null race to this actor."); } this.Race = race; }
LocationPickerPage(IRepository repo, IRace race) { // todo - summarise the race details Title = race.Code; Picker locationpicker = new Picker { WidthRequest = 300, Title = "Locations" }; locationpicker.Items.Clear(); repo.LocationList.Select(l => l.Name).ForEach (locationpicker.Items.Add); var entry = new Entry {Placeholder = "token"}; var button = new Button { Text = "Go!", IsEnabled = false }; // Accomodate iPhone status bar. this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5); Func<bool> enable = () => (!string.IsNullOrEmpty(_token) && locationpicker.SelectedIndex >= 0 && !string.IsNullOrEmpty(locationpicker.Items[locationpicker.SelectedIndex])); entry.TextChanged += (object sender, TextChangedEventArgs e) => { _token = entry.Text; button.IsEnabled = enable(); }; locationpicker.SelectedIndexChanged += (object sender, EventArgs e) => { button.IsEnabled = enable(); }; button.Clicked += (object sender, EventArgs e) => { IEnumerable<IBoat> boats = repo.BoatList; var location = new LocationFactory() .SetName(locationpicker.Items[locationpicker.SelectedIndex]) .SetToken(_token) .SetItems(repo) .Create(); var tim = new TimingItemManager(new List<IRepository> { repo}, location, boats); var page = TimingMasterDetailPage.Create(tim); Navigation.PushAsync(page); }; var dump = new Button { Text = "Dump", IsEnabled = true }; dump.Clicked += (object sender, EventArgs e) => { repo.Dump(); }; Content = new StackLayout { Children = { locationpicker, entry, button, dump } }; }
public MatchedBetRaceViewModel(BetfairService service, IRace race) { this.race = race; this.service = service; CreateRunners(); SetupTimer(); this.timer.Start(); }
protected Character(int lifes, IRace race) { this.IsAlive = true; this.Life = lifes; this.Health = DeffHealth; this.Race = race; this.AggressionRange = race.DefaultAggressionRange; this.Aggression = race.DefaultAggression; this.Description = race.Description; this.AvatarUri = race.DefaultAvatar; }
public Character(string playerName, string name, int age, string sex, string bio, IRace race, IClass klass) { PlayerName = playerName; Name = name; Age = age; Sex = sex; Bio = bio; Race = race; Class = klass; }
public MatchedBetViewModel(BetfairService service, IRace race, double currentFunds) { this.service = service; this.race = race; this.matchedBetCalculator = new MatchedBetCalculatorViewModel(); this.matchedBetRace = new MatchedBetRaceViewModel(service, race); this.orders = new MatchedBetOrderListViewModel(service, race.MarketId); this.CurrentRaceView = this.matchedBetRace; this.ShowRunners = true; this.ShowOrders = false; this.action = new MatchedBetActionViewModel(service, race.MarketId, currentFunds); }
public MainWindow(IRace selectedPlayerRace) { InitializeComponent(); try { var renderer = new WpfRenderer(this.GameCanvas); var inputHandlerer = new WpfInputHandlerer(this.GameCanvas); this.Engine = new GameEngine(renderer, inputHandlerer); this.Engine.InitGame(selectedPlayerRace); this.Engine.StartGame(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Creates a list of Car performance items sorted by the Car consumption ascending /// </summary> public IEnumerable<CarPerformance> ComparePerformanceOnRace(IRace Race, List<ICar> Cars) { Race.AssertNotNull(); Cars.AssertNotNull(); Cars.AssertNotEmpty(); var CarsPerformance = new List<CarPerformance>(); foreach (var Car in Cars) { var fuelConsumption = Car.GetAverageFuelConsumption(Race); var CarPerformance = new CarPerformance(Car.Name, fuelConsumption); CarsPerformance.Add(CarPerformance); } var sortedList = CarsPerformance.OrderBy(x => x.FuelConsumption).ToList(); return sortedList; }
private Account(string username, string password, IRace race) { if (String.IsNullOrEmpty(username)) { throw new ArgumentNullException("username"); } if (String.IsNullOrEmpty(password)) { throw new ArgumentNullException("password"); } if (race == null) { throw new ArgumentNullException("race"); } this.Username = username; this.Race = race; SetPassword(password); }
public TimingItemRepositoryDatabase(string racecode, string locationcode, string locationtoken) { Race race = DatabaseUtils.GetAll<DbRace>().Where(r => r.Code == racecode).First().As(); ILocation location = new Location(locationcode, locationtoken, new List<ISequenceItem>()); IList<Boat> boats = DatabaseUtils.GetAll<DbBoat>().Where(b => b.RaceCode == racecode).Select(b => b.As(race, location)).ToList(); //boats.ForEach(race.AddBoat); //race.AddLocation(location); var items = new List<DbTimingItem>(); // DatabaseUtils.GetAll<DbTimingItem>().Where(i => i.Race == racecode && i.Location == location.Endpoint.ToString() && i.Token == location.Code); foreach(DbTimingItem item in items) { // fixme: if the boat is null (startnumber is negative), then it should be logged against the location's unidentified list Boat boat = boats.Where(b => b.Number == item.StartNumber).First(); SequenceItem ts = item.As(boat, location); //boat.AddTime(location, ts); } _location = location; _race = race; }
public override Character Create(IRace race) { var friend = new Friend(race, new RandomAIProvider(), new TargetCharacterAIProvider()); return friend; }
public double CalculateRaceSpeed(IRace race) { var speed = this.Engine.Output - (this.Weight - this.CargoWeight) + (race.OceanCurrentSpeed / 2d); return speed; }
public void SetRace(IRace race) { throw new NotImplementedException(); }
public override double CalculateRaceSpeed(IRace race) { //(Oars * 100) - Boat Weight + Race Ocean Current Speed return (this.Oars * 100) - this.Weight + race.OceanCurrentSpeed; }
private double CalculateTime(IBoat participant, IRace race) { var speed = participant.CalculateRaceSpeed(race); var time = this.CurrentRace.Distance / speed; time = time < 0 ? double.PositiveInfinity : time; return time; }
public BoatSimulatorController(IBoatSimulatorDatabase database, IRace currentRace = null) { this.Database = database; this.CurrentRace = currentRace; }
public Friend(IRace race, AIProvider ai, AIProvider healAI) : base(race, ai, DefaultLifes) { this.HealAI = healAI; this.NormalAI = ai; }
public double CalculateRaceSpeed(IRace race) { var speed = this.Engines.Sum(x => x.Output) - this.Weight + (race.OceanCurrentSpeed / 5d); return speed; }
public void InitGame(IRace selectedPlayerRace) { var mapLoader = new MapLoader(); mapLoader.Load(selectedPlayerRace); this.Player = mapLoader.Player; this.Friend = mapLoader.Friend; this.Friend.AddFrined(this.Player); this.Enemies = mapLoader.Enemies; this.ItemsToCollect = mapLoader.ItemToCollect; this.Maze = mapLoader.Maze; Hud.Instance.PopulateElements(this.Player, this.Friend); this.Bullets = new List<Bullet>(); }
public double CalculateRaceSpeed(IRace race) { var speed = (this.Oars * 100) - this.Weight + race.OceanCurrentSpeed; return speed; }