public CoffeeMachine(IGrinder grinder, IHeater heater, IPump pump, ITank tank) { this.grinder = grinder; this.heater = heater; this.pump = pump; this.tank = tank; }
public TankContainsHindranceException(ITank tank, IHindrance hindrance) : base(String.Format( "Tank ({0}) contains hindrance ({1})).", tank, hindrance )) { }
public LiquidTank(Texture2D textureFront, Texture2D textureBack, ITank tank) { BackTexture = textureBack; FrontTexture = textureFront; _tank = tank; }
public LiquidTank(Texture2D texture, ITank tank) { BackTexture = texture.SubImage(0, 0, 20, 28); FrontTexture = texture.SubImage(20, 0, 20, 28); _tank = tank; }
private void DoFire(ITank tank, int x, int y) { switch (field.cells[x, y].TankDirection) { case Direction.Down: if (y + 2 < field.cells.GetLength(1)) { field.cells[x, y + 2].SetBullet(field.cells[x, y].TankDirection); } break; case Direction.Up: if (y - 2 >= 0) { field.cells[x, y - 2].SetBullet(field.cells[x, y].TankDirection); } break; case Direction.Left: if (x - 2 >= 0) { field.cells[x - 2, y].SetBullet(field.cells[x, y].TankDirection); } break; case Direction.Right: if (x + 2 < field.cells.GetLength(0)) { field.cells[x + 2, y].SetBullet(field.cells[x, y].TankDirection); } break; } }
public ActionResult GetTankStatistics() { _TankService = new TankService(); var obj = _TankService.GetTotalConsumption(); return(PartialView("_TankMenu", obj)); }
public double CalcWaterVolume(TankShape tankShape, double underfillHeight, double soilHeight) { ITank tank = GetTank(tankShape, TankProperties); double result = tank.CalcWaterVolume(underfillHeight, soilHeight); return(result); }
public bool RemoveEnemy(ITank enemy) { if (!_enemies.Contains(enemy)) return false; _enemies.Remove(enemy); return true; }
private static Directions[] DirectionsForTank(ITank tank) { if (tank.Direction == 0 || tank.Direction == 360) { return(new Directions[] { Directions.Up }); } else if (tank.Direction == 90) { return(new Directions[] { Directions.Right }); } else if (tank.Direction == 180) { return(new Directions[] { Directions.Down }); } else if (tank.Direction == 270) { return(new Directions[] { Directions.Left }); } else if (tank.Direction > 0 && tank.Direction < 90) { return(new Directions[] { Directions.Up, Directions.Right }); } else if (tank.Direction > 90 && tank.Direction < 180) { return(new Directions[] { Directions.Down, Directions.Right }); } else if (tank.Direction > 180 && tank.Direction < 270) { return(new Directions[] { Directions.Down, Directions.Left }); } else { return(new Directions[] { Directions.Up, Directions.Left }); } }
public bool AddEnemy(ITank enemy) { if(_enemies.Contains(enemy)) return false; _enemies.AddLast(enemy); return true; }
// GET: Tank public ActionResult Index() { _TankService = new TankService(); var Category = _TankService.GetList(); return(View(Category)); }
public static void Main(string[] args) { //对于反射的学习 ITank tank = new HeavyTank(); //======华丽的分割线======= Type t = tank.GetType(); //获得tank类对应的type Object o = Activator.CreateInstance(t); //从Type出发利用激活器来创建实例 //从Type出发,获取某个类的方法的信息 MethodInfo fireMi = t.GetMethod("Fire"); MethodInfo RunMi = t.GetMethod("Run"); //将方法和实例绑定,调用方法 fireMi.Invoke(o, null); RunMi.Invoke(o, null); Console.WriteLine(); //依赖注入相关学习 var sc = new ServiceCollection();//容器,ServiceCollection(用来装载“服务”,即各种接口,类型) sc.AddScoped(typeof(ITank), typeof(HeavyTank)); var sp = sc.BuildServiceProvider();//ServiceProvider(用来提供“服务”) //===========华丽的分割线========== ITank tank1 = sp.GetService <ITank>(); tank1.Fire(); tank1.Run(); Console.ReadLine(); }
public double CalcSoilVolume(TankShape tankShape, double soilHeight) { ITank tank = GetTank(tankShape, TankProperties); double result = tank.CalcSoilVolume(soilHeight); return(result); }
static void Main(string[] args) { var sc = new ServiceCollection(); sc.AddScoped(typeof(ITank), typeof(HeavyTank)); //**依赖注入**,只要将这里 HeavyTank 改成MediumTank sc.AddScoped(typeof(IVehicle), typeof(MediumTank)); sc.AddScoped <Driver>(); var sp = sc.BuildServiceProvider(); //==========华丽的分割线===========// var driver = sp.GetService <Driver>(); driver.Drive(); ITank tank = sp.GetService <ITank>(); tank.Fire(); tank.Run(); /* * ITank tank = new HeavyTank(); * var t = tank.GetType(); * object o = Activator.CreateInstance(t); * MethodInfo fireMi = t.GetMethod("Fire"); //反射 * MethodInfo runMi = t.GetMethod("Run"); * fireMi.Invoke(o, null); * runMi.Invoke(o, null); */ /* * //var driver = new Driver(new HeavyTank()); //接口 * //driver.Drive(); */ Console.WriteLine("Hello World!"); }
public void Shoot(ITank opponent) { if (Ammo.IsZero) { BuyAmmo(); return; } else { Ammo.Subtract(1); Random r = new Random(); double shootChance = r.NextDouble(); float currentDamage = Damage; var message = "Был произведён выстрел."; // Шанс критического выстрела if (shootChance <= 0.1) { currentDamage *= 1.2f; message = "Был произведён критический выстрел."; } // Шанс промаха else if (shootChance <= 0.3) { currentDamage = 0; message = "Случился промах."; } Console.WriteLine(message); opponent.TakeDamage(currentDamage); } }
public ITank GetTank(TankShape tankShape, string str) { Type tankType = ALData.TankTypes[(int)tankShape]; ITank result = (ITank)StringSerializer.Deserialize(tankType, str); return(result); }
static void Main(string[] args) { /* * How to use DependencyInjection: * must using Microsoft.Extensions.DependencyInjection; * * In VS code please install Nuget Package Manager and modify fetchPackageVersion.js file at below folder: * /Users/UserName/.vscode/extensions/jmrog.vscode-nuget-package-manager-1.1.6/out/src/actions/add-methods/fetchPackageVersions.js * Modified content: * return new Promise((resolve) => { * node_fetch_1.default(`${versionsUrl}${selectedPackageName.toLowerCase()}/index.json`, utils_1.getFetchOptions(vscode.workspace.getConfiguration('http'))) * .then((response) => { * shared_1.clearStatusBar(); * resolve({ response, selectedPackageName }); * }); */ // Dependency Injection has a container(ServiceCollection ), we can put type and interface into this container. // ServiceCollection is a containter var ServiceContainter = new ServiceCollection(); // register type in Service Containter ServiceContainter.AddScoped(typeof(ITank), typeof(MyTank)); ServiceContainter.AddScoped(typeof(IVehicle), typeof(Car)); ServiceContainter.AddScoped <Driver>(); // define a Service Provider provide type information which registed in service containter var ServiceProvider = ServiceContainter.BuildServiceProvider(); // Injection type from service containter to Implement ITank tank = ServiceProvider.GetService <ITank>(); var driver = ServiceProvider.GetService <Driver>(); }
/// <summary> /// Определяет действие, которое нужно совершить танку /// </summary> /// <param name="EnemyTank">Танк-противник</param> /// <returns>Действие, которое нужно совершить</returns> public Actions ComputerTurn(ITank EnemyTank) { // По-умолчанию, стреляем. Actions action = Actions.Shoot; // Если нас, вероятно, убивают на следующем ходу, то лечимся. if (EnemyTank.Damage > Health) { action = Actions.Repair; } // Если патронов меньше 10 и нас не убивают, то покупаем патроны. if (action != Actions.Repair && RoundsNum < 10) { action = Actions.Buy; } // Если мы убиваем на этом ходу и у нас есть патроны, то стреляем. if (EnemyTank.Health < Damage && RoundsNum > 0) { action = Actions.Shoot; } return(action); }
public double CalcTankVolume(TankShape tankShape) { ITank tank = GetTank(tankShape, TankProperties); double result = tank.CalcTankVolume(); return(result); }
public EnemyTankController(ITank tank) { if (tank == null) throw new ArgumentNullException("tank"); _tank = tank; _tank.Destroyed += TankOnDestroyed; }
public ActionResult Edit(int id) { _TankService = new TankService(); var obj = _TankService.Find(id); return(View(obj)); }
private void onDeathAnimation(ITank tankToDestroy) { imagecount = ExplImages.Count - 1; dillay = (imagecount * 100) * 2; deadTank = tankToDestroy; animation = true; }
public static void SideScreen(ITank player, LevelType level, Dictionary <TankRank, int> tanks) { WriteLabels(); ShowLives(player.Lives); ShowLevel(level); ShowScore(); EnemiesCount(tanks); }
public Car(IBody body, IEngine engine, ITank tank) { Body = body ?? throw new ArgumentNullException(nameof(body), "Корпус машины не может быть равен null."); Engine = engine ?? throw new ArgumentNullException(nameof(engine), "Двигатель машины не может быть равен null."); Tank = tank ?? throw new ArgumentNullException(nameof(tank), "Корпус машины не может быть равен null."); Serial = Guid.NewGuid().ToString(); }
public void DestroyTank(ITank tank) { tank.Died -= OnTankDied; var tankObject = (tank as TankController).gameObject; BulletManager.RemoveWeapon(tankObject.GetComponent<TankWeaponComponent>()); tank.Broke(); GameObject.Destroy(tankObject); }
public static void MyMethod(object myObject) { ITank tank = (ITank)myObject; tank.Shirk(); tank.TankStance(); tank.DamageReduction(); }
public ITank CreteTank(IInputController inputController, Transform spawnPoint) { var tankObject = Instantiate(tankPrefab, spawnPoint.position, Quaternion.identity); var shootingController = tankObject.GetComponent <IShootingController>(); _tank = tankObject.GetComponent <ITank>(); _tank.Initialize(inputController, shootingController); return(_tank); }
static void Main(string[] args) { //Console.WriteLine("Hello World!"); var driver = new Driver(new HeavyTank()); driver.Drive(); int[] nums1 = { 1, 2, 3, 4, 5 }; ArrayList nums2 = new ArrayList { 1, 2, 3, 4, 5 }; Console.WriteLine(Sum(nums1)); Console.WriteLine(Sum(nums2)); var roc = new ReadOnlyCollection(nums1); Console.WriteLine(Sum(roc)); //foreach(var n in roc) //{ // Console.WriteLine(n); //} IKiller killer = new WarmKiller(); killer.Kill(); //var wk =killer as WarmKiller; var wk = (IGentleman)killer; wk.Love(); ITank tank = new HeavyTank(); var t = tank.GetType(); object o = Activator.CreateInstance(t); MethodInfo fireMi = t.GetMethod("Fire"); MethodInfo runMi = t.GetMethod("Run"); fireMi.Invoke(o, null); runMi.Invoke(o, null); //reflection var sc = new ServiceCollection(); sc.AddScoped(typeof(ITank), typeof(HeavyTank)); sc.AddScoped(typeof(IVehicle), typeof(LightTank)); sc.AddScoped <Driver>(); var sp = sc.BuildServiceProvider(); var driver1 = sp.GetService <Driver>(); driver1.Drive(); ITank tank1 = sp.GetService <ITank>(); tank1.Fire(); tank1.Run(); }
public Bullet(ITank sender) { Sender = sender; Element = sender.Element; X = sender.GunPosition.X; Y = sender.GunPosition.Y; Direction = sender.Direction; Width = Height = 64; MoveSpeed = 10; }
public Vector2 GetReleasePosition() { ITank parentTank = parent as ITank; float angle = -parentTank.Angle; double rad = Utils.Deg2Rad(angle); Vector2 aimDirection = new Vector2((float)Math.Cos(rad), (float)Math.Sin(rad)); Vector2 spawnPoint = transform.position + aimDirection * barrelLength; return(spawnPoint); }
public void MoveProjectile(ITank tank) { tank.FiredProjectiles.ToList().ForEach(p => { if (this.mover.MoveTank(p, p.Direction)) { tank.FiredProjectiles.Remove(p); } }); }
public void RefreshProps(TankShape tankShape) { ITank tank = fRecord.GetTank(tankShape, fRecord.TankProperties); TypeDescriptor.AddAttributes(tank, new Attribute[] { new ReadOnlyAttribute(true) }); tank.SetPropNames(); fView.PropsGrid.SelectedObject = tank; RecalcValues(); }
public string ToggleTankDefenseMode(string tankName) { if (this.machines.FirstOrDefault(n => n.Name == tankName && n.GetType().Name == "Tank") != null) { ITank wantedTank = (Tank)this.machines.FirstOrDefault(n => n.Name == tankName && n.GetType().Name == "Tank"); wantedTank.ToggleDefenseMode(); return($"Tank {wantedTank.Name} toggled defense mode"); } return($"Machine {tankName} could not be found"); }
void Awake() { tank_hp_slider = GameObject.Find("Tank_HP").GetComponent <Slider>(); player = PlayerTank.GetComponent <Tank>(); max_hp = player.GetMaxHP(); GameObject.Find("Tank_Aim_Point").GetComponent <RawImage>().enabled = false; tank_shell_info = GameObject.Find("Tank_Shell_Info").GetComponent <Slider>(); shell_n = GameObject.Find("Shell_Amount").GetComponent <Text>(); tank_shell_force = GameObject.Find("Tank_Shell_Force").GetComponent <Slider>(); rotation_line = GameObject.Find("Line").GetComponent <RectTransform>(); }
public TankView(ITank tank, Texture2D bodyTexture, Texture2D towerTexture) { if (tank == null) throw new ArgumentNullException("tank"); if (bodyTexture == null) throw new ArgumentNullException("bodyTexture"); _tank = tank; _bodyTexture = bodyTexture; _towerTexture = towerTexture; _tank.Destroyed += TankOnDestroyed; _bodyTextureCenter = new Vector2(_bodyTexture.Width, _bodyTexture.Height) / 2; _towerTextureCenter = new Vector2(_towerTexture.Width, _towerTexture.Height) / 2; }
public SimpleBullet(World world, Vector2 position, float rotation, ITank ownerTank, float damage) { _world = world; _ownerTank = ownerTank; _damage = damage; _body = new Body(_world, position, rotation, BodyType.Dynamic) { FixedRotation = true, IsBullet = true, IsSensor = true, UserData = this }; FixtureFactory.AttachCircle(0.1f, 1, _body, Vector2.Zero); _body.LinearVelocity = Rotation.ToVector() * 50; _body.OnCollision += BodyOnCollision; }
public IController Create(ITank tank) { return new UserTankController(tank); }
public TankTower(ITank tank, IBulletSpawner bulletSpawner) { _bulletSpawner = bulletSpawner; _tank = tank; }
public TankIsNotInsideFieldException(ITank tank, IField field) : base(String.Format( "Tank ({0}) is not inside field (Panel with Size=({1}, {2})).", tank, field.Size.Width, field.Size.Height)) { }
public HindranceContainsTankException(IHindrance hindr, ITank tank) : base(String.Format( "Hindrance ({0}) contains tank ({1}).", hindr, tank )) { }
public TankTower Create(ITank tank) { return new TankTower(tank, _bulletSpawner) { AimingSpeed = 3 }; }
public IBullet Create(Vector2 position, float rotation, ITank ownerTank) { return new SimpleBullet(_world, position, rotation, ownerTank, 1); }
public bool IsTankInBounds(ITank tank, double newX, double newY, IGameState gameState) { return newX + tank.Size.Width < gameState.Size.Width && newX > 0 && newY + tank.Size.Height < gameState.Size.Height && newY > 0; }
public IView Create(ITank tank) { return new TankView(tank, _bodyTexture, _towerTexture); }
public Bullet(string resourceId, ITank tank) { ResourceId = resourceId; Tank = tank; Direction = tank.Direction; }
public IController Create(ITank tank) { return new EnemyTankController(tank); }