Esempio n. 1
0
 public void Run()
 {
     worm.Draw();
     timer.Elapsed += elapsed;
     timer.Interval = 300;
     timer.Start();
     food.Draw();
     wall.Draw();
 }
Esempio n. 2
0
 private void Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     worm.Clear();
     worm.Move();
     worm.Draw();
     CheckColision();
     CheckWallColision();
     CheckSelfCollision();
     ShowStatusBar(worm.body.Count.ToString());
 }
Esempio n. 3
0
 private void Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     w.Clear();
     w.Move();
     w.Draw();
     CheckFood();
 }
Esempio n. 4
0
 private void Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     worm.Clear();
     worm.Move();
     worm.Draw();
     CheckCollision();
 }
Esempio n. 5
0
        public void Run()
        {
            CheckCollision();
            food.Draw();
            worm.Draw();
            wall.Draw();
            consoleKeyInfo = Console.ReadKey();
            switch (consoleKeyInfo.Key)
            {
            case ConsoleKey.UpArrow:
                dir = Dir.UP;
                break;

            case ConsoleKey.DownArrow:
                dir = Dir.DOWN;
                break;

            case ConsoleKey.LeftArrow:
                dir = Dir.LEFT;
                break;

            case ConsoleKey.RightArrow:
                dir = Dir.RIGHT;
                break;
            }
        }
Esempio n. 6
0
 private void T_Elapsed(object sender, ElapsedEventArgs e)
 {
     worm.Clear();
     worm.Move();
     CanWormEat();
     IsItCrash();
     worm.Draw();
 }
Esempio n. 7
0
 public void Draw()
 {
     if (!gameOver)
     {
         worm.Draw();
         food.Draw();
         wall.Draw();
     }
 }
Esempio n. 8
0
 public void Draw()
 {
     if (!gameOver)
     {
         w.Draw();
         f.Draw();
         b.Draw();
     }
 }
Esempio n. 9
0
        public void Draw()
        {
            if (!end)
            {
                w.Draw();
            }

            f.Draw();
            b.Draw();
        }
Esempio n. 10
0
 public void Draw()
 {
     worm.Draw();
     wall.Draw();
     if (food.body.Count == 0)
     {
         food.Generate(worm.body, wall.body);
     }
     food.Draw();
 }
Esempio n. 11
0
 private void Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     CheckGameOver();
     CheckFood();
     Console.ForegroundColor = ConsoleColor.Green;
     f.Draw();
     w.Move();
     Console.ForegroundColor = ConsoleColor.Yellow;
     w.Draw();
 }
Esempio n. 12
0
        public void ChangeFrame()
        {
            worm.Clear();
            worm.Move();
            worm.Draw();

            PrintInfo(worm.body[0].ToString() + "===" + food.body[0].ToString());

            CheckCollision();
        }
Esempio n. 13
0
 private void Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     w.Clear();
     w.Move();
     w.Draw();
     CheckWall();
     CheckBody();
     CheckFood();
     timer.Interval = speed;
     comment();
 }
Esempio n. 14
0
 public void Draw()
 {
     if (!gameOver)
     {
         wall = new Wall('#', LevelNumber);
         worm.Draw();
         food.Draw();
         wall.Draw();
         //player.score.Draw();
         scoreLevel.Draw();
         player.Draw();
     }
 }
Esempio n. 15
0
        public void MoveSnake()
        {
            while (anal)
            {
                worm.Clear();

                worm.Move();
                worm.Draw();
                ShowStatusBar(worm.body.Count.ToString());
                //worm.Draw();

                //CheckCollision();
                if (worm.IsIntersected(wall.body))
                {
                    Console.Clear();
                    Console.SetCursorPosition(15, 20);
                    Console.Write("Game over!");
                    anal = false;
                }
                if (worm.IsIntersected(food.body))
                {
                    anal = true;
                    worm.Eat(food.body);
                    food.GenerateLocation(worm.body, wall.body);
                    food.Draw();
                }
                else if (worm.snakegavno(worm.body))
                {
                    Console.Clear();
                    Console.SetCursorPosition(15, 20);
                    Console.Write("Game over!");
                    anal = false;
                }
                if ((Convert.ToInt32(worm.body.Count.ToString()) >= 1 && (Convert.ToInt32(worm.body.Count.ToString()) <= 3)))
                {
                    Thread.Sleep(150);
                }
                else if ((Convert.ToInt32(worm.body.Count.ToString()) >= 4 && (Convert.ToInt32(worm.body.Count.ToString()) <= 7)))
                {
                    Thread.Sleep(100);
                }
                else if ((Convert.ToInt32(worm.body.Count.ToString()) >= 8 && (Convert.ToInt32(worm.body.Count.ToString()) <= 10)))
                {
                    Thread.Sleep(50);
                }
                else if ((Convert.ToInt32(worm.body.Count.ToString()) >= 11))
                {
                    Thread.Sleep(10);
                }
            }
        }
