Пример #1
0
 public TankController(Tank tank)
 {
     this.action = TankAction.None;
     this.Tank = tank;
     this.autoReset = new AutoResetEvent(false);
 }
Пример #2
0
        protected override void Initialize()
        {
            this.IsGameActive = true;
            var players = this.Players.ToList();
            if (players != null)
            {
                //var x = this.rand.Next((int)TankConfig.ArenaEndX - (int)TankConfig.ArenaStartX) + TankConfig.ArenaStartX;
                //var y = this.rand.Next((int)TankConfig.ArenaEndY - (int)TankConfig.ArenaStartY) + TankConfig.ArenaStartY;
                var mid = new PointF((TankConfig.ArenaEndX - TankConfig.ArenaStartX)/2,
                    (TankConfig.ArenaEndY - TankConfig.ArenaStartY)/2);
                var slice = (2*Math.PI)/players.Count();
                var currentPieAngle = -(Math.PI / 2);

                foreach (var player in players)
                {
                    var localPlayer = player;

                    var position = new PointF(mid.X + (float) Math.Sin(currentPieAngle)*(TankConfig.ArenaEndX/4),
                        mid.Y + (float) Math.Cos(currentPieAngle)*(TankConfig.ArenaEndY/4));
                    currentPieAngle += slice;

                    var tank = new Tank { ControllerName = localPlayer.GetType().Name, Position = position };
                    var controller = new TankController(tank);
                    localPlayer.Controller = controller;
                    localPlayer.Enviroment = this;
                    var task = Task.Factory.StartNew(() => localPlayer.Run(), this.CancelToken);
                    this.Managers.Add(new Manager
                                         {
                                             Player = player,
                                                             Controller = controller,
                                                             Task = task,
                                         });
                }
            }
        }