Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Marble Solitaire Game for Green and Purple Shoes

View marble_solitaire_for_green_and_purple.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
# little marble solitaire game
# by lljk
#
# revised for Green and Purple Shoes by ashbb
#
 
class SolitaireMarble < Shoes::Widget
attr_accessor :x, :y
def initialize(x, y)
@x = x; @y = y
stroke darkgreen; fill gradient(lime, green)
@o = oval(11, 11, 27, 27)
@o.click{yield if block_given?}
self.move(x, y)
end
def pick_up
@o.style stroke: gold
end
def drop
@o.style stroke: darkgreen
end
def set_coords(x, y)
@x = x; @y = y
self.move(x, y)
end
def move x, y
@o.move x+11, y+11
end
def clear
@o.clear
end
end
 
 
class SolitaireCell < Shoes::Widget
attr_accessor :x, :y, :occupied
def initialize(x, y, occupied)
@x = x; @y = y
@occupied = occupied
stroke gradient(gray, silver)
@r = rect 0, 0, 49, 49, 5, fill: gradient(rgb(55, 55, 55), dimgray)
stroke gradient(black, gray)
@o = oval 10, 10, 29, 29, fill: gradient(black, rgb(55, 55, 55))
set_coords(x, y)
end
def set_coords(x, y)
@x = x; @y = y
self.move(x, y)
end
def move x, y
@r.move x, y
@o.move x+10, y+10
end
end
 
 
########################
 
 
Shoes.app title: "Shoes Marble Solitaire", width: 470, height: 470 do
style Shoes::Link, underline: false
def init_game
background gradient(dimgray, rgb(55, 55, 55))
shape_array = [
[0, 0, 0, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 2, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0, 0]
]
@board = {}
@marbles = {}
@undo_state = {}
self.append{
y = 10
shape_array.each{|row|
x = 10
row.each{|pos|
case pos
when 0
@board[[x, y]] = "no_cell"
x +=50
when 1
cell = solitaire_cell(x, y, true)
@board[[x, y]] = cell
x += 50
when 2
cell = solitaire_cell(x, y, false)
@board[[x, y]] = cell
x += 50
end
}
y += 50
}
@board.each{|pos, cell|
unless cell == "no_cell"
if cell.occupied
x = pos[0]; y = pos[1]
marble = solitaire_marble(x, y){move_marble(marble)}
@marbles[[x, y]] = marble
end
end
}
undo_btn = link(fg("undo", black)){undo_move}
para undo_btn, top: 0, left: 1
restart_btn = link(fg("new", black)){
if confirm("start new game?")
clear; init_game
end
}
para restart_btn, top: 0, left: 430
}
end
def move_marble(marble)
@board.each{|k, v|
if v == "no_cell"
@undo_state[k] = v
elsif v.occupied
@undo_state[k] = "occupied"
else
@undo_state[k] = "empty"
end
}
marble.pick_up
marble.move(mouse[1] - 25, mouse[2] - 25)
@direction = nil
m = motion{|x, y|
if mouse[0] == 1
marble.move(x - 25, y - 25)
else
marble.drop
m.clear
if x > marble.x + 70 && x < marble.x + 135; @direction = "right"
elsif x < marble.x - 20 && x > marble.x - 85; @direction = "left"
elsif y > marble.y + 70 && y < marble.y + 135; @direction = "down"
elsif y < marble.y - 20 && y > marble.y - 85; @direction = "up"
else marble.set_coords(marble.x, marble.y)
end
if @direction
case @direction
when "right"
jump_over = [marble.x + 50, marble.y]
jump_to = [marble.x + 100, marble.y]
when "left"
jump_over = [marble.x - 50, marble.y]
jump_to = [marble.x - 100, marble.y]
when "down"
jump_over = [marble.x, marble.y + 50]
jump_to = [marble.x, marble.y + 100]
when "up"
jump_over = [marble.x, marble.y - 50]
jump_to = [marble.x, marble.y - 100]
end
if @board[jump_over].class == SolitaireCell && @board[jump_over].occupied == true &&
@board[jump_to].class == SolitaireCell && @board[jump_to].occupied == false
@marbles.delete([marble.x, marble.y])
@board[[marble.x, marble.y]].occupied = false
marble.set_coords(jump_to[0], jump_to[1])
@board[jump_to].occupied = true
@marbles[jump_to] = marble
@marbles[jump_over].clear
@marbles.delete(jump_over)
@board[jump_over].occupied = false
else
marble.set_coords(marble.x, marble.y)
end
end
end
}
end
def undo_move
@marbles.each{|pos, marble| marble.clear}
@marbles.clear
@undo_state.each{|pos, cell|
unless cell == "no_cell"
x = pos[0]; y = pos[1]
if cell == "occupied"
@board[[x, y]].occupied = true
self.append{marble = solitaire_marble(x, y){move_marble(marble)}
@marbles[[x, y]] = marble}
else
@board[[x, y]].occupied = false
end
end
}
end
init_game
end
Owner
ashbb commented

Original code, Marble Solitaire Game for Red Shoes, was created by lljk (j. kaiden).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.