예제 #1
0
        public static void Draw(PlayerProjectile projectile, ref bool impact)
        {
            Console.BackgroundColor = ConsoleColor.Cyan;
            for (byte i = 0; i < projectile.height; i++)
            {
                for (byte j = 0; j < projectile.width; j++)
                {
                    if (Buf.Buffer[projectile.Posy + i, projectile.Posx + j] == 'v')// || Buf.Buffer[projectile.Posy + i, projectile.Posx + j] == 'e')
                    {
                        Console.SetCursorPosition(projectile.Posx + j, projectile.Posy + i);
                        Buf.Buffer[projectile.Posy + i, projectile.Posx + j] = 'z';
                        Console.Write(' ');
                    }

                    else if ((
                                 Buf.Buffer[projectile.Posy + i, projectile.Posx + j] == 'e' ||//why??
                                 Buf.Buffer[projectile.Posy + i, projectile.Posx + j] == 'r' ||
                                 Buf.Buffer[projectile.Posy + i, projectile.Posx + j] == 'g' ||
                                 Buf.Buffer[projectile.Posy + i, projectile.Posx + j] == 'b' ||
                                 Buf.Buffer[projectile.Posy + i, projectile.Posx + j] == 'y') &&
                             projectile.Posy < 25)
                    {
                        impact = true;
                    }
                }
            }
        }
예제 #2
0
        public static void KillEnemy()
        {
            //proverka na stolknovenie

            /*
             * for (int q = 0; q < Zaps.Count; q++)
             * {
             *  var playerProjectile = Zaps[q];
             */
            for (int w = 0; w < Swarm.Count; w++)
            {
                for (int q = 0; q < Zaps.Count; q++)
                {
                    var playerProjectile = Zaps[q];
                    try
                    {
                        var enemy = Swarm[w];

                        for (int i = 0; i < 8; i++)
                        {
                            if (playerProjectile.Posx - i == enemy.Posx && playerProjectile.Posy - 7 == enemy.Posy)
                            {
                                PlayerProjectile.Clear(playerProjectile);
                                Zaps.Remove(playerProjectile);
                                enemy.Life--;
                                if (enemy.Life < 1)
                                {
                                    Ship.Cleaner(enemy);
                                    Swarm.Remove(enemy);
                                }

                                else
                                {
                                    Console.BackgroundColor = ConsoleColor.Red;
                                    for (int a = 0; a < 8; a++)
                                    {
                                        for (int b = 0; b < 8; b++)
                                        {
                                            Console.SetCursorPosition(enemy.Posx + b, enemy.Posy + a);
                                            Console.Write(' ');
                                        }
                                    }
                                    Thread.Sleep(5);
                                }
                            }
                        }
                    }
                    catch
                    {
                        break;
                    }
                }
            }
        }
예제 #3
0
 public static void Destroyed()
 {
     foreach (var prj in RainOfProjectiles)
     {
         Projectile.Clear(prj);
     }
     RainOfProjectiles.Clear();
     foreach (var playerProjectile in Zaps)
     {
         PlayerProjectile.Clear(playerProjectile);
     }
     Zaps.Clear();
     Player.Life--;
     Ship.MovePlayer(Player, (90 - Player.Posx), 0);
     Console.SetCursorPosition(0, Console.BufferHeight - 1);
     Console.BackgroundColor = ConsoleColor.Red;
     Console.Write("TOTAL LIVES: " + Player.Life);
 }
예제 #4
0
 public static void Clear(PlayerProjectile projectile)
 {
     Console.BackgroundColor = ConsoleColor.Black; //Cleaner
     {
         for (byte i = 0; i < projectile.height; i++)
         {
             for (byte j = 0; j < projectile.width; j++)
             {
                 switch (Buf.Buffer[projectile.Posy + i, projectile.Posx + j])
                 {
                 case 'z':
                 case 'v':
                     Console.SetCursorPosition(projectile.Posx + j, projectile.Posy + i);
                     Buf.Buffer[projectile.Posy + i, projectile.Posx + j] = 'v';
                     Console.Write(' ');
                     break;
                 }
             }
         }
     }
 }
