class Scrabble_laubedan
Attributes
board[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/scrabble_laubedan.rb, line 7 def initialize super 975, 900, false #window size @path = File.expand_path(File.dirname(__FILE__)) @path = @path.to_s self.caption = "Scrabble" #window label @background_image = Gosu::Image.new(@path+"/media/boardNew.png", :tileable => true) #background image (board) @cursor = Gosu::Image.new(self, @path+"/media/cursor.png", false) #cursor initButtons @gameEnded = false #is game still going on end
Public Instance Methods
draw()
click to toggle source
# File lib/scrabble_laubedan.rb, line 102 def draw #call draw on board and active buttons and other visible elements @cursor.draw(self.mouse_x, self.mouse_y, 10, 0.1, 0.1) @background_image.draw(0,0,0, (self.width/@background_image.width.to_f), (self.height/@background_image.height.to_f) ) if @board != nil && !@gameEnded @board.draw end @activeButtons.each do |i| i.draw end if @gameEnded == true @gameOver.draw("#{@gameOverText}", self.width/2.0 - (@board.player1.score == @board.player2.score ? 75 : 350) , self.height/2.0-50, 3, 1.0, 1.0, Gosu::Color::YELLOW) end end
exitGame()
click to toggle source
# File lib/scrabble_laubedan.rb, line 29 def exitGame self.close #close gosu window end
gameFinished()
click to toggle source
# File lib/scrabble_laubedan.rb, line 86 def gameFinished #end game and show which player won or if it was tie @gameOver = Gosu::Font.new(150) @activeButtons.delete(@nextTurnButton) @gameOverText = @board.player1.score == @board.player2.score ? "Tie!" : @board.player1.score > @board.player2.score ? "Player1 win!" : "Player2 wins!" @gameEnded = true end
initButtons()
click to toggle source
# File lib/scrabble_laubedan.rb, line 39 def initButtons #initialization of menu buttons @checkSpelling = false @activeButtons = Array.new #array containing active buttons to be drawn, updated, clicked @startButton = Button.new(self.width/2.0 - 75, self.height/2.0 - 100 , Gosu::Image.new(@path+"/media/startButton.png", :tileable => true), Gosu::Image.new(@path+"/media/startButtonPressed.png", :tileable => true), lambda { startGame }, self) @quitButton = Button.new(self.width/2.0 - 75, self.height/2.0 , Gosu::Image.new(@path+"/media/quitButton.png", :tileable => true), Gosu::Image.new(@path+"/media/quitButtonPressed.png", :tileable => true) , lambda{ exitGame }, self) @nextTurnButton = Button.new(@quitButton.buttonWidth+20, self.height-10-@quitButton.buttonHeight , Gosu::Image.new(@path+"/media/nextTurnButton.png", :tileable => true), Gosu::Image.new(@path+"/media/nextTurnButtonPressed.png", :tileable => true) , lambda{ @board.nextTurn }, self) @checkSpellingButtonOnImg = Gosu::Image.new(@path+"/media/checkSpellingButtonOn.png", :tileable => true) @checkSpellingButtonOffImg = Gosu::Image.new(@path+"/media/checkSpellingButtonOff.png", :tileable => true) @checkSpellingButtonOffImgPressed = Gosu::Image.new(@path+"/media/checkSpellingButtonPressedOff.png", :tileable => true) @checkSpellingButtonOnImgPressed = Gosu::Image.new(@path+"/media/checkSpellingButtonPressedOn.png", :tileable => true) @checkSpellingButton = Button.new(self.width - 300, self.height-5-@quitButton.buttonHeight, @checkSpellingButtonOffImg, @checkSpellingButtonOffImgPressed, lambda{ setSpellingButtonImage }, self) @activeButtons << @startButton @activeButtons << @quitButton @activeButtons << @checkSpellingButton end
setSpellingButtonImage()
click to toggle source
# File lib/scrabble_laubedan.rb, line 33 def setSpellingButtonImage #spelling button controler, setting @checkSpelling and button images @checkSpelling = !@checkSpelling @checkSpellingButton.image = @checkSpelling ? @checkSpellingButtonOnImg : @checkSpellingButtonOffImg @checkSpellingButton.imageOver = @checkSpelling ? @checkSpellingButtonOnImgPressed : @checkSpellingButtonOffImgPressed end
startGame()
click to toggle source
# File lib/scrabble_laubedan.rb, line 19 def startGame @board = Board.new(self,Gosu::Image.new(@path+"/media/dot.png", :tileable => true), @checkSpelling, @path) @activeButtons.delete(@startButton) #remove start button @activeButtons.delete(@checkSpellingButton) #remove check spelling button @quitButton.posY = self.height-10-@quitButton.buttonHeight #reposition quit button @quitButton.posX = 10 @activeButtons << @nextTurnButton #allow next turn button end
update()
click to toggle source
# File lib/scrabble_laubedan.rb, line 93 def update #call update on board and active buttons if @board != nil @board.update end @activeButtons.each do |i| i.update end end