static void CambiaCas(ref Tablero tab, ref int cX, ref int cY, char c, out MenuOutput menu) { int fils, cols; tab.getDims(out fils, out cols); menu = MenuOutput.Juega; switch (c) { case 'u': cX--; if (cX < 0) { cX = fils - 1; } break; case 'd': cX++; if (cX >= fils) { cX = 0; } break; case 'l': cY--; if (cY < 0) { cY = fils - 1; } break; case 'r': cY++; if (cY >= fils) { cY = 0; } break; case '1': tab.cambiaCasilla(cX, cY, Tablero.Casilla.Muro); break; case '2': tab.cambiaCasilla(cX, cY, Tablero.Casilla.Blanco); break; case '3': tab.cambiaCasilla(cX, cY, Tablero.Casilla.MuroCelda); break; case '4': tab.cambiaCasilla(cX, cY, Tablero.Casilla.Comida); break; case '5': tab.cambiaCasilla(cX, cY, Tablero.Casilla.Vitamina); break; case '6': case '7': case '8': case '9': tab.cambiaCasilla(cX, cY, Tablero.Casilla.Blanco); int n = int.Parse(c.ToString()) - 5; tab.BorraPers(); tab.setPersonaje(n, cX, cY, 0, 0); break; case '0': tab.cambiaCasilla(cX, cY, Tablero.Casilla.Blanco); tab.BorraPers(); tab.setPersonaje(0, cX, cY, 0, 0); break; case 'e': menu = MenuOutput.Salir; break; case 'q': menu = MenuOutput.Guardar; break; case 'b': tab = new Tablero(fils, cols); Console.SetCursorPosition(0, 0); tab.Dibuja(); break; } }
static void LevelCreator() { Console.WriteLine("Introduzca el tamaño del tablero [fils] x [cols]: Max (50 x 50)"); bool valido = false; int fils = 0, cols = 0; while (!valido) { Console.Write("Fils: "); valido = int.TryParse(Console.ReadLine(), out fils) && fils != 0 && fils < 51; if (valido) { Console.Write("Cols: "); valido = int.TryParse(Console.ReadLine(), out cols) && cols != 0 && cols < 51; } if (!valido) { Console.WriteLine("Datos no validos, introduzcalos de nuevo"); } } Tablero tab = new Tablero(fils, cols); MenuOutput menu = MenuOutput.Juega; //Setup int cY = 0, cX = 0; Console.Clear(); tab.Dibuja(); tab.DibujaBordes(); for (int i = 0; i < tab.pers.Length; i++) { tab.setPersonaje(i, 0, cols + i + 1, 0, 0); } tab.DibujaPers(); Console.SetCursorPosition(0, fils + 2); Console.Write(@"1 - Muro 2 - Blanco 3 - Muro Fant 4 - Comida 5 - Vitamina 6, 7, 8, 9 - Fantasmas 0 - Pacman Esc - Salir sin guardar Enter - Salir y guardar Return - Borrar"); Console.SetCursorPosition(0, 0); //Menu Principal while (menu != MenuOutput.Salir && menu != MenuOutput.Guardar) { Console.SetCursorPosition(cY, cX); char c = LeeInput(); /* * 1-Muro * 2-Blanco * 3-Muro Fant * 4-Comida * 5-Vitamina * 6,7,8,9 - Fantasmas * 0 -Pacman */ if (c != ' ') { CambiaCas(ref tab, ref cX, ref cY, c, out menu); } if (c != ' ' && c != 'u' && c != 'd' && c != 'l' && c != 'r') { } tab.BorraPers(); tab.DibujaCasilla(cX, cY); tab.DibujaPers(); Console.SetCursorPosition(cY, cX); System.Threading.Thread.Sleep(100); } if (menu == MenuOutput.Guardar) { Console.Write("Introduzca el numero del nivel (Mayor que 9): "); //Si el jugador se equivoca o introduce mal el dato lo guardaremos en el archivo lvl 00 (Reservado para copia de seguridad) int level = 0; int.TryParse(Console.ReadLine(), out level); tab.guarda(level); } }
static void MenuIni(out MenuOutput option) { //Dibujamos el header del titulo pac-man Tablero tab = new Tablero("Menus/Header.dat"); tab.DibujaMenu(); option = MenuOutput.Juega; int indice = 0; //Dibujamos las opciones Console.ForegroundColor = ConsoleColor.Green; Console.SetCursorPosition(30, 7); Console.WriteLine(" JUGAR"); Console.ForegroundColor = ConsoleColor.Cyan; Console.SetCursorPosition(30, 9); Console.WriteLine(" LOGIN"); Console.ForegroundColor = ConsoleColor.Blue; Console.SetCursorPosition(30, 11); Console.WriteLine(" CEAR"); Console.ForegroundColor = ConsoleColor.DarkCyan; Console.SetCursorPosition(30, 13); Console.WriteLine(" CARGAR"); Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition(30, 15); Console.WriteLine(" SALIR"); //Y dibujamos el cursor Console.BackgroundColor = ConsoleColor.Yellow; Console.ForegroundColor = ConsoleColor.Black; Console.SetCursorPosition(29, 2 * indice + 7); Console.Write(">"); Console.SetCursorPosition(38, 2 * indice + 7); Console.Write("<"); Console.BackgroundColor = ConsoleColor.Black; Console.SetCursorPosition(0, 12); string input = ""; while (input != "Enter") { input = Console.ReadKey().Key.ToString(); while (Console.KeyAvailable) { Console.ReadKey(); } if (input == "UpArrow" || input == "DownArrow") { //Si el usuario cambia la opcion, primero borramos los marcadores actuales Console.BackgroundColor = ConsoleColor.Black; Console.SetCursorPosition(29, 2 * indice + 7); Console.Write(" "); Console.SetCursorPosition(38, 2 * indice + 7); Console.Write(" "); //Luego, cambiamos el indice (Con forma toroidal!) if (input == "UpArrow") { indice--; if (indice < 0) { indice = 4; } } else { indice++; if (indice > 4) { indice = 0; } } //Y dibujamos el cursor Console.BackgroundColor = ConsoleColor.Yellow; Console.SetCursorPosition(29, 2 * indice + 7); Console.Write(">"); Console.SetCursorPosition(38, 2 * indice + 7); Console.Write("<"); Console.SetCursorPosition(0, 12); Console.BackgroundColor = ConsoleColor.Black; } Console.BackgroundColor = ConsoleColor.Black; } switch (indice) { case 0: option = MenuOutput.Juega; break; case 1: option = MenuOutput.Login; break; case 2: option = MenuOutput.Crear; break; case 3: option = MenuOutput.Cargar; break; case 4: option = MenuOutput.Salir; break; } }
static void MenuPausa(out MenuOutput option) { Console.Clear(); //Dibujamos el header del menu Tablero tab = new Tablero("Menus/Pausa.dat"); tab.DibujaMenu(); option = MenuOutput.Juega; int indice = 0; int margen = 15; //Dibujamos las opciones Console.ForegroundColor = ConsoleColor.Green; Console.SetCursorPosition(margen, 7); Console.WriteLine(" CONTINUAR"); Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition(margen, 9); Console.WriteLine(" SALIR"); //Y dibujamos el cursor Console.BackgroundColor = ConsoleColor.Yellow; Console.ForegroundColor = ConsoleColor.Black; Console.SetCursorPosition(margen - 1, 2 * indice + 7); Console.Write(">"); Console.SetCursorPosition(margen + 11, 2 * indice + 7); Console.Write("<"); Console.BackgroundColor = ConsoleColor.Black; Console.SetCursorPosition(0, 12); string input = ""; while (input != "Enter") { input = Console.ReadKey().Key.ToString(); while (Console.KeyAvailable) { Console.ReadKey(); } if (input == "UpArrow" || input == "DownArrow") { //Si el usuario cambia la opcion, primero borramos los marcadores actuales Console.BackgroundColor = ConsoleColor.Black; Console.SetCursorPosition(margen - 1, 2 * indice + 7); Console.Write(" "); Console.SetCursorPosition(margen + 11, 2 * indice + 7); Console.Write(" "); //Luego, cambiamos el indice (Con forma toroidal!) if (input == "UpArrow") { indice--; if (indice < 0) { indice = 1; } } else { indice++; if (indice > 1) { indice = 0; } } //Y dibujamos el cursor Console.BackgroundColor = ConsoleColor.Yellow; Console.SetCursorPosition(margen - 1, 2 * indice + 7); Console.Write(">"); Console.SetCursorPosition(margen + 11, 2 * indice + 7); Console.Write("<"); Console.SetCursorPosition(0, 12); Console.BackgroundColor = ConsoleColor.Black; } Console.BackgroundColor = ConsoleColor.Black; } switch (indice) { case 0: option = MenuOutput.Continuar; break; case 1: option = MenuOutput.Salir; break; } }
static void Main(string[] args) { int level = 1; //LevelCreator(); //Arrancamos la lista de usuarios users = Usuarios.cargaUsuarios("usuarios"); MenuOutput option = MenuOutput.Login; while (option == MenuOutput.Login) { Console.Clear(); MenuIni(out option); if (option == MenuOutput.Login) { Console.Clear(); Login(); } else if (option == MenuOutput.Crear) { Console.Clear(); Console.ResetColor(); LevelCreator(); } else if (option == MenuOutput.Cargar) { option = MenuOutput.Juega; level = 10; } } //Inicializamos las variables bool exit = false; if (option == MenuOutput.Juega) { bool next = false; bool gameOver = false; puntuacion = 0; //Empezamos el juego while (!exit && !gameOver && level < 11) { Console.Clear(); //Bucle ppal del juego Juega(level, out next, out exit, out gameOver); //Si no sale, esperamos un poco para pasar de nivel if (!exit) { System.Threading.Thread.Sleep(3000); } //Y si se pasa el nivel, ponemos el siguiente if (next) { level++; } } if (Usuario != null) { Usuario.Save(level, puntuacion); SaveUser(); Usuarios.vuelcaLista(users, "usuarios"); } } Console.Clear(); ScoreBoard(); Console.ForegroundColor = ConsoleColor.White; }