示例#1
0
        static void  Main(string[] args)
        {
            // Gameboard contiene las reglas del juego
            GameBoard Juego = new GameBoard(3, .1f);

            Console.WriteLine("Qué nivel quieres jugar? (1. Facil, 2. Normal, 3.Dificil)");
            var respuesta = Console.ReadLine();

            //Aquí metemos la frecuencia de spawn y los enemigos a eliminar para ganar la partida
            if (respuesta == "1")
            {
                Juego = new GameBoard(3, .1f);
            }
            else if (respuesta == "2")
            {
                Juego = new GameBoard(5, .2f);
            }
            else if (respuesta == "3")
            {
                Juego = new GameBoard(10, .3f);
            }
            else
            {
                Console.WriteLine("Qué nivel quieres jugar? -1. Facil, 2. Normal, 3.Dificil-");
            }
            while (Juego.Fin() != 0)
            {
                var AccionCorrecta = true;
                var accion         = UserComand().ToUpper();
                //Esto se podría mejorar
                if (accion.StartsWith("ADD"))
                {
                    string LaPlanta = accion.Split('<', '>')[1];
                    string LaX      = accion.Split('<', '>')[3];
                    string LaY      = accion.Split('<', '>')[5];
                    if (int.TryParse(LaX, out int X) && int.TryParse(LaY, out int Y))
                    {
                        var posicionOcupada = Juego.PosicionOcupada(X, Y);
                        if (posicionOcupada == false)
                        {
                            Juego.GenerarNPC(LaPlanta, int.Parse(LaX), int.Parse(LaY));
                        }
                        else
                        {
                            AccionCorrecta = false;
                            Console.WriteLine("Posición ocupada");
                        }
                    }
                    else
                    {
                        AccionCorrecta = false;

                        Console.WriteLine("Las coordenadas son incorrectas");
                    }
                }
                else if (accion.StartsWith("LIST"))
                {
                    foreach (var item in Juego.Tablero)
                    {
                        Console.Write(item.Tipo + "- (" + item.X + "," + item.Y + ")");
                    }
                }
                else if (string.IsNullOrWhiteSpace(accion))
                {
                }

                // No he puesto las demás acciones pero son triviales de hacer
                else
                {
                    AccionCorrecta = false;
                }
                if (AccionCorrecta == true)
                {
                    Update(Juego);
                    Draw(Juego);
                    var HaTerminado = Juego.Fin();
                    if (HaTerminado != 0)
                    {
                        GameOver(HaTerminado);
                    }
                    else
                    {
                        Juego.SiguienteTurno();
                    }
                }
            }
        }