class Stone

Attributes

checked[RW]
followCursor[RW]
imageDown[RW]
letter[RW]
myField[RW]
posX[RW]
posY[RW]
score[RW]
static[RW]

Public Class Methods

new(pos_x,pos_y, img, stn, scr, ltr, gme, imgDown) click to toggle source
# File lib/stone.rb, line 4
def initialize (pos_x,pos_y, img, stn, scr, ltr, gme, imgDown)
  #stone position
  @posX = pos_x
  @posY = pos_y
  @image = img #stone image
  @score = scr #stone score
  @letter = ltr #letter
  @actualImage = img #actual image to show
  @game = gme #gosu game window
  @imageDown = imgDown #hover image
  @buttonWidth = @image.width.to_f #stone image width
  @buttonHeight = @image.height.to_f #stone image height
  @static = false #can stone be moved
  @followCursor = false #is stone attached to cursor
  @myField = nil #fild stone is on
  @checked = false #is stone properly connected to starting field/stone
end

Public Instance Methods

clicked() click to toggle source
# File lib/stone.rb, line 48
def clicked #evaluate click
  isOver = isHovering
  if @followCursor #&& isOver #if is attached to cursor then detach it and try to place it on board
    @followCursor = false
    @game.board.placeStone(self)
    return
  elsif !(@followCursor) && !(@static) && isOver #if is not static and not following and cursor is over it, then attach it to cursor and detach it from field
    @followCursor = true
    @game.board.markAvailableFields
    if @myField != nil
      @myField.stone = nil
      @myField = nil
    end
    true
  end
end
draw() click to toggle source
# File lib/stone.rb, line 22
def draw #draw stone
  @actualImage.draw(@posX, @posY, 2)
end
isHovering() click to toggle source
# File lib/stone.rb, line 26
def isHovering #is cursor hovering over this stone
  x = @game.mouse_x
  y = @game.mouse_y
  if x >= @posX && x <= (@posX + @buttonWidth) && y >= @posY && y <= @posY + @buttonHeight
    true
  else
    false
  end
end
update() click to toggle source
# File lib/stone.rb, line 36
def update
  if @followCursor #if is attached to cursor, then set it's possition to it
    @posX = @game.mouse_x
    @posY = @game.mouse_y
  end
  if isHovering #set image based on if is cursor hovering over it
    @actualImage = @imageDown
  else
    @actualImage = @image
  end
end