Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Rafa Castillo Passols
/
peponator
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2efccfc7
authored
May 14, 2025
by
Rafa Castillo Passols
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Ahora se guarda la dificultad en las preferencias
parent
85fe25b0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
23 deletions
lib/modelo/listaDificultad.dart
lib/paginas/pantalla_dificultad.dart
lib/paginas/pantalla_juego.dart
lib/modelo/listaDificultad.dart
View file @
2efccfc7
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:peponator/modelo/dificultad.dart'
;
import
'package:peponator/modelo/dificultad.dart'
;
import
'package:shared_preferences/shared_preferences.dart'
;
// TODO: CARGAR LAS DIFICULTADES CARGADAS EN MEMORIA
// TODO: CARGAR LAS DIFICULTADES CARGADAS EN MEMORIA
class
ListaDificultad
extends
ChangeNotifier
{
class
ListaDificultad
extends
ChangeNotifier
{
...
@@ -8,13 +9,30 @@ class ListaDificultad extends ChangeNotifier {
...
@@ -8,13 +9,30 @@ class ListaDificultad extends ChangeNotifier {
Dificultad
.
normal
,
Dificultad
.
normal
,
Dificultad
.
dificil
Dificultad
.
dificil
];
];
int
_indiceSeleccionado
=
0
;
int
_indiceSeleccionado
=
0
;
bool
_cargando
=
true
;
ListaDificultad
()
{
_getDificultadPreferencias
();
}
List
<
Dificultad
>
get
dificultades
=>
List
.
unmodifiable
(
_dificultades
);
List
<
Dificultad
>
get
dificultades
=>
List
.
unmodifiable
(
_dificultades
);
int
get
length
=>
_dificultades
.
length
;
int
get
length
=>
_dificultades
.
length
;
int
get
indiceSeleccionado
=>
_indiceSeleccionado
;
int
get
indiceSeleccionado
=>
_indiceSeleccionado
;
Dificultad
get
seleccionada
=>
_dificultades
[
_indiceSeleccionado
];
Dificultad
get
seleccionada
=>
_dificultades
[
_indiceSeleccionado
];
bool
get
cargando
=>
_cargando
;
bool
get
listo
=>
!
_cargando
;
void
_getDificultadPreferencias
()
async
{
final
prefs
=
await
SharedPreferences
.
getInstance
();
_indiceSeleccionado
=
prefs
.
getInt
(
"dificultad"
)
??
0
;
_cargando
=
false
;
notifyListeners
();
}
Dificultad
get
(
int
index
)
{
Dificultad
get
(
int
index
)
{
return
_dificultades
[
index
];
return
_dificultades
[
index
];
}
}
...
@@ -34,8 +52,11 @@ class ListaDificultad extends ChangeNotifier {
...
@@ -34,8 +52,11 @@ class ListaDificultad extends ChangeNotifier {
notifyListeners
();
notifyListeners
();
}
}
void
select
(
int
indice
)
{
void
select
(
int
indice
)
async
{
_indiceSeleccionado
=
indice
;
_indiceSeleccionado
=
indice
;
notifyListeners
();
notifyListeners
();
final
prefs
=
await
SharedPreferences
.
getInstance
();
prefs
.
setInt
(
"dificultad"
,
_indiceSeleccionado
);
}
}
}
}
\ No newline at end of file
lib/paginas/pantalla_dificultad.dart
View file @
2efccfc7
...
@@ -10,12 +10,15 @@ class PantallaDificultad extends StatelessWidget {
...
@@ -10,12 +10,15 @@ class PantallaDificultad extends StatelessWidget {
return
Consumer
<
ListaDificultad
>(
return
Consumer
<
ListaDificultad
>(
builder:
(
context
,
manager
,
child
)
{
builder:
(
context
,
manager
,
child
)
{
return
SafeArea
(
return
SafeArea
(
child:
ListView
.
separated
(
child:
manager
.
listo
?
ListView
.
separated
(
itemBuilder:
(
context
,
index
)
{
itemBuilder:
(
context
,
index
)
{
return
DificultadWidget
(
indice:
index
,);
return
DificultadWidget
(
indice:
index
,);
},
},
separatorBuilder:
(
context
,
index
)
=>
const
SizedBox
(
height:
8
),
separatorBuilder:
(
context
,
index
)
=>
const
SizedBox
(
height:
8
),
itemCount:
manager
.
length
)
itemCount:
manager
.
length
)
:
CircularProgressIndicator
()
);
);
}
}
);
);
...
...
lib/paginas/pantalla_juego.dart
View file @
2efccfc7
...
@@ -10,7 +10,6 @@ import 'package:peponator/modelo/pista.dart';
...
@@ -10,7 +10,6 @@ import 'package:peponator/modelo/pista.dart';
import
'package:peponator/paginas/paginas.dart'
;
import
'package:peponator/paginas/paginas.dart'
;
import
'package:peponator/widgets/pantalla_pausa.dart'
;
import
'package:peponator/widgets/pantalla_pausa.dart'
;
import
'package:peponator/widgets/peponator_mensaje.dart'
;
import
'package:peponator/widgets/peponator_mensaje.dart'
;
import
'dart:math'
;
import
'package:peponator/widgets/teclado_numerico.dart'
;
import
'package:peponator/widgets/teclado_numerico.dart'
;
import
'package:peponator/widgets/tu_mensaje.dart'
;
import
'package:peponator/widgets/tu_mensaje.dart'
;
...
@@ -37,6 +36,7 @@ class _PantallaJuegoState extends State<PantallaJuego>
...
@@ -37,6 +36,7 @@ class _PantallaJuegoState extends State<PantallaJuego>
double
animatedValue
=
0.0
;
double
animatedValue
=
0.0
;
bool
_updateMaximum
=
false
;
bool
_updateMaximum
=
false
;
late
Dificultad
dificultad
;
late
Dificultad
dificultad
;
late
int
limiteInferior
;
late
int
limiteInferior
;
late
int
limiteSuperior
;
late
int
limiteSuperior
;
...
@@ -50,8 +50,8 @@ class _PantallaJuegoState extends State<PantallaJuego>
...
@@ -50,8 +50,8 @@ class _PantallaJuegoState extends State<PantallaJuego>
late
bool
manoDerecha
=
true
;
late
bool
manoDerecha
=
true
;
List
<
Pista
>
pistas
=
[];
List
<
Pista
>
pistas
=
[];
late
bool
mostrarPistas
;
bool
mostrarPistas
=
false
;
late
bool
todasPistasBien
;
late
bool
todasPistasBien
;
late
bool
porDesbloquear
;
late
bool
porDesbloquear
;
late
bool
algunaDesbloqueada
;
late
bool
algunaDesbloqueada
;
...
@@ -71,9 +71,6 @@ class _PantallaJuegoState extends State<PantallaJuego>
...
@@ -71,9 +71,6 @@ class _PantallaJuegoState extends State<PantallaJuego>
super
.
initState
();
super
.
initState
();
_loadRecords
();
_loadRecords
();
ListaDificultad
dificultades
=
context
.
read
<
ListaDificultad
>();
dificultad
=
dificultades
.
seleccionada
;
recordTextController
.
addListener
(()
=>
recordTextController
.
addListener
(()
=>
setState
(()
{
setState
(()
{
jugador
=
recordTextController
.
text
;
jugador
=
recordTextController
.
text
;
...
@@ -89,12 +86,9 @@ class _PantallaJuegoState extends State<PantallaJuego>
...
@@ -89,12 +86,9 @@ class _PantallaJuegoState extends State<PantallaJuego>
animatedValue
=
_controller
.
value
;
animatedValue
=
_controller
.
value
;
});
});
});
});
_nuevaPartida
();
}
}
void
_nuevaPartida
(){
void
_nuevaPartida
(){
setState
(()
{
textController
.
clear
();
textController
.
clear
();
mensajes
.
clear
();
mensajes
.
clear
();
pistas
.
clear
();
pistas
.
clear
();
...
@@ -125,7 +119,8 @@ class _PantallaJuegoState extends State<PantallaJuego>
...
@@ -125,7 +119,8 @@ 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
;
mostrarPistas
=
false
;
todasPistasBien
=
false
;
todasPistasBien
=
false
;
...
@@ -139,7 +134,6 @@ class _PantallaJuegoState extends State<PantallaJuego>
...
@@ -139,7 +134,6 @@ class _PantallaJuegoState extends State<PantallaJuego>
puntuacion
=
0
;
puntuacion
=
0
;
posicion
=
PantallaRecords
.
maxRecords
;
posicion
=
PantallaRecords
.
maxRecords
;
jugador
=
""
;
jugador
=
""
;
});
}
}
void
_cambiarDificultadPausa
()
async
{
void
_cambiarDificultadPausa
()
async
{
...
@@ -166,13 +160,10 @@ class _PantallaJuegoState extends State<PantallaJuego>
...
@@ -166,13 +160,10 @@ class _PantallaJuegoState extends State<PantallaJuego>
super
.
dispose
();
super
.
dispose
();
}
}
@override
Widget
_buildPaginaJuego
(
BuildContext
context
,
Orientation
orientation
)
{
Widget
build
(
BuildContext
context
)
{
dificultad
=
context
.
read
<
ListaDificultad
>().
seleccionada
;
return
OrientationBuilder
(
_nuevaPartida
();
builder:
(
context
,
orientation
)
{
return
SafeArea
(
return
Scaffold
(
backgroundColor:
(
mostrarPistas
)?
Theme
.
of
(
context
).
colorScheme
.
surfaceDim
:
null
,
body:
SafeArea
(
child:
Stack
(
child:
Stack
(
children:
[
children:
[
Positioned
(
Positioned
(
...
@@ -212,7 +203,7 @@ class _PantallaJuegoState extends State<PantallaJuego>
...
@@ -212,7 +203,7 @@ class _PantallaJuegoState extends State<PantallaJuego>
});
});
break
;
break
;
case
OpcionPausa
.
nuevaPartida
:
case
OpcionPausa
.
nuevaPartida
:
_nuevaPartida
(
);
setState
(()
{
_nuevaPartida
();}
);
break
;
break
;
case
OpcionPausa
.
cambiarDificultad
:
case
OpcionPausa
.
cambiarDificultad
:
_cambiarDificultadPausa
();
_cambiarDificultadPausa
();
...
@@ -267,10 +258,21 @@ class _PantallaJuegoState extends State<PantallaJuego>
...
@@ -267,10 +258,21 @@ class _PantallaJuegoState extends State<PantallaJuego>
)
)
],
],
)
)
),
);
);
}
}
@override
Widget
build
(
BuildContext
context
)
{
return
Consumer
<
ListaDificultad
>(
builder:
(
context
,
manager
,
child
)
{
return
OrientationBuilder
(
builder:
(
context
,
orientation
)
{
return
Scaffold
(
backgroundColor:
(
mostrarPistas
)?
Theme
.
of
(
context
).
colorScheme
.
surfaceDim
:
null
,
body:
manager
.
listo
?
_buildPaginaJuego
(
context
,
orientation
)
:
CircularProgressIndicator
()
);
);
});
});
}
}
void
_scrollDown
()
{
void
_scrollDown
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment