Exemple #1
0
 public void Move(int offset, Direction dir)
 {
     if (dir == Direction.right) x = x + offset;
       else  if (dir == Direction.left) x = x - offset;
       else  if (dir == Direction.up) y = y - offset;
       else  if (dir == Direction.down) y = y + offset;
 }
Exemple #2
0
 public void HandlKey(ConsoleKey key)
 {
     if (key == ConsoleKey.LeftArrow)
     {
         direct = Direction.left;
     }
     else
     {
         if (key == ConsoleKey.RightArrow)
         {
            direct = Direction.right;
         }
         else
         {
             if (key == ConsoleKey.DownArrow)
             {
                direct = Direction.down;
             }
             else
             {
                 direct = Direction.up;
             }
         }
     }
 }
Exemple #3
0
 public void Move(int offset, Direction direct)
 {
     if (direct == Direction.right)
     {
         x = x + offset;
     }
     else
     {
         if (direct == Direction.left)
         {
             x = x - offset;
         }
         else
         {
             if (direct == Direction.up)
             {
                 y = y - offset;
             }
             else
             {
                 y = y + offset;
             }
         }
     }
 }
Exemple #4
0
 public override bool CanStand(Creature creature, Direction direction)
 {
     creature.X += direction.dx;
     creature.Y += direction.dy;
     creature.Lifes++;
     return true;
 }
Exemple #5
0
 public Snape(Point tail , int lenght , Direction _direction)
 {
     direction = _direction;
     pLine = new List<Point>();
     for(int i = 0 ; i< lenght; i++)
     {
         Point p = new Point(tail);
         p.Move(i, _direction);
         pLine.Add(p);
     }
 }
Exemple #6
0
 public void HandleKey(ConsoleKey key)
 {
     if (key == ConsoleKey.LeftArrow)
         dir = Direction.left;
     if (key == ConsoleKey.RightArrow)
         dir = Direction.right;
     if (key == ConsoleKey.UpArrow)
         dir = Direction.up;
     if (key == ConsoleKey.DownArrow)
         dir = Direction.down;
 }
Exemple #7
0
 public Snake(Point tail, int lenght, Direction _dir)
 {
     dir = _dir;
     pList = new List<Point>();
     for (int i = 0; i < lenght; i++)
     {
         Point p = new Point(tail);
         p.Move(i, dir);
         pList.Add(p);
     }
 }
Exemple #8
0
        public Snake(Point tail, int length, Direction _direct)
        {
            PointList = new List<Point>();
            direct = _direct;

            for (int i = 0; i < length; i++)
            {
                Point p = new Point(tail);
                p.Move(i, direct);
                PointList.Add(p);
            }
        }
Exemple #9
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;
 }
Exemple #10
0
 public void Move(int offset, Direction direction)
 {
     if (direction == Direction.LEFT)
         x = x - offset;
     else
         if (direction == Direction.RIGHT)
             x = x + offset;
         else
             if (direction == Direction.UP)
                 y = y - offset;
             else if (direction == Direction.DOWN)
                 y = y + offset;
 }
Exemple #11
0
        public bool TryToMove(Creature creature, Direction direction)
        {
            while(creature.IsAlive())
            {
                var result = map[creature.X + direction.dx, creature.Y + direction.dy].CanStand(creature, direction);

                if (result)
                    OnChanged(EventArgs.Empty);

                return result;
            }
            Console.WriteLine("Move is impossible. {0} is dead", creature.Name);
            return false;
        }
Exemple #12
0
 public void SwitchDirection(Direction.Dir newDir)
 {
     switch (newDir)
     {
         case Direction.Dir.Up:
             NewHeadCoord.Y--;
             break;
         case Direction.Dir.Right:
             NewHeadCoord.X++;
             break;
         case Direction.Dir.Down:
             NewHeadCoord.Y++;
             break;
         default:
             NewHeadCoord.X--;
             break;
     }
 }
Exemple #13
0
 public bool Down(Direction direction)
 {
     return KeyInfo.Key == ConsoleKey.DownArrow && direction.LastDirection != Direction.Dir.Up;
 }
Exemple #14
0
 public abstract bool CanStand(Creature creature, Direction direction);
Exemple #15
0
 public override bool CanStand(Creature creature, Direction direction)
 {
     return false;
 }
 public static void PlaceOnBoard(string word, Position pos, Direction dir)
 {
     int x = pos.X;
     int y = pos.Y;
     for (int i = 0; i < word.Length; i++)
     {
         switch (dir)
         {
             case Direction.Down:
                 Board[y + i][x] = word[i];
                 break;
             case Direction.Left:
                 Board[y][x - i] = word[i];
                 break;
             case Direction.Right:
                 Board[y][x + i] = word[i];
                 break;
             case Direction.Up:
                 Board[y - i][x] = word[i];
                 break;
         }
     }
 }
Exemple #17
0
 public bool Up(Direction direction)
 {
     return KeyInfo.Key == ConsoleKey.UpArrow && direction.LastDirection != Direction.Dir.Down;
 }
Exemple #18
0
        private void Initiliaze()
        {
            GameIsPlaying = true;
            Paused = false;
            AppleEaten = false;

            TailCoordsList = new List<Coord>();

            PlayField = new PlayField(TailCoordsList);

            Tick  = new Stopwatch();
            Renderer = new SnakeRenderer();

            Player = new Snake(TailCoordsList);
            Direction = new Direction();

            Tick.Start();
            UpdatePlayField();
        }
Exemple #19
0
 public bool Right(Direction direction)
 {
     return KeyInfo.Key == ConsoleKey.RightArrow && direction.LastDirection != Direction.Dir.Left;
 }