Esempio n. 16
0
        public void Load()
        {
            worm = new Worm();
            worm.AttachGameLink(this);

            wall = new Wall();
            food = new Food();
            food.Generate(wall, worm);
            worm.Generate(wall);
            wall.Generate(level);
            worm.Draw();
            wall.Draw();
            food.Draw();
        }
Esempio n. 17
0
        static void Main(string[] args)
        {
            Worm worm = new Worm();
            Food food = new Food();
            Wall wall = new Wall(1);

            while (worm.isAlive)
            {
                Console.Clear();
                worm.Draw();
                food.Draw();
                wall.Draw();
                ConsoleKeyInfo pressedKey = Console.ReadKey();
                switch (pressedKey.Key)
                {
                case ConsoleKey.UpArrow:
                    worm.Move(0, -1);
                    break;

                case ConsoleKey.DownArrow:
                    worm.Move(0, 1);
                    break;

                case ConsoleKey.LeftArrow:
                    worm.Move(-1, 0);
                    break;

                case ConsoleKey.RightArrow:
                    worm.Move(1, 0);
                    break;

                case ConsoleKey.Escape:
                    worm.isAlive = false;
                    break;
                }

                if (worm.CanEat(food))
                {
                    food = new Food();
                }
            }
        }
Esempio n. 18
0
        public void Draw()
        {
            food.Draw();


            wall.Draw();

            while (true)
            {
                worm.Move();


                if (worm.body[0].Equals(food.body[0]))
                {
                    worm.body.Add(new Point {
                        X = food.body[0].X, Y = food.body[0].Y
                    });
                    food.body[0] = food.CreateFood(wall.body, worm.body);
                }
                else
                {
                    foreach (Point p in wall.body)
                    {
                        if (p.Equals(worm.body[0]))
                        {
                            Console.Clear();
                            Console.SetCursorPosition(10, Game.boardH / 2);
                            Console.WriteLine("GAME OVER!!!");
                            isAlive = false;
                            Console.ForegroundColor = ConsoleColor.Black;

                            Stop();
                        }
                    }
                }

                worm.Draw();
                food.Draw();
                Thread.Sleep(Game.interval);
            }
        }
