예제 #1
0
        public void MoveInDirection(Snake.Directions dir, int momentum)
        {
            switch (dir)
            {
            case (Snake.Directions.UP):
            {
                head.Y -= momentum;
                break;
            }

            case (Snake.Directions.DOWN):
            {
                head.Y += momentum;
                break;
            }

            case (Snake.Directions.LEFT):
            {
                head.X -= momentum;
                break;
            }

            case (Snake.Directions.RIGHT):
            {
                head.X += momentum;
                break;
            }
            }
        }
예제 #2
0
 public SnakeBodyPart(Point p, Snake.Directions dir)
 {
     nextShifts   = new Queue <Shift>();
     bodyPart     = new Rectangle(p, defaultSize);
     myDirection  = dir;
     defaultBrush = Brushes.SteelBlue;
 }
예제 #3
0
        public CorsairLedId?GetNextKey(CorsairLedId originKey, Snake.Directions direction)
        {
            var rowAndKeyIndex = GetRowAndKeyIndex(originKey);
            var originRowIndex = rowAndKeyIndex[0];
            var originKeyIndex = rowAndKeyIndex[1];

            switch (direction)
            {
            case Snake.Directions.Up:
                return(GetKeyAtIndex(
                           new int[]
                {
                    originRowIndex - 1,
                    originKeyIndex
                }
                           ));

            case Snake.Directions.Left:
                return(GetKeyAtIndex(
                           new int[]
                {
                    originRowIndex,
                    originKeyIndex - 1
                }
                           ));

            case Snake.Directions.Right:
                return(GetKeyAtIndex(
                           new int[]
                {
                    originRowIndex,
                    originKeyIndex + 1
                }
                           ));

            case Snake.Directions.Down:
                return(GetKeyAtIndex(
                           new int[]
                {
                    originRowIndex + 1,
                    originKeyIndex
                }
                           ));

            default:
                return(null);
            }
        }
예제 #4
0
        protected void MovementThread()
        {
            while (true)
            {
                var key = Console.ReadKey(true).Key;
                if (
                    key == ConsoleKey.LeftArrow ||
                    key == ConsoleKey.RightArrow ||
                    key == ConsoleKey.UpArrow ||
                    key == ConsoleKey.DownArrow
                    )
                {
                    //_snake.MoveSnake(GetDirection(key).GetValueOrDefault());
                    _currentMovementDirection = GetDirection(key).GetValueOrDefault();
                }
            }

            Snake.Directions?GetDirection(ConsoleKey pressedKey)
            {
                switch (pressedKey)
                {
                case ConsoleKey.LeftArrow:
                    return(Snake.Directions.Left);

                case ConsoleKey.RightArrow:
                    return(Snake.Directions.Right);

                case ConsoleKey.DownArrow:
                    return(Snake.Directions.Down);

                case ConsoleKey.UpArrow:
                    return(Snake.Directions.Up);

                default:
                    return(null);
                }
            }
        }
예제 #5
0
        public void Move(int momentum)
        {
            if (nextShifts.Count() > 0)
            {
                if (bodyPart.Location == nextShifts.ToList().First().ShiftSpot.Location)
                {
                    Shift s = nextShifts.Dequeue();
                    myDirection = s.Direction;
                }
            }
            switch (myDirection)
            {
            case (Snake.Directions.UP):
            {
                bodyPart.Y -= momentum;
                break;
            }

            case (Snake.Directions.DOWN):
            {
                bodyPart.Y += momentum;
                break;
            }

            case (Snake.Directions.LEFT):
            {
                bodyPart.X -= momentum;
                break;
            }

            case (Snake.Directions.RIGHT):
            {
                bodyPart.X += momentum;
                break;
            }
            }
        }
예제 #6
0
파일: Shift.cs 프로젝트: martinhschei/snake
 public Shift(Rectangle snapShot, Snake.Directions dir)
 {
     ShiftSpot = snapShot;
     Direction = dir;
 }