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
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