[Tux4kids-commits] r1253 - in tuxmath/branches/lan: server src
akash gangil
gangil-guest at alioth.debian.org
Wed Jul 22 19:39:23 UTC 2009
Author: gangil-guest
Date: 2009-07-22 19:39:21 +0000 (Wed, 22 Jul 2009)
New Revision: 1253
Modified:
tuxmath/branches/lan/server/testclient.h
tuxmath/branches/lan/server/transtruct.h
tuxmath/branches/lan/src/game.c
tuxmath/branches/lan/src/transtruct.h
Log:
Both clients receiving same questions now , working on removing questions , or rather disappearing em for now
Modified: tuxmath/branches/lan/server/testclient.h
===================================================================
--- tuxmath/branches/lan/server/testclient.h 2009-07-22 09:07:06 UTC (rev 1252)
+++ tuxmath/branches/lan/server/testclient.h 2009-07-22 19:39:21 UTC (rev 1253)
@@ -11,9 +11,6 @@
*/
-/*I really doubt the existence of this file */
-
-
#ifndef TESTCLIENT_H
#define TESTCLIENT_H
Modified: tuxmath/branches/lan/server/transtruct.h
===================================================================
--- tuxmath/branches/lan/server/transtruct.h 2009-07-22 09:07:06 UTC (rev 1252)
+++ tuxmath/branches/lan/server/transtruct.h 2009-07-22 19:39:21 UTC (rev 1253)
@@ -23,7 +23,7 @@
#define MC_FORMULA_LEN 40
#define MC_ANSWER_LEN 5
-#define TEST_COMETS 4
+#define TEST_COMETS 10
#ifndef MC_USE_NEWARC
Modified: tuxmath/branches/lan/src/game.c
===================================================================
--- tuxmath/branches/lan/src/game.c 2009-07-22 09:07:06 UTC (rev 1252)
+++ tuxmath/branches/lan/src/game.c 2009-07-22 19:39:21 UTC (rev 1253)
@@ -138,8 +138,11 @@
static game_message s1, s2, s3, s4, s5;
static int start_message_chosen = 0;
-static MC_FlashCard flash;
+MC_FlashCard comets_questions[TEST_COMETS]; //current questions
+int remaining_quests = 0;
+static int j=0;
+
typedef struct {
int x_is_blinking;
int extra_life_is_blinking;
@@ -196,7 +199,12 @@
void putpixel(SDL_Surface* surface, int x, int y, Uint32 pixel);
void seperate_commmand_and_buf(char command[NET_BUF_LEN],char buf[NET_BUF_LEN]);
-
+int erase_flashcard(MC_FlashCard* fc);
+int add_quest_recvd(char* buf);
+/* Display to player: */
+void print_current_quests(void);
+MC_FlashCard* find_comet_by_id(int id);
+int remove_quest_recvd(char* buf);
#ifdef TUXMATH_DEBUG
static void print_exit_conditions(void);
static void print_status(void);
@@ -237,8 +245,14 @@
return GAME_OVER_OTHER;
}
-
+ /* Start out with our "comets" empty: */
+ {
+ int i;
+ for(i = 0; i < TEST_COMETS; i ++)
+ erase_flashcard(&(comets_questions[i]));
+ }
+
/* --- MAIN GAME LOOP: --- */
do
{
@@ -488,8 +502,91 @@
return game_status;
}
}
+/**********************************These functions will be moved somewhere else probably a new header file**************************************/
+int erase_flashcard(MC_FlashCard* fc)
+{
+ if(!fc)
+ return 0;
+ fc->formula_string[0] = '\0';
+ fc->answer_string[0] = '\0';
+ fc->question_id = -1;
+ fc->answer = 0;
+ fc->difficulty = 0;
+ return 1;
+}
+int add_quest_recvd(char* buf)
+{
+ MC_FlashCard* fc = find_comet_by_id(-1);
+ if(!fc || !buf)
+ {
+ printf("NULL fc or buf\n");
+ return 0;
+ }
+ /* function call to parse buffer and receive question */
+ if(!Make_Flashcard(buf, fc))
+ {
+ printf("Unable to parse buffer into FlashCard\n");
+ return 0;
+ }
+
+ return 1;
+}
+
+int remove_quest_recvd(char* buf)
+{
+ int id = 0;
+ char* p = NULL;
+ MC_FlashCard* fc = NULL;
+
+ if(!buf)
+ return 0;
+
+ p = strchr(buf, '\t');
+ if(!p)
+ return 0;
+
+ id = atoi(p);
+ fc = find_comet_by_id(id);
+ if(!fc)
+ return 0;
+
+ erase_flashcard(fc);
+ return 1;
+}
+
+/* Display the current questions and the number of remaining questions: */
+void print_current_quests(void)
+{
+ int i;
+ printf("\n------------ Current Questions: -----------\n");
+ for(i = 0; i < TEST_COMETS; i ++)
+ {
+ if(comets_questions[i].question_id != -1)
+ printf("Comet %d - question %d:\t%s\n", i, comets_questions[i].question_id, comets_questions[i].formula_string);
+ else
+ printf("Comet %d:\tEmpty\n", i);
+ }
+ printf("-----------------------------------------------\n");
+}
+
+
+/* Return a pointer to an empty comet slot, */
+/* returning NULL if no vacancy found: */
+
+MC_FlashCard* find_comet_by_id(int id)
+{
+ int i = 0;
+ for(i = 0; i < TEST_COMETS; i++)
+ {
+ if(comets_questions[i].question_id == id)
+ return &comets_questions[i];
+ }
+ //if we don't find a match:
+ return NULL;
+}
+/***************************************************************************************************************************/
/*Examines the network messages from the buffer and calls
appropriate function accordingly*/
/*Do we want a well defined function for each of the condition
@@ -499,6 +596,8 @@
But if it starts to get long, I would have a function for each that is
local to this file and located immediately below this function - DSB */
+
+
void game_handle_net_messages(char buf[NET_BUF_LEN],char command[NET_BUF_LEN])
{
if(strncmp(command,"PLAYER_MSG",strlen("PLAYER_MSG"))==0)
@@ -508,12 +607,29 @@
else if(strncmp(command,"SEND_QUESTION",strlen("SEND_QUESTION"))==0)
{
- if(!Make_Flashcard(buf, &(flash)))
- {
- printf("Unable to parse buffer into flashcard..\n");
- }
+ if(!add_quest_recvd(buf))
+ printf("SEND_QUESTION received but could not add question\n");
+ else
+ // If we successfully added question, show new questions to user:
+ print_current_quests();
}
+ else if(strncmp(buf, "REMOVE_QUESTION", strlen("REMOVE_QUESTION")) == 0)
+ {
+ if(!remove_quest_recvd(buf)) //remove the question with id in buf
+ printf("REMOVE_QUESTION received but could not remove question\n");
+ else
+ print_current_quests();
+ }
+
+ else if(strncmp(buf, "ADD_QUESTION", strlen("ADD_QUESTION")) == 0)
+ {
+ if(!add_quest_recvd(buf))
+ printf("ADD_QUESTION received but could not add question\n");
+ else
+ print_current_quests();
+ }
+
else if(strncmp(command,"TOTAL_QUESTIONS",strlen("TOTAL_QUESTIONS"))==0)
{
sscanf(buf,"%*s %d",&total_questions_left);
@@ -529,7 +645,6 @@
with a warning until they get implemented - DSB */
}
-
/*
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.
@@ -739,6 +854,8 @@
#ifdef HAVE_LIBSDL_NET
LAN_Cleanup();
#endif
+
+
/* Free background: */
if (bkgd != NULL)
{
@@ -2603,7 +2720,6 @@
static int prev_city = -1;
int i;
float y_spacing;
- //extern int n;
/* Look for a free comet slot and see if all live comets are far */
/* enough down to avoid overlap and keep formulas legible: */
@@ -2636,7 +2752,7 @@
/* Get math question for new comet - the following function fills in */
/* the flashcard struct that is part of the comet struct: */
#ifdef HAVE_LIBSDL_NET
- LAN_NextQuestion(); // Let it be for now until we think of something else
+// LAN_NextQuestion(); // Let it be for now until we think of something else
#else
if (!MC_NextQuestion(&(comets[found].flashcard)))
{
@@ -2651,12 +2767,15 @@
/* time we happen to need it to make a new comet. So I'm commenting out */
/* the 'say_to_server()' call as well - DSB */
#ifdef HAVE_LIBSDL_NET
- copy_card(&flash,&(comets[found].flashcard)); //will be replaced on set up of new system
-#else
- if(!Make_Flashcard(buf, &(comets[found].flashcard)))
+ for (j;j<TEST_COMETS;j++)
{
- return 0;
+ if(comets_questions[j].question_id!=-1){
+ copy_card(&(comets_questions[j]),&(comets[found].flashcard)); //will be replaced on set up of new system
+ j++;
+ break;}
}
+ if(j==TEST_COMETS)
+ j=0;
#endif
/* If we make it to here, create a new comet!*/
comets[found].answer = comets[found].flashcard.answer;
Modified: tuxmath/branches/lan/src/transtruct.h
===================================================================
--- tuxmath/branches/lan/src/transtruct.h 2009-07-22 09:07:06 UTC (rev 1252)
+++ tuxmath/branches/lan/src/transtruct.h 2009-07-22 19:39:21 UTC (rev 1253)
@@ -23,7 +23,7 @@
#define MC_FORMULA_LEN 40
#define MC_ANSWER_LEN 5
-#define TEST_COMETS 4
+#define TEST_COMETS 10
#ifndef MC_USE_NEWARC
/* struct for individual "flashcard" */
More information about the Tux4kids-commits
mailing list