Class: FenetreJeuUI

Inherits:
Object
  • Object
show all
Defined in:
lib/Hashiparmentier/UI/FenetreJeuUI.rb

Instance Method Summary collapse

Constructor Details

#initialize(mode, grille, pseudo, window, window1) ⇒ FenetreJeuUI

Returns a new instance of FenetreJeuUI.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/Hashiparmentier/UI/FenetreJeuUI.rb', line 28

def initialize(mode, grille ,pseudo,window,window1)
    @grille=grille
    @mode = mode
    @pseudo = pseudo
    @scoreCourant = 500 * @grille.tailleX
    #puts "Pseudo : #{@pseudo}";
    @compte = Compte.recuperer(@pseudo)

    # puts "Mode : #{@mode}";
    # puts "Taille : #{@taille}";
    # puts "Difficulté : #{@difficulte}";

    window.destroy()
    window1.destroy()
    # CREATION FENETRE
    @builderJeu = Gtk::Builder.new
    @builderJeu.add_from_file("lib/Hashiparmentier/glade/jeu.glade")
    @window = @builderJeu.get_object("windowJeu")
    @window.signal_connect('destroy') { |_widget| 
        @grille.sauvegarder(@compte)
        Thread.kill(@threadChrono)
        @window.destroy()
        Gtk.main_quit }

    if (@grille.tailleX == 15)
        @window.style_context.add_provider(@@CSS_BG_JEU15, Gtk::StyleProvider::PRIORITY_USER)
    else
        @window.style_context.add_provider(@@CSS_BG_JEU, Gtk::StyleProvider::PRIORITY_USER)
    end



    #autre
    @labelPseudo = @builderJeu.get_object("lbPseudo")
    @labelPseudo.set_label("Joueur : "+ @pseudo)
    @labelChrono = @builderJeu.get_object("chrono")
    @labelScore = @builderJeu.get_object("lbVarScore")
    @labelScore.set_label(@grille.score.to_s)

    #Creation de la grille
    grilleJeux = @builderJeu.get_object("grilleJeux")
    grilleJeux.pack_start(@grilleJouable = GrilleJouableUI.new(grille))
    #@jeu = Jeu.creer(@difficulte,@taille,@compte,self, @labelChrono, @labelScore)

    @checkpoints = Pile.creer()
    @verifGrille = VerifierGrille.creer(@grille)
    @donnerTech = DonnerTechnique.creer(@grille)

    #fonctions
    @clickUndo = @builderJeu.get_object("btnUndo")
    @clickUndo.signal_connect('clicked'){@grille.undo()}

    @clickRedo = @builderJeu.get_object("btnRedo")
    @clickRedo.signal_connect('clicked'){@grille.redo()}

    @btnReinit = @builderJeu.get_object("btnReinit")
    @btnReinit.signal_connect('clicked'){@grille.recommencer()}

    @btnRetour = @builderJeu.get_object("btnRetour")
    @btnRetour.signal_connect('clicked'){
        @grille.sauvegarder(@compte)
        Thread.kill(@threadChrono)
        @window.destroy()
        Gtk.main_quit
        Menu.new()
    }

    @btnValid1 = @builderJeu.get_object("btnvalid1")
    @btnValid1.signal_connect('clicked'){@grille.creerHypothese()}

    @btnSuppr1 = @builderJeu.get_object("btnsup1")
    @btnSuppr1.signal_connect('clicked'){@grille.supprimeHypothese()}

    @btnValCP = @builderJeu.get_object("btnVerifCP")
    @btnValCP.signal_connect('clicked'){@grille.valideHypothese()}

    @btnSauvegarder = @builderJeu.get_object("btnsave")
    @btnSauvegarder.signal_connect('clicked'){@grille.sauvegarder(@compte)}

    @labelIndice = @builderJeu.get_object("labelIndice")

    @btnDonnerTech = @builderJeu.get_object("btnIndice")
    @btnDonnerTech.signal_connect('clicked'){@labelIndice.set_label(@donnerTech.aider())}

    @btnVerif = @builderJeu.get_object("btnVerifGrille")
    @btnVerif.signal_connect('clicked'){@verifGrille.aider()}

    @btnValidGrille = @builderJeu.get_object("btnValidGrille")
    @btnValidGrille.signal_connect('clicked'){
        @grille.sauvegarder(@compte)
        if(@grille.fini?() == true)
            Thread.kill(@threadChrono)
            fenetre_fin = FenetreFinUI.new(@grille,@compte,@window)
            #Gtk.main_quit 
        else
            @labelIndice.set_label("Vous n'avez pas trouvé la solution ! \n Continuez ...")
        end
    }

    @chronoGrille = Chrono.new(self,  @labelChrono)
    @threadChrono = Thread.new{@chronoGrille.lancerChrono()}

    @btnAide = @builderJeu.get_object("btnAide")
    @btnRegles = @builderJeu.get_object("btnRegles")
    @btnAstuces = @builderJeu.get_object("btnAstuces")

    @grille111 = @builderJeu.get_object("grid1")
    @grille111.style_context.add_provider(@@CSS_BOX_STAT, Gtk::StyleProvider::PRIORITY_USER)



    @btnAide.style_context.add_provider(@@CSS_BTN_JEU, Gtk::StyleProvider::PRIORITY_USER)
    @btnRegles.style_context.add_provider(@@CSS_BTN_JEU, Gtk::StyleProvider::PRIORITY_USER)
    @btnAstuces.style_context.add_provider(@@CSS_BTN_JEU, Gtk::StyleProvider::PRIORITY_USER)

    @btnValid1.style_context.add_provider(@@CSS_BTN_JEU, Gtk::StyleProvider::PRIORITY_USER)
    @btnSuppr1.style_context.add_provider(@@CSS_BTN_JEU, Gtk::StyleProvider::PRIORITY_USER)
    @btnValCP.style_context.add_provider(@@CSS_BTN_JEU, Gtk::StyleProvider::PRIORITY_USER)
    @btnSauvegarder.style_context.add_provider(@@CSS_BTN_JEU, Gtk::StyleProvider::PRIORITY_USER)

    @btnRetour.style_context.add_provider(@@CSS_BTN_JEU, Gtk::StyleProvider::PRIORITY_USER)
    @btnDonnerTech.style_context.add_provider(@@CSS_BTN_JEU, Gtk::StyleProvider::PRIORITY_USER)
    @clickRedo.style_context.add_provider(@@CSS_BTN_JEU, Gtk::StyleProvider::PRIORITY_USER)
    @clickUndo.style_context.add_provider(@@CSS_BTN_JEU, Gtk::StyleProvider::PRIORITY_USER)
    @btnReinit.style_context.add_provider(@@CSS_BTN_JEU, Gtk::StyleProvider::PRIORITY_USER)
    @btnVerif.style_context.add_provider(@@CSS_BTN_JEU, Gtk::StyleProvider::PRIORITY_USER)
    @btnValidGrille.style_context.add_provider(@@CSS_BTN_JEU, Gtk::StyleProvider::PRIORITY_USER)

    @btnAide.signal_connect('clicked') { |_widget| AfficherAideJeu() }
    @btnRegles.signal_connect('clicked') { |_widget| AfficherRegles()  }
    @btnAstuces.signal_connect('clicked') { |_widget| AfficherAstuces() }

    @boxStat = @builderJeu.get_object("boxStat")
    @boxStat.style_context.add_provider(@@CSS_BOX_STAT, Gtk::StyleProvider::PRIORITY_USER)
    #@chronoGrille = Chrono.new(@jeu)
    #@threadChrono = Thread.new{@chronoGrille.lancerChrono()}
    #@threadJeu = Thread.new{@jeu.lanceToi()}
    @window.show_all()
    #Gtk.main()
end

Instance Method Details

#actualiseScoreObject



177
178
179
# File 'lib/Hashiparmentier/UI/FenetreJeuUI.rb', line 177

def actualiseScore()
    @labelScore.set_label(@grille.score.to_s)
end

#AfficherAideJeuObject



181
182
183
# File 'lib/Hashiparmentier/UI/FenetreJeuUI.rb', line 181

def AfficherAideJeu()
	@aide = AideJeuUI.new()
end

#AfficherAstucesObject



189
190
191
# File 'lib/Hashiparmentier/UI/FenetreJeuUI.rb', line 189

def AfficherAstuces()
	@astuces = AstucesUI.new()
end

#AfficherReglesObject



185
186
187
# File 'lib/Hashiparmentier/UI/FenetreJeuUI.rb', line 185

def AfficherRegles()
	@regles = ReglesUI.new()
end

#modifScore(val) ⇒ Object



169
170
171
172
173
174
175
# File 'lib/Hashiparmentier/UI/FenetreJeuUI.rb', line 169

def modifScore(val)
    @grille.score += val
    if(@grille.score<0)
        @grille.score = 0
    end
    @labelScore.set_label(@grille.score.to_s)
end