This email list is read-only.  Emails sent to this list will be discarded
----------------------------------
 Makefile.am                     |    2 +-
 colortext/colortext.c           |    2 +-
 configure.ac                    |    4 +
 tictactoe/Makefile.am           |   20 +
 tictactoe/clutter_tictactoe.png |  Bin 0 -> 466 bytes
 tictactoe/grid.png              |  Bin 0 -> 1521 bytes
 tictactoe/o.png                 |  Bin 0 -> 11478 bytes
 tictactoe/tictactoe.c           |  859 +++++++++++++++++++++++++++++++++++++++
 tictactoe/tictactoe.desktop     |   10 +
 tictactoe/x.png                 |  Bin 0 -> 10851 bytes
 10 files changed, 895 insertions(+), 2 deletions(-)

New commits:
commit e4caa830ac1ecbbefd12418a217a44e44245c1b8
Author: Felicia Decker <[EMAIL PROTECTED]>
Date:   Thu Aug 28 13:25:30 2008 -0700

    Added a clutter tic-tac-toe app. Displays at 4 different resolutions.
    Changed line in colortext.c to point to correct install path of word_file


Diff in this email is a maximum of 400 lines.
diff --git a/Makefile.am b/Makefile.am
index a3a1afe..182fe23 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = helloworld apple colortext squares
+SUBDIRS = helloworld apple colortext squares tictactoe
 
 MAINTAINERCLEANFILES = aclocal.m4 compile config.guess config.sub configure 
depcomp install-sh ltmain.sh Makefile.in missing
 
diff --git a/colortext/colortext.c b/colortext/colortext.c
index 7cadc82..d6037e5 100644
--- a/colortext/colortext.c
+++ b/colortext/colortext.c
@@ -9,7 +9,7 @@
 #define SCN_HEIGHT 480
 int scn_width = 0;
 int scn_height = 0;
-#define FILENAME "/usr/local/share/colortext/word_file"
+#define FILENAME "/usr/share/colortext/word_file"
 #define LENGTH_LIMIT 12
 #define NUM_ACTORS 20
 #define NUM_COLORS 20
diff --git a/configure.ac b/configure.ac
index 56b4c5e..dd3c067 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,6 +40,9 @@ AC_SUBST(colorttextdir)
 squaresdir = ${datadir}/squares
 AC_SUBST(squaresdir)
 
+tictactoedir = ${datadir}/tictactoe
+AC_SUBST(tictactoedir)
+
 desktopdir = ${datadir}/applications
 AC_SUBST(desktopdir)
 
@@ -53,6 +56,7 @@ helloworld/Makefile
 apple/Makefile
 colortext/Makefile
 squares/Makefile
+tictactoe/Makefile
 ])
 
 