Esempio n. 19
0
        static void Main(string[] args)
        {
VeryBegin:
            int l = 1;

            /*
             * while (true)
             * {
             *   Console.Clear();
             *   Console.WriteLine("Chose level (1-5)");
             *   l = int.Parse(Console.ReadLine());
             *   if (l > 0 && l <= 5)
             *       break;
             * }
             */
Begin:
            int score = 0;

            Wall wall = new Wall(l);
            Worm worm = new Worm();
            Food food = new Food();

            worm.Start();

            string way = "none";

            bool f0 = true;

            while (f0 == true)
            {
                worm = new Worm();
                food = new Food();
                worm.Start();
                f0 = false;
                for (int i = 0; i < wall.bricks.Count; i++)
                {
                    if (wall.bricks[i].Equals(worm.body[0]))
                    {
                        f0 = true;
                    }
                }
            }

            bool s0 = true;
            bool s1 = true;

            while (s0 == true || s1 == true)
            {
                worm = new Worm();
                worm.Start();
                s0 = false;
                s1 = false;
                for (int i = 0; i < wall.bricks.Count; i++)
                {
                    if (wall.bricks[i].Equals(worm.body[0]))
                    {
                        s0 = true;
                    }
                }
                if (worm.body[0].Equals(food.location))
                {
                    s1 = true;
                }
            }
            while (worm.isAlive)
            {
                Console.Clear();
                worm.Draw();
                food.Draw();
                wall.Draw();
                Console.WriteLine("\n\nScore: {0}", score);
                if (score >= 10)
                {
                    Console.WriteLine("\n\n Next level availible");
                }

                ConsoleKeyInfo pressedKey = Console.ReadKey();
                switch (pressedKey.Key)
                {
                case ConsoleKey.UpArrow:
                    if (way != "down" || worm.body.Count == 1)
                    {
                        worm.Move(0, -1);
                        way = "up";
                    }
                    break;

                case ConsoleKey.DownArrow:
                    if (way != "up" || worm.body.Count == 1)
                    {
                        worm.Move(0, 1);
                        way = "down";
                    }
                    break;

                case ConsoleKey.LeftArrow:
                    if (way != "right" || worm.body.Count == 1)
                    {
                        worm.Move(-1, 0);
                        way = "left";
                    }
                    break;

                case ConsoleKey.RightArrow:
                    if (way != "left" || worm.body.Count == 1)
                    {
                        worm.Move(1, 0);
                        way = "right";
                    }
                    break;

                case ConsoleKey.Escape:
                    worm.isAlive = false;
                    Console.Clear();
                    goto End;

                case ConsoleKey.F5:
                    Game game = new Game(food, wall, worm, score, l);
                    Serialize(game);
                    break;

                case ConsoleKey.F9:
                    Game game2 = Deserialize();
                    food  = game2.food;
                    wall  = game2.wall;
                    worm  = game2.worm;
                    score = game2.score;
                    l     = game2.l;
                    break;

                case ConsoleKey.OemPlus:
                    if (score >= 10)
                    {
                        l++;
                        goto Begin;
                    }
                    break;

                case ConsoleKey.OemMinus:
                    if (l > 1)
                    {
                        l--;
                        goto Begin;
                    }
                    break;
                }

                for (int i = 0; i < wall.bricks.Count; i++)
                {
                    if (wall.bricks[i].Equals(worm.body[0]))
                    {
                        worm.isAlive = false;
                    }
                }

                for (int i = 1; i < worm.body.Count; i++)
                {
                    if (worm.body[0].Equals(worm.body[i]))
                    {
                        worm.isAlive = false;
                    }
                }

                if (worm.CanEat(food))
                {
                    score++;
                    bool f1 = true;
                    bool f2 = true;
                    while (f1 == true || f2 == true)
                    {
                        f1   = false;
                        f2   = false;
                        food = new Food();
                        for (int i = 0; i < worm.body.Count; i++)
                        {
                            if (worm.body[i].Equals(food.location))
                            {
                                f1 = true;
                            }
                        }

                        for (int i = 0; i < wall.bricks.Count; i++)
                        {
                            if (wall.bricks[i].Equals(food.location))
                            {
                                f2 = true;
                            }
                        }
                    }
                }
            }

            Console.Clear();
            Console.WriteLine("GAME OVER\n\n Again?");
            Console.ReadKey();
            goto VeryBegin;
End:
            Console.WriteLine("GAME OVER");
        }
Esempio n. 20
0
        static void Keys(Wall wall, Worm worm, Food food)
        {
            System system = new System(wall, worm);


            while (worm.isAlive)
            {
                Console.Clear();
                worm.Draw();


                food.Draw(); Console.ForegroundColor = ConsoleColor.Yellow;
                wall.Draw();
                Console.WriteLine(" Your points:");
                Console.WriteLine(Global.points);
                Console.WriteLine(" Your level:");
                Console.WriteLine(Global.level);
                ConsoleKeyInfo pressedKey = Console.ReadKey();

                switch (pressedKey.Key)
                {
                case ConsoleKey.UpArrow:

                    worm.Move(0, -1);
                    break;

                case ConsoleKey.DownArrow:

                    worm.Move(0, 1);
                    break;

                case ConsoleKey.LeftArrow:

                    worm.Move(-1, 0);
                    break;

                case ConsoleKey.RightArrow:

                    worm.Move(1, 0);
                    break;

                case ConsoleKey.Escape:
                    Serialize(system);
                    worm.isAlive = false;
                    break;

                case ConsoleKey.Backspace:
                    Console.Clear();
                    Console.WriteLine(Global.points);
                    break;

                case ConsoleKey.Spacebar:
                    Serialize(system);

                    break;

                case ConsoleKey.F2:
                    Console.Clear();
                    System system2 = Deserialize();
                    food.WhereisFood(system2.wall, system2.worm);
                    Keys(system.wall, system.worm, food);
                    break;
                }

                if (worm.IsDead(wall))
                {
                    worm.isAlive = false;
                }
                if (worm.body.Count > 3)
                {
                    Global.level++;
                    Global.points = +50;
                    Worm newworm = new Worm();
                    Console.Clear();
                    Wall newwall = new Wall(Global.level);
                    newwall.Draw();
                    Food newfood = new Food();
                    newfood.WhereisFood(newwall, newworm);

                    worm.isAlive = true;
                    Keys(newwall, newworm, newfood);
                }
                if (worm.CanEat(food))
                {
                    food = new Food();
                    food.WhereisFood(wall, worm);
                    Global.points += 10;
                }

                Serialize(system);


                if (worm.IsDead(wall))
                {
                    Console.Clear();
                    Console.WriteLine();
                    Console.WriteLine("GAME OVER");
                    Console.WriteLine("Your points:");
                    Console.WriteLine(Global.points);
                    Console.WriteLine("max level:");
                    Console.WriteLine(Global.level);
                }
            }
        }
