Esempio n. 1
0
 private void Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     worm.Clear();
     worm.Move();
     worm.Draw();
     CheckColision();
     ShowStatusBar(worm.body.Count.ToString());
 }
Esempio n. 2
0
 void CheckWallColision()
 {
     if (wall.CheckIntersection(worm.body) == true)
     {
         worm.Clear();
         food.Clear();
         wall.Clear();
         Console.WriteLine("     ");
         Console.WriteLine("Game over");
         Environment.Exit(0);
     }
 }
Esempio n. 3
0
 public void elapsed(object sender, ElapsedEventArgs e)
 {
     if (Butter.gameOver)
     {
         gameover();
     }
     else
     {
         if (Butter.score == 2)
         {
             timer.Enabled = !timer.Enabled;
             Nextlvl.Serialize(2, Butter.username, 20, 20, 1, 3);
             System.Diagnostics.Process.Start(System.AppDomain.CurrentDomain.FriendlyName);
             Environment.Exit(0);
         }
         else
         if (Butter.score == 5)
         {
             timer.Enabled = !timer.Enabled;
             Nextlvl.Serialize(3, Butter.username, 20, 20, 1, 6);
             System.Diagnostics.Process.Start(System.AppDomain.CurrentDomain.FriendlyName);
             Environment.Exit(0);
         }
         worm.Clear();
         worm.Move();
         worm.Draw();
         CheckCollision();
     }
 }
Esempio n. 4
0
 private void Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     worm.Clear();
     worm.Move();
     worm.Draw();
     CheckCollision();
 }
Esempio n. 5
0
 private void Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     w.Clear();
     w.Move();
     w.Draw();
     CheckFood();
 }
Esempio n. 6
0
        public void KeyPressed(ConsoleKeyInfo pressedKey)
        {
            if (cnt > 3)
            {
                wall = new Wall('#', ConsoleColor.DarkYellow, @"Levels/level2.txt");
            }


            change = false;
            switch (pressedKey.Key)
            {
            case ConsoleKey.UpArrow:
                w.ChangeDirection(0, -1);
                break;

            case ConsoleKey.DownArrow:
                w.ChangeDirection(0, 1);
                break;

            case ConsoleKey.LeftArrow:
                w.ChangeDirection(-1, 0);
                break;

            case ConsoleKey.RightArrow:
                w.ChangeDirection(1, 0);
                break;

            case ConsoleKey.S:
                w.Save("worm");
                break;

            case ConsoleKey.L:
                wormTimer.Stop();
                w.Clear();
                f    = new Food('@', ConsoleColor.Yellow);
                wall = new Wall('#', ConsoleColor.DarkYellow, @"Levels/level1.txt");
                w    = Worm.Load("worm");
                wormTimer.Start();
                break;

            case ConsoleKey.Escape:
                IsRunning = false;
                // wormTimer.Stop();
                break;

            case ConsoleKey.Spacebar:
                if (!pause)
                {
                    wormTimer.Stop();
                    pause = true;
                }
                else
                {
                    wormTimer.Start();
                    pause = false;
                }
                break;
            }
        }
Esempio n. 7
0
 private void T_Elapsed(object sender, ElapsedEventArgs e)
 {
     worm.Clear();
     worm.Move();
     CanWormEat();
     IsItCrash();
     worm.Draw();
 }
Esempio n. 8
0
        public void ChangeFrame()
        {
            worm.Clear();
            worm.Move();
            worm.Draw();

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

            CheckCollision();
        }
Esempio n. 9
0
 private void Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     w.Clear();
     w.Move();
     w.Draw();
     CheckWall();
     CheckBody();
     CheckFood();
     timer.Interval = speed;
     comment();
 }
Esempio n. 10
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. 11
0
        /* private void ChangeTime(object sender, ElapsedEventArgs e)
         * {
         *   Console.SetCursorPosition(47, 27);
         *   Console.WriteLine(DateTime.Now.Second);
         * }*/

        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            w.Clear();
            w.Move();
            if (!end)
            {
                w.Draw();
            }
            CheckFood();
            if (Bally.Score >= 20)
            {
                b.body.Clear();
                Console.Clear();
                b.LoadLevel(2);
                Bally.PrevS += Bally.Score;
                Bally.Score  = 0;
            }
            CheckWall();
            if (w.body.Count >= 4)
            {
                CheckBody();
            }
        }
