Permalink
Browse files

add reset button

  • Loading branch information...
1 parent 724f969 commit c7eba61de3f9442df7eb6dc6812c0398f2102383 @siuying committed Aug 17, 2012
View
@@ -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
@@ -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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c7eba61

Please sign in to comment.