示例#1
0
        public static bool SnakePieceSpawned = false; //True, when a new snakepiece is spawned,but not picked up yet

        #endregion Fields

        #region Methods

        //Happens when the player picks up a new SnakePiece
        static void AddNewPiece()
        {
            SnakePiece Piece = new SnakePiece();
            Piece.DirectionOfPiece = Snake[Snake.Count - 1].DirectionOfPiece;

            if (Snake[Snake.Count - 1].DirectionOfPiece == Direction.up)
            {
                Piece.PosX = Snake[Snake.Count - 1].PosX + 1;
                Piece.PosY = Snake[Snake.Count - 1].PosY;
            }

            if (Snake[Snake.Count - 1].DirectionOfPiece == Direction.down)
            {
                Piece.PosX = Snake[Snake.Count - 1].PosX - 1;
                Piece.PosY = Snake[Snake.Count - 1].PosY;
            }

            if (Snake[Snake.Count - 1].DirectionOfPiece == Direction.left)
            {
                Piece.PosX = Snake[Snake.Count - 1].PosX;
                Piece.PosY = Snake[Snake.Count - 1].PosY + 1;
            }

            if (Snake[Snake.Count - 1].DirectionOfPiece == Direction.right)
            {
                Piece.PosX = Snake[Snake.Count - 1].PosX;
                Piece.PosY = Snake[Snake.Count - 1].PosY - 1;
            }

            Snake.Add(Piece);
        }
示例#2
0
        static void Main(string[] args)
        {
            MainMenu();
            Console.Clear();

            //Adding the fist SnakePiece,the head
            SnakePiece Head = new SnakePiece();
            Head.Character = (char)2;
            Head.PosX = 8;
            Head.PosY = 9;
            Head.DirectionOfPiece = Direction.up;

            Snake.Add(Head);

            Thread GameThread = new Thread(new ThreadStart(Game));
            Thread SpawnThread = new Thread(new ThreadStart(SpawnNewPiece));

            //Starting threads
            GameThread.Start();
            SpawnThread.Start();

            while (!GameIsOver)
            {
                ConsoleKeyInfo input = Console.ReadKey();

                if (input.Key == ConsoleKey.UpArrow || input.Key == ConsoleKey.DownArrow || input.Key == ConsoleKey.LeftArrow || input.Key == ConsoleKey.RightArrow || input.Key == ConsoleKey.Escape)
                {
                    TurnHead(input, GameThread);
                }

            }

            //Ending threads
            GameThread.Abort();
            SpawnThread.Abort();

            GameOverScreen();
        }