Commit e7c7e494 by Diego Pérez Peña Committed by Tecnicos

Arreglada página de récords y agregada parcialmente la pantalla de puntuación final

parent 6c25f5e9
import 'package:flutter/material.dart';
import 'package:peponator/modelo/pista.dart';
import 'package:peponator/paginas/paginas.dart';
import 'package:peponator/widgets/pantalla_pausa.dart';
import 'package:peponator/widgets/peponator_mensaje.dart';
import 'dart:math';
......@@ -21,6 +22,7 @@ class PantallaJuego extends StatefulWidget {
class _PantallaJuegoState extends State<PantallaJuego>
with SingleTickerProviderStateMixin {
late final TextEditingController textController = TextEditingController();
late final TextEditingController recordTextController = TextEditingController();
late final ScrollController scrollController = ScrollController();
late final AnimationController _controller;
......@@ -49,6 +51,10 @@ class _PantallaJuegoState extends State<PantallaJuego>
late bool espera;
late bool victoria;
late int puntuacion;
late int posicion;
late String jugador;
@override
void initState() {
super.initState();
......@@ -56,6 +62,12 @@ class _PantallaJuegoState extends State<PantallaJuego>
// TODO: Cargar el máximo de intentos
maxIntentos = 21;
recordTextController.addListener(() =>
setState(() {
jugador = recordTextController.text;
})
);
_controller = AnimationController(
duration: Duration(milliseconds: 200),
vsync: this
......@@ -114,10 +126,21 @@ class _PantallaJuegoState extends State<PantallaJuego>
error = false;
espera = false;
victoria = false;
puntuacion = 0;
posicion = PantallaRecords.maxRecords;
jugador = "";
});
}
@override
void dispose() {
textController.dispose();
recordTextController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return OrientationBuilder(
builder: (context, orientation) {
......@@ -624,6 +647,97 @@ class _PantallaJuegoState extends State<PantallaJuego>
final fullHeight = (orientation == Orientation.portrait)?
380.0 : MediaQuery.of(context).size.height - MediaQuery.of(context).padding.vertical;
if(victoria && posicion < PantallaRecords.maxRecords){
return SizedBox(
width: fullWidth,
height: fullHeight,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Column(
children: [
Text(
'¡Nuevo récord!',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headlineMedium,
),
const SizedBox(height: 16.0),
Text(
(posicion == 0)? '¡Esta es tu mejor puntuación!' : 'Esta es tu ${posicion+1}ª mejor puntuación',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge,
),
],
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'Introduce aquí tu nombre:',
style: Theme.of(context).textTheme.bodyLarge,
),
TextField(
controller: recordTextController,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge,
maxLength: 10,
decoration: InputDecoration(
hintText: 'Tu nombre...',
border: OutlineInputBorder(),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.red,
width: 5.0
)
),
errorText: (jugador.isEmpty)? '' : null,
errorStyle: TextStyle(
fontSize: 0
)
),
)
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.green,
disabledBackgroundColor: Colors.white12,
foregroundColor: Color.fromARGB(255, 237, 237, 237)
),
onPressed: (jugador.isNotEmpty)? () {} : null,
child: Text(
'Guardar récord',
textScaler: TextScaler.linear(1.1),
)
)
),
Expanded(
child: TextButton(
onPressed: () {},
child: Text(
'Salir sin guardar',
textScaler: TextScaler.linear(1.1),
)
)
)
],
)
],
),
),
);
}
return SizedBox(
width: fullWidth,
height: fullHeight,
......@@ -815,6 +929,10 @@ class _PantallaJuegoState extends State<PantallaJuego>
}
if(numeroEscogido! == numeroAdivinar){
victoria = true;
// TODO: Calcular puntuación
puntuacion = 2000;
// TODO: Calcular posición en la tabla de récords
posicion = 0;
}
numeroEscogido = null;
intentos++;
......
......@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:peponator/modelo/modelo.dart';
class PantallaRecords extends StatelessWidget {
static const int maxRecords = 20;
const PantallaRecords({super.key});
......@@ -83,8 +84,7 @@ class PantallaRecords extends StatelessWidget {
final records = _loadMockData();
if(records.isNotEmpty) {
return Expanded(
child: ListView.builder(
final vistaRecords = ListView.builder(
shrinkWrap: true,
itemCount: records.length,
itemBuilder: (context, index){
......@@ -164,24 +164,34 @@ class PantallaRecords extends StatelessWidget {
),
);
},
)
);
if(orientation == Orientation.portrait){
return Expanded(
child: vistaRecords
);
}
else{
return vistaRecords;
}
}
else {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Center(
final message = 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,
)
),
),
],
);
if(orientation == Orientation.portrait){
return Expanded(
child: message,
);
}
else{
return message;
}
}
}
......
......@@ -17,7 +17,7 @@ class PeponatorApp extends StatelessWidget {
),
darkTheme: ThemeData.dark(),
themeMode: ThemeMode.system,
home: PantallaRecords()
home: PantallaJuego(fromHome: true)
);
}
}
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