Esempio n. 21
0
        static void Main(string[] args)
        {
            FileStream fs = new FileStream("save.xml", FileMode.Create);
            fs.Close();
        VeryBegin:
            Point p;
            int l = 1;
            Console.CursorVisible = false;
        /*
         while (true)
         {
             Console.Clear();
             Console.WriteLine("Chose level (1-5)");
             l = int.Parse(Console.ReadLine());
             if (l > 0 && l <= 5)
                 break;
         } 
        */
        Begin:
            dx = 0;
            dy = 0;
            Console.Clear();
            int score = 0;

            Wall wall = new Wall(l);
            worm = new Worm();
            Food food = new Food();
            worm.Start();

            way = "none";

            bool f0 = true;
            while (f0 == true)
            {                
                worm = new Worm();
                food = new Food();
                worm.Start();
                f0 = false;
                for (int i = 0; i < wall.bricks.Count; i++)
                    if (wall.bricks[i].Equals(worm.body[0]))
                        f0 = true;
            }

            bool s0 = true;
            bool s1 = true;
            while (s0 == true || s1 == true)
            {
                worm = new Worm();
                worm.Start();
                s0 = false;
                s1 = false;
                for (int i = 0; i < wall.bricks.Count; i++)
                    if (wall.bricks[i].Equals(worm.body[0]))
                        s0 = true;
                if (worm.body[0].Equals(food.location))
                    s1 = true;
            }                       
            while (worm.isAlive)
            {                                
                p = new Point(worm.body[worm.body.Count - 1].x, worm.body[worm.body.Count - 1].y);
                worm.Draw();                               
                food.Draw();                                                                                
                wall.Draw();
                Console.WriteLine("\n\nScore: {0}", score);
                if (score >= 10)
                {
                    Console.WriteLine("\n\n Next level availible");
                }

                
                Thread.Sleep(200);
                worm.Move(dx, dy);
                Thread t = new Thread(new ThreadStart(Keys));
                t.Start();

                /*ConsoleKeyInfo pressedKey = Console.ReadKey();
                switch (pressedKey.Key)
                {
                    case ConsoleKey.UpArrow:
                        if (way != "down"  || worm.body.Count == 1)
                        {
                            worm.Move(0, -1);
                            way = "up";
                        }
                        break;
                    case ConsoleKey.DownArrow:
                        if (way != "up" || worm.body.Count == 1)
                        {
                            worm.Move(0, 1);
                            way = "down";
                        }
                        break;
                    case ConsoleKey.LeftArrow:
                        if (way != "right" || worm.body.Count == 1)
                        {
                            worm.Move(-1, 0);
                            way = "left";
                        }
                        break;
                    case ConsoleKey.RightArrow:
                        if (way != "left" || worm.body.Count == 1)
                        {
                            worm.Move(1, 0);
                            way = "right";
                        }
                        break;
                    case ConsoleKey.Escape:
                        worm.isAlive = false;
                        Console.Clear();
                        goto End;                        
                    case ConsoleKey.F5:
                        Game game = new Game(food, wall, worm, score, l);
                        Serialize(game);                        
                        break;
                    case ConsoleKey.F9:
                        Game game2 = Deserialize();                                              
                        food = game2.food;
                        wall = game2.wall;
                        worm = game2.worm;
                        score = game2.score;
                        l = game2.l;
                        Console.Clear();
                        break;
                    case ConsoleKey.OemPlus:
                        if(score >=10)
                        {
                            l++;
                            goto Begin;
                        }
                        break;
                    case ConsoleKey.OemMinus:
                        if (l > 1)
                        {
                            l--;
                            goto Begin;
                        }
                        break;
                }*/

                Console.SetCursorPosition(p.x, p.y);
                Console.Write(' ');

                for (int i = 0; i < wall.bricks.Count; i++)
                    if (wall.bricks[i].Equals(worm.body[0]))
                    {
                        worm.isAlive = false;
                    }

                for (int i = 1; i < worm.body.Count; i++)
                {
                    if (worm.body[0].Equals(worm.body[i]))
                        worm.isAlive = false;
                }

                if (worm.CanEat(food))
                {
                    score++;
                    bool f1 = true;
                    bool f2 = true;
                    while (f1==true || f2==true)
                    {
                        f1 = false;
                        f2 = false;
                        food = new Food();
                        for (int i = 0; i < worm.body.Count; i++)
                            if (worm.body[i].Equals(food.location))
                                f1=true;

                        for (int i = 0; i < wall.bricks.Count; i++)
                            if (wall.bricks[i].Equals(food.location))
                                f2 = true;
                    }                  
                }                
            }

            Console.Clear();
            Console.WriteLine("GAME OVER\n\n Again?");
          
            Console.ReadKey();
            goto VeryBegin;
        End:
            Console.WriteLine("GAME OVER");
        }
Esempio n. 22
0
 public void Draw()
 {
     w.Draw();
     f.Draw();
     b.Draw();
 }
Esempio n. 23
0
        static void Main(string[] args)
        {
            Worm worm = new Worm();
            Food food = new Food();
            Wall wall = new Wall(1);

            worm.Start();
            while (worm.isAlive)
            {
                Console.Clear();
                worm.Draw();
                food.Draw();

                int currx = worm.Getheadx();
                int curry = worm.Getheady();
                int k     = wall.Draw(currx, curry);
                if (k == 1)
                {
                    break;
                }
                ConsoleKeyInfo pressedKey = Console.ReadKey();
                switch (pressedKey.Key)
                {
                case ConsoleKey.F8:
                    Game q = new Game(worm, wall, food);
                    Serialize(q);
                    break;

                case ConsoleKey.F9:

                    Game h = Deserialize();
                    worm = h.worm;
                    food = h.food;
                    wall = h.wall;

                    break;

                case ConsoleKey.UpArrow:
                    worm.Move(0, -1);
                    break;

                case ConsoleKey.DownArrow:
                    worm.Move(0, 1);
                    break;

                case ConsoleKey.LeftArrow:
                    worm.Move(-1, 0);
                    break;

                case ConsoleKey.RightArrow:
                    worm.Move(1, 0);
                    break;

                case ConsoleKey.Escape:
                    worm.isAlive = false;
                    break;
                }

                if (worm.CanEat(food))
                {
                    food = new Food();
                }
            }
            Console.Clear();
            Console.WriteLine("YOU LOSE");
        }
Esempio n. 24
0
        public void Draw()
        {
            food.Draw();
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.SetCursorPosition(15, 24);

            Console.WriteLine("SCORE:{0}", score);
            wall.Draw();

            while (true)
            {
                worm.Move();
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.SetCursorPosition(15, 24);
                Console.WriteLine("              ");
                Console.SetCursorPosition(15, 24);
                Console.WriteLine("SCORE:{0}", score);

                if (worm.body[0].Equals(food.body[0]))
                {
                    worm.body.Add(new Point {
                        X = food.body[0].X, Y = food.body[0].Y
                    });
                    food.body[0] = food.CreateFood(wall.body, worm.body);

                    score++;
                }
                else
                {
                    foreach (Point p in wall.body)
                    {
                        if (p.Equals(worm.body[0]))
                        {
                            Console.Clear();
                            Console.SetCursorPosition(10, Game.boardH / 2);
                            Console.WriteLine("GAME OVER!!!");
                            isAlive = false;
                            Console.ForegroundColor = ConsoleColor.Black;

                            Stop();
                        }
                    }
                }
                if (score == 3)
                {
                    wall.CleanBody();


                    interval  = 200;
                    gameLevel = GameLevel.Second;
                    wall.LoadLevel(GameLevel.Second);

                    Console.Clear();
                    wall.Draw();

                    food.body[0] = food.CreateFood(wall.body, worm.body);
                    worm.body.Clear();
                    worm.body.Add(new Point {
                        X = 24, Y = 16
                    });
                    score++;
                    continue;
                }
                worm.Draw();
                food.Draw();
                Thread.Sleep(Game.interval);
            }
        }
