Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add reset button

  • Loading branch information...
commit c7eba61de3f9442df7eb6dc6812c0398f2102383 1 parent 724f969
@siuying authored
View
6 Rakefile
@@ -47,14 +47,16 @@ end
require 'fileutils'
task :prepare do
+ files = FileList["resources_src/block/*@2x.png"] + FileList["resources_src/button_reset/*@2x.png"]
+
# rename @2x files to -hd file
- FileList["resources_src/block/*@2x.png"].each do |filename|
+ files.each do |filename|
new_filename = filename.gsub(/@2x.png$/, '-hd.png')
FileUtils.cp(filename, new_filename)
end
# copy files to resources
- FileList["resources_src/block/*.png"].each do |filename|
+ files.each do |filename|
unless filename =~ /@2x.png$/
FileUtils.cp(filename, "resources/#{File.basename(filename)}")
end
View
40 app/stage.rb
@@ -1,7 +1,9 @@
class Stage < CCLayer
PAGE_MARGIN = 14.0
+ attr_reader :score_label
attr_reader :rows, :cols
+ attr_reader :score
## CCNode Life Cycle
@@ -14,7 +16,8 @@ def init
def onEnter
super
- setup_scene
+ setup_ui
+ setup_scene
setup_observers
end
@@ -49,7 +52,7 @@ def update(dt)
end
# reset the scene
- def reset
+ def reset(sender)
@blocks.each do |block|
self.removeChild(block, cleanup:true)
end
@@ -101,11 +104,28 @@ def group_at(x, y)
end
private
+ def setup_ui
+ @score_label = CCLabelTTF.labelWithString("Score: 0", fontName:"AppleGothic", fontSize:20, dimensions:[200, 24], hAlignment:KCCTextAlignmentLeft)
+ @score_label.position = [0, 0]
+ @score_label.anchorPoint = [0, 0]
+ self.addChild @score_label
+
+ @reset_button = CCMenuItemImage.itemFromNormalImage("Reset.png", selectedImage:"ResetSelected.png", target:self, selector:'reset:')
+ @reset_button.anchorPoint = [1, 0]
+
+ @menu = CCMenu.menuWithArray [@reset_button]
+ @menu.position = [320, 0]
+ @menu.anchorPoint = [1, 0]
+ self.addChild @menu
+ end
+
def setup_scene
@removed = []
@blocks = []
@rows = []
@cols = []
+ @score = 0
+
18.times do |y|
15.times do |x|
block = build_colored_block(x, y)
@@ -119,6 +139,8 @@ def setup_scene
@blocks << block
end
end
+
+ refresh_score
end
def setup_observers
@@ -145,11 +167,13 @@ def setup_observers
group_size = group.size
group.each do |block|
block.group_touch_ended
+ @removed << block if group_size > 1
+ end
- if group_size > 1
- @add_score = (group_size - 2)**2
- @removed << block
- end
+ # score by group
+ if group_size > 1
+ @score += (group_size - 2)**2
+ refresh_score
end
end
end
@@ -177,4 +201,8 @@ def adjacent_blocks(block)
end.compact
end
+ def refresh_score
+ @score_label.string = "Score: #{@score}"
+ end
+
end
View
BIN  resources/Reset-hd.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  resources/Reset.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  resources/ResetSelected-hd.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  resources/ResetSelected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  resources_src/button_reset.psd
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  resources_src/button_reset.pxm
Binary file not shown
View
BIN  resources_src/button_reset/Reset-hd.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  resources_src/button_reset/Reset.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  resources_src/button_reset/Reset@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  resources_src/button_reset/ResetSelected-hd.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  resources_src/button_reset/ResetSelected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  resources_src/button_reset/ResetSelected@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.