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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
180 additions
and
153 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,13 +10,16 @@ class PantallaDificultad extends StatelessWidget {
...
@@ -10,13 +10,16 @@ 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
itemBuilder:
(
context
,
index
)
{
?
ListView
.
separated
(
return
DificultadWidget
(
indice:
index
,);
itemBuilder:
(
context
,
index
)
{
},
return
DificultadWidget
(
indice:
index
,);
separatorBuilder:
(
context
,
index
)
=>
const
SizedBox
(
height:
8
),
},
itemCount:
manager
.
length
)
separatorBuilder:
(
context
,
index
)
=>
const
SizedBox
(
height:
8
),
);
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,57 +86,54 @@ class _PantallaJuegoState extends State<PantallaJuego>
...
@@ -89,57 +86,54 @@ 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
();
limiteInferior
=
1
;
limiteInferior
=
1
;
limiteSuperior
=
dificultad
.
limite
;
limiteSuperior
=
dificultad
.
limite
;
numeroAdivinar
=
dificultad
.
generarNumero
();
numeroAdivinar
=
dificultad
.
generarNumero
();
maxIntentos
=
dificultad
.
maxIntentos
;
maxIntentos
=
dificultad
.
maxIntentos
;
intentos
=
0
;
intentos
=
0
;
for
(
int
i
=
0
;
i
<
ClasePista
.
values
.
length
&&
i
<
((
maxIntentos
-
1
)/
5
).
floor
();
i
++){
for
(
int
i
=
0
;
i
<
ClasePista
.
values
.
length
&&
i
<
((
maxIntentos
-
1
)/
5
).
floor
();
i
++){
pistas
.
add
(
Pista
(
pistas
.
add
(
Pista
(
clase:
ClasePista
.
values
[
i
],
clase:
ClasePista
.
values
[
i
],
numero:
numeroAdivinar
,
numero:
numeroAdivinar
,
onPressed:
()
{
onPressed:
()
{
if
(
pistas
[
i
].
estado
==
EstadoPista
.
disponible
){
if
(
pistas
[
i
].
estado
==
EstadoPista
.
disponible
){
setState
(()
{
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
(()
{
setState
(()
{
pistas
[
i
].
estado
=
EstadoPista
.
desbloqueado
;
pistas
[
i
].
estado
=
EstadoPista
.
desbloqueado
;
});
});
_actualizarPistas
();
_actualizarPistas
();
}
}
},
},
));
));
}
}
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
;
porDesbloquear
=
false
;
porDesbloquear
=
false
;
algunaDesbloqueada
=
false
;
algunaDesbloqueada
=
false
;
error
=
false
;
error
=
false
;
espera
=
false
;
espera
=
false
;
victoria
=
false
;
victoria
=
false
;
puntuacion
=
0
;
puntuacion
=
0
;
posicion
=
PantallaRecords
.
maxRecords
;
posicion
=
PantallaRecords
.
maxRecords
;
jugador
=
""
;
jugador
=
""
;
});
}
}
void
_cambiarDificultadPausa
()
async
{
void
_cambiarDificultadPausa
()
async
{
...
@@ -166,113 +160,121 @@ class _PantallaJuegoState extends State<PantallaJuego>
...
@@ -166,113 +160,121 @@ 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
(
child:
Stack
(
backgroundColor:
(
mostrarPistas
)?
Theme
.
of
(
context
).
colorScheme
.
surfaceDim
:
null
,
children:
[
body:
SafeArea
(
Positioned
(
child:
Stack
(
top:
0
,
children:
[
right:
(
orientation
==
Orientation
.
portrait
||
!
manoDerecha
)?
0
:
null
,
Positioned
(
left:
(
orientation
==
Orientation
.
portrait
||
!
manoDerecha
)?
null
:
0
,
top:
0
,
child:
SizedBox
(
right:
(
orientation
==
Orientation
.
portrait
||
!
manoDerecha
)?
0
:
null
,
width:
(
orientation
==
Orientation
.
portrait
)?
left:
(
orientation
==
Orientation
.
portrait
||
!
manoDerecha
)?
null
:
0
,
MediaQuery
.
of
(
context
).
size
.
width
-
MediaQuery
.
of
(
context
).
padding
.
horizontal
:
child:
SizedBox
(
MediaQuery
.
of
(
context
).
size
.
width
-
MediaQuery
.
of
(
context
).
padding
.
horizontal
-
420
,
width:
(
orientation
==
Orientation
.
portrait
)?
height:
(
orientation
==
Orientation
.
portrait
)?
MediaQuery
.
of
(
context
).
size
.
width
-
MediaQuery
.
of
(
context
).
padding
.
horizontal
:
MediaQuery
.
of
(
context
).
size
.
height
-
420
:
MediaQuery
.
of
(
context
).
size
.
width
-
MediaQuery
.
of
(
context
).
padding
.
horizontal
-
420
,
MediaQuery
.
of
(
context
).
size
.
height
-
MediaQuery
.
of
(
context
).
padding
.
vertical
,
height:
(
orientation
==
Orientation
.
portrait
)?
child:
(
mostrarPistas
)?
_buildVistaPistas
(
orientation
)
:
_buildVistaMensajes
()
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
,
if
(!(
victoria
||
intentos
>=
maxIntentos
))
Positioned
(
left:
(
orientation
==
Orientation
.
portrait
||
!
manoDerecha
)?
null
:
10
,
top:
0
,
child:
ElevatedButton
(
right:
(
orientation
==
Orientation
.
portrait
||
!
manoDerecha
)?
10
:
null
,
onPressed:
()
async
{
left:
(
orientation
==
Orientation
.
portrait
||
!
manoDerecha
)?
null
:
10
,
switch
(
await
showDialog
<
OpcionPausa
>(
context:
context
,
child:
ElevatedButton
(
builder:
(
context
)
{
onPressed:
()
async
{
return
PantallaPausa
(
switch
(
await
showDialog
<
OpcionPausa
>(
context:
context
,
orientacion:
orientation
,
builder:
(
context
)
{
manoDerecha:
manoDerecha
,
return
PantallaPausa
(
);
orientacion:
orientation
,
}
manoDerecha:
manoDerecha
,
))
{
);
case
null
:
}
case
OpcionPausa
.
reanudar
:
))
{
break
;
case
null
:
case
OpcionPausa
.
cambioMano
:
case
OpcionPausa
.
reanudar
:
setState
(()
{
break
;
manoDerecha
=
!
manoDerecha
;
case
OpcionPausa
.
cambioMano
:
});
setState
(()
{
break
;
manoDerecha
=
!
manoDerecha
;
case
OpcionPausa
.
nuevaPartida
:
});
setState
(()
{
_nuevaPartida
();});
break
;
break
;
case
OpcionPausa
.
nuevaPartida
:
case
OpcionPausa
.
cambiarDificultad
:
_nuevaPartida
();
_cambiarDificultadPausa
();
break
;
break
;
case
OpcionPausa
.
cambiarDificultad
:
case
OpcionPausa
.
salir
:
_cambiarDificultadPausa
();
// TODO: Handle this case.
break
;
break
;
case
OpcionPausa
.
salir
:
}
// TODO: Handle this case.
},
break
;
style:
ButtonStyle
(
}
},
style:
ButtonStyle
(
elevation:
WidgetStatePropertyAll
<
double
>(
5.0
),
elevation:
WidgetStatePropertyAll
<
double
>(
5.0
),
shape:
WidgetStatePropertyAll
<
OutlinedBorder
>(
CircleBorder
()),
shape:
WidgetStatePropertyAll
<
OutlinedBorder
>(
CircleBorder
()),
padding:
WidgetStatePropertyAll
<
EdgeInsets
>(
padding:
WidgetStatePropertyAll
<
EdgeInsets
>(
EdgeInsets
.
all
(
16.0
)
EdgeInsets
.
all
(
16.0
)
),
),
side:
WidgetStatePropertyAll
<
BorderSide
>(
side:
WidgetStatePropertyAll
<
BorderSide
>(
BorderSide
(
BorderSide
(
width:
2.0
,
width:
2.0
,
color:
(
Theme
.
of
(
context
).
brightness
==
Brightness
.
light
)?
color:
(
Theme
.
of
(
context
).
brightness
==
Brightness
.
light
)?
Colors
.
black12
:
Colors
.
black12
:
Colors
.
grey
.
shade400
,
Colors
.
grey
.
shade400
,
)
)
)
)
),
),
child:
Icon
(
child:
Icon
(
Icons
.
pause
,
Icons
.
pause
,
size:
28.0
,
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:
(
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
)
)
)
],
)
);
);
}
}
@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
()
{
scrollController
.
animateTo
(
scrollController
.
animateTo
(
scrollController
.
position
.
maxScrollExtent
,
scrollController
.
position
.
maxScrollExtent
,
...
...
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