Пример #1
0
        public Schuss(int left, int top, Program.Direction direction)
        {
            this.direction = direction;
            switch (direction)
            {
            case Program.Direction.UP:
                this.left = left;
                this.top  = --top;
                break;

            case Program.Direction.DOWN:
                this.left = left;
                this.top  = ++top;
                break;

            case Program.Direction.LEFT:
                this.left = --left;
                this.top  = top;
                break;

            case Program.Direction.RIGHT:
                this.left = ++left;
                this.top  = top;
                break;
            }
        }
Пример #2
0
        public void Move(string d, int a)
        {
            switch (d)
            {
            case "left":
                if (this.PosY - a <= 5)
                {
                    SetPosition(this.PosX, this.PosY - a);
                    Dir = Program.Direction.Left;
                }
                else
                {
                    Console.WriteLine("Out Of Bounds");
                }
                break;

            case "down":
                if (this.PosX + a <= 5)
                {
                    SetPosition(this.PosX + a, this.PosY);
                    Dir = Program.Direction.Down;
                }
                else
                {
                    Console.WriteLine("Out Of Bounds");
                }
                break;



            case "up":
                if (this.PosX - a <= 5)
                {
                    SetPosition(this.PosX - a, this.PosY);
                    Dir = Program.Direction.Up;
                }
                else
                {
                    Console.WriteLine("Out Of Bounds");
                }
                break;

            case "right":
                if (this.PosY + a <= 5)
                {
                    SetPosition(this.PosX, this.PosY + a);
                    Dir = Program.Direction.Right;
                }
                else
                {
                    Console.WriteLine("Out Of Bounds");
                }
                break;

            default:
                Console.WriteLine("Invalid Direction");
                break;
            }
        }
Пример #3
0
        public Player(int x, int y, Program.Direction d) : base(x, y)
        {
            Dir  = d;
            PosX = x;
            PosY = y;

            AddObject(x, y);
        }
Пример #4
0
        public static void Move(this Program.Direction direction)
        {
            var tmp = UserLocation;

            lock (LocationLock)
            {
                User.Direction = direction;
                UserLocation   = UserLocation.Move(direction);
                if (Map.Things[UserLocation.X, UserLocation.Y].HasMass)
                {
                    throw new Exception("Ya done crashed boi!");
                }
                else
                {
                    Map.Things[UserLocation.X, UserLocation.Y] = User;
                    Map.Things[tmp.X, tmp.Y] = new Thing();
                }
            }
        }
Пример #5
0
        public static Location Move(this Location location, Program.Direction direction)
        {
            switch (direction)
            {
            case Program.Direction.Up:
                return(new Location(location.X, location.Y + 1));

            case Program.Direction.Down:
                return(new Location(location.X, location.Y - 1));

            case Program.Direction.Left:
                return(new Location(location.X - 1, location.Y));

            case Program.Direction.Right:
                return(new Location(location.X + 1, location.Y));

            default:
                throw new ArgumentOutOfRangeException(nameof(direction), direction, null);
            }
        }
Пример #6
0
        public Program.GameStatus UpdateSnake(Program.Direction?currentDirection, ref Program.Direction?previousDirection, Program.BlockType[,] gameGrid, int gameWidth, int gameHeight)
        {
            if (currentDirection == null)
            {
                return(Program.GameStatus.Playing);
            }
            Point snakeHeadOldPosition = Head;

            Head = DirectionTransofrmation[(int)currentDirection](Head);
            if (previousDirection != null && Body.Count > 0)
            {
                Program.Direction oppistieDirection = (Program.Direction)(3 - currentDirection);
                if (previousDirection == oppistieDirection && gameGrid[snakeHeadOldPosition.X, snakeHeadOldPosition.Y] == Program.BlockType.Snake)
                {
                    currentDirection = previousDirection;
                    Head             = DirectionTransofrmation[(int)previousDirection](snakeHeadOldPosition);
                }
            }

            // Border check
            if (Head.X == -1 || Head.X == gameWidth || Head.Y == -1 ||
                Head.Y == gameHeight)
            {
                return(Program.GameStatus.Lost);
            }
            // Check if the snake ate itself
            if (gameGrid[Head.X, Head.Y] == Program.BlockType.Snake)
            {
                return(Program.GameStatus.Lost);
            }
            if (Grow)
            {
                Body.Insert(0, Body.Count > 0 ? Body[0] : snakeHeadOldPosition);
                gameGrid[Body[0].X, Body[0].Y] = Program.BlockType.Snake;
                for (int i = 1; i < Body.Count; i++)
                {
                    Body[i] = i + 1 == Body.Count ? snakeHeadOldPosition : Body[i + 1];
                    gameGrid[Body[i].X, Body[i].Y] = Program.BlockType.Snake;
                }
                Grow = false;
            }
            else if (Body.Count > 0)
            {
                gameGrid[Body[0].X, Body[0].Y] = Program.BlockType.Empty;
                for (int i = 0; i < Body.Count; i++)
                {
                    Body[i] = i + 1 == Body.Count ? snakeHeadOldPosition : Body[i + 1];
                    gameGrid[Body[i].X, Body[i].Y] = Program.BlockType.Snake;
                }
            }
            else
            {
                gameGrid[snakeHeadOldPosition.X, snakeHeadOldPosition.Y] = Program.BlockType.Empty;
            }

            if (gameGrid[Head.X, Head.Y] == Program.BlockType.Apple)
            {
                Grow = true;
                if (PlaceRandomApple(gameGrid, gameWidth, gameHeight))
                {
                    gameGrid[Head.X, Head.Y] = Program.BlockType.Snake;
                    return(Program.GameStatus.Won);
                }
            }


            gameGrid[Head.X, Head.Y] = Program.BlockType.Snake;
            previousDirection        = (Program.Direction)currentDirection;
            return(Program.GameStatus.Playing);
        }
Пример #7
0
 public void Move(Program.Direction DirectionOfMove)
 {
     CharacterDirection = DirectionOfMove;
     x += (int)CharacterDirection;
 }
Пример #8
0
 public Bullet(int x, int y, Program.Direction bulletDirection)
 {
     X = x;
     Y = y;
     BulletDirection = bulletDirection;
 }