Beispiel #1
0
        public void Choque(Nave nave)
        {
            if (X >= nave.X && X < nave.X + 5 && Y >= nave.Y && Y <= nave.Y + 2)
            {
                nave.COR();
                nave.Pintar();
                nave.PintarCorazones();

                X = rand.Next(4, 75); // Para que nos de un numero aleatorio entre 4 y 75
                Y = 4;                // Para volver a subirlo
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            Console.CursorVisible  = false;
            Console.WindowHeight   = 40;
            Console.WindowWidth    = 80;

            Helper.PintarLimites();

            Nave nave1 = new Nave(37, 30, 3, 3);

            nave1.Pintar();
            nave1.PintarCorazones();

            Random  rand     = new Random();
            Boolean gameOver = false;
            Int32   puntos   = 0;

            ConsoleKeyInfo tecla;

            List <Asteroide> asteroides = new List <Asteroide>();

            for (int i = 0; i < 5; i++)
            {
                asteroides.Add(new Asteroide(rand.Next(3, 74), rand.Next(4, 5)));
            }

            while (!gameOver)
            {
                Console.SetCursorPosition(4, 2);
                Console.Write("Puntos {0}", puntos);

                if (Console.KeyAvailable)
                {
                    tecla = Console.ReadKey(true);

                    nave1.Mover(tecla);
                    // nave1.Disparar(tecla);
                }

                for (int i = 0; i < asteroides.Count; i++)
                {
                    asteroides[i].Mover();
                    asteroides[i].Choque(nave1);
                }

                for (int i = 0; i < nave1.balas.Count; i++)
                {
                    nave1.balas[i].Mover();

                    if (nave1.balas[i].Fuera())
                    {
                        Console.SetCursorPosition(nave1.balas[i].X, nave1.balas[i].Y);
                        Console.WriteLine(" ");
                        nave1.balas.Remove(nave1.balas[i]);
                    }
                }

                for (int i = 0; i < asteroides.Count; i++)
                {
                    for (int j = 0; j < nave1.balas.Count; j++)
                    {
                        if (asteroides[i].X == nave1.balas[j].X && asteroides[i].Y + 1 == nave1.balas[j].Y || asteroides[i].Y == nave1.balas[j].Y)
                        {
                            Console.SetCursorPosition(nave1.balas[j].X, nave1.balas[j].Y);
                            Console.WriteLine(" ");
                            nave1.balas.Remove(nave1.balas[j]);

                            asteroides.Add(new Asteroide(rand.Next(3, 74), 4));
                            Console.SetCursorPosition(asteroides[i].X, asteroides[i].Y);
                            Console.WriteLine(" ");
                            asteroides.Remove(asteroides[i]);

                            puntos += 5;
                        }
                    }
                }

                if (nave1.Vidas == 0)
                {
                    gameOver = true;
                }

                nave1.Morir();

                if (Console.KeyAvailable)
                {
                    tecla = Console.ReadKey(true);

                    nave1.Mover(tecla);
                }

                Thread.Sleep(30);
            }

            Console.Read();
        }