0

我正在使用鞋子编写赛马/投注游戏,我想知道如何在不同的代码区域更改 GUI。当我运行它时,我在一个应用程序上获得马,然后在另一个应用程序上获得比赛线,但我希望它们都在同一个应用程序上。我是否需要将实际的 Shoes 应用程序本身设置为变量?

class Horse 
  def initialize()
    #puts "YOYOYOYO"
    #@number=i
    Shoes.app{
      @icon= image 'horsey.jpg'
      @icon.left = 100
      @icon.top = 50
    }
  end

  def neigh()
    #puts "Neighhhh"
  end

  def raceTime()
    time=rand(100)%20
    return time+10
  end
end

class HorseIcon
  def initialize(h)
    @horse= h
    @imageloc='horsey.jpg'
  end
end

class Game
  def initialize(h1, h2)
    contestants=[h1, h2]
    Shoes.app{
      @icon= image 'raceline.jpg'
      @icon.left = 100
      @icon.top = 70
    }
  end

  def race()
  end
end

game= Game.new(1,2) 
seabiscuit= Horse.new()
4

1 回答 1

0

您正在使用两个单独的 Shoes.app类。我认为这是你的问题。

从你的代码来看,你似乎有其他语言的背景,比如 Python。我建议您克隆 Shoes git 并查看“Shoes/samples”目录并使用它。或者只是看看这个。

它将帮助您查看代码的外观。

PS:它也会给你一些关于 Ruby 风格的指导。使用多行时,您通常不使用{}来阻止。你会使用:

    Shoes.app do
      # code goes here
    end
于 2013-05-26T06:18:20.967 回答