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
c84cb9f8
Commit
c84cb9f8
authored
Apr 04, 2015
by
Fardale
Browse files
Merge remote-tracking branch 'origin/master'
parents
7a51253a
16ad1137
Changes
7
Hide whitespace changes
Inline
Side-by-side
boum.scala
View file @
c84cb9f8
...
...
@@ -40,16 +40,22 @@ class Demineur extends Jeu[MonBouton] {
tailleY
=
y
nb_mines
=
n
c_restantes
=
tailleX
*
tailleY
-
nb_mines
// champ = ofDim[Int](tailleX, tailleY)
boutons
=
ofDim
[
MonBouton
](
tailleX
,
tailleY
)
}
// Pour récupérer les valeurs tailleX et tailleY
def
getTailleX
=
tailleX
def
getTailleY
=
tailleY
// On n'aura normalement pas à utiliser cette fonction, mais elle doit exister
def
reparametrage
(
x
:
Int
,
y
:
Int
)
=
reparametrage
(
x
,
y
,
10
)
// Pour récupérer la matrice de boutons.
def
getBoutons
(
x
:
Int
,
y
:
Int
)
=
boutons
(
x
)(
y
)
// Focntion de redémarrage
def
redemarre
()
=
{
for
(
i
<-
0
to
(
tailleX
-
1
))
{
for
(
j
<-
0
to
(
tailleY
-
1
))
{
boutons
(
i
)(
j
).
reset
boutons
(
i
)(
j
).
icon
=
scala
.
swing
.
Swing
.
EmptyIcon
boutons
(
i
)(
j
).
enabled
=
true
}
}
}
// Réactive la variable de premier coup
def
resetPremierCoup
=
premierCoup
=
true
...
...
@@ -125,7 +131,7 @@ class Demineur extends Jeu[MonBouton] {
var
voisin
=
voisinEtendu
(
x
,
y
):::(
Nil
)
for
((
vx
,
vy
)
<-
voisin
){
if
(
boutons
(
vx
)(
vy
).
estLibre
&&
!
boutons
(
vx
)(
vy
).
mines
){
clique_action
(
vx
,
vy
)}}
if
(
boutons
(
vx
)(
vy
).
estLibre
&&
!
boutons
(
vx
)(
vy
).
mines
){
clique_action
_gauche
(
vx
,
vy
)}}
}
}
...
...
@@ -134,12 +140,12 @@ class Demineur extends Jeu[MonBouton] {
var
voisin
=
voisinEtendu
(
x
,
y
):::(
Nil
)
for
((
vx
,
vy
)
<-
voisin
){
if
(
boutons
(
vx
)(
vy
).
estLibre
){
perdu
=
perdu
||
clique_action
(
vx
,
vy
)}}
if
(
boutons
(
vx
)(
vy
).
estLibre
){
perdu
=
perdu
||
clique_action
_gauche
(
vx
,
vy
)}}
perdu
}
// Définit les conséquences d'un clic sur un bouton.
def
clique_action
(
x
:
Int
,
y
:
Int
)
:
Boolean
=
{
def
clique_action
_gauche
(
x
:
Int
,
y
:
Int
)
:
Boolean
=
{
if
(
boutons
(
x
)(
y
).
estLibre
){
//Cases non dévoilée, on la dévoile
boutons
(
x
)(
y
).
getContenu
match
{
case
0
=>
boutons
(
x
)(
y
).
icon
=
new
ImageIcon
(
getClass
.
getResource
(
"case_zero.png"
))
...
...
@@ -215,7 +221,7 @@ class Demineur extends Jeu[MonBouton] {
}
// Affichage des drapeaux
def
drapeau
(
x
:
Int
,
y
:
Int
)
=
{
def
clique_action_droit
(
x
:
Int
,
y
:
Int
)
=
{
if
(
boutons
(
x
)(
y
).
enabled
==
true
)
{
boutons
(
x
)(
y
).
icon
=
new
ImageIcon
(
getClass
.
getResource
(
"case_drapeau.png"
))
boutons
(
x
)(
y
).
enabled
=
false
...
...
@@ -233,5 +239,6 @@ class Demineur extends Jeu[MonBouton] {
if
(
boutons
(
x
)(
y
).
mines
)
{
m_trouvees
-=
1
}
else
{
m_trouvees
+=
1
}
}
}
victoire
()
}
}
boutons.scala
View file @
c84cb9f8
...
...
@@ -6,13 +6,13 @@ class MonBouton(protected var x : Int, protected var y : Int) extends Button {
preferredSize
=
new
Dimension
(
50
,
50
)
borderPainted
=
true
def
getTheX
=
x
def
getTheY
=
y
// Gestion des éléments du Démineur
private
var
contenu
=
0
// 0-8 nbre mines, 9 mine
private
var
libre
=
true
//case sans rien
private
var
drapeau
=
false
def
getTheX
=
x
def
getTheY
=
y
def
estLibre
=
libre
def
chgLibre
=
libre
=
!
libre
...
...
@@ -30,21 +30,43 @@ class MonBouton(protected var x : Int, protected var y : Int) extends Button {
libre
=
true
drapeau
=
false
// Gestion des icones
def
chgIconEtEnable
(
im
:
ImageIcon
,
en
:
Boolean
)
=
{
icon
=
im
enabled
=
en
disabledIcon
=
im
}
// Gestion de la couleur du bouton
private
var
couleur
=
Color
.
white
private
var
couleur
=
Color
.
gray
private
var
colore
=
false
def
getCouleur
=
couleur
def
estColore
=
colore
def
estColore
(
c
:
Color
)
=
colore
&&
(
couleur
==
c
)
def
setColoration
(
b
:
Boolean
)
=
{
colore
=
b
}
def
setCouleur
(
c
:
Color
)
=
{
couleur
=
c
}
def
active_couleur
=
{
def
active_couleur
()
=
{
background
=
couleur
colore
=
true
}
}
def
active_couleur
(
c
:
Color
)
=
{
couleur
=
c
background
=
c
colore
=
true
}
def
desactive_couleur
()
=
{
couleur
=
Color
.
gray
background
=
couleur
colore
=
false
}
}
flip.scala
View file @
c84cb9f8
...
...
@@ -6,31 +6,28 @@ class Flip extends Jeu[MonBouton] {
// Cotés du terrain.
tailleX
=
5
tailleY
=
5
def
getTailleX
=
tailleX
def
getTailleY
=
tailleY
// Matrice des boutons.
override
protected
var
boutons
=
ofDim
[
MonBouton
](
tailleX
,
tailleY
)
def
getBoutons
(
x
:
Int
,
y
:
Int
)
=
boutons
(
x
)(
y
)
// Sauvegarde nécessaire pour le redémarrage
private
var
sauvegardeMat
=
ofDim
[
Color
](
tailleX
,
tailleY
)
// Pour reparamétrer la configuration du terrain
def
reparametrage
(
x
:
Int
,
y
:
Int
)
=
{
tailleX
=
x
tailleY
=
y
boutons
=
ofDim
[
MonBouton
](
tailleX
,
tailleY
)
sauvegardeMat
=
ofDim
[
Color
](
tailleX
,
tailleY
)
}
// Pour fixer la couleur d'un bouton.
// Le champ "libre" de MonBouton permettra de représenter la couleur :
// A true, la case est blanche ; à false elle est noire.
def
fixCouleur
(
i
:
Int
,
j
:
Int
)
=
{
if
(
boutons
(
i
)(
j
).
estLibre
)
{
boutons
(
i
)(
j
).
background
=
Color
.
white
}
else
{
boutons
(
i
)(
j
).
background
=
Color
.
black
def
reparametrage
(
x
:
Int
,
y
:
Int
,
n
:
Int
)
=
reparametrage
(
x
,
y
)
def
redemarre
()
=
{
for
(
i
<-
0
to
(
tailleX
-
1
))
{
for
(
j
<-
0
to
(
tailleY
-
1
))
{
boutons
(
i
)(
j
).
active_couleur
(
sauvegardeMat
(
i
)(
j
))
}
}
}
...
...
@@ -38,34 +35,49 @@ class Flip extends Jeu[MonBouton] {
def
initialise
()
=
{
map_init
((
i
,
j
)
=>
new
MonBouton
(
i
,
j
),
boutons
)
var
x
=
Random
.
nextBoolean
def
f
(
b
:
MonBouton
)
=
{
var
i
=
b
.
getTheX
var
j
=
b
.
getTheY
if
(
x
)
{
boutons
(
i
)(
j
).
chgLibre
}
fixCouleur
(
i
,
j
)
x
=
Random
.
nextBoolean
}
def
f
(
b
:
MonBouton
)
=
{
var
i
=
b
.
getTheX
var
j
=
b
.
getTheY
if
(
x
)
{
boutons
(
i
)(
j
).
active_couleur
(
Color
.
black
)
}
else
{
boutons
(
i
)(
j
).
active_couleur
(
Color
.
white
)
}
x
=
Random
.
nextBoolean
}
map_apply
(
f
,
boutons
)
def
init
(
b
:
MonBouton
)
=
{
var
i
=
b
.
getTheX
var
j
=
b
.
getTheY
sauvegardeMat
(
i
)(
j
)
=
boutons
(
i
)(
j
).
getCouleur
}
map_apply
(
init
,
boutons
)
}
// Génération aléatoire avec graine
def
initialise
(
n
:
Int
)
=
{
map_init
((
i
,
j
)
=>
new
MonBouton
(
i
,
j
),
boutons
)
var
ran
=
new
Random
(
n
)
var
x
=
ran
.
nextBoolean
def
f
(
b
:
MonBouton
)
=
{
var
i
=
b
.
getTheX
var
j
=
b
.
getTheY
if
(
x
)
{
boutons
(
i
)(
j
).
chgLibre
}
fixCouleur
(
i
,
j
)
x
=
Random
.
nextBoolean
}
map_apply
(
f
,
boutons
)
map_init
((
i
,
j
)
=>
new
MonBouton
(
i
,
j
),
boutons
)
var
ran
=
new
Random
(
n
)
var
x
=
ran
.
nextBoolean
def
f
(
b
:
MonBouton
)
=
{
var
i
=
b
.
getTheX
var
j
=
b
.
getTheY
if
(
x
)
{
boutons
(
i
)(
j
).
active_couleur
(
Color
.
black
)
}
else
{
boutons
(
i
)(
j
).
active_couleur
(
Color
.
white
)
}
x
=
Random
.
nextBoolean
}
map_apply
(
f
,
boutons
)
def
init
(
b
:
MonBouton
)
=
{
var
i
=
b
.
getTheX
var
j
=
b
.
getTheY
sauvegardeMat
(
i
)(
j
)
=
boutons
(
i
)(
j
).
getCouleur
}
map_apply
(
init
,
boutons
)
}
// Modification de la couleur d'un bouton.
def
chgBouton
(
i
:
Int
,
j
:
Int
)
=
{
boutons
(
i
)(
j
).
chgLibre
fixCouleur
(
i
,
j
)
if
(
boutons
(
i
)(
j
).
estColore
(
Color
.
white
))
{
boutons
(
i
)(
j
).
active_couleur
(
Color
.
black
)
}
else
{
boutons
(
i
)(
j
).
active_couleur
(
Color
.
white
)
}
}
// Renvoire true si toutes les cases du terrain sont blanches
...
...
@@ -74,18 +86,20 @@ class Flip extends Jeu[MonBouton] {
def
f
(
b
:
MonBouton
)
=
{
var
i
=
b
.
getTheX
var
j
=
b
.
getTheY
res
=
(
res
&&
boutons
(
i
)(
j
).
est
Libre
)
res
=
(
res
&&
boutons
(
i
)(
j
).
est
Colore
(
Color
.
white
)
)
}
map_apply
(
f
,
boutons
)
res
}
// Conséquence du clic d'un bouton.
def
clique_action
(
i
:
Int
,
j
:
Int
)
:
Boolean
=
{
def
clique_action
_gauche
(
i
:
Int
,
j
:
Int
)
:
Boolean
=
{
chgBouton
(
i
,
j
)
var
voisin
=
voisinDirect
(
i
,
j
)
for
((
x
,
y
)
<-
voisin
){
chgBouton
(
x
,
y
)}
false
}
def
clique_action_droit
(
i
:
Int
,
j
:
Int
)
=
false
}
jeu.scala
View file @
c84cb9f8
...
...
@@ -5,11 +5,12 @@ import javax.swing.ImageIcon
import
scala.math._
abstract
class
Jeu
[
T
<:
Button
]
{
// Variables de base
protected
var
tailleX
:
Int
=
9
protected
var
tailleY
:
Int
=
9
protected
var
boutons
:
Array
[
Array
[
T
]]
// Fonctions utilitaires
protected
def
map_init
(
f
:
(
Int
,
Int
)
=>
T
,
a
:
Array
[
Array
[
T
]])
=
{
for
(
i
<-
0
to
(
tailleX
-
1
))
for
(
j
<-
0
to
(
tailleY
-
1
))
...
...
@@ -20,9 +21,7 @@ abstract class Jeu[T<:Button] {
a
.
map
(
x
=>
x
.
map
(
f
))
}
def
victoire
()
:
Boolean
def
voisinDirect
(
x
:
Int
,
y
:
Int
)
=
{
protected
def
voisinDirect
(
x
:
Int
,
y
:
Int
)
=
{
var
voisin
=
List
[(
Int
,
Int
)]()
if
(
x
>
0
){
voisin
=
(
x
-
1
,
y
)
::
voisin
}
if
(
x
<
tailleX
-
1
){
voisin
=
(
x
+
1
,
y
)
::
voisin
}
...
...
@@ -32,7 +31,7 @@ abstract class Jeu[T<:Button] {
voisin
}
def
voisinEtendu
(
x
:
Int
,
y
:
Int
)
:
List
[(
Int
,
Int
)]
=
{
protected
def
voisinEtendu
(
x
:
Int
,
y
:
Int
)
:
List
[(
Int
,
Int
)]
=
{
var
voisin
=
List
[(
Int
,
Int
)]()
if
(
x
>
0
){
voisin
=
(
x
-
1
,
y
)
::
voisin
...
...
@@ -49,4 +48,19 @@ abstract class Jeu[T<:Button] {
voisin
}
// Transimission d'informations
def
getTailleX
=
tailleX
def
getTailleY
=
tailleY
def
getBoutons
(
x
:
Int
,
y
:
Int
)
=
boutons
(
x
)(
y
)
// Fonctions obligatoires
def
victoire
()
:
Boolean
def
initialise
()
:
Unit
def
initialise
(
n
:
Int
)
:
Unit
def
reparametrage
(
x
:
Int
,
y
:
Int
)
:
Unit
def
reparametrage
(
x
:
Int
,
y
:
Int
,
n
:
Int
)
:
Unit
def
redemarre
()
:
Unit
def
clique_action_droit
(
x
:
Int
,
y
:
Int
)
:
Boolean
def
clique_action_gauche
(
x
:
Int
,
y
:
Int
)
:
Boolean
}
main.scala
View file @
c84cb9f8
...
...
@@ -84,13 +84,7 @@ object CercleInvocation extends SimpleSwingApplication {
// Redémarrage du jeu
private
def
redemarrage
=
{
for
(
i
<-
0
to
(
jeu
.
getTailleX
-
1
))
{
for
(
j
<-
0
to
(
jeu
.
getTailleY
-
1
))
{
jeu
.
getBoutons
(
i
,
j
).
reset
jeu
.
getBoutons
(
i
,
j
).
icon
=
scala
.
swing
.
Swing
.
EmptyIcon
jeu
.
getBoutons
(
i
,
j
).
enabled
=
true
}
}
jeu
.
redemarre
jeu
.
resetPremierCoup
contents
=
genContents
listen
...
...
@@ -177,7 +171,7 @@ object CercleInvocation extends SimpleSwingApplication {
// Réaction aux évènements.
reactions
+=
{
case
ButtonClicked
(
component
:
MonBouton
)
=>
var
bo
=
jeu
.
clique_action
(
component
.
getTheX
,
component
.
getTheY
)
case
ButtonClicked
(
component
:
MonBouton
)
=>
var
bo
=
jeu
.
clique_action
_gauche
(
component
.
getTheX
,
component
.
getTheY
)
if
(
bo
)
{
Dialog
.
showMessage
(
contents
.
head
,
"Désolé, vous avez perdu !"
,
"Boum !!!"
,
Dialog
.
Message
.
Info
,
new
ImageIcon
(
getClass
.
getResource
(
"case_mine.png"
)))
...
...
@@ -189,8 +183,8 @@ object CercleInvocation extends SimpleSwingApplication {
new_game
}
}
case
(
e
:
MouseEvent
)
=>
if
(
e
.
peer
.
getButton
()
==
java
.
awt
.
event
.
MouseEvent
.
BUTTON3
)
{
jeu
.
drapeau
(
e
.
peer
.
getComponent
.
getY
/
50
,
e
.
peer
.
getComponent
.
getX
/
50
)
if
(
jeu
.
victoire
)
{
var
bo
=
jeu
.
clique_action_droit
(
e
.
peer
.
getComponent
.
getY
/
50
,
e
.
peer
.
getComponent
.
getX
/
50
)
if
(
bo
)
{
Dialog
.
showMessage
(
contents
.
head
,
"Félicitations, vous avez gagné !"
,
"Victoire !!!"
,
Dialog
.
Message
.
Info
,
new
ImageIcon
(
getClass
.
getResource
(
"case_drapeau.png"
)))
new_game
...
...
test2.scala
0 → 100644
View file @
c84cb9f8
import
swing._
import
event._
import
Array._
import
java.awt.
{
Color
,
Graphics2D
}
import
javax.swing.ImageIcon
object
CercleInvocationTropMieux
extends
SimpleSwingApplication
{
def
top
=
new
MainFrame
{
cela
=>
// Valeurs de choix de jeu :
// 1 : Démineur
// 2 : Flip
// 3 : Unruly
private
var
choix_de_jeu
=
3
private
var
jeu
:
Jeu
[
MonBouton
]
=
new
Unruly
// Convertisseur sécurisé
private
def
string_to_int
(
s
:
String
)
=
{
try
{
s
.
toInt
}
catch
{
case
e
:
Exception
=>
-
1
}
}
// Boutons pour la sélection de la difficulté
private
val
but_fac
=
new
RadioButton
(
"Facile"
)
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
(
but_fac
,
but_moy
,
but_dur
,
but_per
)
mutex
.
select
(
but_fac
)
// Boutons pour la sélection du jeu
private
val
tt_dem
=
new
RadioButton
(
"Démineur"
)
private
val
tt_fli
=
new
RadioButton
(
"Flip"
)
private
val
tt_unr
=
new
RadioButton
(
"Unruly"
)
private
val
touslesjeux
=
new
ButtonGroup
(
tt_dem
,
tt_fli
,
tt_unr
)
touslesjeux
.
select
(
tt_unr
)
// Base de crétaion de nouveau jeu
private
def
nouveau
=
{
choix_de_jeu
match
{
case
1
=>
jeu
=
new
Demineur
case
2
=>
jeu
=
new
Flip
case
3
=>
jeu
=
new
Unruly
}
mutex
.
selected
.
get
match
{
case
`but_fac`
=>
case
`but_moy`
=>
choix_de_jeu
match
{
case
1
=>
jeu
.
reparametrage
(
16
,
16
,
40
)
case
2
=>
jeu
.
reparametrage
(
7
,
7
)
case
3
=>
jeu
.
reparametrage
(
10
,
10
)
}
case
`but_dur`
=>
choix_de_jeu
match
{
case
1
=>
jeu
.
reparametrage
(
16
,
16
,
99
)
case
2
=>
jeu
.
reparametrage
(
9
,
9
)
case
3
=>
jeu
.
reparametrage
(
14
,
14
)
}
case
`but_per`
=>
choix_de_jeu
match
{
case
1
=>
jeu
.
reparametrage
(
diff_fr
.
li
,
diff_fr
.
co
,
diff_fr
.
mn
)
case
2
=>
jeu
.
reparametrage
(
diff_fr
.
li
,
diff_fr
.
co
)
case
3
=>
jeu
.
reparametrage
(
2
*(
diff_fr
.
li
/
2
),
2
*(
diff_fr
.
co
/
2
))
}
}
}
// Création d'un nouveau jeu
private
def
new_game
=
{
nouveau
jeu
.
initialise
contents
=
genContents
listen
}
// Activation des surveillances de boutons.
private
def
listen
=
for
(
i
<-
0
to
(
jeu
.
getTailleX
-
1
))
{
for
(
j
<-
0
to
(
jeu
.
getTailleY
-
1
))
{
listenTo
(
jeu
.
getBoutons
(
i
,
j
))
listenTo
(
jeu
.
getBoutons
(
i
,
j
).
mouse
.
clicks
)
}
}
// Genesation de la grille
private
def
genContents
=
new
GridPanel
(
jeu
.
getTailleX
,
jeu
.
getTailleY
)
{
for
(
i
<-
0
to
(
jeu
.
getTailleX
-
1
))
{
for
(
j
<-
0
to
(
jeu
.
getTailleY
-
1
))
{
contents
+=
jeu
.
getBoutons
(
i
,
j
)
}
}
}
// Redémarrage du jeu
private
def
redemarrage
=
{
jeu
.
redemarre
contents
=
genContents
listen
}
// Génération à partir d'une graine aléatoire
private
def
genere_a_parametre
=
{
val
r
=
Dialog
.
showInput
(
contents
.
head
,
"Entrez une graine de génération :"
,
title
=
"Génération paramétrée"
,
initial
=
"12"
,
icon
=
new
ImageIcon
(
getClass
.
getResource
(
"case_mine.png"
)))
r
match
{
case
Some
(
s
)
=>
nouveau
jeu
.
initialise
(
string_to_int
(
s
))
contents
=
genContents
listen
case
None
=>
}
}
object
plop
extends
TextField
{
columns
=
5
}
object
bing
extends
TextField
{
columns
=
5
}
object
grao
extends
TextField
{
columns
=
5
}
private
var
diff_fr
=
new
Frame
{
ceci
=>
title
=
"Difficulté personnalisée"
var
li
=
9
var
co
=
9
var
mn
=
10
def
facile
=
{
li
=
9
;
co
=
9
;
mn
=
10
}
def
moyen
=
{
li
=
16
;
co
=
16
;
mn
=
10
}
def
difficile
=
{
li
=
16
;
co
=
16
;
mn
=
99
}
contents
=
new
BoxPanel
(
Orientation
.
Vertical
)
{
contents
+=
new
GridPanel
(
3
,
2
)
{
contents
+=
new
Label
(
" Nombre de lignes : "
)
contents
+=
plop
contents
+=
new
Label
(
" Nombre de colonnes : "
)
contents
+=
bing
contents
+=
new
Label
(
" Nombre de mines : "
)
contents
+=
grao
border
=
Swing
.
EmptyBorder
(
10
,
20
,
10
,
20
)
}
contents
+=
new
FlowPanel
{
contents
+=
new
Button
(
Action
(
"Valider"
)
{
cela
.
jeu
=
new
Unruly
if
(
string_to_int
(
plop
.
text
)
>
0
)
{
li
=
string_to_int
(
plop
.
text
)
}
if
(
string_to_int
(
bing
.
text
)
>
0
)
{
co
=
string_to_int
(
bing
.
text
)
}
if
(
string_to_int
(
grao
.
text
)
>
0
)
{
mn
=
string_to_int
(
grao
.
text
)
}
cela
.
jeu
.
reparametrage
(
li
,
co
,
mn
)
cela
.
jeu
.
initialise
cela
.
contents
=
genContents
cela
.
listen
ceci
.
dispose
()
})
}
}
}
// Création d'un jeu initial.
jeu
.
initialise
// Elément de décor.
title
=
"The Great Satanist Programming Project Test"
// Barre de menu.
menuBar
=
new
MenuBar
{
contents
+=
new
Menu
(
"Jeu"
)
{
contents
+=
new
MenuItem
(
Action
(
"Nouveau jeu"
)
{
new_game
})
contents
+=
new
MenuItem
(
Action
(
"Redémarrer"
)
{
redemarrage
})
contents
+=
new
MenuItem
(
Action
(
"Génération paramétrée..."
)
{
genere_a_parametre
})
contents
+=
new
Menu
(
"Difficulté"
)
{
contents
++=
mutex
.
buttons
}
contents
+=
new
MenuItem
(
Action
(
"Sortir"
){
sys
.
exit
(
0
)
})
}
contents
+=
new
Menu
(
"Autres jeux"
)
{
contents
++=
touslesjeux
.
buttons
}
}
//contents += new Label("Il te reste 10 mines !")
// Elements de la fenêtre.
contents
=
genContents
// Activation des surveillances de boutons.
listen
listenTo
(
but_fac
)
listenTo
(
but_moy
)
listenTo
(
but_dur
)
listenTo
(
but_per
)
listenTo
(
tt_dem
)
listenTo
(
tt_fli
)
listenTo
(
tt_unr
)
// Réaction aux évènements.
reactions
+=
{
case
(
e
:
MouseEvent
)
if
(
e
.
peer
.
getButton
()
==
java
.
awt
.
event
.
MouseEvent
.
BUTTON1
)
=>
if
(
choix_de_jeu
==
1
)
{
var
bo
=
jeu
.
clique_action_gauche
(
e
.
peer
.
getComponent
.
getY
/
50
,
e
.
peer
.
getComponent
.
getX
/
50
)
if
(
bo
)
{
Dialog
.
showMessage
(
contents
.
head
,
"Désolé, vous avez perdu !"
,
"Boum !!!"
,
Dialog
.
Message
.
Info
,
new
ImageIcon
(
getClass
.
getResource
(
"case_mine.png"
)))
redemarrage
}
else
{
if
(
jeu
.
victoire
)
{
Dialog
.
showMessage
(
contents
.
head
,
"Félicitations, vous avez gagné !"
,
"Victoire !!!"
,
Dialog
.
Message
.
Info
,
new
ImageIcon
(
getClass
.
getResource
(
"case_drapeau.png"
)))
new_game
}
}
}
if
(
choix_de_jeu
==
2
)
{
var
bo
=
jeu
.
clique_action_gauche
(
e
.
peer
.
getComponent
.
getY
/
50
,
e
.
peer
.
getComponent
.
getX
/
50
)
if
(
jeu
.
victoire
)
{
Dialog
.
showMessage
(
contents
.
head
,
"Félicitations, vous avez gagné !"
,
"Victoire !!!"
,
Dialog
.
Message
.
Info
,
new
ImageIcon
(
getClass
.
getResource
(
"case_drapeau.png"
)))
new_game
}
}
if
(
choix_de_jeu
==
3
)
{
if
(
jeu
.
clique_action_gauche
(
e
.
peer
.
getComponent
.
getY
/
50
,
e
.
peer
.
getComponent
.
getX
/
50
))
{
Dialog
.
showMessage
(
contents
.
head
,
"Félicitations, vous avez gagné !"
,
"Bravo !!!"
,
Dialog
.
Message
.
Info
,
new
ImageIcon
(
getClass
.
getResource
(
"blanc_inchangeable.png"
)))
new_game
}
}
case
(
e
:
MouseEvent
)
if
(
e
.
peer
.
getButton
()
==
java
.
awt
.
event
.
MouseEvent
.
BUTTON3
)
=>
if
(
choix_de_jeu
==
1
)
{
var
bo
=
jeu
.
clique_action_droit
(
e
.
peer
.
getComponent
.
getY
/
50
,
e
.
peer
.
getComponent
.
getX
/
50
)
if
(
bo
)
{
Dialog
.
showMessage
(
contents
.
head
,
"Félicitations, vous avez gagné !"
,
"Victoire !!!"
,
Dialog
.
Message
.
Info
,
new
ImageIcon
(
getClass
.
getResource
(
"case_drapeau.png"
)))
new_game
}
}
if
(
choix_de_jeu
==
3
)
{
if
(
jeu
.
clique_action_droit
(
e
.
peer
.
getComponent
.
getY
/
50
,
e
.
peer
.
getComponent
.
getX
/
50
))
{
Dialog
.
showMessage
(
contents
.
head
,
"Félicitations, vous avez gagné !"
,
"Bravo !!!"
,
Dialog
.
Message
.
Info
,
new
ImageIcon
(
getClass
.
getResource
(
"noir_inchangeable.png"
)))
new_game
}
}
case
ButtonClicked
(
comp
)
if
(
comp
==
but_fac
)
||
(
comp
==
but_moy
)
||
(
comp
==
but_dur
)
=>
new_game
case
ButtonClicked
(
comp
)
if
comp
==
but_per
=>
diff_fr
.
open
case
ButtonClicked
(
comp
)
if
(
comp
==
tt_dem
)
=>
choix_de_jeu
=
1
;
new_game
case
ButtonClicked
(
comp
)
if
(
comp
==
tt_fli
)
=>
choix_de_jeu
=
2
;
new_game
case
ButtonClicked
(
comp
)
if
(
comp
==
tt_unr
)
=>
choix_de_jeu
=
3
;
new_game
}
}