private KeyValuePair <double, IBoat> FindFastest(IList <IBoat> participants) { // TODO probably bottle neck here double bestTime = double.MaxValue; IBoat winner = null; foreach (var participant in participants) { var speed = participant.CalculateRaceSpeed(this.CurrentRace); var time = this.CurrentRace.Distance / speed; if (time < bestTime && time > 0) { bestTime = time; winner = participant; } } if (winner == null) { winner = participants.FirstOrDefault(); bestTime = 0; } return(new KeyValuePair <double, IBoat>(bestTime, winner)); }
/// <summary> /// Shoots a missile at location /// </summary> /// <param name="location"> location to shoot </param> /// <param name="hitMarkers"> Collection of hitmarkers to add shot to</param> private void Shoot(Coordinate location, Player targetPlayer) { // get tile state TileState tileState = targetPlayer.GameBoard[location.YCoord, location.XCoord]; // if boat: display red 'x' on grid if (tileState == TileState.Boat) { AddHitMarker(location, targetPlayer, TileState.Hit); // Locates the boat that has a coordinate equal to the coordinate being shot i.e. get the boat being shot IBoat boatToHit = (from boat in targetPlayer.Boats from coord in boat.CoordinateRange.GetAllCoordinates() where coord.ToString() == location.ToString() select boat).ElementAt(0); boatToHit.Health--; // TODO: better way of doing this OnPropertyChanged(nameof(User.Health)); OnPropertyChanged(nameof(Computer.Health)); _boatApearanceManager.CheckForSunkBoats(targetPlayer.Boats); } // if empty: display green 'o' on grid else if (tileState == TileState.Empty) { AddHitMarker(location, targetPlayer, TileState.Miss); } }
public void RegisterBoat(IBoat unregisteredBoat) { if (!IsBoatRegistered(unregisteredBoat)) { _registeredBoats.Add(unregisteredBoat); } }
private static void BoatBuilderPattern() { BoatBuilder builder = new MotorBoatBuilder(); BoatDirector director = new MotorBoatDirector(); IBoat boat = director.Build(builder); Console.WriteLine(boat); }
public string CreateSailBoat(string model, int weight, int sailEfficiency) { IBoat boat = SailBoatFactory.CreateBoat(model, weight, sailEfficiency); this.Database.Boats.Add(boat); return(string.Format("Sail boat with model {0} registered successfully.", model)); }
public static void ShowBoatPlace(IBoat boat) { Console.ForegroundColor = boat.BoatPlace ? ConsoleColor.Green : ConsoleColor.Red; Console.WriteLine(boat); Console.WriteLine(); Console.ResetColor(); }
public string CreateRowBoat(string model, int weight, int oars) { IBoat boat = RowBoatFactory.CreateBoat(model, weight, oars); this.Database.Boats.Add(boat); return(string.Format("Row boat with model {0} registered successfully.", model)); }
public void AddParticipant(IBoat boat) { if (this.RegisteredBoats.ContainsKey(boat.Model)) { throw new DuplicateModelException(Constants.DuplicateModelMessage); } this.RegisteredBoats.Add(boat.Model, boat); }
// Implementation in Homework4 private static void BuilderPatternDemo() { AbstractPleasureBoat pleasureBoat = new HouseBoat(new InboardEngine(400), BoatColor.Forrest_Green); BoatBuilder builder = new PleasureBoatBuilder(pleasureBoat); BoatDirector director = new PleasureBoatDirector(); IBoat boat = director.Build(builder); Console.WriteLine(boat); }
public string CreateYacht(string model, int weight, string boatEngineModel, int cargoWeight) { IBoatEngine boatEngine = this.Database.BoatEngines.GetItem(boatEngineModel); IBoat boat = YachtFactory.CreateBoat(model, weight, boatEngine, cargoWeight); this.Database.Boats.Add(boat); return(string.Format("Yacht with model {0} registered successfully.", model)); }
public virtual void PrepareForSale(IBoat boat) { Registration reg = new Registration(boat); reg.AllocateBoatNumber(); Documentation.PrintBrochure(boat); boat.CleanBoat(); boat.LoadTrailer(); boat.ParkInLot(); }
public void TestMethod1() { FactoryCatalog catalog = new FactoryCatalog(); catalog.Bind <IBoat, SailBoat>(); // catalog.Bind<IBoat, SailBoat>().Singleton.Builder(b => b.AuxiliaryMotor = false); // catalog.Bind<ICar, SportCar>().Builder(c => c.MaxRotations = 8000); // ICar car = catalog.CreateInstance<ICar>(); IBoat boat = catalog.CreateInstance <IBoat>(); }
private void Form1_Load(object sender, EventArgs e) { HouseBoat houseBoat = new HouseBoat(); int sf1 = houseBoat.SquareFeet; House house = houseBoat; int sf2 = house.SquareFeet; IBoat boat = houseBoat; }
public void Should_not_be_able_to_register_an_already_registered_boat() { ICustomer customer = CreateSUT( ); IBoat boat = ObjectMother.Boat( ); customer.RegisterBoat(boat); customer.RegisterBoat(boat); Assert.AreEqual(1, ListFactory.From(customer.RegisteredBoats( )).Count); }
public IBoat Dequeue() { IBoat _result = null; if (_head == null) { throw new Exception("Queue is Empty"); } _result = _head.Data; _head = _head.Next; return(_result); }
public static DbTimingItem Create(IRace race, ILocation location, IBoat boat, DateTime now, string notes) { return(new DbTimingItem { Race = race.Code, Token = location.Token, Location = location.Name, StartNumber = boat.Number, Time = now, Milliseconds = now.Millisecond, Notes = notes }); }
private void Form1_Load(object sender, EventArgs e) { HouseBoat houseboat = new HouseBoat(); houseboat.SetHeading(180); IBoat iboat = houseboat; iboat.SetHeading(90); House house = houseboat; house.SetTemperature(72); }
public string SignUpBoat(string model) { IBoat boat = this.Database.Boats.GetItem(model); this.ValidateRaceIsSet(); if (!this.CurrentRace.AllowsMotorboats && boat is IEngineHolder) { throw new ArgumentException(Constants.IncorrectBoatTypeMessage); } this.CurrentRace.AddParticipant(boat); return(string.Format("Boat with model {0} has signed up for the current Race.", model)); }
private void Start() { if (OceanRenderer.Instance == null || !OceanRenderer.Instance.CreateDynamicWaveSim) { enabled = false; return; } _localOffset = transform.localPosition; _mat = GetComponent <Renderer>().material; _boat = GetComponentInParent <IBoat>(); }
static void Main(string[] args) { FactoryCatalog catalog = new FactoryCatalog(); catalog.Bind <IBoat, SailBoat>().Singleton. Builder(b => b.AuxiliaryMotor = false); catalog.Bind <ICar, SportCar>().Builder(c => c.MaxRotations = 8000); ICar car = catalog.CreateInstance <ICar>(); IBoat boat = catalog.CreateInstance <IBoat>(); car.Show(); boat.Show(); }
private static void MakeMeABoatBuilderPattern() { IBoatMotor bm = new SailBoatMotor(); IBoatColor bc = new SailBoatColor("Blue", false); IBoatBody bb = new SailBoatBody(); AbstractSailBoat boat = new SailBoat(bm, bc, bb); BoatBuilder builder = new SailBoatBuilder(boat); BoatDirector director = new SailBoatDirector(); IBoat b = director.Build(builder); Console.WriteLine(b.ToString()); }
public void AddNewBoatToField(IBoat boat) { if (boat == null) { throw new ArgumentNullException(); } if (CheckIfAllowed(boat.coordinates.Count()) == false) { throw new ArgumentException(); } _boats.Add(boat); }
public GameService() { LeftCoast = new List <IPassenger>(); RightCoast = new List <IPassenger>(); Wolf = new Passenger(PassengerRoles.Wolf); Goat = new Passenger(PassengerRoles.Goat); Cabbage = new Passenger(PassengerRoles.Cabbage); Boat = new Boat(); Count = 0; ActionAddToArea(RightCoast, Wolf); ActionAddToArea(RightCoast, Goat); ActionAddToArea(RightCoast, Cabbage); }
public string CreatePowerBoat( string model, int weight, string firstBoatEngineModel, string secondBoatEngineModel) { IBoatEngine firstBoatEngine = this.Database.BoatEngines.GetItem(firstBoatEngineModel); IBoatEngine secondBoatEngine = this.Database.BoatEngines.GetItem(secondBoatEngineModel); IBoat boat = PowerBoatFactory.CreateBoat(model, weight, firstBoatEngine, secondBoatEngine); this.Database.Boats.Add(boat); return(string.Format("Power boat with model {0} registered successfully.", model)); }
public BoatDTO(IBoat boat) { if (boat.Id < 0) { throw new ArgumentOutOfRangeException($"{nameof(boat.Id)} cannot be less than 0."); } ValidateInParameters(boat.SailNo, boat.Name, boat.Type, boat.Handicap); Id = boat.Id; SailNo = boat.SailNo; Name = boat.Name; Type = boat.Type; Handicap = boat.Handicap; Active = boat.Active; sa_Info = boat.sa_Info; }
public void Enqueue(IBoat data) { Node_old _newNode = new Node_old(data); if (_head == null) { _head = _newNode; _tail = _head; } else { _tail.Next = _newNode; _tail = _tail.Next; } _count++; }
public void addToLast(IBoat data_param, Node_old nodeObj) { Node_old _newNode = new Node_old(data_param); if (_head == null) { _head = _newNode; _tail = _head; } else { while (_newNode.g) { } } }
public static NSDictionary ToDictionary(this IBoat boat) { var keys = new NSString[] { new NSString("StartNumber"), new NSString("Name"), new NSString("Category"), new NSString("Scratched"), }; var values = new NSObject[] { new NSNumber(boat.Number), new NSString(boat.Name), new NSString(boat.Category), new NSNumber(boat.End ? 1 : 0), }; return(NSDictionary.FromObjectsAndKeys(values, keys)); }
private KeyValuePair <double, IBoat> FindFastest(IList <IBoat> participants) { double bestTime = double.MaxValue; IBoat winner = null; foreach (var participant in participants) { var speed = participant.CalculateRaceSpeed(this.CurrentRace); var time = this.CurrentRace.Distance / speed; if (time < bestTime) { bestTime = time; winner = participant; } } return(new KeyValuePair <double, IBoat>(bestTime, winner)); }
public static ISequenceItem ToItem(this DBRecord record, IBoat boat) { var rd = record.Fields["Timestamp"]; var nsd = (NSDate)rd; var dt = DateTime.SpecifyKind(nsd, DateTimeKind.Unspecified); if (record.Fields.ContainsKey(new NSString("Milliseconds"))) { var ms = ((NSNumber)record.Fields["Milliseconds"]).IntValue; dt = dt.AddMilliseconds(ms); } return (new SequenceItemFactory() .SetBoat(boat) .SetTime(dt) .SetNotes(record.Fields["Notes"].ToString()) .Create()); }
public Tuna(IFish fish, IFisherman fisherman, IBoat boat) { }
public SmoothBoatMove( IBoat boat, List<IEntity> entities, Point3D offset, Direction d, BoatMovementSpeed speed ) : base(0xF6) { EnsureCapacity( 18 + entities.Count * 10 ); m_Stream.Write( (int) boat.Serial ); m_Stream.Write( (byte) speed ); m_Stream.Write( (byte) d ); m_Stream.Write( (byte) boat.Facing ); m_Stream.Write( (short) ( boat.X + offset.X ) ); m_Stream.Write( (short) ( boat.Y + offset.Y ) ); m_Stream.Write( (byte) 0xFF ); m_Stream.Write( (sbyte) ( boat.Z + offset.Z ) ); m_Stream.Write( (byte) 0 ); m_Stream.Write( (byte) entities.Count ); for ( int i = 0; i < entities.Count; i++ ) { IEntity entity = entities[i]; m_Stream.Write( (int) entity.Serial ); m_Stream.Write( (short) ( entity.X + offset.X ) ); m_Stream.Write( (short) ( entity.Y + offset.Y ) ); m_Stream.Write( (byte) 0xFF ); m_Stream.Write( (sbyte) ( entity.Z + offset.Z ) ); } }
public static ISequenceItem ToItem(this DBRecord record, IBoat boat) { var rd = record.Fields["Timestamp"]; var nsd = (NSDate)rd; var dt = DateTime.SpecifyKind(nsd, DateTimeKind.Unspecified); if(record.Fields.ContainsKey(new NSString("Milliseconds"))) { var ms = ((NSNumber)record.Fields["Milliseconds"]).IntValue; dt = dt.AddMilliseconds(ms); } return new SequenceItemFactory() .SetBoat(boat) .SetTime(dt) .SetNotes(record.Fields["Notes"].ToString()) .Create(); }
public bool Equals(IBoat other) { return Number == other.Number; }
public SequenceItem(IBoat boat, DateTime timestamp, string notes) { _timeStamp = timestamp; Notes = notes; _boat = boat; }
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; }
void Awake() { this.spinning = this.spinningGameObject.GetComponent<ISpinning> (); if (this.spinning == null) { throw new UnityException ("Spinning are not initialized"); } this.spinning.SetOwner (this); this.boat = this.boatGameObject.GetComponent<IBoat> (); if (this.boat == null) { throw new UnityException ("Boat are not initialized"); } this.spinning.OnEndTryCatch += (ICatchable catchedStaff) => { if (catchedStaff != null) { catchedStaff.Use(this); StartCoroutine(StartAfterDelay()); } else { this.ChangeState(FisherState.LookingFor); } }; this.ChangeState (FisherState.Nothing); // Началное состояние обязательно задается в Awake }