[gnome-games] lightsoff: fix misinterpreted clicks when mouse moves



commit 838ef1987de5d68b5f871e202d87677585280412
Author: Tim Horton <hortont424 gmail com>
Date:   Sat May 8 00:23:39 2010 -0400

    lightsoff: fix misinterpreted clicks when mouse moves
    
    Use location where mouse is clicked, not released, to determine what light to flip. Fixes BGO 614698

 lightsoff/src/Board.js |   40 ++++++++++++++++++++++++++++------------
 1 files changed, 28 insertions(+), 12 deletions(-)
---
diff --git a/lightsoff/src/Board.js b/lightsoff/src/Board.js
index 30526e6..41af94a 100644
--- a/lightsoff/src/Board.js
+++ b/lightsoff/src/Board.js
@@ -2,10 +2,8 @@ Settings = imports.Settings;
 GLib = imports.gi.GLib;
 Clutter = imports.gi.Clutter;
 Light = imports.Light;
-Puzzle = imports.Puzzle;
 
 var tiles = 5;
-var puzzle_gen = new Puzzle.Gen(tiles);
 
 // All lights need to be shifted down and right by half a light,
 // as lights have center gravity.
@@ -95,7 +93,7 @@ BoardView = new GType({
 					var l = new Light.LightView();
 					var loc = position_for_light(x, y);
 					l.set_position(loc.x, loc.y);
-					l.signal.button_release_event.connect(light_clicked, {"x":x, "y":y});
+					l.signal.button_press_event.connect(light_clicked, {"x":x, "y":y});
 					
 					lights[x][y] = l;
 					self.add_actor(l);
@@ -113,7 +111,7 @@ BoardView = new GType({
 				self.signal.game_won.emit();
 		}
 		
-		// Callback for button_release_event from each light; user_data
+		// Callback for button_press_event from each light; user_data
 		// is an object containing the coordinates of the clicked light.
 		var light_clicked = function(light, event, coords)
 		{
@@ -185,15 +183,33 @@ BoardView = new GType({
 			
 			GLib.random_set_seed(level);
 			
-			// Determine the solution length (number of clicks required)
-			// based on the level number.
-			var solution_length = Math.floor(2 * Math.log(level) + 1);
-			var sol = puzzle_gen.minimal_solution(solution_length);
+			do
+			{
+				// Simulate log(level^2) clicks; this seems to give
+				// a reasonable progression of difficulty
+				var count = Math.floor(Math.log(level * level) + 1);
+				var sym = Math.floor(3 * GLib.random_double());
 
-			for(var x = 0; x < tiles; x++)
-				for(var y = 0; y < tiles; y++)
-					if(sol[tiles * y + x])
-						self.light_toggle(x, y);
+				for (var q = 0; q < count; ++q)
+				{
+					i = Math.round((tiles - 1) * GLib.random_double());
+					j = Math.round((tiles - 1) * GLib.random_double());
+					
+					self.light_toggle(i, j);
+					
+					// Ensure some level of "symmetry"
+					var x_sym = Math.abs(i - (tiles - 1));
+					var y_sym = Math.abs(j - (tiles - 1));
+					
+					if(sym == 0)
+						self.light_toggle(x_sym, j);
+					else if(sym == 1)
+						self.light_toggle(x_sym, y_sym);
+					else
+						self.light_toggle(i, y_sym);
+				}
+			}
+			while(cleared());
 			
 			loading_level = false;
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]