class RpsslAi

  def initialize

  end

  def choose
    choices = ["Rock", "Paper", "Scissors", "Spock", "Lizard"]
    choices[rand(choices.length)]
  end

end

Shoes.app(:width=>450, :height=>300) do
  background beige
  stroke black

  b_w = 50
  b_h = 50
  border_w = 10
  border_h = 10
  margin_w = 125
  margin_h = 50
  corner_rad = 15

  @ai = RpsslAi.new
  @your_score = 0
  @comp_score = 0

  @selection_stack = stack do
    @your_text = para "Select one and the"
    @comp_text = para "Computer will select one."
  end

  @score_stack = stack do
    @your_score_para = para "Your Score:"
    @comp_score_para = para "Comp Score:"
  end
  @score_stack.move(margin_w+3*border_w+3*b_w, 0)

  @rock_stack = stack do
    para  "Rock"
    fill brown
    @rock = rect 0, 25 , b_w, b_h, corner_rad
  end
  @rock_stack.move(margin_w+2*border_w+b_w, margin_h+border_h)

  @paper_stack = stack do
    para  "Paper"
    fill white
    @paper = rect 0, 25 , b_w, b_h, corner_rad
  end
  @paper_stack.move(margin_w+border_w, margin_h+2*border_h+b_h)

  @scissors_stack = stack do
    para  "Scissors"
    fill gainsboro
    @scissors = rect 0, 25 , b_w, b_h, corner_rad
  end
  @scissors_stack.move(margin_w+3*border_w+2*b_w, margin_h+2*border_h+b_h)

  @spock_stack = stack do
    para  "Spock"
    fill blue
    @spock = rect 0, 25 , b_w, b_h, corner_rad
  end
  @spock_stack.move(margin_w + (b_w/2) + border_w, margin_h+4*border_h+2*b_h)

  @lizard_stack = stack do
    para  "Lizard"
    fill green
    @lizard = rect 0, 25 , b_w, b_h, corner_rad
  end
  @lizard_stack.move(margin_w+3*border_w+b_w+(b_w/2), margin_h+4*border_h+2*b_h)
  @selection = "Rock"

  def winner your_selection, comp_selection
    result = 1
    if "Rock" == your_selection then
      if ("Rock" == comp_selection) then
        result = 0
      elsif ("Paper" == comp_selection) or ("Spock" == comp_selection) then
        result = -1
      end
    elsif "Paper" == your_selection then
      if ("Paper" == comp_selection) then
        result = 0
      elsif ("Scissors" == comp_selection) or ("Lizard" == comp_selection) then
        result = -1
      end
    elsif "Scissors" == your_selection then
      if ("Scissors" == comp_selection) then
        result = 0
      elsif ("Spock" == comp_selection) or ("Rock" == comp_selection) then
        result = -1
      end
    elsif "Spock" == your_selection then
      if ("Spock" == comp_selection) then
        result = 0
      elsif ("Lizard" == comp_selection) or ("Paper" == comp_selection) then
        result = -1
      end
    elsif "Lizard" == your_selection then
      if ("Lizard" == comp_selection) then
        result = 0
      elsif ("Scissors" == comp_selection) or ("Rock" == comp_selection) then
        result = -1
      end
    end
    result
  end

  def when_clicked
    @your_text.replace "You selected: #{@selection}"
    @ai_selection = @ai.choose
    @comp_text.replace "Comp selected: #{@ai_selection}"
    if (winner @selection, @ai_selection) == 1 then
      @your_score +=1
    elsif (winner @selection, @ai_selection) == -1
      @comp_score +=1
    end
    @your_score_para.replace "Your Score: #{@your_score}"
    @comp_score_para.replace "Comp Score: #{@comp_score}"
  end

  @rock.click do
    @selection = "Rock"
    when_clicked
  end
  @paper.click do
    @selection = "Paper"
    when_clicked
  end
  @scissors.click do
    @selection = "Scissors"
    when_clicked
  end
  @spock.click do
    @selection = "Spock"
    when_clicked
  end
  @lizard.click do
    @selection = "Lizard"
    when_clicked
  end

end
