public static void MostrarPuntuación(Tablero tablero, Serpiente serpiente) { Console.ForegroundColor = ConsoleColor.Red; Util.DibujarPosicion(tablero.Anchura / 2, tablero.Altura / 2, "Game Over"); Util.DibujarPosicion(tablero.Anchura / 2, (tablero.Altura / 2) + 1, $"Puntuacion {serpiente.Puntos}"); Console.ResetColor(); }
public static Caramelo CrearCaramelo(Serpiente serpiente, Tablero tablero) { bool carameloValido; int x, y; do { Random random = new Random(); x = random.Next(1, tablero.Anchura - 1); y = random.Next(1, tablero.Altura - 1); carameloValido = serpiente.PosicionEnCola(x, y); } while (carameloValido); tablero.ContieneCaramelo = true; return(new Caramelo(x, y)); }
static void Main(string[] args) { Tablero tablero = new Tablero(20, 20); Serpiente serpiente = new Serpiente(10, 10); Caramelo caramelo = new Caramelo(0, 0); bool haComido = false; do { Console.Clear(); tablero.DibujarTablero(); //movemos y comprobamos si ha comido en el turno anterior. serpiente.Moverse(haComido); //Comprobamos si se ha comido el caramelo haComido = serpiente.ComeCaramelo(caramelo, tablero); //Dibujamos serpiente serpiente.DibujarSerpiente(); //Si no contiene el caramelo, instanciamos uno nuevo. if (!tablero.ContieneCaramelo) { caramelo = Caramelo.CrearCaramelo(serpiente, tablero); } //Dibujamos caramelo caramelo.DibujarCaramelo(); //Leemos informacion por teclado de la direccion. var sw = Stopwatch.StartNew(); while (sw.ElapsedMilliseconds <= 250) { serpiente.Direccion = Util.LeerMovimiento(serpiente.Direccion); } } while (serpiente.ComprobarMorir(tablero)); Util.MostrarPuntuación(tablero, serpiente); Console.ReadKey(); }