예제 #1
0
 private void UserControl_Loaded(object sender, RoutedEventArgs e)
 {
     schart.CreateCoordinate(0, 800, 0, 1);
     mDataList.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(mDataList_CollectionChanged);
     dataDia.ItemsSource          = mDataList;
     mFormatDouble = GlobalProvider.FormatNumber;
     mGPIOMove     = MoveEnum.Move0_5mm;
 }
예제 #2
0
 public void Move(MoveEnum moveDirection)
 {
     if (!Dead)
     {
         CheckNeighbour(moveDirection);
     }
     CheckIfDead();
 }
예제 #3
0
 public Move(MoveEnum type, Dictionary <string, object> args)
 {
     if (args == null)
     {
         throw new ArgumentException("Arguments cannot be null");
     }
     this.Type      = type;
     this.Arguments = args;
 }
예제 #4
0
        public static DateTime TestWeekDay(DateTime dato, MoveEnum Move = MoveEnum.Next)
        {
            DateTime res = dato;

            while (Convert.ToInt32(res.DayOfWeek) < Convert.ToInt32(DayOfWeek.Monday) || Convert.ToInt32(res.DayOfWeek) > Convert.ToInt32(DayOfWeek.Friday))
            {
                res = AddDays(res, Convert.ToInt32(Move));
            }
            return(res);
        }
예제 #5
0
        public static DateTime FindWeekDay(DateTime dato, MoveEnum Move = MoveEnum.Next)
        {
            DateTime res = dato;

            //while (!((int) res.DayOfWeek < System.Convert.ToInt32(DayOfWeek.Monday)| (int) res.DayOfWeek > System.Convert.ToInt32(DayOfWeek.Friday)))
            while (!(Convert.ToInt32(res.DayOfWeek) < Convert.ToInt32(DayOfWeek.Monday) || Convert.ToInt32(res.DayOfWeek) > Convert.ToInt32(DayOfWeek.Friday)))
            {
                res = AddDays(res, Convert.ToInt32(Move));
            }
            return(res);
        }
예제 #6
0
        /// <summary>
        /// Send movement command to with connector
        /// </summary>
        /// <param name="command">Command to send with speed</param>
        /// <param name="speed">Speed from <c>MinInputSpeed</c> to <c>MaxInputSpeed</c> interval</param>
        /// <returns>true, if all is good, else false</returns>
        protected bool SendMovement(MoveEnum command, double speed)
        {
            if (speed < MinInputSpeed || speed > MaxInputSpeed)
            {
                return(false);
            }

            byte[] buff = CalcSpeed(speed).NumToArray().Add((byte)command, 0);
            SendCommand(ControllerEnum.MovementController, buff);

            return(true);
        }
예제 #7
0
        public void Move()
        {
            MoveEnum movement = CalculateMoveDirection();

            if (!Dead)
            {
                CheckNeighbour(movement);
            }
            else
            {
                this.tile.BackgroundImage = Image.FromFile(@"..\..\Images\follower_dead.png");
            }
        }
예제 #8
0
        private Tile CheckNeighbour(Tile neighbour, MoveEnum moveDirection)
        {
            KeyValuePair<Tile, MoveEnum> neighbourObject = neighbour.Neighbours.Where(tile => tile.Value == moveDirection).FirstOrDefault();  // Returns first TileNeighbourDto that match condition (or null if condition isn't matched)
            if (neighbourObject.Key != null)
            {
                Tile boxNeighbour = neighbourObject.Key;

                if (!(boxNeighbour.GameObject is IUnmoveable || boxNeighbour.GameObject is IArtificial))
                {
                    if (boxNeighbour.GameObject is IMovable)
                    {
                        boxNeighbour = CheckNeighbour(boxNeighbour, moveDirection) ?? boxNeighbour; // Overwrites boxNeighbour when CheckNeighbour is not null
                    }

                    IObject playerGameObject = neighbour.GameObject;
                    IObject neighbourGameObject = boxNeighbour.GameObject;

                    if (!(boxNeighbour.GameObject is IMovable))
                    {
                        neighbour.GameObject = neighbourGameObject;
                        boxNeighbour.GameObject = playerGameObject;
                        Tile returnTile = neighbour;
                        neighbour = boxNeighbour;
                        return returnTile;
                    }
                }
                else if (boxNeighbour.GameObject is Portal)
                {
                    Portal neighbourGameObject = boxNeighbour.GameObject as Portal;
                    KeyValuePair<Tile, MoveEnum> targetNeighbour = neighbourGameObject.Target.Neighbours.Where(tile => tile.Value == moveDirection).FirstOrDefault();
                    if (targetNeighbour.Key != null && !(targetNeighbour.Key.GameObject is IUnmoveable))
                    {
                        if (targetNeighbour.Key.GameObject is IMovable box)
                        {
                            neighbourGameObject.Target.Neighbours.Remove(targetNeighbour.Key);
                            neighbourGameObject.Target.Neighbours.Add(box.Move(targetNeighbour.Key, moveDirection) ?? neighbour, moveDirection);  
                        }
                        IObject boxGameObject = neighbour.GameObject;

                        if (!(targetNeighbour.Key.GameObject is IMovable))
                        {
                            neighbour.GameObject = targetNeighbour.Key.GameObject;
                            targetNeighbour.Key.GameObject = boxGameObject;
                            Tile returnTile = neighbour;
                            return returnTile;
                        }
                    }
                }
            }
            return null;
        }
