Created
January 20, 2009 08:35
-
-
Save robertpfeiffer/49402 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
overtcards = [] | |
currentplayer = 0 | |
score = {0=>0,1=>0} | |
def shuffle(arr) | |
new=[] | |
new2=arr.select do |x|x end | |
arr.size.downto(1) { |n| new.push new2.delete_at(rand(n)) } | |
new | |
end | |
cardimages = shuffle(shuffle(Dir["memory-karten/*.png"][0..15]) * 2) | |
cards = [] | |
Shoes.app do | |
stack do | |
@namecap = caption "" | |
@playercap = caption "Your Turn: Player 1" | |
@scorecap = caption "0:0" | |
@remcap = caption cards.length / 2 | |
flow do | |
cardimages.each do |name| | |
stack :width => 120, :height => 120 do | |
background darkred | |
img = image "Pictures/back.jpg", :top => 10,:left => 10 | |
cards << img | |
img.click do | |
if img.path == "Pictures/back.jpg" and overtcards.length < 2 | |
@namecap.text = name.split("/").last[/[^\.]+/] | |
img.path = name | |
(overtcards << img) | |
elsif overtcards.length == 2 | |
if overtcards[0].path==overtcards[1].path | |
score[currentplayer]+=1 | |
overtcards.select do |x| | |
cards.delete(x) | |
x.path = "" | |
x.click | |
end | |
@scorecap.text= score[0].to_s + ":" + score[1].to_s | |
else | |
currentplayer = (currentplayer + 1) % 2 | |
@playercap.text= "Your Turn: Player "+ (1+currentplayer).to_s | |
end | |
overtcards = [] | |
cards.each {|i| i.path="Pictures/back.jpg"} | |
@remcap.text = cards.length / 2 | |
if cards.length < 1 | |
@playercap.text = "Game ends. Tie" | |
if score[0] > score [1] | |
@playercap.text = "Player 1 wins." | |
end | |
if score[0] < score [1] | |
@playercap.text = "Player 2 wins." | |
end | |
end | |
end | |
end | |
end | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment