Ejemplo n.º 1
0
 public void LoadGame()
 {
     wall.Clear();
     worm.Clear();
     food.Clear();
     wall = wall.Load() as Wall;
     worm = worm.Load() as Worm;
     food = food.Load() as Food;
     Console.Clear();
     wall.Draw();
     worm.Draw();
     food.Draw();
 }
Ejemplo n.º 2
0
        public void Load()
        {
            worm = new Worm();
            worm.LinkToGame(this);

            wall = new Wall();
            food = new Food();
            food.Generate();
            //food.SetRandomPosition();
            worm.Generate();

            wall.Generate(LEVEL);
        }
Ejemplo n.º 3
0
        public void Load()
        {
            worm = new Worm();
            worm.LinkToGame(this);

            wall = new Wall();
            food = new Food();
            food.Generate();
            worm.Generate();
            wall.Generate();
            worm.Draw();
            wall.Draw();
            food.Draw();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// starting the game by creating snake, wall, food
        /// </summary>
        public void Start()
        {
            worm = new Worm();
            worm.AttachGameLink(this);

            wall = new Wall();
            food = new Food();

            food.Draw();
            wall.Draw();

            // snake will move with the timer by reading commands from the console
            Thread t = new Thread(new ThreadStart(worm.Move));

            t.Start();
            while (true)
            {
                ConsoleKeyInfo pressedKey = Console.ReadKey();
                switch (pressedKey.Key)
                {
                case ConsoleKey.UpArrow:
                    worm.dx = 0;
                    worm.dy = -1;
                    break;

                case ConsoleKey.DownArrow:
                    worm.dx = 0;
                    worm.dy = 1;
                    break;

                case ConsoleKey.LeftArrow:
                    worm.dx = -1;
                    worm.dy = 0;
                    break;

                case ConsoleKey.RightArrow:
                    worm.dx = 1;
                    worm.dy = 0;
                    break;

                case ConsoleKey.Escape:
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        public void Start(bool is_new_game)
        {
            if (is_new_game)
            {
                Load();
            }
            else
            {
                worm = new Worm();
                worm = worm.Load() as Worm;
                worm.LinkToGame(this);

                food = new Food();

                food = food.Load() as Food;
                wall = new Wall();
                wall = wall.Load() as Wall;
            }


            worm.Draw();
            wall.Draw();
            food.Draw();

            t = new Thread(new ThreadStart(worm.Move));

            t.IsBackground = true;
            t.Start();

            isalive = true;
            while (isalive)
            {
                ConsoleKeyInfo pressedKey = Console.ReadKey();
                switch (pressedKey.Key)
                {
                case ConsoleKey.F3:
                    wall = wall.Load() as Wall;
                    worm = worm.Load() as Worm;
                    worm.LinkToGame(this);
                    t.Abort();

                    t = new Thread(new ThreadStart(worm.Move));
                    t.IsBackground = true;
                    Console.Clear();
                    worm.Draw();
                    wall.Draw();
                    food.Draw();
                    t.Start();

                    break;

                case ConsoleKey.F2:
                    this.Save();
                    break;

                case ConsoleKey.UpArrow:
                    worm.dx = 0;
                    worm.dy = -1;
                    break;

                case ConsoleKey.DownArrow:
                    worm.dx = 0;
                    worm.dy = 1;
                    break;

                case ConsoleKey.LeftArrow:
                    worm.dx = -1;
                    worm.dy = 0;
                    break;

                case ConsoleKey.RightArrow:
                    worm.dx = 1;
                    worm.dy = 0;
                    break;

                case ConsoleKey.Escape:
                    isalive = false;
                    Console.Clear();
                    Menu m = new Menu();

                    m.MenuBar();
                    break;
                }
            }
        }
Ejemplo n.º 6
0
 public static void Init()
 {
     food = new Food();
     worm = new Worm();
     wall = new Wall();
 }