예제 #9
0
        private bool CanMoveThisDirection(MoveEnum moveDirection)
        {
            KeyValuePair <Tile, MoveEnum> neighbourObject = tile.Neighbours.Where(tile => tile.Value == moveDirection).FirstOrDefault();

            if (neighbourObject.Key != null)
            {
                Tile neighbour = neighbourObject.Key;

                if (!(neighbour.GameObject is IUnmoveable) && !(neighbour.GameObject is IMovable))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #10
0
        private void CheckNeighbour(MoveEnum moveDirection)
        {
            KeyValuePair <Tile, MoveEnum> neighbourObject = tile.Neighbours.Where(tile => tile.Value == moveDirection).FirstOrDefault();  // Returns first TileNeighbourDto that match condition (or null if condition isn't matched)

            if (neighbourObject.Key != null)
            {
                Tile neighbour = neighbourObject.Key;

                if (!(neighbour.GameObject is IUnmoveable))
                {
                    if (neighbour.GameObject is IMovable box)                        // Checks if GameObject is of type IMovable. If so, then GameObject is assigned to variable 'box'.
                    {
                        neighbour = box.Move(neighbour, moveDirection) ?? neighbour; // Overwrite neighbour if returned Tile from box.Move() is not null
                    }

                    IObject playerGameObject    = tile.GameObject;
                    IObject neighbourGameObject = neighbour.GameObject;

                    if (!(neighbour.GameObject is IMovable))
                    {
                        tile.GameObject      = neighbourGameObject;
                        neighbour.GameObject = playerGameObject;
                        this.tile            = neighbour;
                    }
                }
                else if (neighbour.GameObject is Portal)                                                                                                               //checks if neighbour is a portal
                {
                    Portal neighbourGameObject = neighbour.GameObject as Portal;                                                                                       //makes neighbour.GameObject a portal, which doesn't conflict since it is a portal
                    KeyValuePair <Tile, MoveEnum> targetNeighbour = neighbourGameObject.Target.Neighbours.Where(tile => tile.Value == moveDirection).FirstOrDefault(); //checks target portal neighbours
                    if (targetNeighbour.Key != null && !(targetNeighbour.Key.GameObject is IUnmoveable))                                                               //checks to see if the target neighbour isn't null or isn't unmoveable
                    {
                        if (targetNeighbour.Key.GameObject is IMovable box)
                        {
                            neighbourGameObject.Target.Neighbours.Remove(targetNeighbour.Key);                                                   //temporarily deletes the neighbour
                            neighbourGameObject.Target.Neighbours.Add(box.Move(targetNeighbour.Key, moveDirection) ?? neighbour, moveDirection); // Overwrite neighbour if returned Tile from box.Move() is not null
                        }
                        IObject playerGameObject = tile.GameObject;

                        if (!(targetNeighbour.Key.GameObject is IMovable)) //checks if targetneighbour isn't movable
                        {
                            tile.GameObject = targetNeighbour.Key.GameObject;
                            targetNeighbour.Key.GameObject = playerGameObject;
                            this.tile = targetNeighbour.Key;
                        }
                    }
                }
            }
        }
예제 #11
0
        /// <summary>
        /// 电机到指定位置
        /// </summary>
        /// <param name="order"></param>
        public static void MotorMove(MoveEnum move)
        {
            switch (move)
            {
            case MoveEnum.Move0_5mm:
                SendCommand("AB");
                break;

            case MoveEnum.Move0_2mm:
                SendCommand("AC");
                break;

            case MoveEnum.Move0_05mm:
                SendCommand("AD");
                break;
            }
        }
예제 #12
0
        private MoveEnum CalculateMoveDirection()
        {
            Array    values = Enum.GetValues(typeof(MoveEnum));
            MoveEnum randomMoveDirection = (MoveEnum)values.GetValue(RandomEnum.Next(values.Length));


            while (!CanMoveThisDirection(randomMoveDirection))  // If randomMoveDirection is false loop till plausible
            {
                randomMoveDirection = (MoveEnum)values.GetValue(RandomEnum.Next(values.Length));
                if (tile.Neighbours.All(neighbour => CanMoveThisDirection(neighbour.Value) == false))  // Checks if all neighbours are inmovable
                {
                    Dead = true;
                    break;
                }
            }

            return(randomMoveDirection);
        }
예제 #13
0
    IEnumerator MoveCamera_StopWhenRectCashPlayerOrCollider_IEnumerator(MoveEnum moveEnum, float speed, StoryHander OnMoveFished = null)
    {
        yield return(new WaitForSeconds(0.01f));

        if (moveEnum == MoveEnum.right)
        {
            transform.Translate(1 * Time.deltaTime * speed, 0, 0);
            if (RectLeft.Contains(Camera.main.WorldToScreenPoint(Player.transform.position)))
            {
                isUseCamera = false;

                if (OnMoveFished != null)
                {
                    OnMoveFished();
                }
                yield break;
            }
            else if (RectRight.Contains(Camera.main.WorldToScreenPoint(Player.transform.position)))
            {
                isUseCamera = false;
                if (OnMoveFished != null)
                {
                    OnMoveFished();
                }
                yield break;
            }
        }

        else if (moveEnum == MoveEnum.left)
        {
            transform.Translate(-1 * Time.deltaTime * speed, 0, 0);
            if (RectLeft.Contains(Camera.main.WorldToScreenPoint(Player.transform.position)))
            {
                isUseCamera = false;
                yield break;
            }
            else if (RectRight.Contains(Camera.main.WorldToScreenPoint(Player.transform.position)))
            {
                isUseCamera = false;
                yield break;
            }
        }
        StartCoroutine(MoveCamera_StopWhenRectCashPlayerOrCollider_IEnumerator(moveEnum, speed, OnMoveFished));
    }
예제 #14
0
        private void CheckNeighbour(MoveEnum moveDirection)
        {
            KeyValuePair <Tile, MoveEnum> neighbourObject = tile.Neighbours.Where(tile => tile.Value == moveDirection).FirstOrDefault(); // Returns first TileNeighbourDto that match condition (or null if condition isn't matched)

            if (neighbourObject.Key != null)
            {
                Tile neighbour = neighbourObject.Key;

                if (!(neighbour.GameObject is IUnmoveable) || !(neighbour.GameObject is IMovable))
                {
                    IObject playerGameObject    = tile.GameObject;
                    IObject neighbourGameObject = neighbour.GameObject;

                    tile.GameObject      = neighbourGameObject;
                    neighbour.GameObject = playerGameObject;
                    this.tile            = neighbour;
                }
            }
        }
예제 #15
0
        /// <summary>
        /// 计算Y轴
        /// </summary>
        /// <returns></returns>
        public static double[] CalcY(MoveEnum markOrder)
        {
            double[] blankList   = null;
            double[] measureList = null;
            switch (markOrder)
            {
            case MoveEnum.Move0_5mm:
                blankList   = mBlankList_1;
                measureList = mMeasureList_1;
                break;

            case MoveEnum.Move0_2mm:
                blankList   = mBlankList_2;
                measureList = mMeasureList_2;
                break;

            case MoveEnum.Move0_05mm:
                blankList   = mBlankList_2;
                measureList = mMeasureList_2;
                break;
            }
            return(CalcY(blankList, measureList));
        }
예제 #16
0
        /// <summary>
        /// 获取并保存测量数据到实例
        /// </summary>
        ///<param name="markOrder">0.5mm,0.2mm,0.05mm</param>
        /// <returns></returns>
        public static double[] GetMeasureList(MoveEnum markOrder)
        {
            if (!isSimulate)
            {
                MotorMove(markOrder);
            }
            double[] list = GetSpectrum();
            switch (markOrder)
            {
            case MoveEnum.Move0_5mm:
                mMeasureList_1 = list;
                break;

            case MoveEnum.Move0_2mm:
                mMeasureList_2 = list;
                break;

            case MoveEnum.Move0_05mm:
                mMeasureList_3 = list;
                break;
            }
            return(list);
        }
예제 #17
0
        /// <summary>
        /// 获得指定波长的吸光值
        /// </summary>
        /// <param name="blank"></param>
        /// <param name="measure"></param>
        /// <param name="bestWave"></param>
        /// <returns></returns>
        public static double GetAbs(double wave, MoveEnum markOrder)
        {
            double[] blankList   = null;
            double[] measureList = null;
            switch (markOrder)
            {
            case MoveEnum.Move0_5mm:
                blankList   = mBlankList_1;
                measureList = mMeasureList_1;
                break;

            case MoveEnum.Move0_2mm:
                blankList   = mBlankList_2;
                measureList = mMeasureList_2;
                break;

            case MoveEnum.Move0_05mm:
                blankList   = mBlankList_2;
                measureList = mMeasureList_2;
                break;
            }

            return(GetAbs(wave, blankList, measureList));
        }
예제 #18
0
 public MoveCommand(CharacterController characterController, MoveEnum direction, float moveSpeed)
 {
     _characterController = characterController;
     _direction           = direction;
     _moveSpeed           = moveSpeed;
 }
예제 #19
0
        public Point Move(MoveEnum move)
        {
            switch (Direction)
            {
            case DirectionEnum.Right:
                switch (move)
                {
                case MoveEnum.Left:
                    Direction = DirectionEnum.Up;
                    break;

                case MoveEnum.Right:
                    Direction = DirectionEnum.Down;
                    break;

                default:
                    this.Position.Y++;
                    return(Position);
                }
                break;

            case DirectionEnum.Left:
                switch (move)
                {
                case MoveEnum.Left:
                    Direction = DirectionEnum.Down;
                    break;

                case MoveEnum.Right:
                    Direction = DirectionEnum.Up;
                    break;

                default:
                    this.Position.Y--;
                    return(Position);
                }
                break;

            case DirectionEnum.Up:
                switch (move)
                {
                case MoveEnum.Left:
                    Direction = DirectionEnum.Left;
                    break;

                case MoveEnum.Right:
                    Direction = DirectionEnum.Right;
                    break;

                default:
                    this.Position.X--;
                    return(Position);
                }
                break;

            case DirectionEnum.Down:
                switch (move)
                {
                case MoveEnum.Left:
                    Direction = DirectionEnum.Right;
                    break;

                case MoveEnum.Right:
                    Direction = DirectionEnum.Left;
                    break;

                default:
                    this.Position.X++;
                    return(Position);
                }
                break;

            default:
                break;
            }
            return(Position);
        }
예제 #20
0
파일: IAIPlugin.cs 프로젝트: xul8tr/CSharp
 public AIStep()
 {
     nextStep = StepEnum.STAY;
     nextMove = MoveEnum.RIGHT;
 }
예제 #21
0
        /// <summary>
        /// Turtle Challenge
        /// 1. Read from the file game-settings the settings necessairy for the game
        /// 2. Read from the file moves the moves tha the turtle has to make
        /// 3. Write in the file moves the what happens after every move of the turtle
        /// </summary>
        /// <param name="settingsFilePath"> The file path for the game settings</param>
        /// <param name="movesFilePath"> The file path for the moves</param>
        public static void RunTurtleChallenge(string settingsFilePath, string movesFilePath)
        {
            List <MoveEnum> moves        = new List <MoveEnum>();
            Settings        gameSettings = new Settings();

            //Read and map settings
            using (StreamReader sr = new StreamReader(settingsFilePath))
            {
                // Read the stream to a string, and write the string to the console.
                String line = sr.ReadToEnd();
                Console.WriteLine(line);
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Settings));
                MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(line));
                gameSettings = (Settings)serializer.ReadObject(ms);
            }

            //Read and map Moves
            using (StreamReader sr = new StreamReader(movesFilePath))
            {
                // Read the stream to a string, and write the string to the console.
                String   line        = sr.ReadToEnd();
                string[] stringMoves = line.Split(',');


                foreach (string m in stringMoves)
                {
                    MoveEnum mov = (MoveEnum)Enum.Parse(typeof(MoveEnum), m);
                    moves.Add(mov);
                }
            }

            // Append in the file moves all the results from the turtle movement
            using (StreamWriter file = new StreamWriter(movesFilePath, append: true))
            {
                // First append a line with the Board dimensions and Mine positions for guidance
                StringBuilder set = new StringBuilder();
                set.Append("Board" + ": " + "(" + gameSettings.Board.MaxX + "," + gameSettings.Board.MaxY + ")/ ");
                foreach (var min in gameSettings.MinePositions)
                {
                    set.Append("Mine" + ": " + "(" + min.X + "," + min.Y + ") ");
                }
                file.WriteLine(Environment.NewLine);
                file.WriteLine(set.ToString(), Environment.NewLine);

                Tile          currentPosition = gameSettings.StartingPosition;
                DirectionEnum direction       = gameSettings.Direction;

                foreach (MoveEnum m in moves)
                {
                    Tile          newPosition = new Tile();
                    StringBuilder str         = new StringBuilder();
                    str.Append(m.ToString() + ": ");
                    switch (m)
                    {
                    case MoveEnum.MOVE:
                        newPosition = GetPositionFromMove(currentPosition, direction, gameSettings.Board);
                        break;

                    case MoveEnum.ROTATE:
                        direction   = (int)direction != 4 ? direction + 1 : DirectionEnum.NORTH;
                        newPosition = currentPosition;
                        break;
                    }
                    // Evaluate case and get log message (among with a WIN flag)
                    EvaluationAndLog eval = GetLogMessage(gameSettings, newPosition, currentPosition, m, direction);
                    currentPosition = newPosition; // Now we can set as the current position the new position
                    // Write the line in the file
                    file.WriteLine(m.ToString() + ": " + eval.Message + " CurrentPosition: (" + currentPosition.X + "," + currentPosition.Y + ")", Environment.NewLine);
                    // If the evaluation has given the flag WIN true then the game is over.
                    if (eval.Win)
                    {
                        break;
                    }
                }
            }
        }
