Пример #1
0
        private void timer1_Tick(object sender, EventArgs e) // Timer koj menuva lokaciite na aktivnite zadaci/labels
        {
            List <int> indexes = new List <int>();

            for (int i = label.Count - 1; i >= 0; i--) // Porveruvanje na pozicijata i soodvetno menuvanje na boite
            {
                label[i].Location = new Point(label[i].Location.X, label[i].Location.Y + 5 * checkDifficulty);
                int processNumber = checkLocation(label[i]);
                if (processNumber == 0)
                {
                    label[i].ForeColor = Color.Green;
                }
                if (processNumber == 1)
                {
                    label[i].ForeColor = Color.Orange;
                }
                if (processNumber == 2)
                {
                    label[i].ForeColor = Color.Red;
                }
                if (processNumber == 3) // brishenje na labelot i soodvetno namaluvanje na zivoti
                {
                    int broj = Int32.Parse(lblBrZivotiText.Text);
                    broj--;
                    if (broj <= 0)
                    {
                        lblBrZivotiText.Text = "0";
                    }
                    else
                    {
                        lblBrZivotiText.Text = broj.ToString();
                    }
                    label[i].Visible = false;
                    label.RemoveAt(i);
                }
            }
            if (lblBrZivotiText.Text.Equals("0")) // ako brojot na zivoti e 0, game over, pocni nova igra
            {
                GameOver gameover = new GameOver(this.sendDifficulty(), this.sendScore());
                //gameover.Show();
                timer1.Enabled = false;
                DialogResult result = gameover.ShowDialog();
                if (result == DialogResult.OK)
                {
                    foreach (Label l in label)
                    {
                        l.Visible = false;
                    }
                    label.RemoveRange(0, label.Count);
                    gameInProgress = false;
                    this.btnEasy_Click(sender, null);
                }
                else if (result == DialogResult.Retry)
                {
                    foreach (Label l in label)
                    {
                        l.Visible = false;
                    }
                    label.RemoveRange(0, label.Count);
                    gameInProgress = false;
                    this.btnMedium_Click(sender, null);
                }
                else if (result == DialogResult.Yes)
                {
                    foreach (Label l in label)
                    {
                        l.Visible = false;
                    }
                    label.RemoveRange(0, label.Count);
                    gameInProgress = false;
                    this.btnHard_Click(sender, null);
                }
                else
                {
                    foreach (Label l in label)
                    {
                        l.Visible = false;
                    }
                    label.RemoveRange(0, label.Count);
                    gameInProgress = false;
                }
            }
            if (label.Count < BRZADACI && !lblBrZivotiText.Text.Equals("0")) // ako brojot na prisutni labels e pomal od 5 dodadi nov label
            {
                Random random   = new Random();
                Label  newLabel = createNewLabel(random.Next(0, baseList.Count), random.Next(0, 5));
                label.Add(newLabel);
                panel1.Controls.Add(newLabel);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(102, 30);

            string name;

            while (true)
            {
                Console.Write("Введите свое имя: ");
                name = Console.ReadLine();
                if (name.Length < 3)
                {
                    Console.Clear();
                    Console.WriteLine("Имя должно быть больше 3 символа.");
                    continue;
                }
                else if (name.Length > 8)
                {
                    Console.Clear();
                    Console.WriteLine("Имя не должно быть больше 8 символов.");
                    continue;
                }
                else
                {
                    Console.Clear();
                    break;
                }
            }

            Music music = new Music();

            music.MainMusic();

            Walls walls = new Walls(100, 25);

            walls.Draw();

            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(100, 24);
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            Text text = new Text();

            int xOffsetO4ki = 40;
            int yOffsetO4ki = 26;

            int size = 4;

            text.WriteText("Длина змеи:" + size, xOffsetO4ki - 35, yOffsetO4ki);

            int o4ki = 0;

            text.WriteText("Баллы:" + o4ki, xOffsetO4ki, yOffsetO4ki);

            Stopwatch stopWatch = new Stopwatch(); // секундомер

            stopWatch.Start();                     // запустить секундомер

            while (true)
            {
                Console.SetCursorPosition(xOffsetO4ki, 27);
                TimeSpan ts = stopWatch.Elapsed;                       // структура для работы с временем
                Console.WriteLine($"{ts.Minutes:00}:{ts.Seconds:00}"); // вывод секунд и минут
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    stopWatch.Stop();
                    break;
                }
                if (snake.Eat(food))
                {
                    music.EatSound();
                    FoodCreator food1 = new FoodCreator(100, 24);
                    food = food1.CreateFood();
                    food.FoodDraw();
                    o4ki++;
                    Console.SetCursorPosition(xOffsetO4ki, yOffsetO4ki);
                    text.WriteText("Баллы:" + o4ki, xOffsetO4ki, yOffsetO4ki);
                    size++;
                    Console.SetCursorPosition(xOffsetO4ki, yOffsetO4ki);
                    text.WriteText("Длина змеи:" + size, xOffsetO4ki - 35, yOffsetO4ki);
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }

            Console.WriteLine(stopWatch.ElapsedTicks);

            var time = stopWatch.Elapsed;

            music.GameOver();

            GameOver game = new GameOver();

            game.WriteGameOver(o4ki);

            SaveFiles saveFiles = new SaveFiles();

            saveFiles.to_file(name, o4ki, size, time);

            ConsoleKeyInfo btn = Console.ReadKey();

            if (btn.Key == ConsoleKey.Enter)
            {
                var fileName = Assembly.GetExecutingAssembly().Location;
                System.Diagnostics.Process.Start(fileName);
                Environment.Exit(0);
            }
        }