2013-05-13 15 views
0

我正在用鞋子寫一場賽馬/投注遊戲,我想知道如何能夠改變GUI在不同的代碼區域。當我運行這個時,我在一個應用程序上獲得馬,然後在另一個應用程序上獲得賽馬線,但是我希望它們都在同一個應用程序上。我是否需要將實際的鞋子應用程序本身設置爲變量?使用Ruby Shoes GUI工具包,我該如何去編輯我的GUI在不同的代碼區域

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() 

回答

0

您正在使用兩個單獨的Shoes.app類。我認爲這是你的問題。

從你的代碼判斷你似乎有一些其他語言的背景,比如Python。 我建議你克隆Shoes git,看看'Shoes/samples'目錄並且隨它一起玩。 或者只是看看this.

它會幫助你看看代碼應該是什麼樣子。 PS:它也會給你一些指向Ruby風格的指針。使用多行時,通常不會使用{}作爲塊。您可以使用:

Shoes.app do 
     # code goes here 
    end 
相關問題