예제 #5
0
        static void Main()
        {
            var stars = new List <Star>();

            Console.Title         = "Space War";
            Console.WindowLeft    = Console.WindowTop = 0;
            Console.WindowHeight  = Console.BufferHeight = 50; //60
            Console.WindowWidth   = Console.BufferWidth = 160; //180
            Console.CursorVisible = false;
            int enemies  = 2;
            int hardness = 4;

            Console.WriteLine("Choose Your Destiny!\n1) New Game\n2) Exit");
            int choice = Convert.ToInt32(Console.ReadLine());

            //заполняем рабочую зону
            if (choice == 1)
            {
                Player.Life = 5;
                Console.Clear();
                reset();
                for (byte i = 0; i < Console.BufferHeight; i++)
                {
                    for (byte j = 0; j < Console.BufferWidth; j++)
                    {
                        Buf.Buffer[i, j] = 'v';
                    }
                }

                Console.SetCursorPosition(0, Console.BufferHeight - 1);
                Console.BackgroundColor = ConsoleColor.Red;
                Console.Write("TOTAL LIVES: " + Player.Life);

                for (byte i = 0; i < 15; i++)
                {
                    stars.Add(new Star());
                }

                CreateSwarm(enemies);
                Ship.MovePlayer(Player, 90, 38);
                while (true)//let's go
                {
                    if (Swarm.Count == 0)
                    {
                        foreach (var pp in Zaps)
                        {
                            PlayerProjectile.Clear(pp);
                        }
                        foreach (var prj in RainOfProjectiles)
                        {
                            Projectile.Clear(prj);
                        }
                        Zaps.Clear();
                        RainOfProjectiles.Clear();
                        Player.Life++;
                        Console.SetCursorPosition(0, Console.BufferHeight - 1);
                        Console.BackgroundColor = ConsoleColor.Red;
                        Console.Write("TOTAL LIVES: " + Player.Life);
                        if (hardness > 1)
                        {
                            hardness--;
                        }
                        CreateSwarm(++enemies);
                    }

                    Star.GoStars(stars);
                    if (Player.Life == 0)
                    {
                        break;
                    }

                    foreach (var enemy in Swarm)
                    {
                        Ship.Move(enemy, R.Next(-2, 3), R.Next(-2, 3));
                        if (R.Next(0, enemy.Life * hardness) == 0 && enemy.Delay == 0)
                        {
                            RainOfProjectiles.Add(new Projectile(R.Next(1, 4), R.Next(1, 4), enemy.Posx + 4, enemy.Posy + 8));
                        }
                        enemy.Delay++;
                        if (enemy.Delay == 4)
                        {
                            enemy.Delay = 0;
                        }
                    }

                    for (byte i = 0; i < 5 - hardness; i++)
                    {
                        if (Projectile.Fire(RainOfProjectiles))//front impact of projectile and player
                        {
                            Destroyed();
                        }
                    }

                    int delay = 0;
                    for (byte i = 0; i < 7; i++)
                    {
                        bool destroyed = false;
                        switch (Buf.Reader())
                        {
                        case 3:
                            for (byte ii = 0; ii < 7; ii++)
                            {
                                if (Buf.Buffer[Player.Posy + ii, Player.Posx + 9] == 'p')
                                {
                                    destroyed = true;
                                }
                            }
                            Ship.MovePlayer(Player, 2, 0);
                            break;

                        case 4:
                            for (byte ii = 0; ii < 7; ii++)
                            {
                                if (Buf.Buffer[Player.Posy + ii, Player.Posx - 2] == 'p')
                                {
                                    destroyed = true;
                                }
                            }
                            Ship.MovePlayer(Player, -2, 0);
                            break;

                        case 5:
                            if (delay == 0 && Zaps.Count < 2)
                            {
                                Zaps.Add(new PlayerProjectile(1, 3, Player.Posx + 1, Player.Posy - 1));
                                Zaps.Add(new PlayerProjectile(1, 3, Player.Posx + 5, Player.Posy + 1));    // - 1));
                                delay++;
                            }
                            break;

                        case 6:    //test
                            if (delay == 0 && Zaps.Count < 2)
                            {
                                Zaps.Add(new PlayerProjectile(1, 4, Player.Posx + 3, Player.Posy + 1));
                                delay++;
                            }
                            break;
                        }

                        if (PlayerProjectile.Fire(Zaps))//or if?!
                        {
                            KillEnemy();
                        }

                        if (destroyed)
                        {
                            Destroyed();
                        }

                        if (delay > 0)
                        {
                            delay++;
                        }
                        if (delay == 2000)
                        {
                            delay = 0;
                        }
                        Thread.Sleep(5);
                    }
                }
                reset();
                const string msg = "Вы храбро сражались, вам было тяжело...настолько тяжело, что вас победили, это печально, но факт...удачи в следующий раз D:";
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine();
                foreach (var c in msg)
                {
                    Console.Write(c);
                    Thread.Sleep(100);
                }
                Console.ReadLine();
                Console.Clear();
                enemies = 2;
                Swarm.Clear();
                RainOfProjectiles.Clear();
                Zaps.Clear();
                Ship.MovePlayer(Player, 90, 38);
                Main();
            }

            if (choice == 2)
            {
                Environment.Exit(0);
            }
        }