[Tux4kids-commits] r1187 - tuxmath/branches/lan/src
akash gangil
gangil-guest at alioth.debian.org
Sun Jul 12 11:32:30 UTC 2009
Author: gangil-guest
Date: 2009-07-12 11:32:29 +0000 (Sun, 12 Jul 2009)
New Revision: 1187
Modified:
tuxmath/branches/lan/src/game.c
tuxmath/branches/lan/src/network.c
Log:
Added game_handle_net_messages() , everything easier to understand
Modified: tuxmath/branches/lan/src/game.c
===================================================================
--- tuxmath/branches/lan/src/game.c 2009-07-12 04:22:15 UTC (rev 1186)
+++ tuxmath/branches/lan/src/game.c 2009-07-12 11:32:29 UTC (rev 1187)
@@ -88,6 +88,7 @@
static int score;
static int pre_wave_score;
static int prev_wave_comets;
+static int found;
static int slowdown;
static int num_attackers;
static float speed;
@@ -149,9 +150,10 @@
static void game_handle_user_events(void);
static void game_handle_demo(void);
static void game_handle_answer(void);
+static void game_handle_net_messages(char*,char*);
static void game_countdown(void);
static void game_handle_tux(void);
-static void game_handle_comets(char *,char *);
+static void game_handle_comets();
static void game_handle_cities(void);
static void game_handle_penguins(void);
static void game_handle_steam(void);
@@ -175,7 +177,7 @@
static void draw_console_image(int i);
static void reset_level(void);
-static int add_comet(char *,char *);
+static int add_comet(void);
static void add_score(int inc);
static void reset_comets(void);
@@ -194,6 +196,20 @@
static void print_exit_conditions(void);
static void print_status(void);
#endif
+MC_FlashCard flash;
+void copy_card(MC_FlashCard* src, MC_FlashCard* dest)
+{
+ if (!src || !dest)
+ return;
+ mcdprintf("Copying '%s' to '%s', ", src->formula_string,dest->formula_string);
+ mcdprintf("copying '%s' to '%s'\n", src->answer_string, dest->answer_string);
+ strncpy(dest->formula_string, src->formula_string, MC_FORMULA_LEN);
+ strncpy(dest->answer_string, src->answer_string, MC_ANSWER_LEN);
+ mcdprintf("Card is: '%s', '%s'\n", dest->formula_string, dest->answer_string);
+ dest->answer = src->answer;
+ dest->difficulty = src->difficulty;
+ dest->question_id = src->question_id;
+}
void seperate_commmand_and_buf(char command[NET_BUF_LEN],char buf[NET_BUF_LEN])
@@ -220,6 +236,7 @@
int game(void)
{
+
/*connecting to the server*/
if(!setup_net("localhost",DEFAULT_PORT))
{
@@ -278,8 +295,12 @@
laser.alive--;
}
- check_messages(buf);
- seperate_commmand_and_buf(command,buf);
+ while(!check_messages(buf))
+ {
+ seperate_commmand_and_buf(command,buf);
+ game_handle_net_messages(buf,command);
+ }
+
@@ -289,7 +310,7 @@
game_handle_answer();
game_countdown();
game_handle_tux();
- game_handle_comets(command,buf);
+ game_handle_comets();
game_handle_cities();
game_handle_penguins();
game_handle_steam();
@@ -506,6 +527,25 @@
}
}
+
+/*Examines the network messages from the buffer and calls
+ appropriate function accordingly*/
+void game_handle_net_messages(char buf[NET_BUF_LEN],char command[NET_BUF_LEN])
+{
+ if(strncmp(command,"PLAYER_MSG",strlen("PLAYER_MSG"))==0)
+ {
+ printf("buf is =DDDDD %s\n",buf);
+ }
+ else if(strncmp(command,"SEND_QUESTION",strlen("SEND_QUESTION"))==0)
+ {
+ if(!Make_Flashcard(buf, &(flash)))
+ {
+ printf("Unable to parse buffer into flashcard..\n");
+ }
+ }
+
+}
+
/*
Set one to four lines of text to display at the game's start. Eventually
this should stylishly fade out over the first few moments of the game.
@@ -1350,7 +1390,7 @@
//FIXME might be simpler to store vertical position (and speed) in terms of time
//rather than absolute position, and determine the latter in game_draw_comets()
-void game_handle_comets(char command[NET_BUF_LEN],char buf[NET_BUF_LEN])
+void game_handle_comets(void)
{
/* Handle comets. Since the comets also are the things that trigger
changes in the cities, we set some flags in them, too. */
@@ -1492,7 +1532,7 @@
{
if ((rand() % 2) == 0 || num_comets_alive == 0)
{
- if (add_comet(command,buf))
+ if (add_comet())
{
num_attackers--;
}
@@ -2269,7 +2309,7 @@
int check_exit_conditions(void)
{
- int x;
+// int x;
if (user_quit_received)
{
@@ -2572,10 +2612,10 @@
/* Add a comet to the game (if there's room): */
-int add_comet(char command[NET_BUF_LEN], char buf[NET_BUF_LEN])
+int add_comet(void)
{
static int prev_city = -1;
- int i, found;
+ int i;
float y_spacing;
//extern int n;
@@ -2627,16 +2667,16 @@
/*Server replacement for the above 5 comments*/
say_to_server("NEXT_QUESTION");
- printf("buf is %s\n",buf);
- if(strncmp(command,"SEND_QUESTION",strlen("SEND_QUESTION"))==0)
- {
- if(!Make_Flashcard(buf, &(comets[found].flashcard)))
- {
- return 0;
- }
-
+// printf("buf is %s\n",buf);
+// if(strncmp(command,"SEND_QUESTION",strlen("SEND_QUESTION"))==0)
+// {
+// if(!Make_Flashcard(buf, &(comets[found].flashcard)))
+// {
+// return 0;
+// }
+ printf("Made the flashcard\n");
+ copy_card(&flash,&(comets[found].flashcard));
-
/* If we make it to here, create a new comet!*/
comets[found].answer = comets[found].flashcard.answer;
comets[found].alive = 1;
@@ -2681,7 +2721,8 @@
/* Record the time at which this comet was created */
comets[found].time_started = SDL_GetTicks();
- }
+// }
+ printf("Success\n");
/* comet slot found and question found so return successfully: */
return 1;
}
Modified: tuxmath/branches/lan/src/network.c
===================================================================
--- tuxmath/branches/lan/src/network.c 2009-07-12 04:22:15 UTC (rev 1186)
+++ tuxmath/branches/lan/src/network.c 2009-07-12 11:32:29 UTC (rev 1187)
@@ -150,6 +150,7 @@
fprintf(stderr, "In play_game(), SDLNet_TCP_Recv() failed!\n");
exit(EXIT_FAILURE);
}
+ return 0;
}
}
return 1;
More information about the Tux4kids-commits
mailing list