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

parent 53f5f12b
export 'pista.dart';
\ No newline at end of file
export 'pista.dart';
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{
late final int divisible;
late final String mensaje;
EstadoPista estado = EstadoPista.BLOQUEADO;
EstadoPista estado = EstadoPista.bloqueado;
Pista ({
required this.clase,
required int numero,
this.onPressed
}) {
if(clase != ClasePista.DIVISIBLE){
if(clase != ClasePista.divisible){
divisible = 0;
}
else{
......@@ -43,29 +43,29 @@ class Pista{
}
String _generaPista(int numero){
switch(this.clase){
case ClasePista.PAR_IMPAR:
switch(clase){
case ClasePista.parImpar:
if(numero%2 == 0){
return 'El número es par';
}
return 'El número es impar';
case ClasePista.DIVISIBLE:
case ClasePista.divisible:
if(divisible == 1){
return 'El número es primo inferior a 100';
}
if(divisible == -1){
return 'El número NO es divisible entre primos inferiores a 100';
}
return 'El número es divisible entre ${divisible}';
case ClasePista.SUMA_CIFRAS:
return 'El número es divisible entre $divisible';
case ClasePista.sumaCifras:
int pseudo = numero;
int suma = 0;
while(pseudo > 0){
suma += pseudo%10;
pseudo = (pseudo/10).floor();
}
return 'La suma de las cifras del número da ${suma}';
case ClasePista.NUMERO_CIFRAS:
return 'La suma de las cifras del número da $suma';
case ClasePista.numeroCifras:
int div = 10;
int num = 1;
while(numero/div > 1){
......@@ -75,15 +75,15 @@ class Pista{
if(num == 1){
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){
switch(this.clase){
case ClasePista.PAR_IMPAR:
switch(clase){
case ClasePista.parImpar:
return adivinar%2 == numero%2;
case ClasePista.DIVISIBLE:
case ClasePista.divisible:
if(divisible == 1){
return primos.contains(numero);
}
......@@ -97,7 +97,7 @@ class Pista{
return true;
}
return adivinar%divisible == numero%divisible;
case ClasePista.SUMA_CIFRAS:
case ClasePista.sumaCifras:
int a = adivinar, b = numero;
int sumaA = 0, sumaB = 0;
while(a > 0 && b > 0){
......@@ -107,7 +107,7 @@ class Pista{
b = (b/10).floor();
}
return sumaA == sumaB;
case ClasePista.NUMERO_CIFRAS:
case ClasePista.numeroCifras:
int div = 10;
while(adivinar/div > 10){
div *= 10;
......@@ -118,63 +118,83 @@ class Pista{
Widget createWidget(){
return PistaWidget(
key: Key(this.clase.name),
titulo: this.clase.getTitle(),
key: Key(clase.name),
titulo: clase.getTitle(),
mensaje: (estado.desbloqueada())? mensaje : estado.getMensaje(),
fondo: estado.getColorFondo(),
texto: estado.getColorTexto(),
onPressed: (estado == EstadoPista.DISPONIBLE || estado == EstadoPista.CONFIRMACION)? onPressed : null
estado: estado,
onPressed: (estado == EstadoPista.disponible || estado == EstadoPista.confirmacion)? onPressed : null
);
}
}
enum ClasePista {
PAR_IMPAR,
DIVISIBLE,
SUMA_CIFRAS,
NUMERO_CIFRAS;
parImpar,
divisible,
sumaCifras,
numeroCifras;
String getTitle(){
switch(this){
case PAR_IMPAR:
case parImpar:
return '¿Es par o impar?';
case DIVISIBLE:
case divisible:
return '¿Entre qué número es divisible?';
case SUMA_CIFRAS:
case sumaCifras:
return '¿Cuál es la suma de sus cifras?';
case NUMERO_CIFRAS:
case numeroCifras:
return '¿Cuántas cifras tiene?';
}
}
}
enum EstadoPista {
BLOQUEADO,
DISPONIBLE,
CONFIRMACION,
DESBLOQUEADO,
CORRECTO,
INCORRECTO;
Color getColorFondo() {
bloqueado,
disponible,
confirmacion,
desbloqueado,
correcto,
incorrecto;
Color getColorFondo(Brightness brillo) {
switch(this){
case BLOQUEADO:
case bloqueado:
if(brillo == Brightness.dark){
return Colors.grey.shade800;
}
return Colors.black87;
case DISPONIBLE:
case disponible:
if(brillo == Brightness.dark){
return Colors.orange.shade700;
}
return Colors.orange;
case CONFIRMACION:
case confirmacion:
if(brillo == Brightness.dark){
return Colors.yellow.shade700;
}
return Colors.yellow;
case DESBLOQUEADO:
case desbloqueado:
if(brillo == Brightness.dark){
return Colors.grey.shade400;
}
return Colors.white;
case CORRECTO:
case correcto:
if(brillo == Brightness.dark){
return Colors.green.shade700;
}
return Colors.green.shade400;
case INCORRECTO:
case incorrecto:
if(brillo == Brightness.dark){
return Colors.red.shade700;
}
return Colors.red;
}
}
Color getColorTexto() {
if(this.index < 1 || this == EstadoPista.INCORRECTO){
Color getColorTexto(Brightness brillo) {
if(index < 1 || this == EstadoPista.incorrecto){
return Colors.white;
}
if(brillo == Brightness.dark && this == EstadoPista.correcto){
return Colors.white;
}
return Colors.black;
......@@ -182,11 +202,11 @@ enum EstadoPista {
String getMensaje(){
switch(this){
case BLOQUEADO:
case bloqueado:
return "PISTA BLOQUEADA";
case DISPONIBLE:
case disponible:
return "PULSA PARA DESBLOQUEAR";
case CONFIRMACION:
case confirmacion:
return "¿Seguro? Pulsa de nuevo para confirmar";
default:
return "";
......@@ -194,6 +214,6 @@ enum EstadoPista {
}
bool desbloqueada(){
return this.index >= EstadoPista.DESBLOQUEADO.index;
return index >= EstadoPista.desbloqueado.index;
}
}
export 'pantalla_juego.dart';
\ No newline at end of file
export 'pantalla_juego.dart';
export 'pantalla_records.dart';
\ No newline at end of file
......@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:peponator/modelo/pista.dart';
import 'package:peponator/widgets/pantalla_pausa.dart';
import 'package:peponator/widgets/peponator_mensaje.dart';
import 'package:peponator/widgets/pista_widget.dart';
import 'dart:math';
import 'package:peponator/widgets/teclado_numerico.dart';
......@@ -19,10 +18,15 @@ class PantallaJuego extends StatefulWidget {
State<PantallaJuego> createState() => _PantallaJuegoState();
}
class _PantallaJuegoState extends State<PantallaJuego> {
class _PantallaJuegoState extends State<PantallaJuego>
with SingleTickerProviderStateMixin {
late final TextEditingController textController = TextEditingController();
late final ScrollController scrollController = ScrollController();
late final AnimationController _controller;
double animatedValue = 0.0;
bool _updateMaximum = false;
late int numeroAdivinar;
late final int maxIntentos;
......@@ -52,11 +56,21 @@ class _PantallaJuegoState extends State<PantallaJuego> {
// TODO: Cargar el máximo de intentos
maxIntentos = 21;
_controller = AnimationController(
duration: Duration(milliseconds: 200),
vsync: this
);
_controller.addListener(() {
setState(() {
animatedValue = _controller.value;
});
});
_nuevaPartida();
}
void _nuevaPartida(){
Random random = new Random();
Random random = Random();
setState(() {
textController.clear();
......@@ -75,14 +89,14 @@ class _PantallaJuegoState extends State<PantallaJuego> {
clase: ClasePista.values[i],
numero: numeroAdivinar,
onPressed: () {
if(pistas[i].estado == EstadoPista.DISPONIBLE){
if(pistas[i].estado == EstadoPista.disponible){
setState(() {
pistas[i].estado = EstadoPista.CONFIRMACION;
pistas[i].estado = EstadoPista.confirmacion;
});
}
else if(pistas[i].estado == EstadoPista.CONFIRMACION) {
else if(pistas[i].estado == EstadoPista.confirmacion) {
setState(() {
pistas[i].estado = EstadoPista.DESBLOQUEADO;
pistas[i].estado = EstadoPista.desbloqueado;
});
_actualizarPistas();
}
......@@ -90,7 +104,7 @@ class _PantallaJuegoState extends State<PantallaJuego> {
));
}
mensajes.add(PeponatorMensaje(message: "¡Hola! Estoy pensando en un número del ${limiteInferior} al ${limiteSuperior}. ¿Te crees capaz de adivinarlo?"));
mensajes.add(PeponatorMensaje(message: "¡Hola! Estoy pensando en un número del $limiteInferior al $limiteSuperior. ¿Te crees capaz de adivinarlo?"));
mostrarPistas = false;
todasPistasBien = false;
......@@ -105,92 +119,108 @@ class _PantallaJuegoState extends State<PantallaJuego> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: (mostrarPistas)? Theme.of(context).colorScheme.surfaceDim : null,
body: SafeArea(
child: Stack(
children: [
Positioned(
top: 0,
left: 0,
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height - 420,
child: (mostrarPistas)? _buildVistaPistas() : _buildVistaMensajes()
)
),
Positioned(
top: 0,
right: 10,
child: ElevatedButton(
onPressed: () async {
switch(await showDialog<OpcionPausa>(context: context,
builder: (context) {
return PantallaPausa();
return OrientationBuilder(
builder: (context, orientation) {
return Scaffold(
backgroundColor: (mostrarPistas)? Theme.of(context).colorScheme.surfaceDim : null,
body: SafeArea(
child: Stack(
children: [
Positioned(
top: 0,
right: (orientation == Orientation.portrait || !manoDerecha)? 0 : null,
left: (orientation == Orientation.portrait || !manoDerecha)? null : 0,
child: SizedBox(
width: (orientation == Orientation.portrait)?
MediaQuery.of(context).size.width - MediaQuery.of(context).padding.horizontal :
MediaQuery.of(context).size.width - MediaQuery.of(context).padding.horizontal - 420,
height: (orientation == Orientation.portrait)?
MediaQuery.of(context).size.height - 420 :
MediaQuery.of(context).size.height - MediaQuery.of(context).padding.vertical,
child: (mostrarPistas)? _buildVistaPistas(orientation) : _buildVistaMensajes()
)
),
if(!(victoria || intentos >= maxIntentos)) Positioned(
top: 0,
right: (orientation == Orientation.portrait || !manoDerecha)? 10 : null,
left: (orientation == Orientation.portrait || !manoDerecha)? null : 10,
child: ElevatedButton(
onPressed: () async {
switch(await showDialog<OpcionPausa>(context: context,
builder: (context) {
return PantallaPausa(
orientacion: orientation,
manoDerecha: manoDerecha,
);
}
)) {
case null:
case OpcionPausa.reanudar:
break;
case OpcionPausa.cambioMano:
setState(() {
manoDerecha = !manoDerecha;
});
break;
case OpcionPausa.nuevaPartida:
_nuevaPartida();
break;
case OpcionPausa.cambiarDificultad:
// TODO: Handle this case.
break;
case OpcionPausa.salir:
// TODO: Handle this case.
break;
}
)) {
case null:
case OpcionPausa.REANUDAR:
break;
case OpcionPausa.CAMBIO_MANO:
setState(() {
manoDerecha = !manoDerecha;
});
break;
case OpcionPausa.NUEVA_PARTIDA:
_nuevaPartida();
break;
case OpcionPausa.CAMBIAR_DIFICULTAD:
// TODO: Handle this case.
break;
case OpcionPausa.SALIR:
// TODO: Handle this case.
break;
}
},
style: ButtonStyle(
elevation: WidgetStatePropertyAll<double>(5.0),
shape: WidgetStatePropertyAll<OutlinedBorder>(CircleBorder()),
padding: WidgetStatePropertyAll<EdgeInsets>(
EdgeInsets.all(16.0)
),
side: WidgetStatePropertyAll<BorderSide>(
BorderSide(
width: 2.0,
color: Colors.black12
},
style: ButtonStyle(
elevation: WidgetStatePropertyAll<double>(5.0),
shape: WidgetStatePropertyAll<OutlinedBorder>(CircleBorder()),
padding: WidgetStatePropertyAll<EdgeInsets>(
EdgeInsets.all(16.0)
),
side: WidgetStatePropertyAll<BorderSide>(
BorderSide(
width: 2.0,
color: (Theme.of(context).brightness == Brightness.light)?
Colors.black12 :
Colors.grey.shade400,
)
)
),
child: Icon(
Icons.pause,
size: 28.0,
)
)
),
child: Icon(
Icons.pause,
size: 28.0,
Positioned(
bottom: 0,
left: (manoDerecha)? null : 0,
right: (manoDerecha)? 0 : null,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: <Color>[
Theme.of(context).colorScheme.surface,
Theme.of(context).colorScheme.surface.withAlpha(0)
],
stops: <double>[
(orientation == Orientation.portrait)? 0.97 : 1.0,
1.0
]
)
),
child: (victoria || intentos >= maxIntentos)? _buildPantallaFinal(orientation) :_buildTeclado(orientation)
)
)
)
),
Positioned(
bottom: 0,
left: 0,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: <Color>[
Theme.of(context).colorScheme.surface,
Theme.of(context).colorScheme.surface.withAlpha(0)
],
stops: <double>[
0.97,
1.0
]
)
),
child: (victoria || intentos >= maxIntentos)? _buildPantallaFinal() :_buildTeclado()
)
],
)
],
)
),
),
);
}
);
}
......@@ -213,21 +243,25 @@ class _PantallaJuegoState extends State<PantallaJuego> {
);
}
Widget _buildVistaPistas(){
Widget _buildVistaPistas(Orientation orientation){
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(right: 56.0),
padding: (orientation == Orientation.portrait || !manoDerecha)?
const EdgeInsets.only(right: 56.0) :
const EdgeInsets.only(left: 56.0),
child: Text(
'Pistas Especiales',
style: Theme.of(context).textTheme.headlineLarge,
),
),
Padding(
padding: const EdgeInsets.only(top: 8.0, right: 56.0),
padding: (orientation == Orientation.portrait || !manoDerecha)?
const EdgeInsets.only(top: 8.0, right: 56.0) :
const EdgeInsets.only(top: 8.0, left: 56.0),
child: Text(
'¡Atención! Usarlas quita puntos',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
......@@ -235,21 +269,28 @@ class _PantallaJuegoState extends State<PantallaJuego> {
),
),
),
ListView.builder(
itemBuilder: (context, index) {
return pistas[index].createWidget();
},
itemCount: pistas.length,
shrinkWrap: true,
SizedBox(
height: (orientation == Orientation.portrait)?
MediaQuery.of(context).size.height - MediaQuery.of(context).padding.vertical - 448.0 :
MediaQuery.of(context).size.height - MediaQuery.of(context).padding.vertical - 76.0,
child: ListView.builder(
itemBuilder: (context, index) {
return pistas[index].createWidget();
},
itemCount: pistas.length,
shrinkWrap: true,
),
),
],
),
);
}
Widget _buildTeclado() {
final fullWidth = MediaQuery.of(context).size.width;
final fullHeight = 380.0;
Widget _buildTeclado(Orientation orientation) {
final fullWidth = (orientation == Orientation.portrait)?
MediaQuery.of(context).size.width - MediaQuery.of(context).padding.horizontal : 400.0;
final fullHeight = (orientation == Orientation.portrait)?
380.0 : MediaQuery.of(context).size.height - MediaQuery.of(context).padding.vertical;
final primeraFila = <Widget>[
SizedBox(
......@@ -273,6 +314,8 @@ class _PantallaJuegoState extends State<PantallaJuego> {
onNumberPress: _onNumberPress,
onBackspacePress: _onBackspacePress,
onEnterPress: _onEnterPress,
numberBackgroundColor: (Theme.of(context).brightness == Brightness.light)?
Colors.cyan : Theme.of(context).colorScheme.inversePrimary,
invertBackspaceEnter: !manoDerecha,
disableEnter: (numeroEscogido == null || error || espera),
),
......@@ -301,14 +344,16 @@ class _PantallaJuegoState extends State<PantallaJuego> {
Widget _buildHintToggleButton(){
onPressed() {
setState(() {
mostrarPistas = !mostrarPistas;
for(Pista p in pistas){
if(p.estado == EstadoPista.CONFIRMACION){
p.estado = EstadoPista.DISPONIBLE;
if(!espera){
setState(() {
mostrarPistas = !mostrarPistas;
for(Pista p in pistas){
if(p.estado == EstadoPista.confirmacion){
p.estado = EstadoPista.disponible;
}
}
}
});
});
}
}
const icon = Icon(
......@@ -316,7 +361,7 @@ class _PantallaJuegoState extends State<PantallaJuego> {
size: 35.0,
);
const style = ButtonStyle(
final style = ButtonStyle(
shape: WidgetStatePropertyAll<OutlinedBorder>(CircleBorder()),
padding: WidgetStatePropertyAll<EdgeInsets>(
EdgeInsets.all(16.0)
......@@ -324,7 +369,9 @@ class _PantallaJuegoState extends State<PantallaJuego> {
side: WidgetStatePropertyAll<BorderSide>(
BorderSide(
width: 2.0,
color: Colors.black12
color: (Theme.of(context).brightness == Brightness.light)?
Colors.black12 :
Colors.grey.shade600,
)
)
);
......@@ -359,30 +406,34 @@ class _PantallaJuegoState extends State<PantallaJuego> {
);
}
return IconButton(
onPressed: onPressed,
style: style,
icon: (badgeIcon != null)?
Badge(
label: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Icon(
badgeIcon,
size: 24,
color: Colors.white,
return Stack(
children: [
Center(
child: IconButton(
onPressed: onPressed,
style: style,
icon: icon
),
),
if(badgeIcon != null) Positioned(
right: manoDerecha? 0 : null,
left: manoDerecha? null : 0,
top: 0,
child: IgnorePointer(
child: Badge(
label: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Icon(
badgeIcon,
size: 24,
color: Colors.white,
),
),
backgroundColor: (numeroEscogido != null && algunaDesbloqueada && todasPistasBien)? Colors.green : Colors.red,
),
backgroundColor: (numeroEscogido != null && algunaDesbloqueada && todasPistasBien)? Colors.green : Colors.red,
offset: Offset(
manoDerecha? 16.0 : -58.0,
-16.0
),
child: const Icon(
Icons.lightbulb,
size: 35.0,
),
) :
icon
),
)
],
);
}
......@@ -439,13 +490,19 @@ class _PantallaJuegoState extends State<PantallaJuego> {
padding: const EdgeInsets.only(left: 8.0, right: 8.0, top: 8.0),
child: Container(
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
side: BorderSide(
color: Theme.of(context).colorScheme.primary,
width: 3.0
),
borderRadius: BorderRadius.all(Radius.circular(16.0))
)
shape: RoundedRectangleBorder(
side: BorderSide(
color: Theme.of(context).colorScheme.primary,
width: 3.0
),
borderRadius: BorderRadius.all(Radius.circular(16.0))
),
color: Color.lerp(
Theme.of(context).colorScheme.surface,
Theme.of(context).colorScheme.primary,
-(2.5*animatedValue*animatedValue)
+ (2.5*animatedValue)
)
),
child: Text(
(maxIntentos - intentos).toString(),
......@@ -478,6 +535,12 @@ class _PantallaJuegoState extends State<PantallaJuego> {
width: 3.0
),
borderRadius: BorderRadius.all(Radius.circular(16.0))
),
color: (!_updateMaximum)? null : Color.lerp(
Theme.of(context).colorScheme.surface,
Colors.red,
-(2.5*animatedValue*animatedValue)
+ (2.5*animatedValue)
)
),
child: Text(
......@@ -525,6 +588,12 @@ class _PantallaJuegoState extends State<PantallaJuego> {
width: 3.0
),
borderRadius: BorderRadius.all(Radius.circular(16.0))
),
color: (_updateMaximum)? null : Color.lerp(
Theme.of(context).colorScheme.surface,
Colors.green,
-(2.5*animatedValue*animatedValue)
+ (2.5*animatedValue)
)
),
child: Text(
......@@ -548,7 +617,8 @@ class _PantallaJuegoState extends State<PantallaJuego> {
);
}
Widget _buildPantallaFinal(){
// TODO: Agregar una pantalla de registro de récords
Widget _buildPantallaFinal(Orientation orientation){
final fullWidth = MediaQuery.of(context).size.width;
final fullHeight = 380.0;
......@@ -581,18 +651,18 @@ class _PantallaJuegoState extends State<PantallaJuego> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: OpcionesFinPartida.values.map((element) {
final onPressed;
final VoidCallback onPressed;
switch(element){
case OpcionesFinPartida.REPETIR:
case OpcionesFinPartida.repetir:
onPressed = () {
_nuevaPartida();
};
break;
case OpcionesFinPartida.CAMBIAR_DIFICULTAD:
case OpcionesFinPartida.cambiarDificultad:
// TODO: Handle this case.
onPressed = () { };
break;
case OpcionesFinPartida.SALIR:
case OpcionesFinPartida.salir:
// TODO: Handle this case.
onPressed = () { };
break;
......@@ -603,19 +673,22 @@ class _PantallaJuegoState extends State<PantallaJuego> {
onPressed: onPressed,
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.black26,
color: (Theme.of(context).brightness == Brightness.light)?
Colors.black26 :
Colors.grey,
width: 3.0
)
),
icon: 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
),
label: Text(
element.text,
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
),
),
),
......@@ -690,29 +763,29 @@ class _PantallaJuegoState extends State<PantallaJuego> {
});
for(int i = 0; i<pistas.length && i<(intentos/5).floor(); i++){
if(pistas[i].estado == EstadoPista.BLOQUEADO){
if(pistas[i].estado == EstadoPista.bloqueado){
setState(() {
porDesbloquear = true;
pistas[i].estado = EstadoPista.DISPONIBLE;
pistas[i].estado = EstadoPista.disponible;
});
}
else if(pistas[i].estado.desbloqueada()){
if(!algunaDesbloqueada) algunaDesbloqueada = true;
if(error || numeroEscogido == null){
setState(() {
pistas[i].estado = EstadoPista.DESBLOQUEADO;
pistas[i].estado = EstadoPista.desbloqueado;
});
}
else{
if(pistas[i].validarNumero(numeroAdivinar, numeroEscogido!)){
setState(() {
pistas[i].estado = EstadoPista.CORRECTO;
pistas[i].estado = EstadoPista.correcto;
});
}
else{
setState(() {
todasPistasBien = false;
pistas[i].estado = EstadoPista.INCORRECTO;
pistas[i].estado = EstadoPista.incorrecto;
});
}
}
......@@ -729,12 +802,14 @@ class _PantallaJuegoState extends State<PantallaJuego> {
await Future.delayed(Duration(milliseconds: 600));
setState(() {
// TODO: Construir respuesta de Peponator con cierto retardo
mensajes.add(PeponatorMensaje(message: "¡Hola! Estoy pensando en un número del ${limiteInferior} al ${limiteSuperior}. ¿Te crees capaz de adivinarlo?"));
mensajes.add(PeponatorMensaje(message: "¡Hola! Estoy pensando en un número del $limiteInferior al $limiteSuperior. ¿Te crees capaz de adivinarlo?"));
if(numeroEscogido! < numeroAdivinar){
limiteInferior = numeroEscogido!;
limiteInferior = numeroEscogido! + 1;
_updateMaximum = false;
}
if(numeroEscogido! > numeroAdivinar){
limiteSuperior = numeroEscogido!;
limiteSuperior = numeroEscogido! - 1;
_updateMaximum = true;
}
if(numeroEscogido! == numeroAdivinar){
victoria = true;
......@@ -742,6 +817,9 @@ class _PantallaJuegoState extends State<PantallaJuego> {
numeroEscogido = null;
intentos++;
espera = false;
_controller.reset();
_controller.forward();
});
_actualizarPistas();
......@@ -752,13 +830,29 @@ class _PantallaJuegoState extends State<PantallaJuego> {
}
enum OpcionesFinPartida {
REPETIR(Icons.play_arrow_outlined, "Jugar otra vez", Color.fromARGB(255, 0, 125, 0)),
CAMBIAR_DIFICULTAD(Icons.settings_outlined, "Cambiar de dificultad"),
SALIR(Icons.logout, "Volver al inicio", Color.fromARGB(255, 213, 0, 0));
repetir(Icons.play_arrow_outlined, "Jugar otra vez"),
cambiarDificultad(Icons.settings_outlined, "Cambiar de dificultad"),
salir(Icons.logout, "Volver al inicio");
final IconData icon;
final String text;
final Color? color;
const OpcionesFinPartida(this.icon, this.text, [this.color]);
const OpcionesFinPartida(this.icon, this.text);
Color? getColor(Brightness brillo) {
switch(this){
case repetir:
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;
}
}
}
import 'package:flutter/material.dart';
import 'package:peponator/modelo/modelo.dart';
class PantallaRecords extends StatelessWidget {
const PantallaRecords({super.key});
@override
Widget build(BuildContext context) {
// TODO: Cargar los récords (esto se haría con un archivo de texto en la carpeta privada de la aplicación)
final records = <PeponatorRecord>[];
records.add(PeponatorRecord(
jugador: "AAA",
puntuacion: 12211350,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "BBB",
puntuacion: 25,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "CCC",
puntuacion: 13,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "DDD",
puntuacion: 7,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "EEE",
puntuacion: 6,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "FFF",
puntuacion: 5,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "GGG",
puntuacion: 4,
fecha: DateTime.now()
));
records.add(PeponatorRecord(
jugador: "HHH",
puntuacion: 3,
fecha: DateTime.now()
));
return Scaffold(
body: SafeArea(
child: LayoutBuilder(
builder: (context, constraints) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
color: Theme.of(context).colorScheme.primary,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'Récords',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
color: Theme.of(context).colorScheme.onPrimary,
fontWeight: FontWeight.bold
),
),
const SizedBox(height: 8.0),
Text(
'¡Las 20 mejores puntuaciones registradas en el juego!',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: Theme.of(context).colorScheme.onPrimary,
fontStyle: FontStyle.italic
),
),
],
),
)
),
if(records.isNotEmpty) Expanded(
child: ListView.builder(
itemBuilder: (context, index){
Color c = Theme.of(context).colorScheme.inversePrimary;
Color? t = Theme.of(context).textTheme.titleLarge?.color;
if(index == 0){
if(Theme.of(context).brightness == Brightness.dark){
c = Colors.yellow.shade600;
}
else{
c = Colors.yellow;
}
t = Colors.black;
}
else if(index == 1){
c = Colors.grey.shade400;
t = Colors.black;
}
else if(index == 2){
if(Theme.of(context).brightness == Brightness.dark){
c = Color.fromARGB(255, 180, 76, 12);
}
else{
c = Colors.orange.shade800;
}
t = Colors.white;
}
DateTime fecha = records[index].fecha.toLocal();
return Padding(
padding: EdgeInsets.only(
top: 8.0,
bottom: (index >= records.length-1)? 100 : 0
),
child: Container(
color: c,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
records[index].jugador.toString(),
textAlign: TextAlign.start,
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
color: t,
fontWeight: FontWeight.bold
),
),
const SizedBox(height: 8.0),
Text(
'${fecha.day}/${fecha.month}/${fecha.year}',
textAlign: TextAlign.start,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: t,
),
),
],
)
),
Flexible(
child: Text(
records[index].puntuacion.toString(),
textAlign: TextAlign.end,
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
color: t,
),
)
)
],
),
),
),
);
},
shrinkWrap: true,
itemCount: records.length,
)
)
else Expanded(
child: Center(
child: Text(
'No hay ningún récord registrado de momento.\n\n¡Juega y registra el primero!',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge,
)
),
)
],
);
}
)
),
floatingActionButton: Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.only(left: 32.0),
child: FloatingActionButton.extended(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Center(child: Text(
'Borrar récords',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge,
)),
content: Text(
'Esta acción no se puede deshacer. ¿Seguro que quieres borrar todos los récords?',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleMedium,
),
actionsAlignment: MainAxisAlignment.spaceAround,
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.grey,
width: 2.0
)
),
child: Text(
'Sí',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.primary
),
)
),
TextButton(
onPressed: () {
Navigator.pop(context);
},
style: TextButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary
),
child: Text(
'No',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onPrimary
),
)
)
],
);
}
);
},
backgroundColor: Colors.red,
label: Text(
'Borrar récords',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: Colors.white
),
),
),
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:peponator/paginas/paginas.dart';
import 'package:peponator/paginas/pantalla_juego.dart';
class PeponatorApp extends StatelessWidget {
......@@ -10,11 +11,13 @@ class PeponatorApp extends StatelessWidget {
return MaterialApp(
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.cyan)
colorScheme: ColorScheme.fromSeed(seedColor: Colors.cyan),
brightness: Brightness.light,
useMaterial3: true
),
darkTheme: ThemeData.dark(),
themeMode: ThemeMode.system,
home: PantallaJuego(fromHome: true,),
home: PantallaRecords()
);
}
}
import 'package:flutter/material.dart';
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
Widget build(BuildContext context) {
return SimpleDialog(
alignment: alignment,
title: Center(child: Text(
'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) {
return SimpleDialogOption(
......@@ -19,19 +35,22 @@ class PantallaPausa extends StatelessWidget {
},
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.black26,
color: (Theme.of(context).brightness == Brightness.light)?
Colors.black26 :
Colors.grey,
width: 3.0
)
),
icon: 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
),
label: Text(
element.text,
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 {
}
enum OpcionPausa {
REANUDAR(Icons.play_arrow_outlined, "Reanudar", Color.fromARGB(255, 0, 125, 0)),
CAMBIO_MANO(Icons.front_hand_outlined, "Cambiar de mano"),
NUEVA_PARTIDA(Icons.refresh, "Nueva partida"),
CAMBIAR_DIFICULTAD(Icons.settings_outlined, "Cambiar dificultad"),
SALIR(Icons.logout, "Terminar partida", Color.fromARGB(255, 213, 0, 0));
reanudar(Icons.play_arrow_outlined, "Reanudar"),
cambioMano(Icons.front_hand_outlined, "Cambiar de mano"),
nuevaPartida(Icons.refresh, "Nueva partida"),
cambiarDificultad(Icons.settings_outlined, "Cambiar dificultad"),
salir(Icons.logout, "Terminar partida");
final IconData icon;
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 {
alignment: Alignment.center,
transform: Matrix4.rotationY(pi),
child: CustomPaint(
painter: _Triangle(Colors.grey.shade300),
painter: _Triangle(
(Theme.of(context).brightness == Brightness.light)?
Colors.grey.shade300 : Colors.grey.shade800
),
),
),
Flexible(
......@@ -41,7 +44,8 @@ class PeponatorMensaje extends StatelessWidget {
child: Container(
padding: EdgeInsets.all(14),
decoration: BoxDecoration(
color: Colors.grey.shade300,
color: (Theme.of(context).brightness == Brightness.light)?
Colors.grey.shade300 : Colors.grey.shade800,
borderRadius: BorderRadius.only(
topRight: Radius.circular(18),
bottomLeft: Radius.circular(18),
......@@ -50,7 +54,12 @@ class PeponatorMensaje extends StatelessWidget {
),
child: Text(
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:peponator/modelo/modelo.dart';
class PistaWidget extends StatelessWidget {
final String titulo;
final String mensaje;
final Color fondo;
final Color texto;
final EstadoPista estado;
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);
@override
......@@ -27,12 +27,12 @@ class PistaWidget extends StatelessWidget {
child: TextButton(
onPressed: onPressed,
style: TextButton.styleFrom(
backgroundColor: fondo,
backgroundColor: estado.getColorFondo(Theme.of(context).brightness),
),
child: Text(
mensaje,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: texto
color: estado.getColorTexto(Theme.of(context).brightness)
),
),
),
......
import 'package:flutter/material.dart';
import 'dart:math';
class TuMensaje extends StatelessWidget {
final String message;
......@@ -12,30 +11,30 @@ class TuMensaje extends StatelessWidget {
@override
Widget build(BuildContext context) {
final messageTextGroup = Flexible(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flexible(
child: Container(
padding: EdgeInsets.all(14),
decoration: BoxDecoration(
color: Colors.blueAccent.shade400,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(18),
bottomLeft: Radius.circular(18),
bottomRight: Radius.circular(18),
),
),
child: Text(
message,
style: TextStyle(color: Colors.white, fontFamily: 'Monstserrat', fontSize: 18),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flexible(
child: Container(
padding: EdgeInsets.all(14),
decoration: BoxDecoration(
color: Colors.blueAccent.shade400,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(18),
bottomLeft: Radius.circular(18),
bottomRight: Radius.circular(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(
padding: EdgeInsets.only(right: 18.0, left: 50, top: 5, bottom: 5),
......
export 'tu_mensaje.dart';
export 'peponator_mensaje.dart';
export 'pista_widget.dart';
export 'teclado_numerico.dart';
\ No newline at end of file
export 'teclado_numerico.dart';
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