Example #1
0
 public void Move(int offset,Direction d)
 {
     if (d == Direction.RIGHT) { x = x + offset; }
     if (d == Direction.LEFT) { x = x - offset; }
     if (d == Direction.DOWN) { y = y + offset; }
     if (d == Direction.UP) { y = y - offset; }
 }
Example #2
0
 public void Move(int offset, Direction direction)
 {
     switch(direction)
     {
         case Direction.RIGHT:
             {
                 x += offset;
                 break;
             }
         case Direction.LEFT:
             {
                 x -= offset;
                 break;
             }
         case Direction.UP:
             {
                 y -= offset;
                 break;
             }
         case Direction.DOWN:
             {
                 y += offset;
                 break;
             }
     }
 }
Example #3
0
 public override void Update(GameTime gameTime, IInput input)
 {
     if (input != null)
     {
         if (input.IsKeyDown(Keys.Left) && direction != Direction.Right)
         {
             Direction = Direction.Left;
             return;
         }
         if (input.IsKeyDown(Keys.Right) && direction != Direction.Left)
         {
             Direction = Direction.Right;
             return;
         }
         if (input.IsKeyDown(Keys.Up) && direction != Direction.Bottom)
         {
             Direction = Direction.Top;
             return;
         }
         if (input.IsKeyDown(Keys.Down) && direction != Direction.Top)
         {
             Direction = Direction.Bottom;
             return;
         }
     }
 }
Example #4
0
 //Updates the current movement direction
 void UpdateMovementDirection(Snake.Direction dir)
 {
     if (!IsDirectionOpposite(dir, snake.movementDirection))
     {
         snake.movementDirection = dir;
     }
 }
Example #5
0
 public SnakeHead(Game game, IRenderItemFactory factory)
     : base(game, factory, new Vector2I(0, 0))
 {
     Direction = Game.Rules.SnakeStartDirection;
     direction = Direction;
     Position = Game.Rules.SnakeStartPosition;
     RenderItem = factory.CreateRenderItem(RenderItemType.SnakeHead);
 }
Example #6
0
 public SnakePlayer(SnakeForm Form)
 {
     m_SnakeParts.Add(new BodyPart(100, 0, Direction.right));
     m_SnakeParts.Add(new BodyPart(80, 0, Direction.right));
     m_SnakeParts.Add(new BodyPart(60, 0, Direction.right));
     m_MoveDirection = Direction.right;
     m_PendingSegments = 0;
     GameForm = Form;
 }
Example #7
0
        public override void SnakeTick(World world)
        {
            Vector2I oldPosition = Position;
            Move();
            direction = Direction;

            CheckCollision(world);
            world.AddBody(new SnakeBody(Game, Factory, oldPosition));
        }
Example #8
0
File: Snake.cs Project: anzed/snake
 public Snake(Point tail, int length, Direction direction)
 {
     pList = new List<Point>();
     for(int i = 0; i < length; i++)
     {
         Point p = new Point(tail);
         p.Move(i, direction);
         pList.Add(p);
     }
 }
Example #9
0
 public Settings()
 {
     Width = 16;
     Height = 16;
     Speed = 17;
     Score = 0;
     Points = 10;
     GameOver = false;
     direction = Direction.Left;
 }
Example #10
0
File: Snake.cs Project: UnSi/Snake
 public void HandleKey(ConsoleKey key)
 {
     switch (key)
     {
         case (ConsoleKey.RightArrow): direction = Direction.RIGHT; break;
         case (ConsoleKey.LeftArrow): direction = Direction.LEFT; break;
         case (ConsoleKey.UpArrow): direction = Direction.UP; break;
         case (ConsoleKey.DownArrow): direction = Direction.DOWN; break;
     }
 }
Example #11
0
 public void HandleKey(ConsoleKey key)
 {
     if (key == ConsoleKey.LeftArrow && this.direction != Direction.RIGHT)
         this.direction = Direction.LEFT;
     else if (key == ConsoleKey.RightArrow && this.direction != Direction.LEFT)
         this.direction = Direction.RIGHT;
     else if (key == ConsoleKey.DownArrow && this.direction != Direction.UP)
         this.direction = Direction.DOWN;
     else if (key == ConsoleKey.UpArrow && this.direction != Direction.DOWN)
         this.direction = Direction.UP;
 }
Example #12
0
 public Snake(CPoint tail, int length, Direction _direction)
 {
     direction = _direction;
     pList = new List<CPoint>();
     for (int i = 0; i < length; i++)
     {
         CPoint p = new CPoint(tail);
         p.Move(i, direction);
         pList.Add(p);
     }
 }
Example #13
0
 public void Move(int offset, Direction direction)
 {
     if (direction == Direction.RIGHT)
         x = x + offset;
     else if (direction == Direction.LEFT)
         x = x - offset;
     else if (direction == Direction.UP)
         y = y - offset;
     else
         y = y + offset;
 }
Example #14
0
 public void HandleKey(ConsoleKeyInfo key)
 {
     if (key.Key == ConsoleKey.LeftArrow)
         direction = Direction.LEFT;
     else if (key.Key == ConsoleKey.UpArrow)
         direction = Direction.TOP;
     else if (key.Key == ConsoleKey.RightArrow)
         direction = Direction.RIGHT;
     else if (key.Key == ConsoleKey.DownArrow)
         direction = Direction.BOTTOM;
 }
Example #15
0
 public Snake(Point tail, int length, Direction _direction)
 {
    points = new List<Point>();
    direction = _direction;
    for(int _x = 0; _x < length; _x++)
     {
         Point p = new Point(tail);
         p.Move(_x, direction);
         points.Add(p);
     }
 }
Example #16
0
 public void iMoveTo(ConsoleKey Key)
 {
     if (Key == ConsoleKey.LeftArrow)
         direction = Direction.LEFT;
     if (Key == ConsoleKey.RightArrow)
         direction = Direction.RIGHT;
     if (Key == ConsoleKey.UpArrow)
         direction = Direction.UP;
     if (Key == ConsoleKey.DownArrow)
         direction = Direction.DOWN;
 }
Example #17
0
File: Point.cs Project: UnSi/Snake
 public void Move(int offset, Direction direction)
 {
     switch(direction)
     {
         case (Direction.DOWN): y=y+offset; break;
         case (Direction.LEFT): x=x-offset; break;
         case (Direction.RIGHT): x=x+offset; break;
         case (Direction.UP): y=y-offset; break;
         default: Console.WriteLine("Error"); break;
     }
 }
Example #18
0
 public Snake(Point tail,int Lenth,Direction _direct)
 {
     direct = _direct;
     pList = new List<Point>();
     for (int i = 0; i < Lenth; i++)
     {
         Point p = new Point(tail);
         p.Move(i, direct);
         pList.Add(p);
     }
 }
Example #19
0
 public void Move(int i, Direction d)
 {
     if (d == Direction.right)
         x = x + i;
     if (d == Direction.left)
         x = x - i;
     if (d == Direction.up)
         y = y - i;
     if (d == Direction.down)
         y = y + i;
 }
Example #20
0
 public void HandleKey(ConsoleKey key)
 {
     if (key == ConsoleKey.LeftArrow)
         direction = Direction.LEFT;
     else if (key == ConsoleKey.RightArrow)
         direction = Direction.RIGHT;
     else if (key == ConsoleKey.UpArrow)
         direction = Direction.UP;
     else if (key == ConsoleKey.DownArrow)
         direction = Direction.DOWN;
 }
Example #21
0
 public Snake(Point tail, int length, Direction _direction)
 {
     direction = _direction;
     pList = new List<Point>();
     //Snake snake = new Snake(p, 5, Direction.RIGHT);
     for (int i = 0; i < length; i++)
     {
         Point p = new Point(tail);
         p.Move(i, direction);
         pList.Add(p);
     }
 }
Example #22
0
        public Hero(Point tail, int lenght, Direction direction)
        {
            this.direction = direction;
            pointList = new List<Point>();

            for (int i = 0; i < lenght; i++)
            {
                Point point = new Point(tail);
                point.ChangeDirection(i, direction);
                pointList.Add(point);
            }
        }
Example #23
0
        private int _width = 20; // ���

        #endregion Fields

        #region Constructors

        public Palette(int width, int height, int size, Color bgColor, Graphics g, int lvl)
        {
            this._width = width;
            this._height = height;
            this._bgColor = bgColor;
            this._gpPalette = g;
            this._size = size;
            this._level = lvl;
            this._blocks = new ArrayList();
            this._blocks.Insert(0, (new Block(Color.Red, this._size, new Point(width / 2, height / 2))));
            this._direction = Direction.Right;
        }
Example #24
0
        public Snake(Point tail, int length, Direction direction)
        {
            this.direction = direction;
            this.length = length;

            plist = new List<Point>();
            for (int iter = 0; iter < this.length; iter++)
            {
                Point p = new Point(tail);
                p.Move(iter, direction);
                plist.Add(p);
            }
        }
Example #25
0
        public void ChangeDirectionKey(ConsoleKey key)
        {
            if (key == ConsoleKey.LeftArrow)
                direction = Direction.LEFT;

            if (key == ConsoleKey.RightArrow)
                direction = Direction.RIGHT;

            if (key == ConsoleKey.DownArrow)
                direction = Direction.DOWN;

            if (key == ConsoleKey.UpArrow)
                direction = Direction.UP;
        }
Example #26
0
 public Snake(Point tail, int lengh, Direction _direction)
 {
     direction = _direction;
     objectType = ObjectTypes.SNAKE;
     pList = new List<Point>();
     for(int i = 0; i < lengh; i++)
     {
         // Пересоздаём точку и передвигаем её, тем самым рисуя змейку
         Point p = new Point(tail);
         p.Move(i, direction);
         pList.Add(p);
         Draw();
     }
 }
Example #27
0
        public Snake(int startX, int startY, Direction startDirection, PlayerModel player, int startLength = 6)
        {
            Name = player.Name;
            Color = player.Color;
            Left = player.Left;
            Right = player.Right;
            Id = player.Id;

            SnakePieces = new List<Position>() {
                new Position(startX, startY)
            };
            Length = startLength;
            Heading = startDirection;
        }
Example #28
0
        public void ChangeDirection(int offset, Direction direction)
        {
            if (direction == Direction.RIGHT)
                xPos = xPos + offset;

            if (direction == Direction.LEFT)
                xPos = xPos - offset;

            if (direction == Direction.UP)
                yPos = yPos - offset;

            if (direction == Direction.DOWN)
                yPos = yPos + offset;
        }
Example #29
0
        public Snake(int startPositionX, int startPositionY, Direction startingDirection, int startingLength)
        {
            this.startPositionX = startPositionX;
            this.startPositionY = startPositionY;
            this.Direction = startingDirection;
            this.Body = new List<BodyPart>();
            this.startingLength = startingLength;

            if (startingLength > 0)
            {
                for (int index = 0; index < startingLength; index++)
                {
                    this.AddBodyPart();
                }
            }
        }
Example #30
0
 public Line(Direction direction, int a, int b, int c, char sym)
 {
     this.plist = new List<Point>();
     for (int iter = a; iter <= b; iter++)
     {
         if (direction == Direction.RIGHT || direction == Direction.LEFT)
         {
             // Horizontal line
             this.plist.Add(new Point(iter, c, sym));
         }
         else if (direction == Direction.UP || direction == Direction.DOWN)
         {
             // Vertical line
             this.plist.Add(new Point(c, iter, sym));
         }
     }
 }
Example #31
0
        public GameRules(int duration, Vector2I worldSize, Vector2I snakeStartPosition, Direction snakeStartDirection)
            : this()
        {
            WorldSize = worldSize;
            Duration = duration;
            SnakeStartPosition = snakeStartPosition;
            SnakeStartDirection = snakeStartDirection;
            Exponential = false;
            IsDegenerativeSpeedEnabled = false;
            DegenerativeSpeed = 1;
            DegenerativeSpeedMax = duration;

            ClearPowerupEnabled = false;
            ClearPowerupScore = 10;
            SpeedPowerupEnabled = false;
            SpeedPowerupScore = 10;
        }
Example #32
0
        static void MakeStep(Direction newDir)
        {
            int headRow = 0, headColumn = 0, tailRow = 0, tailColumn = 0;

            ItemState state;

            for (int i = 0; i < FieldHeight; i++)
            {
                for (int j = 0; j < FieldWidth; j++)
                {
                    state = FieldState[i, j];
                    if (state == ItemState.Head)
                    {
                        headRow    = i;
                        headColumn = j;
                    }
                    if (state == ItemState.HorizontalTail || state == ItemState.VerticalTail)
                    {
                        tailRow    = i;
                        tailColumn = j;
                    }
                }
            }

            InitDirs(newDir);

            ItemState newState;
            bool      flag = newDir == A1;

            if (HeadDir == B1)
            {
                newState = flag ? ItemState.TopLeftBottomRightBend : ItemState.TopRightBottomLeftBend;
            }
            else if (HeadDir == B2)
            {
                newState = flag ? ItemState.TopRightBottomLeftBend : ItemState.TopLeftBottomRightBend;
            }
            else
            {
                newState = S;
            }

            if ((newDir != A1 || HeadDir != A2) && (newDir != A2 || HeadDir != A1))
            {
                HeadDir = newDir;
            }
            else
            {
                flag = HeadDir == A1;
            }

            FieldState[headRow, headColumn] = newState;
            int offset       = flag ? -1 : 1;
            int rowOffset    = headRow + offset * I1;
            int columnOffset = headColumn + offset * I2;

            if (rowOffset < 0 || rowOffset >= FieldHeight || columnOffset < 0 || columnOffset >= FieldWidth)
            {
                GameOver = true;
                return;
            }
            if (FieldState[rowOffset, columnOffset] == ItemState.Food)
            {
                FieldState[rowOffset, columnOffset] = ItemState.Head;
                PlaceFood();
                return;
            }
            if (FieldState[rowOffset, columnOffset] != ItemState.Empty)
            {
                GameOver = true;
                return;
            }
            FieldState[rowOffset, columnOffset] = ItemState.Head;

            FieldState[tailRow, tailColumn] = ItemState.Empty;
            InitDirs(TailDir);

            flag   = TailDir == A1;
            offset = flag ? -1 : 1;

            state = FieldState[tailRow + offset * I1, tailColumn + offset * I2];
            var newTailState = ItemState.Empty;

            if (state == S)
            {
                newTailState = S1;
                TailDir      = flag ? A1 : A2;
            }
            if (state == ItemState.TopLeftBottomRightBend)
            {
                newTailState = S2;
                TailDir      = flag ? B1 : B2;
            }
            if (state == ItemState.TopRightBottomLeftBend)
            {
                newTailState = S2;
                TailDir      = flag ? B2 : B1;
            }
            FieldState[tailRow + offset * I1, tailColumn + offset * I2] = newTailState;
        }
Example #33
0
 //Returns whether or not 2 directions are opposites
 bool IsDirectionOpposite(Snake.Direction dir1, Snake.Direction dir2)
 {
     return(Mathf.Abs((int)dir1 - (int)dir2) == 2);
 }