static void Main(string[] args) { /* * normal interface * IVehicle vehicle = new Car(); * Driver driver = new Driver(vehicle); * driver.Drive(); */ //*reflection operate ITank _tank = new MyTank(); //get mate data of tank's type var tank = _tank.GetType(); //reflection the methods of MyTank type object otank = Activator.CreateInstance(tank); // MethodInfo must add Microsoft.Extention.DependenceInjection in NuGet MethodInfo FireMethod = tank.GetMethod("Fire"); MethodInfo RunMethod = tank.GetMethod("Run"); //Invoke run and fire methods FireMethod.Invoke(otank, null); RunMethod.Invoke(otank, null); }
private static void PopulateMyHiddenTank(MyTank prevMyTank, List <Tree> trees, Direction?direction) { var prevMyTankStepPosition = prevMyTank.GetNextPositionNotCheckedForCanMove(direction); foreach (var tree in trees) { if (prevMyTankStepPosition != tree.Point) { continue; } var thisHiddenMyTank = prevMyTank.DeepClone(); thisHiddenMyTank.Point = tree.Point; thisHiddenMyTank.Direction = direction; thisHiddenMyTank.UpdateElementByDirection(); var cell = Field.GetCell(tree.Point); cell.Items.Insert(0, thisHiddenMyTank); State.ThisRound.MyTank = thisHiddenMyTank; if (State.PrevRound.CurrentMoveCommands.Contains(Direction.Act)) { var bulletPoint = BaseMobile.Shift(prevMyTank.Point, direction, Bullet.DefaultSpeed); var bullet = new Bullet(Element.BULLET, bulletPoint); bullet.Direction = direction; bullet.IsMyBullet = true; var bulletCell = Field.GetCell(bulletPoint); bulletCell.Items.Insert(0, bullet); State.ThisRound.Bullets.Add(bullet); } } }
public void OnTriggerEnter2D(Collider2D collision) { MyTank hitTank = collision.GetComponent <MyTank>(); if (hitTank != null) { hitTank.TriggerPickup(this.ownType); Destroy(gameObject); } }
public void RegisterTank(MyTank newTank) { parentTank = newTank; if (newTank.shielded) { TurnOnShield(); } else { TurnOffShield(); } }
public Present() { view = new View(); tank = new MyTank(); bot = new BotTanks(); music = new PlayMusic(); gameOver = new GameOver(); post = new PostInFacebook(); Events(); new Task(view.Render).Start(); new Task(ThreadBot).Start(); view.Click(); }
public void Awake() { active = false; if (ownCollider == null) { ownCollider = GetComponent <Collider2D>(); } if (ownSprite == null) { ownSprite = GetComponent <SpriteRenderer>(); } if (parentTank == null) { parentTank = GetComponentInParent <MyTank>(); } }
public bool IsInDeadZone(MyTank myTank) { return(myTank.Point.IsInArea(_start, _end)); }