Esempio n. 12
0
        public void DrawWorm(object sender, ElapsedEventArgs e)
        {
            if (points == 30)
            {
                points = 40;
                LoadLevel2();
            }
            if (points == 70)
            {
                points = 80;
                LoadLevel3();
            }
            if (points == 110)
            {
                points = 120;
                LoadLevelInf();
            }

            DrawBar();
            worm.Clear();
            worm.Move();
            worm.Draw();

            if (worm.body[0].Equals(food.body[0]))
            {
                worm.body.Add(new Point {
                    X = food.body[0].X, Y = food.body[0].Y
                });
                points = points + 10;
                bool goodFood = false;
                while (!goodFood)
                {
                    food = new Food(new Point {
                        X = new Random().Next() % 57 + 1, Y = new Random().Next() % 15 + 6
                    }, ConsoleColor.Red, '+');
                    goodFood = true;
                    foreach (Point p in worm.body)
                    {
                        if (food.body[0].Equals(p))
                        {
                            goodFood = false;
                            break;
                        }
                    }
                    foreach (Point p in wall.body)
                    {
                        if (food.body[0].Equals(p))
                        {
                            goodFood = false;
                            break;
                        }
                    }
                }
                food.Draw();
            }

            else
            {
                foreach (Point p in wall.body)
                {
                    if (p.Equals(worm.body[0]))
                    {
                        Stop();
                        alive = false;
                        DrawGameOver();
                    }
                }

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

            if (points >= 110)
            {
                lev = "inf";
            }
            else if (points >= 70)
            {
                lev = "3";
            }
            else if (points >= 30)
            {
                lev = "2";
            }
        }
Esempio n. 13
0
        public void Process()
        {
            ConsoleKeyInfo pressedButton = Console.ReadKey();

            switch (pressedButton.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:
                break;
            }

            if (worm.body[0].Equals(food.body[0]))
            {
                worm.body.Add(new Point {
                    X = food.body[0].X, Y = food.body[0].Y
                });
                count++;
                if (count == 3)
                {
                    wall.Clear();
                    worm.Clear();
                    worm.body.Clear();
                    wall.LoadLevel(gameLevel);
                    wall.Draw();
                    gameLevel++;
                    count = 0;
                }
                Random rx = new Random();
                while (wall.IsPointBelong(food.body[0]) || worm.IsPointBelong(food.body[0]))
                {
                    food.body[0] = new Point {
                        X = rx.Next(1, 30), Y = rx.Next(1, 30)
                    };
                }
            }
            else
            {
                foreach (Point p in wall.body)
                {
                    if (p.Equals(worm.body[0]))
                    {
                        Console.Clear();
                        Console.WriteLine("GAME OVER!!!");
                        isAlive = false;
                        break;
                    }
                }
                for (int i = 1; i < worm.body.Count; i++)
                {
                    if (worm.body[i].Equals(worm.body[0]))
                    {
                        Console.Clear();
                        Console.WriteLine("GAME OVER!!!");
                        isAlive = false;
                        break;
                    }
                }
            }
        }
Esempio n. 14
0
        public void Start()
        {
            Load();


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

            t.Start();

            while (true)
            {
                wall.Save();
                if (score == 500 && nextLevel == true)
                {
                    level = level + 1;
                    wall.Clear();
                    wall.Generate(level);
                    wall.Draw();
                    nextLevel = false;
                    score     = 0;

                    worm.Clear();
                    Point p = new Point();
                    p = worm.points[0];
                    worm.points.Clear();
                    worm.points.Add(p);
                }

                ConsoleKeyInfo pressedKey = Console.ReadKey();
                switch (pressedKey.Key)
                {
                case ConsoleKey.F2:
                    this.Save();
                    break;

                case ConsoleKey.F3:
                    wall = wall.Load() as Wall;
                    wall.Draw();
                    worm.Clear();
                    worm = worm.Load() as Worm;
                    worm.AttachGameLink(this);
                    t.Abort();

                    t = new Thread(new ThreadStart(worm.Move));
                    t.Start();
                    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:
                    break;
                }
            }
        }
Esempio n. 15
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;
                    }
                }
            }
        }