seed r188 - trunk/examples/lightsoff
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r188 - trunk/examples/lightsoff
- Date: Sat, 8 Nov 2008 03:39:04 +0000 (UTC)
Author: racarr
Date: Sat Nov 8 03:39:03 2008
New Revision: 188
URL: http://svn.gnome.org/viewvc/seed?rev=188&view=rev
Log:
Merge in matts lightsoff changes.
Modified:
trunk/examples/lightsoff/lightsoff.js
Modified: trunk/examples/lightsoff/lightsoff.js
==============================================================================
--- trunk/examples/lightsoff/lightsoff.js (original)
+++ trunk/examples/lightsoff/lightsoff.js Sat Nov 8 03:39:03 2008
@@ -10,6 +10,49 @@
var moves = 0;
var timeout = 0;
+Gtk.init(null, null);
+
+var window = new Gtk.Window({"title": "Lights Off", "resizable" : false});
+var table = new Gtk.Table();
+var buttons;
+window.signal.hide.connect(Gtk.main_quit);
+
+var vbox = new Gtk.VBox();
+
+vbox.pack_start(create_menu());
+Seed.print("Initial size: " + size);
+vbox.pack_start(table);
+
+window.add(vbox);
+
+create_board();
+window.show_all();
+initialize_game();
+
+Gtk.main();
+
+function change_size()
+{
+ destroy_board();
+ size = this.size;
+ create_board();
+ initialize_game();
+ window.show_all();
+ return;
+}
+
+function destroy_board()
+{
+ for ( var i = 0; i < size; ++i )
+ {
+ for ( var j = 0; j < size; ++j )
+ {
+ buttons[i][j].destroy();
+ }
+ }
+ return;
+}
+
function create_board_size_menu()
{
var menu = new Gtk.Menu();
@@ -21,41 +64,16 @@
menu.append(size_5);
menu.append(size_7);
menu.append(size_9);
-
- return menu;
-}
-
-function create_menu()
-{
- var menu = new Gtk.MenuBar();
-
- var game_menu = new Gtk.Menu();
- var size_item = new Gtk.MenuItem({"child":
- new Gtk.Label({"label": "Board Size"})});
- size_item.submenu = create_board_size_menu();
-
- var quit_item = new Gtk.MenuItem({"child":
- new Gtk.Label({"label": "Quit"})});
- quit_item.signal.activate.connect(Gtk.main_quit);
-
- game_menu.append(size_item);
- game_menu.append(quit_item);
-
- var game_menu_item = new Gtk.MenuItem({"child":
- new Gtk.Label({"label": "Game"})});
- game_menu_item.submenu = game_menu;
-
- menu.append(game_menu_item);
-
+ size_5.signal.activate.connect(change_size, {size: 5});
+ size_7.signal.activate.connect(change_size, {size: 7});
+ size_9.signal.activate.connect(change_size, {size: 9});
return menu;
}
function create_board()
{
- var table = new Gtk.Table();
table.resize(size,size);
-
buttons = new Array(size);
for (i = 0; i < size; ++i)
@@ -77,7 +95,33 @@
}
}
- return table;
+ return;
+}
+
+function create_menu()
+{
+ var menu = new Gtk.MenuBar();
+
+ var game_menu = new Gtk.Menu();
+ var size_item = new Gtk.MenuItem({"child":
+ new Gtk.Label({"label": "Board Size"})});
+
+ size_item.submenu = create_board_size_menu();
+
+ var quit_item = new Gtk.MenuItem({"child":
+ new Gtk.Label({"label": "Quit"})});
+ quit_item.signal.activate.connect(Gtk.main_quit);
+
+ game_menu.append(size_item);
+ game_menu.append(quit_item);
+
+ var game_menu_item = new Gtk.MenuItem({"child":
+ new Gtk.Label({"label": "Game"})});
+ game_menu_item.submenu = game_menu;
+
+ menu.append(game_menu_item);
+
+ return menu;
}
function clear_board()
@@ -93,6 +137,7 @@
}
}
+
function initialize_game()
{
wincount = 0;
@@ -181,22 +226,6 @@
buttons[i][j].lit = !buttons[i][j].lit;
}
-Gtk.init(null, null);
-
-var window = new Gtk.Window({"title": "Lights Off", "resizable" : false});
-window.signal.hide.connect(Gtk.main_quit);
-
-vbox = new Gtk.VBox();
-
-vbox.pack_start(create_menu());
-vbox.pack_start(create_board());
-
-window.add(vbox);
-
-window.show_all();
-initialize_game();
-
-Gtk.main();
function lightrow(start, end, col)
{
@@ -237,3 +266,4 @@
lightcol(max - i, i, i);
}
}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]