Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Fardale
Prog2
Commits
f615b56a
Commit
f615b56a
authored
Mar 05, 2015
by
Fardale
Browse files
nettoyage et correction de code
début d'implémentation du dévoilement au clique
parent
98f6d9c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
boum.scala
View file @
f615b56a
...
...
@@ -31,7 +31,7 @@ class Demineur {
private
var
champ
=
ofDim
[
Int
](
tailleX
,
tailleY
)
// Matrice des boutons associés aux cases (il me semble plus pertinent de l'inclure dans le jeu).
private
var
boutons
=
ofDim
[
MonBouton
](
tailleX
,
tailleY
)
var
boutons
=
ofDim
[
MonBouton
](
tailleX
,
tailleY
)
// Réinitialise les paramètres ci-dessus en cas de changement de difficulté.
def
reparametrage
(
x
:
Int
,
y
:
Int
,
n
:
Int
)
=
{
...
...
@@ -49,6 +49,9 @@ class Demineur {
// Pour récupérer la matrice de boutons.
def
getBoutons
=
boutons
// Réactive la variable de premier coup
def
resetPremierCoup
=
premierCoup
=
true
// (Re)crée un champ de boutons sans toucher aux valeurs
def
creation_boutons
=
{
...
...
@@ -149,7 +152,7 @@ class Demineur {
}
// Propagation du dévoilement des cases vides
def
propage
(
c
:
Int
,
x
:
Int
,
y
:
Int
){
private
def
propage
(
c
:
Int
,
x
:
Int
,
y
:
Int
){
if
(
c
==
0
||
premierCoup
){
if
(
premierCoup
){
premierCoup
=
false
}
...
...
@@ -180,6 +183,35 @@ class Demineur {
}
}
}
def
devoile
(
x
:
Int
,
y
:
Int
)
=
{
var
perdu
=
false
if
(
x
>
0
)
{
if
(
boutons
(
x
-
1
)(
y
).
enabled
){
perdu
=
perdu
||
clique_action
(
x
-
1
,
y
)}
if
(
y
>
0
){
if
(
boutons
(
x
-
1
)(
y
-
1
).
enabled
){
perdu
=
perdu
||
clique_action
(
x
-
1
,
y
-
1
)}
}
if
(
y
<
tailleY
-
1
){
if
(
boutons
(
x
-
1
)(
y
+
1
).
enabled
){
perdu
=
perdu
||
clique_action
(
x
-
1
,
y
+
1
)}
}
}
if
(
x
<
tailleX
-
1
)
{
if
(
boutons
(
x
+
1
)(
y
).
enabled
){
perdu
=
perdu
||
clique_action
(
x
+
1
,
y
)}
if
(
y
>
0
){
if
(
boutons
(
x
+
1
)(
y
-
1
).
enabled
){
perdu
=
perdu
||
clique_action
(
x
+
1
,
y
-
1
)}
}
if
(
y
<
tailleY
-
1
){
if
(
boutons
(
x
+
1
)(
y
+
1
).
enabled
){
perdu
=
perdu
||
clique_action
(
x
+
1
,
y
+
1
)}
}
}
if
(
y
>
0
){
if
(
boutons
(
x
)(
y
-
1
).
enabled
){
perdu
=
perdu
||
clique_action
(
x
,
y
-
1
)}
}
if
(
y
<
tailleY
-
1
){
if
(
boutons
(
x
)(
y
+
1
).
enabled
){
perdu
=
perdu
||
clique_action
(
x
,
y
+
1
)}
}
perdu
}
// Définit les conséquences d'un clic sur un bouton.
def
clique_action
(
x
:
Int
,
y
:
Int
)
:
Boolean
=
{
...
...
main.scala
View file @
f615b56a
...
...
@@ -31,9 +31,7 @@ object CercleInvocation extends SimpleSwingApplication {
private
val
but_moy
=
new
RadioButton
(
"Moyen"
)
private
val
but_dur
=
new
RadioButton
(
"Difficile"
)
private
val
but_per
=
new
RadioButton
(
"Personnalisé"
)
private
val
mutex
=
new
ButtonGroup
private
val
radios
=
List
(
but_fac
,
but_moy
,
but_dur
,
but_per
)
mutex
.
buttons
++=
radios
private
val
mutex
=
new
ButtonGroup
(
but_fac
,
but_moy
,
but_dur
,
but_per
)
mutex
.
select
(
but_fac
)
// Création d'un nouveau jeu
...
...
@@ -73,38 +71,36 @@ object CercleInvocation extends SimpleSwingApplication {
renewbts
renewtx
renewty
contents
=
new
GridPanel
(
tx
,
ty
)
{
for
(
i
<-
0
to
(
tx
-
1
))
{
for
(
j
<-
0
to
(
ty
-
1
))
{
contents
+=
bts
(
i
)(
j
)
}
}
}
contents
=
genContents
listen
}
// Activation des surveillances de boutons.
private
def
listen
=
for
(
i
<-
0
to
(
tx
-
1
))
{
for
(
j
<-
0
to
(
ty
-
1
))
{
listenTo
(
bts
(
i
)(
j
))
listenTo
(
bts
(
i
)(
j
).
mouse
.
clicks
)
}
}
}
// Redémarrage du jeu
private
def
redemarrage
=
{
jeu
.
creation_boutons
renewbts
contents
=
new
GridPanel
(
tx
,
ty
)
{
// Genesation de la grille
private
def
genContents
=
new
GridPanel
(
tx
,
ty
)
{
for
(
i
<-
0
to
(
tx
-
1
))
{
for
(
j
<-
0
to
(
ty
-
1
))
{
contents
+=
bts
(
i
)(
j
)
}
}
}
for
(
i
<-
0
to
(
tx
-
1
))
{
for
(
j
<-
0
to
(
ty
-
1
))
{
listenTo
(
bts
(
i
)(
j
))
listenTo
(
bts
(
i
)(
j
).
mouse
.
clicks
)
}
}
// Redémarrage du jeu
private
def
redemarrage
=
{
jeu
.
creation_boutons
jeu
.
resetPremierCoup
renewbts
contents
=
genContents
listen
}
// Génération à partir d'une graine aléatoire
...
...
@@ -148,19 +144,8 @@ object CercleInvocation extends SimpleSwingApplication {
renewbts
renewtx
renewty
contents
=
new
GridPanel
(
tx
,
ty
)
{
for
(
i
<-
0
to
(
tx
-
1
))
{
for
(
j
<-
0
to
(
ty
-
1
))
{
contents
+=
bts
(
i
)(
j
)
}
}
}
for
(
i
<-
0
to
(
tx
-
1
))
{
for
(
j
<-
0
to
(
ty
-
1
))
{
listenTo
(
bts
(
i
)(
j
))
listenTo
(
bts
(
i
)(
j
).
mouse
.
clicks
)
}
}
contents
=
genContents
listen
case
None
=>
}
}
...
...
@@ -184,7 +169,7 @@ object CercleInvocation extends SimpleSwingApplication {
genere_a_parametre
})
contents
+=
new
Menu
(
"Difficulté"
)
{
contents
++=
radio
s
contents
++=
mutex
.
button
s
}
contents
+=
new
MenuItem
(
Action
(
"Sortir"
){
sys
.
exit
(
0
)
...
...
@@ -195,21 +180,10 @@ object CercleInvocation extends SimpleSwingApplication {
//contents += new Label("Il te reste 10 mines !")
// Elements de la fenêtre.
contents
=
new
GridPanel
(
tx
,
ty
)
{
for
(
i
<-
0
to
(
tx
-
1
))
{
for
(
j
<-
0
to
(
ty
-
1
))
{
contents
+=
bts
(
i
)(
j
)
}
}
}
contents
=
genContents
// Activation des surveillances de boutons.
for
(
i
<-
0
to
(
tx
-
1
))
{
for
(
j
<-
0
to
(
ty
-
1
))
{
listenTo
(
bts
(
i
)(
j
))
listenTo
(
bts
(
i
)(
j
).
mouse
.
clicks
)
}
}
listen
// Réaction aux évènements.
reactions
+=
{
...
...
@@ -232,6 +206,13 @@ object CercleInvocation extends SimpleSwingApplication {
new_game
}
}
// if (e.peer.getButton() == java.awt.event.MouseEvent.BUTTON1){
// if (jeu.devoile(e.peer.getComponent.getY/50, e.peer.getComponent.getX/50)) {
// Dialog.showMessage(contents.head, "Désolé, vous avez perdu !", "Boum !!!",
// Dialog.Message.Info, new ImageIcon(getClass.getResource("case_mine.png")))
// redemarrage
// }
// }
}
}
...
...
Write
Preview
Supports
Markdown
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