Agregados soporte para modo oscuro y horizontal. Terminada pantalla de récords

parent 53f5f12b
export 'pista.dart'; export 'pista.dart';
\ No newline at end of file export 'peponator_record.dart';
\ No newline at end of file
class PeponatorRecord {
final String jugador;
final int puntuacion;
final DateTime fecha;
PeponatorRecord({required this.jugador, required this.puntuacion, required this.fecha});
}
\ No newline at end of file
...@@ -10,14 +10,14 @@ class Pista{ ...@@ -10,14 +10,14 @@ class Pista{
late final int divisible; late final int divisible;
late final String mensaje; late final String mensaje;
EstadoPista estado = EstadoPista.BLOQUEADO; EstadoPista estado = EstadoPista.bloqueado;
Pista ({ Pista ({
required this.clase, required this.clase,
required int numero, required int numero,
this.onPressed this.onPressed
}) { }) {
if(clase != ClasePista.DIVISIBLE){ if(clase != ClasePista.divisible){
divisible = 0; divisible = 0;
} }
else{ else{
...@@ -43,29 +43,29 @@ class Pista{ ...@@ -43,29 +43,29 @@ class Pista{
} }
String _generaPista(int numero){ String _generaPista(int numero){
switch(this.clase){ switch(clase){
case ClasePista.PAR_IMPAR: case ClasePista.parImpar:
if(numero%2 == 0){ if(numero%2 == 0){
return 'El número es par'; return 'El número es par';
} }
return 'El número es impar'; return 'El número es impar';
case ClasePista.DIVISIBLE: case ClasePista.divisible:
if(divisible == 1){ if(divisible == 1){
return 'El número es primo inferior a 100'; return 'El número es primo inferior a 100';
} }
if(divisible == -1){ if(divisible == -1){
return 'El número NO es divisible entre primos inferiores a 100'; return 'El número NO es divisible entre primos inferiores a 100';
} }
return 'El número es divisible entre ${divisible}'; return 'El número es divisible entre $divisible';
case ClasePista.SUMA_CIFRAS: case ClasePista.sumaCifras:
int pseudo = numero; int pseudo = numero;
int suma = 0; int suma = 0;
while(pseudo > 0){ while(pseudo > 0){
suma += pseudo%10; suma += pseudo%10;
pseudo = (pseudo/10).floor(); pseudo = (pseudo/10).floor();
} }
return 'La suma de las cifras del número da ${suma}'; return 'La suma de las cifras del número da $suma';
case ClasePista.NUMERO_CIFRAS: case ClasePista.numeroCifras:
int div = 10; int div = 10;
int num = 1; int num = 1;
while(numero/div > 1){ while(numero/div > 1){
...@@ -75,15 +75,15 @@ class Pista{ ...@@ -75,15 +75,15 @@ class Pista{
if(num == 1){ if(num == 1){
return 'El número tiene 1 cifra'; return 'El número tiene 1 cifra';
} }
return 'El número tiene ${num} cifras'; return 'El número tiene $num cifras';
} }
} }
bool validarNumero(int adivinar, int numero){ bool validarNumero(int adivinar, int numero){
switch(this.clase){ switch(clase){
case ClasePista.PAR_IMPAR: case ClasePista.parImpar:
return adivinar%2 == numero%2; return adivinar%2 == numero%2;
case ClasePista.DIVISIBLE: case ClasePista.divisible:
if(divisible == 1){ if(divisible == 1){
return primos.contains(numero); return primos.contains(numero);
} }
...@@ -97,7 +97,7 @@ class Pista{ ...@@ -97,7 +97,7 @@ class Pista{
return true; return true;
} }
return adivinar%divisible == numero%divisible; return adivinar%divisible == numero%divisible;
case ClasePista.SUMA_CIFRAS: case ClasePista.sumaCifras:
int a = adivinar, b = numero; int a = adivinar, b = numero;
int sumaA = 0, sumaB = 0; int sumaA = 0, sumaB = 0;
while(a > 0 && b > 0){ while(a > 0 && b > 0){
...@@ -107,7 +107,7 @@ class Pista{ ...@@ -107,7 +107,7 @@ class Pista{
b = (b/10).floor(); b = (b/10).floor();
} }
return sumaA == sumaB; return sumaA == sumaB;
case ClasePista.NUMERO_CIFRAS: case ClasePista.numeroCifras:
int div = 10; int div = 10;
while(adivinar/div > 10){ while(adivinar/div > 10){
div *= 10; div *= 10;
...@@ -118,63 +118,83 @@ class Pista{ ...@@ -118,63 +118,83 @@ class Pista{
Widget createWidget(){ Widget createWidget(){
return PistaWidget( return PistaWidget(
key: Key(this.clase.name), key: Key(clase.name),
titulo: this.clase.getTitle(), titulo: clase.getTitle(),
mensaje: (estado.desbloqueada())? mensaje : estado.getMensaje(), mensaje: (estado.desbloqueada())? mensaje : estado.getMensaje(),
fondo: estado.getColorFondo(), estado: estado,
texto: estado.getColorTexto(), onPressed: (estado == EstadoPista.disponible || estado == EstadoPista.confirmacion)? onPressed : null
onPressed: (estado == EstadoPista.DISPONIBLE || estado == EstadoPista.CONFIRMACION)? onPressed : null
); );
} }
} }
enum ClasePista { enum ClasePista {
PAR_IMPAR, parImpar,
DIVISIBLE, divisible,
SUMA_CIFRAS, sumaCifras,
NUMERO_CIFRAS; numeroCifras;
String getTitle(){ String getTitle(){
switch(this){ switch(this){
case PAR_IMPAR: case parImpar:
return '¿Es par o impar?'; return '¿Es par o impar?';
case DIVISIBLE: case divisible:
return '¿Entre qué número es divisible?'; return '¿Entre qué número es divisible?';
case SUMA_CIFRAS: case sumaCifras:
return '¿Cuál es la suma de sus cifras?'; return '¿Cuál es la suma de sus cifras?';
case NUMERO_CIFRAS: case numeroCifras:
return '¿Cuántas cifras tiene?'; return '¿Cuántas cifras tiene?';
} }
} }
} }
enum EstadoPista { enum EstadoPista {
BLOQUEADO, bloqueado,
DISPONIBLE, disponible,
CONFIRMACION, confirmacion,
DESBLOQUEADO, desbloqueado,
CORRECTO, correcto,
INCORRECTO; incorrecto;
Color getColorFondo() { Color getColorFondo(Brightness brillo) {
switch(this){ switch(this){
case BLOQUEADO: case bloqueado:
if(brillo == Brightness.dark){
return Colors.grey.shade800;
}
return Colors.black87; return Colors.black87;
case DISPONIBLE: case disponible:
if(brillo == Brightness.dark){
return Colors.orange.shade700;
}
return Colors.orange; return Colors.orange;
case CONFIRMACION: case confirmacion:
if(brillo == Brightness.dark){
return Colors.yellow.shade700;
}
return Colors.yellow; return Colors.yellow;
case DESBLOQUEADO: case desbloqueado:
if(brillo == Brightness.dark){
return Colors.grey.shade400;
}
return Colors.white; return Colors.white;
case CORRECTO: case correcto:
if(brillo == Brightness.dark){
return Colors.green.shade700;
}
return Colors.green.shade400; return Colors.green.shade400;
case INCORRECTO: case incorrecto:
if(brillo == Brightness.dark){
return Colors.red.shade700;
}
return Colors.red; return Colors.red;
} }
} }
Color getColorTexto() { Color getColorTexto(Brightness brillo) {
if(this.index < 1 || this == EstadoPista.INCORRECTO){ if(index < 1 || this == EstadoPista.incorrecto){
return Colors.white;
}
if(brillo == Brightness.dark && this == EstadoPista.correcto){
return Colors.white; return Colors.white;
} }
return Colors.black; return Colors.black;
...@@ -182,11 +202,11 @@ enum EstadoPista { ...@@ -182,11 +202,11 @@ enum EstadoPista {
String getMensaje(){ String getMensaje(){
switch(this){ switch(this){
case BLOQUEADO: case bloqueado:
return "PISTA BLOQUEADA"; return "PISTA BLOQUEADA";
case DISPONIBLE: case disponible:
return "PULSA PARA DESBLOQUEAR"; return "PULSA PARA DESBLOQUEAR";
case CONFIRMACION: case confirmacion:
return "¿Seguro? Pulsa de nuevo para confirmar"; return "¿Seguro? Pulsa de nuevo para confirmar";
default: default:
return ""; return "";
...@@ -194,6 +214,6 @@ enum EstadoPista { ...@@ -194,6 +214,6 @@ enum EstadoPista {
} }
bool desbloqueada(){ bool desbloqueada(){
return this.index >= EstadoPista.DESBLOQUEADO.index; return index >= EstadoPista.desbloqueado.index;
} }
} }
export 'pantalla_juego.dart'; export 'pantalla_juego.dart';
\ No newline at end of file export 'pantalla_records.dart';
\ No newline at end of file
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:peponator/paginas/paginas.dart';
import 'package:peponator/paginas/pantalla_juego.dart'; import 'package:peponator/paginas/pantalla_juego.dart';
class PeponatorApp extends StatelessWidget { class PeponatorApp extends StatelessWidget {
...@@ -10,11 +11,13 @@ class PeponatorApp extends StatelessWidget { ...@@ -10,11 +11,13 @@ class PeponatorApp extends StatelessWidget {
return MaterialApp( return MaterialApp(
theme: ThemeData( theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.cyan) colorScheme: ColorScheme.fromSeed(seedColor: Colors.cyan),
brightness: Brightness.light,
useMaterial3: true
), ),
darkTheme: ThemeData.dark(), darkTheme: ThemeData.dark(),
themeMode: ThemeMode.system, themeMode: ThemeMode.system,
home: PantallaJuego(fromHome: true,), home: PantallaRecords()
); );
} }
} }
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class PantallaPausa extends StatelessWidget { class PantallaPausa extends StatelessWidget {
final Orientation orientacion;
final bool manoDerecha;
late final Alignment alignment;
const PantallaPausa({Key? key}): super(key: key); PantallaPausa({Key? key, required this.orientacion, required this.manoDerecha}): super(key: key) {
if(orientacion == Orientation.portrait){
alignment = Alignment.center;
}
else if(manoDerecha){
alignment = Alignment.centerLeft;
}
else {
alignment = Alignment.centerRight;
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SimpleDialog( return SimpleDialog(
alignment: alignment,
title: Center(child: Text( title: Center(child: Text(
'Pausa', 'Pausa',
style: Theme.of(context).textTheme.headlineLarge, style: (orientacion == Orientation.portrait)?
Theme.of(context).textTheme.headlineLarge :
Theme.of(context).textTheme.headlineSmall,
)), )),
children: OpcionPausa.values.map((element) { children: OpcionPausa.values.map((element) {
return SimpleDialogOption( return SimpleDialogOption(
...@@ -19,19 +35,22 @@ class PantallaPausa extends StatelessWidget { ...@@ -19,19 +35,22 @@ class PantallaPausa extends StatelessWidget {
}, },
style: TextButton.styleFrom( style: TextButton.styleFrom(
side: BorderSide( side: BorderSide(
color: Colors.black26, color: (Theme.of(context).brightness == Brightness.light)?
Colors.black26 :
Colors.grey,
width: 3.0 width: 3.0
) )
), ),
icon: Icon( icon: Icon(
element.icon, element.icon,
color: element.color ?? Theme.of(context).colorScheme.primary, color: element.getColor(Theme.of(context).brightness) ?? Theme.of(context).colorScheme.primary,
size: 32.0 size: 32.0
), ),
label: Text( label: Text(
element.text, element.text,
style: Theme.of(context).textTheme.titleLarge?.copyWith( style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: element.color ?? Theme.of(context).colorScheme.primary fontWeight: (Theme.of(context).brightness == Brightness.light)? null : FontWeight.bold,
color: element.getColor(Theme.of(context).brightness) ?? Theme.of(context).colorScheme.primary
), ),
), ),
), ),
...@@ -42,15 +61,31 @@ class PantallaPausa extends StatelessWidget { ...@@ -42,15 +61,31 @@ class PantallaPausa extends StatelessWidget {
} }
enum OpcionPausa { enum OpcionPausa {
REANUDAR(Icons.play_arrow_outlined, "Reanudar", Color.fromARGB(255, 0, 125, 0)), reanudar(Icons.play_arrow_outlined, "Reanudar"),
CAMBIO_MANO(Icons.front_hand_outlined, "Cambiar de mano"), cambioMano(Icons.front_hand_outlined, "Cambiar de mano"),
NUEVA_PARTIDA(Icons.refresh, "Nueva partida"), nuevaPartida(Icons.refresh, "Nueva partida"),
CAMBIAR_DIFICULTAD(Icons.settings_outlined, "Cambiar dificultad"), cambiarDificultad(Icons.settings_outlined, "Cambiar dificultad"),
SALIR(Icons.logout, "Terminar partida", Color.fromARGB(255, 213, 0, 0)); salir(Icons.logout, "Terminar partida");
final IconData icon; final IconData icon;
final String text; final String text;
final Color? color;
const OpcionPausa(this.icon, this.text, [this.color]); const OpcionPausa(this.icon, this.text);
Color? getColor(Brightness brillo) {
switch(this){
case reanudar:
if(brillo == Brightness.dark){
return Colors.green;
}
return Color.fromARGB(255, 0, 125, 0);
case salir:
if(brillo == Brightness.dark){
return Colors.red;
}
return Color.fromARGB(255, 213, 0, 0);
default:
return null;
}
}
} }
\ No newline at end of file
...@@ -33,7 +33,10 @@ class PeponatorMensaje extends StatelessWidget { ...@@ -33,7 +33,10 @@ class PeponatorMensaje extends StatelessWidget {
alignment: Alignment.center, alignment: Alignment.center,
transform: Matrix4.rotationY(pi), transform: Matrix4.rotationY(pi),
child: CustomPaint( child: CustomPaint(
painter: _Triangle(Colors.grey.shade300), painter: _Triangle(
(Theme.of(context).brightness == Brightness.light)?
Colors.grey.shade300 : Colors.grey.shade800
),
), ),
), ),
Flexible( Flexible(
...@@ -41,7 +44,8 @@ class PeponatorMensaje extends StatelessWidget { ...@@ -41,7 +44,8 @@ class PeponatorMensaje extends StatelessWidget {
child: Container( child: Container(
padding: EdgeInsets.all(14), padding: EdgeInsets.all(14),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.grey.shade300, color: (Theme.of(context).brightness == Brightness.light)?
Colors.grey.shade300 : Colors.grey.shade800,
borderRadius: BorderRadius.only( borderRadius: BorderRadius.only(
topRight: Radius.circular(18), topRight: Radius.circular(18),
bottomLeft: Radius.circular(18), bottomLeft: Radius.circular(18),
...@@ -50,7 +54,12 @@ class PeponatorMensaje extends StatelessWidget { ...@@ -50,7 +54,12 @@ class PeponatorMensaje extends StatelessWidget {
), ),
child: Text( child: Text(
message, message,
style: TextStyle(color: Colors.black, fontFamily: 'Monstserrat', fontSize: 14), style: TextStyle(
color: (Theme.of(context).brightness == Brightness.light)?
Colors.black : Colors.white,
fontFamily: 'Monstserrat',
fontSize: 14
),
), ),
), ),
), ),
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:peponator/modelo/modelo.dart';
class PistaWidget extends StatelessWidget { class PistaWidget extends StatelessWidget {
final String titulo; final String titulo;
final String mensaje; final String mensaje;
final Color fondo; final EstadoPista estado;
final Color texto;
final VoidCallback? onPressed; final VoidCallback? onPressed;
PistaWidget({Key? key, required this.titulo, required this.mensaje, required this.fondo, required this.texto, this.onPressed}): const PistaWidget({Key? key, required this.titulo, required this.mensaje, required this.estado, this.onPressed}):
super(key: key); super(key: key);
@override @override
...@@ -27,12 +27,12 @@ class PistaWidget extends StatelessWidget { ...@@ -27,12 +27,12 @@ class PistaWidget extends StatelessWidget {
child: TextButton( child: TextButton(
onPressed: onPressed, onPressed: onPressed,
style: TextButton.styleFrom( style: TextButton.styleFrom(
backgroundColor: fondo, backgroundColor: estado.getColorFondo(Theme.of(context).brightness),
), ),
child: Text( child: Text(
mensaje, mensaje,
style: Theme.of(context).textTheme.titleMedium?.copyWith( style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: texto color: estado.getColorTexto(Theme.of(context).brightness)
), ),
), ),
), ),
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'dart:math';
class TuMensaje extends StatelessWidget { class TuMensaje extends StatelessWidget {
final String message; final String message;
...@@ -12,30 +11,30 @@ class TuMensaje extends StatelessWidget { ...@@ -12,30 +11,30 @@ class TuMensaje extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final messageTextGroup = Flexible( final messageTextGroup = Flexible(
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Flexible( Flexible(
child: Container( child: Container(
padding: EdgeInsets.all(14), padding: EdgeInsets.all(14),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.blueAccent.shade400, color: Colors.blueAccent.shade400,
borderRadius: BorderRadius.only( borderRadius: BorderRadius.only(
topLeft: Radius.circular(18), topLeft: Radius.circular(18),
bottomLeft: Radius.circular(18), bottomLeft: Radius.circular(18),
bottomRight: Radius.circular(18), bottomRight: Radius.circular(18),
),
),
child: Text(
message,
style: TextStyle(color: Colors.white, fontFamily: 'Monstserrat', fontSize: 18),
), ),
), ),
child: Text(
message,
style: TextStyle(color: Colors.white, fontFamily: 'Monstserrat', fontSize: 18),
),
), ),
CustomPaint(painter: _Triangle(Colors.blueAccent.shade400)), ),
], CustomPaint(painter: _Triangle(Colors.blueAccent.shade400)),
)); ],
));
return Padding( return Padding(
padding: EdgeInsets.only(right: 18.0, left: 50, top: 5, bottom: 5), padding: EdgeInsets.only(right: 18.0, left: 50, top: 5, bottom: 5),
......
export 'tu_mensaje.dart'; export 'tu_mensaje.dart';
export 'peponator_mensaje.dart'; export 'peponator_mensaje.dart';
export 'pista_widget.dart'; export 'pista_widget.dart';
export 'teclado_numerico.dart'; export 'teclado_numerico.dart';
\ No newline at end of file export 'pantalla_pausa.dart';
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment