示例#1
0
        public bool CanEnterOnSide(Robot.Robot robot, TileCoordinates coordinates, FlatDirection side, bool ignoreMovingObjects)
        {
            if (GetIncline(robot.Level, coordinates, side.Opposite()) <= 0 && IsSolidOnSide(robot.Level, coordinates, side.ToDirection()))
            {
                return(false);
            }
            if (IsOccupiedByNonVacatingRobot(robot.Level, coordinates, side, robot, ignoreMovingObjects))
            {
                return(false);
            }
            var belowCoords = coordinates.Below();
            var belowTile   = robot.Level.Tiles[belowCoords];

            if (belowTile.IsConveyor(robot.Level, belowCoords))
            {
                var conveyor          = (Conveyor)belowTile.GetEntity(robot.Level, belowCoords);
                var conveyorDirection = belowTile.GetDirection(robot.Level, belowCoords);
                if (conveyor.CurrentMode == ConveyorMode.Forwards)
                {
                    return(side != conveyorDirection);
                }
                else if (conveyor.CurrentMode == ConveyorMode.Reverse)
                {
                    return(side != conveyorDirection.Opposite());
                }
            }
            return(true);
        }
示例#2
0
        public override void OnSteppedOff(ILevel level, TileCoordinates coordinates, Robot.Robot robot, FlatDirection direction)
        {
            if (m_colour == null || robot.Colour == m_colour)
            {
                switch (m_type)
                {
                case ButtonType.Momentary:
                {
                    if (IsPowered(level, coordinates))
                    {
                        SetPowered(level, coordinates, false, true);
                        if (m_soundPath != null)
                        {
                            level.Audio.PlaySound(m_soundPath);
                        }
                    }
                    break;
                }

                case ButtonType.Directional:
                {
                    OnDirectionalStepOnOff(level, coordinates, direction);
                    break;
                }
                }
            }
        }
 public override void OnSteppedOff(ILevel level, TileCoordinates coordinates, Robot.Robot robot, FlatDirection direction)
 {
     if (m_trigger == FallingTrigger.SteppedOn)
     {
         TryFalling(level, coordinates);
     }
 }
示例#4
0
文件: Boss.cs 项目: spiri91/ToyRobot
        public Boss(ILogger logger, Table.Table table, Robot.Robot robot)
        {
            (logger == null || table == null || robot == null)
            .IfTrue(() => throw new System.Exception("Bad arguments"));

            _logger          = logger;
            _table           = table;
            _robot           = robot;
            _robot.Complain += HearHim;
        }
        public void DefinirCantRobots()
        {
            int cant;

            Console.WriteLine("Digite la cantidad de robots que necesita agregar a su granja: ");
            cant = int.Parse(Console.ReadLine());
            for (int i = 0; i < cant; i++)
            {
                Robot.Robot temp = new Robot.Robot();
                granjaSeleccionada.setRobots(temp);
            }
        }
示例#6
0
 public void OnSteppedOff(ILevel level, TileCoordinates coordinates, Robot.Robot robot, FlatDirection direction)
 {
     if (IsExtension())
     {
         var below = coordinates.Below();
         level.Tiles[below].OnSteppedOff(level, below, robot, direction);
     }
     else
     {
         m_behaviour.OnSteppedOff(level, coordinates, robot, direction);
     }
 }
示例#7
0
        public Orchestrator(ILogger logger)
        {
            var cells = new List <Cell.Cell>();
            var index = 1;

            _numberOfCells.GenerateForLoop(() => { cells.Add(new EmptyCell(index)); index++; });

            var robot = new Robot.Robot(index, _validMove, _calculateIndex);

            cells.Add(robot);

            var table = new Table.Table(logger, cells);

            _boss = new Boss.Boss(logger, table, robot);
        }
 public void setRobots(Robot.Robot value)
 {
     robots.Add(value);
 }
示例#9
0
 public Settings(Robot.Robot robot, Router.Router router)
 {
     this.router = router;
     this.robot  = robot;
 }
示例#10
0
 public Settings(Robot.Robot robot, Router.Router router)
 {
     this.router = router;
     this.robot = robot;
 }