예제 #22
0
        /// <summary>
        /// Evaluate the move and return the appropriate message
        /// </summary>
        /// <param name="settings">The game settings</param>
        /// <param name="newPosition">The new positions after the move</param>
        /// <param name="currentPosition">The current position before the move</param>
        /// <param name="move">The type of move</param>
        /// <param name="direction">The direction of the turtle (if the move if type of ROTATE then we are talking about the new direction)</param>
        /// <returns></returns>
        public static EvaluationAndLog GetLogMessage(Settings settings, Tile newPosition, Tile currentPosition, MoveEnum move, DirectionEnum direction)
        {
            EvaluationAndLog model  = new EvaluationAndLog();
            string           result = string.Empty;

            if (newPosition.X == settings.ExitPosition.X && newPosition.Y == settings.ExitPosition.Y)
            {
                model.Win     = true;
                model.Message = "You found the exit point! YOU WIN!";
                return(model);
            }
            else if (settings.MinePositions.Any(t => t.X == newPosition.X && t.Y == newPosition.Y))
            {
                model.Message = "You have hit a mine"; // According to the example we don't finish the game when a mine is stepped.
                return(model);
            }
            else if (move == MoveEnum.ROTATE)
            {
                if (GetDangerFromRotation(settings.MinePositions, direction, currentPosition))
                {
                    model.Message = "Still in danger";
                    return(model);
                }
            }

            model.Message = "Success!";
            return(model);
        }
예제 #23
0
 public Tile Move(Tile neighbour, MoveEnum moveDirection)
 {
     Tile returnTile = CheckNeighbour(neighbour, moveDirection);
     this.tile = returnTile;
     return returnTile;
 }
예제 #24
0
 /// <summary>
 /// 移动相机,当相机触碰到Rect触碰到玩家或者特殊Collider的时候停止移动
 /// </summary>
 public void MoveCamera_StopWhenRectCashPlayerOrCollider(MoveEnum moveEnum, float speed, StoryHander OnMoveFished = null)
 {
     isUseCamera = true;
     StartCoroutine(MoveCamera_StopWhenRectCashPlayerOrCollider_IEnumerator(moveEnum, speed, OnMoveFished));
 }