Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Got auto levelling working after 3 games

  • Loading branch information...
commit 6630e5535dc388885cbae78c56310fd8cb76a846 1 parent 63d53d5
@darrenrogan authored
Showing with 23 additions and 11 deletions.
  1. +23 −11 app/board_view_controller.rb
View
34 app/board_view_controller.rb
@@ -1,7 +1,7 @@
class BoardViewController < UIViewController
- COLORS = [UIColor.greenColor, UIColor.redColor, UIColor.blueColor, UIColor.brownColor, UIColor.orangeColor, UIColor.yellowColor, UIColor.purpleColor, UIColor.magentaColor]
- COLOR_NAMES = ["Green","Red","Blue","Brown","Orange","Yellow","Purple","Magenta"]
+ COLORS = [UIColor.redColor, UIColor.blueColor,UIColor.yellowColor, UIColor.greenColor,UIColor.brownColor, UIColor.orangeColor, UIColor.purpleColor, UIColor.magentaColor]
+ COLOR_NAMES = ["Red","Blue","Yellow","Green","Brown","Orange","Purple","Magenta"]
UNSET_COLOR = UIColor.grayColor
@@ -82,7 +82,7 @@ def init_views
#@back_view.addSubview(@board_view)
view.addSubview(@back_view)
-
+ @num_of_wins = 0
end
def reset_board
@@ -121,18 +121,17 @@ def drop_old_views
end
def win_alert
- @alert_box = UIAlertView.alloc.initWithTitle("Game Over",
- message:"Well Done, completed in "+ @num_of_moves.to_s + " moves",
+
+ @alert_box = UIAlertView.alloc.initWithTitle("Well Done",
+ message:"Completed Level "+@level.to_s+" in "+ @num_of_moves.to_s + " moves",
delegate: nil,
- cancelButtonTitle: "ok",
- otherButtonTitles:nil)
-
+ cancelButtonTitle: "OK",
+ otherButtonTitles: nil)
+
# Show it to the user
@alert_box.show
-
- change_level(@level+1)
-
end
+
def show_info(text)
@label.text = text
@@ -191,7 +190,20 @@ def touchesEnded(touches, withEvent:event)
# check if the game is over
if @board.game_over?
+ @num_of_wins += 1
+
self.win_alert
+
+
+ if @num_of_wins % 3 == 0
+ if true
+ change_level(@level+1)
+ else
+ new_game
+ end
+ else
+ new_game
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.