示例#11
0
        public RobotControlViewModel(INavigationService navigationService, IMainCommandBar commandBar, IChart chart)
        {
            SecurityList = new List <Entities.Security>();

            this._navigationService = navigationService;
            this.DealList           = new ObservableCollection <Entities.Deal>();
            this.PositionList       = new ObservableCollection <PositionViewModel>();
            this.AnalystDataList    = new ObservableCollection <Robot.AnalystData>();

            this._commandBar = commandBar;
            this._chart      = chart;

            Messenger.Default.Register <SecurityListLoadedMessage>(this, (msg) =>
            {
                this.SecurityList = msg.SecurityList.Where(s => s.AlgoTrade).ToList();
            });

            this.StartRobot = new RelayCommand(() =>
            {
                this._robot = new Robot.Robot(new Robot.CandleStrategy(), SecurityList);

                this._robot.Run();
            });


            this.BuyCmd = new RelayCommand <Robot.AnalystData>(async d =>
            {
                string msg = string.Format("Купить {0} за {1}?", d.Sec, d.LastPrice);
                var dlg    = new Windows.UI.Popups.MessageDialog(msg);

                dlg.Commands.Add(new Windows.UI.Popups.UICommand("Accept"));
                dlg.Commands.Add(new Windows.UI.Popups.UICommand("Cancel"));

                var dialogResult = await dlg.ShowAsync();

                if (dialogResult.Label == "Accept")
                {
                    Messenger.Default.Send <ClientMakeDealMessage>(new ClientMakeDealMessage()
                    {
                        Sec       = d.Sec,
                        Operation = "open long"
                    });
                }
            });

            this.ClosePositionCmd = new RelayCommand <string>(async code =>
            {
                string msg = string.Format("Закрыть позицию {0}?", code);
                var dlg    = new Windows.UI.Popups.MessageDialog(msg);

                dlg.Commands.Add(new Windows.UI.Popups.UICommand("Accept"));
                dlg.Commands.Add(new Windows.UI.Popups.UICommand("Cancel"));

                var dialogResult = await dlg.ShowAsync();

                if (dialogResult.Label == "Accept")
                {
                    Messenger.Default.Send <ClosePositionMessage>(new ClosePositionMessage()
                    {
                        Code = code
                    });
                }
            });

            Messenger.Default.Register <ShowAnalystDataMessage>(this, (msg) =>
            {
                dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    if (AnalystDataList.Count == 0)
                    {
                        foreach (AnalystData data in msg.AnalystDatalist)
                        {
                            this.AnalystDataList.Add(data);
                        }
                    }

                    if (AnalystDataList.Count > 0)
                    {
                        foreach (AnalystData data in msg.AnalystDatalist)
                        {
                            var advice = this.AnalystDataList.Single(d => d.Sec == data.Sec);

                            advice.Advice    = data.Advice;
                            advice.LastPrice = data.LastPrice;
                        }
                    }
                });
            });

            Messenger.Default.Register <ShowDataMessage>(this, (msg) =>
            {
                dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var newdeals = msg.Deals.Where(d => !this.DealList.Select(old => old.Id).Contains(d.Id));

                    foreach (Entities.Deal deal in newdeals)
                    {
                        this.DealList.Add(deal);
                    }

                    var newpos = msg.Positions.Where(p => !this.PositionList.Select(old => old.Code).Contains(p.Code)).ToList();

                    var oldpos = msg.Positions.Where(p => this.PositionList.Select(old => old.Code).Contains(p.Code)).ToList();

                    foreach (Entities.Position pos in newpos)
                    {
                        this.PositionList.Add(new PositionViewModel(pos));
                    }

                    foreach (Entities.Position pos in oldpos)
                    {
                        this.PositionList.Single(p => p.Code == pos.Code).Update(pos);
                    }
                });
            });
        }
示例#12
0
        public void OrderRobot(Robot.Robot robot)
        {
            CheckIfNoRobotAvailable(robot);

            action(robot);
        }
示例#13
0
 protected virtual void CheckIfNoRobotAvailable(Robot.Robot robot)
 {
     (robot == null).IfTrue(() => throw new Exception("Missing robot"));
 }
示例#14
0
 private bool IsOccupiedByNonVacatingRobot(ILevel level, TileCoordinates coordinates, FlatDirection side, Robot.Robot exception, bool ignoreMovingRobots)
 {
     if (IsOccupied(level, coordinates))
     {
         var occupant = GetOccupant(level, coordinates);
         if (occupant is Robot.Robot)
         {
             var robot = (Robot.Robot)occupant;
             if (robot == exception)
             {
                 // Ignore ourselves
                 return(false);
             }
             if (ignoreMovingRobots && robot.IsMoving)
             {
                 // Ignore moving robots
                 return(false);
             }
             if (robot.Location != coordinates && robot.IsTurning)
             {
                 // Ignore robot reserving the space ahead of them when turning
                 return(false);
             }
             if ((robot.Location == coordinates || robot.Location == coordinates.Below()) &&
                 robot.Direction != side &&
                 robot.IsVacating)
             {
                 // Ignore robot about to leave
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
示例#15
0
 public void OnOccupy(ILevel level, TileCoordinates coordinates, Robot.Robot robot)
 {
     Tile.SetSubState(level, coordinates, 1, true);
 }
示例#16
0
 public virtual void OnSteppedOff(ILevel level, TileCoordinates coordinates, Robot.Robot robot, FlatDirection direction)
 {
 }