Esempio n. 25
0
        static void Main(string[] args)
        {
            int l;

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Chose level (1-5)");
                l = int.Parse(Console.ReadLine());
                if (l > 0 && l <= 5)
                {
                    break;
                }
            }

            Wall wall = new Wall(l);
            Worm worm = new Worm();
            Food food = new Food();

            string way = "none";

            bool f0 = true;

            while (f0 == true)
            {
                worm = new Worm();
                food = new Food();
                f0   = false;
                for (int i = 0; i < wall.bricks.Count; i++)
                {
                    if (wall.bricks[i].Equals(worm.body[0]))
                    {
                        f0 = true;
                    }
                }
            }

            bool s0 = true;
            bool s1 = true;

            while (s0 == true || s1 == true)
            {
                worm = new Worm();
                s0   = false;
                s1   = false;
                for (int i = 0; i < wall.bricks.Count; i++)
                {
                    if (wall.bricks[i].Equals(worm.body[0]))
                    {
                        s0 = true;
                    }
                }
                if (worm.body[0].Equals(food.location))
                {
                    s1 = true;
                }
            }

            while (worm.isAlive)
            {
                Console.Clear();
                worm.Draw();
                food.Draw();
                wall.Draw();

                ConsoleKeyInfo pressedKey = Console.ReadKey();
                switch (pressedKey.Key)
                {
                case ConsoleKey.UpArrow:
                    if (way != "down" || worm.body.Count == 1)
                    {
                        worm.Move(0, -1);
                        way = "up";
                    }
                    break;

                case ConsoleKey.DownArrow:
                    if (way != "up" || worm.body.Count == 1)
                    {
                        worm.Move(0, 1);
                        way = "down";
                    }
                    break;

                case ConsoleKey.LeftArrow:
                    if (way != "right" || worm.body.Count == 1)
                    {
                        worm.Move(-1, 0);
                        way = "left";
                    }
                    break;

                case ConsoleKey.RightArrow:
                    if (way != "left" || worm.body.Count == 1)
                    {
                        worm.Move(1, 0);
                        way = "right";
                    }
                    break;

                case ConsoleKey.Escape:
                    worm.isAlive = false;
                    break;
                }

                for (int i = 0; i < wall.bricks.Count; i++)
                {
                    if (wall.bricks[i].x == worm.body[0].x && wall.bricks[i].y == worm.body[0].y)
                    {
                        worm.isAlive = false;
                    }
                }

                for (int i = 1; i < worm.body.Count; i++)
                {
                    if (worm.body[0].x == worm.body[i].x && worm.body[0].y == worm.body[i].y)
                    {
                        worm.isAlive = false;
                    }
                }

                if (worm.CanEat(food))
                {
                    bool f1 = true;
                    bool f2 = true;
                    while (f1 == true || f2 == true)
                    {
                        f1   = false;
                        f2   = false;
                        food = new Food();
                        for (int i = 0; i < worm.body.Count; i++)
                        {
                            if (worm.body[i].Equals(food.location))
                            {
                                f1 = true;
                            }
                        }

                        for (int i = 0; i < wall.bricks.Count; i++)
                        {
                            if (wall.bricks[i].Equals(food.location))
                            {
                                f2 = true;
                            }
                        }
                    }
                }
            }

            Console.Clear();
            Console.WriteLine("GAME OVER");
        }
Esempio n. 26
0
 public void Draw()
 {
     worm.Draw();
     food.Draw();
     wall.Draw();
 }
Esempio n. 27
0
        public void Process(ConsoleKeyInfo pressedButton)
        {
            switch (pressedButton.Key)
            {
            case ConsoleKey.UpArrow:
                worm.Clear();
                worm.Move(0, -1);
                worm.Draw();
                break;

            case ConsoleKey.DownArrow:
                worm.Clear();
                worm.Move(0, 1);
                worm.Draw();

                break;

            case ConsoleKey.LeftArrow:
                worm.Clear();
                worm.Move(-1, 0);
                worm.Draw();

                break;

            case ConsoleKey.RightArrow:
                worm.Clear();
                worm.Move(1, 0);
                worm.Draw();

                break;

            case ConsoleKey.Escape:
                break;

            case ConsoleKey.F2:
                worm.Save();
                food.Save();
                break;

            case ConsoleKey.F1:
                worm = worm.Load() as Worm;
                food = food.Load() as Food;
                break;
            }

            if (worm.body[0].Equals(food.body[0]))
            {
                worm.body.Add(new Point {
                    X = food.body[0].X, Y = food.body[0].Y
                });
                food.Draw();
            }
            else
            {
                foreach (Point p in wall.body)
                {
                    if (p.Equals(worm.body[0]))
                    {
                        Console.Clear();
                        Console.WriteLine("GAME OVER!!!");
                        isAlive = false;
                        break;
                    }
                }
            }
        }