Exemple #1
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();
                }
            }
        }
Exemple #2
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");
        }
Exemple #3
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");
        }
Exemple #4
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");
        }
Exemple #5
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);
                }
            }
        }
Exemple #6
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");
        }