diff --git a/tictactoe/Makefile.am b/tictactoe/Makefile.am
new file mode 100644
index 0000000..fb20b00
--- /dev/null
+++ b/tictactoe/Makefile.am
@@ -0,0 +1,20 @@
+bin_PROGRAMS = tictactoe
+
+AM_CFLAGS = $(CLUTTER_CFLAGS) \
+       $(GCC_CFLAGS) \
+       -D_GNU_SOURCE
+
+tictactoe_LDADD = $(CLUTTER_LIBS)
+tictactoe_SOURCES = tictactoe.c
+
+tictactoedir = $(datadir)/tictactoe
+tictactoe_DATA = grid.png x.png o.png
+
+desktopdir = $(datadir)/applications
+desktop_DATA = tictactoe.desktop
+
+icondir = $(datadir)/icons/hicolor/48x48/apps
+icon_DATA = clutter_tictactoe.png
+
+EXTRA_DIST = clutter_tictactoe.png
+
diff --git a/tictactoe/clutter_tictactoe.png b/tictactoe/clutter_tictactoe.png
new file mode 100644
index 0000000..b1e1559
Binary files /dev/null and b/tictactoe/clutter_tictactoe.png differ
diff --git a/tictactoe/grid.png b/tictactoe/grid.png
new file mode 100644
index 0000000..affe265
Binary files /dev/null and b/tictactoe/grid.png differ
diff --git a/tictactoe/o.png b/tictactoe/o.png
new file mode 100644
index 0000000..b56ffee
Binary files /dev/null and b/tictactoe/o.png differ
diff --git a/tictactoe/tictactoe.c b/tictactoe/tictactoe.c
new file mode 100644
index 0000000..d28c3d0
--- /dev/null
+++ b/tictactoe/tictactoe.c
@@ -0,0 +1,859 @@
+#include <clutter/clutter.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+
+#define SCN_WIDTH  800
+#define SCN_HEIGHT 480
+#define NUM_TILES    9
+
+double xfactor, yfactor;
+int padding1, padding2, paddingx;
+ClutterActor *stage, *tab, *title_label;
+int zero = 0, one = 1, two = 2, three = 3, four = 4;
+int five = 5, six = 6, seven = 7, eight = 8;
+int switch_flag = 0, scn_width, scn_height;
+ClutterBehaviour *scale;
+ClutterAlpha *alpha ;
+ClutterActor *x_img = NULL, *o_img = NULL;
+ClutterActor *end_game_label, *end_game_shadow, *end_game_box;
+ClutterActor *reset_button, *button_label;
+ClutterTimeline *scaling_timeline, *button_press_timeline, 
+                *button_release_timeline;
+ClutterEffectTemplate *button_press_movement, *button_release_movement;
+
+ClutterColor stage_color   = { 0x31, 0x31, 0x31, 0xff };
+ClutterColor title_color   = { 0xff, 0xb4, 0x6e, 0xff };
+ClutterColor title_color2  = { 0xff, 0x7c, 0x39, 0xff };
+ClutterColor tab_color     = { 0x31, 0x31, 0x31, 0xff };
+ClutterColor button_color  = { 0xb0, 0xb7, 0x44, 0xff };
+ClutterColor border_color  = { 0xf6, 0xb8, 0x00, 0xff };
+ClutterColor bright_yellow = { 0xff, 0xff, 0x31, 0xff };
+ClutterColor color_black   = { 0x00, 0x00, 0x00, 0xff };
+ClutterColor color_yellow  = { 0xf6, 0xff, 0x5f, 0xff };
+
+int reset_y, reset_x, reset_label_y, reset_label_x;
+
+static int num_turns = 0;
+static int whos_turn = 1; //X always goes first
+
+typedef struct {
+  ClutterActor *back_square;
+  ClutterActor *img_square;
+  int status;
+} game_tile;
+
+game_tile game_tile_ar[NUM_TILES];
+
+
+/* Clutter Tic-Tac-Toe
+   Rules:
+   X always starts first; X is player one
+   O always goes second;  O is player two
+   Take turns until either opponent has 3
+   in a row or all 9 squares are filled.
+   Once you click a spot on the grid, it
+   is counted as your turn and you may
+   not change it.
+   Stalemate game is called a cat game.
+ */
+
+
+/* Init the 9 game tiles.
+   Each tile's status is -1; meaning
+   an undecided square is showing.
+ */
+void init_game_tiles()
+{
+  int i;
+  for(i == 0; i < NUM_TILES; ++i)
+  {
+     game_tile_ar[i].back_square = NULL;
+     game_tile_ar[i].status = -1;
+     game_tile_ar[i].img_square = NULL;
+  }
+  return;
+}
+
+
+
+/*
+   Load image and return clutter actor
+*/
+ClutterActor *get_actor_from_image (const char *file_name)
+{
+    GError **error = 0;
+    ClutterActor *actor;
+
+    //look in 3 spots for file
+    struct stat statbuf;
+    char path [256];
+
+    sprintf (path, "./%s", file_name);
+    int rval = stat (path, &statbuf);
+    if (rval < 0) {
+        sprintf (path, "/usr/local/share/tictactoe/%s", file_name);
+        rval = stat (path, &statbuf);
+    }
+    if (rval < 0) {
+        sprintf (path, "/usr/share/tictactoe/%s", file_name);
+        rval = stat (path, &statbuf);
+    }
+    if (rval >= 0) {
+        actor = clutter_texture_new_from_file(path, error);
+    }
+    if (!actor) {
+        fprintf(stderr, "Error: %s failed to load.\n", file_name);
+    }
+    return actor;
+}
+
+
+
+/* Initialize the grid by loading the grid image.
+ */
+int init_grid()
+{
+  GError **error = 0;
+  ClutterActor *grid = get_actor_from_image("grid.png");
+  if (!grid) {
+      fprintf(stderr, "Unable to load the grid.\n");
+      return -1;
+  }
+  int grid_y = 28 * yfactor;
+  int grid_x = 328 * xfactor;
+  if (SCN_WIDTH == 800 && SCN_HEIGHT == 600)
+  {
+      grid_y += padding1;
+  }
+  if (SCN_WIDTH == 1024)
+  {
+      grid_x += 120;
+      grid_y += 57;
+      if (SCN_HEIGHT == 768)
+          grid_y += 90;
+  }
+  clutter_actor_set_position(grid, grid_x, grid_y);
+  clutter_container_add_actor(CLUTTER_CONTAINER(stage), (ClutterActor*)grid);
+  clutter_actor_show(grid);
+  return 0;
+}
+
+
+
+/* Apply the 'scale' behaviour to the image;
+   the image is scaled.
+ */
+void scale_image(ClutterActor *image)
+{
+  clutter_behaviour_apply(scale, image);
+  clutter_timeline_start(scaling_timeline);
+  return;
+}
+
+
+
+/* Unreference the cloned timeline once it emits its "completed"
+   signal.
+ */
+void unref_cloned_timeline(ClutterTimeline *timeline, gpointer data)
+{
+  g_object_unref(timeline);
+  return;
+}
+
+
+
+/* Sets all back_squares to lose their
+   reactivity. This is important when
+   we don't want the players to be able
+   to click on the game tiles.
+ */
+void set_all_to_nonreactive()
+{
+  int i;
+  for (i = 0; i < NUM_TILES; ++i) {
+       clutter_actor_set_reactive((ClutterActor*)game_tile_ar[i].back_square, 
+                                  FALSE);
+  }
+  return;
+}
+
+
+
+/* Displays text notifying players of a winner.
+ */
+void display_winner(int winner)
+{
+  int label_pos = 150 * yfactor;
+  int label_pos_x = 220 * xfactor;
+  if (SCN_WIDTH == 800 && SCN_HEIGHT == 600)
+  {
+      label_pos += padding1;
+  }
+  if (SCN_WIDTH == 1024)
+  {
+      label_pos_x += paddingx;
+      if (SCN_HEIGHT == 768)
+          label_pos += 90;
+  }
+  ClutterColor color = { 0xff, 0xff, 0xff, 0xff };
+  clutter_label_set_color((ClutterLabel*)end_game_label, &color);
+  if (winner == 1)
+  {
+      clutter_label_set_text((ClutterLabel*)end_game_label, "X Wins!");
+      clutter_label_set_text((ClutterLabel*)end_game_shadow, "X Wins!");
+  }
+  if (winner == 0)
+  {
+      clutter_label_set_text((ClutterLabel*)end_game_label, "O Wins!");
+      clutter_label_set_text((ClutterLabel*)end_game_shadow, "O Wins!");
+  }
+  clutter_label_set_font_name((ClutterLabel*)end_game_label, "Sans 76");
+  clutter_label_set_font_name((ClutterLabel*)end_game_shadow, "Sans 76");
+  clutter_actor_set_size(end_game_label, 12, 12);
+  clutter_actor_set_size(end_game_shadow, 12, 12);
+  clutter_actor_set_size(end_game_box, 405, 111);
+  clutter_actor_set_position(end_game_label, label_pos_x, label_pos);
+  clutter_actor_set_position(end_game_shadow, label_pos_x + 5, label_pos + 5);
+  clutter_actor_set_position(end_game_box, label_pos_x - 12, label_pos + 3);
+  clutter_actor_set_opacity(end_game_label, 100);
+  clutter_actor_set_opacity(end_game_shadow, 100);
+  clutter_actor_raise_top(end_game_box);
+  clutter_actor_raise_top(end_game_shadow);
+  clutter_actor_raise_top(end_game_label);
+  clutter_actor_show(end_game_box);
+  clutter_actor_show(end_game_shadow);
+  clutter_actor_show(end_game_label);
+
+  return;
+}
+
+
+
+/* Displays text notifying players of a cat game.
+ */
+void display_cats_game()
+{
+  int label_pos = 150 * yfactor;
+  int label_pos_x = 100 * xfactor;
+  int adjustment = 10;
+  if (SCN_WIDTH == 800 && SCN_HEIGHT == 600)
+  {
+      label_pos += padding1;
+  }
+  if (SCN_WIDTH == 1024)
+  {
+      label_pos_x += paddingx + 25;
+      adjustment += 7;
+      if (SCN_HEIGHT == 768)
+          label_pos += 90;
+  }
+  ClutterColor color = { 0xff, 0xff, 0xff, 0xff }; 
+  clutter_label_set_color((ClutterLabel*)end_game_label, &color);
+  clutter_label_set_text((ClutterLabel*)end_game_label, "Cat Game :(");
+  clutter_label_set_text((ClutterLabel*)end_game_shadow, "Cat Game :(");
+  clutter_label_set_font_name((ClutterLabel*)end_game_label, "Sans 76");
+  clutter_label_set_font_name((ClutterLabel*)end_game_shadow, "Sans 76");
+  clutter_actor_set_opacity(end_game_label, 100);
+  clutter_actor_set_opacity(end_game_shadow, 100);
+  clutter_actor_set_size(end_game_label, 12, 12);
+  clutter_actor_set_size(end_game_shadow, 12, 12);
+  clutter_actor_set_size(end_game_box, 650, 111);
+  clutter_actor_set_position(end_game_label, label_pos_x, label_pos);
+  clutter_actor_set_position(end_game_shadow, label_pos_x + 5, label_pos + 5);
+  clutter_actor_set_position(end_game_box, label_pos_x - adjustment, label_pos 
+ 7);
+  clutter_actor_raise_top(end_game_box);
+  clutter_actor_raise_top(end_game_shadow);
+  clutter_actor_raise_top(end_game_label);
+  clutter_actor_show(end_game_box);
+  clutter_actor_show(end_game_shadow);
+  clutter_actor_show(end_game_label);
+  return;
+}
+
+
+
+/* Checks for a win in all possible cases
+   and checks if number of turns equals 9.
+   If so, a cat game has been reached.
+ */
+void check_for_win(int last_went)
+{
+  //check these combos for a win
+  //012, 345, 678, 036, 147, 258, 048, 246
+  if((game_tile_ar[0].status == last_went &&
+      game_tile_ar[1].status == last_went &&
+      game_tile_ar[2].status == last_went)||
+
+     (game_tile_ar[3].status == last_went &&
+      game_tile_ar[4].status == last_went &&
+      game_tile_ar[5].status == last_went)||
+
+     (game_tile_ar[6].status == last_went &&
+      game_tile_ar[7].status == last_went &&
+      game_tile_ar[8].status == last_went)||
+
+     (game_tile_ar[0].status == last_went &&
+      game_tile_ar[3].status == last_went &&
+      game_tile_ar[6].status == last_went)||
+
+     (game_tile_ar[1].status == last_went &&
+      game_tile_ar[4].status == last_went &&
+      game_tile_ar[7].status == last_went)||
+
+     (game_tile_ar[2].status == last_went &&
+      game_tile_ar[5].status == last_went &&
+      game_tile_ar[8].status == last_went)||
+
+     (game_tile_ar[0].status == last_went &&
+      game_tile_ar[4].status == last_went &&
+      game_tile_ar[8].status == last_went)||
+
_______________________________________________
Commits mailing list
[email protected]
https://www.moblin.org/mailman/listinfo/commits

Reply via email to