[Tux4kids-commits] r1182 - in tuxmath/branches/lan: server src
David Bruce
dbruce-guest at alioth.debian.org
Sat Jul 11 20:17:53 UTC 2009
Author: dbruce-guest
Date: 2009-07-11 20:17:52 +0000 (Sat, 11 Jul 2009)
New Revision: 1182
Modified:
tuxmath/branches/lan/server/mathcards.c
tuxmath/branches/lan/server/server.c
tuxmath/branches/lan/server/server.h
tuxmath/branches/lan/src/game.c
tuxmath/branches/lan/src/network.c
Log:
Mostly added review comments to several filese (i.e. FIXME)
Modified: tuxmath/branches/lan/server/mathcards.c
===================================================================
--- tuxmath/branches/lan/server/mathcards.c 2009-07-11 18:01:24 UTC (rev 1181)
+++ tuxmath/branches/lan/server/mathcards.c 2009-07-11 20:17:52 UTC (rev 1182)
@@ -749,6 +749,38 @@
}
+
+int MC_NotAnsweredCorrectly_id(int id)
+{
+ MC_MathQuestion* mq;
+ MC_FlashCard* fc;
+
+ if(!active_quests)
+ {
+ mcdprintf("MC_NotAnsweredCorrectly_id() - active_quests is empty\n");
+ return 0;
+ }
+ //Find the question with the given id, if it exists:
+ //First take the question out of the active_quests list
+ mq = active_quests;
+ // Loop until mq is NULL or card found with matching id:
+ while(mq && (id != mq->card.question_id))
+ {
+ mcdprintf("id is %d, mq->card.question_id is %d\n", id, mq->card.question_id);
+ mq = mq->next;
+ }
+ if(!mq) // Means we didn't find matching card - something is wrong:
+ {
+ fprintf(stderr, "MC_NotAnsweredCorrectly_id() - matching question not found!\n");
+ return 0;
+ }
+ //Now just pass address of card field to MC_NotAnsweredCorrectly():
+ fc = &(mq->card);
+ return MC_NotAnsweredCorrectly(fc);
+}
+
+
+
/* Tells user interface if all questions have been answered correctly! */
/* Requires that at list contained at least one question to start with */
/* and that wrongly answered questions have been recycled. */
Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c 2009-07-11 18:01:24 UTC (rev 1181)
+++ tuxmath/branches/lan/server/server.c 2009-07-11 20:17:52 UTC (rev 1182)
@@ -455,21 +455,23 @@
game_msg_correct_answer(i,id);
}
+ else if(strncmp(command, "NEXT_QUESTION",strlen("NEXT_QUESTION")) == 0) /* Send Next Question */
+ {
+ game_msg_next_question();
+ }
+
else if(strncmp(command, "TOTAL_QUESTIONS_LEFT",strlen("TOTAL_QUESTIONS_LEFT")) == 0) /* Send Total Questions left */
{
game_msg_total_questions_left(i);
}
-
+ //FIXME we're not going to need this one. "MISSION_ACCOMPLISHED" will be one of
+ //the messages the server sends to the client
else if(strncmp(command, "MISSION_ACCOMPLISHED",strlen("MISSION_ACCOMPLISHED")) == 0) /* Check to see if mission is over*/
{
game_msg_mission_accomplished(i);
}
- else if(strncmp(command, "NEXT_QUESTION",strlen("NEXT_QUESTION")) == 0) /* Send Next Question */
- {
- game_msg_next_question();
- }
else if(strncmp(command, "exit",strlen("exit")) == 0) /* Terminate this connection */
{
@@ -489,15 +491,25 @@
}
+/* FIXME these are just sending integers to be sent for the client */
+/* to display to the player - printf() or however we decide to do it */
+/* in the real game. If they are supposed to be messages for the */
+/* client _program_, they need to have their own message type to */
+/* tell the client what to do with it. We want it to get e.g */
+/* TOTAL_QUESTIONS 22 */
+/* rather than: */
+/* PLAYER_MSG 22 */
+
void game_msg_total_questions_left(int i)
{
int total_questions_left;
char ch[10];
- total_questions_left=MC_TotalQuestionsLeft();
- snprintf(ch,10,"%d",total_questions_left);
+ total_questions_left = MC_TotalQuestionsLeft();
+ snprintf(ch, 10, "%d",total_questions_left);
player_msg(i,ch);
}
+
void game_msg_mission_accomplished(int i)
{
int total_questions_left;
@@ -507,11 +519,13 @@
player_msg(i,ch);
}
+
+
+
void game_msg_correct_answer(int i, int id)
{
int n;
char buf[NET_BUF_LEN];
-printf("game_msg_correct_answer() called\n");
//Announcement for server and all clients:
snprintf(buf, NET_BUF_LEN,
"question id %d was answered correctly by %s\n",
Modified: tuxmath/branches/lan/server/server.h
===================================================================
--- tuxmath/branches/lan/server/server.h 2009-07-11 18:01:24 UTC (rev 1181)
+++ tuxmath/branches/lan/server/server.h 2009-07-11 20:17:52 UTC (rev 1182)
@@ -31,6 +31,7 @@
EXIT,
QUIT,
CORRECT_ANSWER,
+ NOT_ANSWERED_CORRECTLY,
NEXT_QUESTION,
TOTAL_QUESTIONS_LEFT,
MISSION_ACCOMPLISHED,
Modified: tuxmath/branches/lan/src/game.c
===================================================================
--- tuxmath/branches/lan/src/game.c 2009-07-11 18:01:24 UTC (rev 1181)
+++ tuxmath/branches/lan/src/game.c 2009-07-11 20:17:52 UTC (rev 1182)
@@ -188,7 +188,7 @@
static void game_recalc_positions(void);
void putpixel(SDL_Surface* surface, int x, int y, Uint32 pixel);
-void seperate_commmand_and_buf(char *,char *);
+void seperate_commmand_and_buf(char command[NET_BUF_LEN],char buf[NET_BUF_LEN]);
#ifdef TUXMATH_DEBUG
static void print_exit_conditions(void);
@@ -1393,8 +1393,10 @@
comets[i].expl < COMET_EXPL_END)
{
/* Tell MathCards about it - question not answered correctly: */
+ /* FIXME will need LAN_NotAnsweredCorrectly() here if using network */
MC_NotAnsweredCorrectly(&(comets[i].flashcard));
+
/* Store the time the question was present on screen (do this */
/* in a way that avoids storing it if the time wrapped around */
ctime = SDL_GetTicks();
@@ -2570,7 +2572,7 @@
/* 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(char command[NET_BUF_LEN], char buf[NET_BUF_LEN])
{
static int prev_city = -1;
int i, found;
@@ -2613,6 +2615,16 @@
// return 0;
// }
+ /* FIXME there's no way this can work. We ask the server for another */
+ /* question, but we don't check the messages before trying to get */
+ /* the next flash card out of the buffer. So the strncmp() is going */
+ /* to get done on whatever was in the buffer before. If somehow there*/
+ /* was a leftover "SEND_QUESTION" in there, we will now make a */
+ /* duplicate comet out of that question. Otherwise (most likely) */
+ /* we come back to here next time through the loop and ask for */
+ /* _another_ question before we have received this one. Either way */
+ /* it isn't what we want - DSB */
+
/*Server replacement for the above 5 comments*/
say_to_server("NEXT_QUESTION");
printf("buf is %s\n",buf);
@@ -2626,34 +2638,7 @@
/* If we make it to here, create a new comet!*/
-
comets[found].answer = comets[found].flashcard.answer;
-// /* The answer may be num1, num2, or num3, depending on format. */
-// switch (comets[found].flashcard.format)
-// {
-// case MC_FORMAT_ANS_LAST: /* e.g. num1 + num2 = ? */
-// {
-// comets[found].answer = comets[found].flashcard.num3;
-// break;
-// }
-// case MC_FORMAT_ANS_MIDDLE: /* e.g. num1 + ? = num3 */
-// {
-// comets[found].answer = comets[found].flashcard.num2;
-// break;
-// }
-// case MC_FORMAT_ANS_FIRST: /* e.g. ? + num2 = num3 */
-// {
-// comets[found].answer = comets[found].flashcard.num1;
-// break;
-// }
-// default: /* should not get to here if MathCards behaves correctly */
-// {
-// fprintf(stderr, "\nadd_comet() - invalid question format");
-// return 0;
-// }
-// }
-
-
comets[found].alive = 1;
num_comets_alive++;
@@ -2675,29 +2660,34 @@
comets[found].zapped = 0;
/* Should it be a bonus comet? */
comets[found].bonus = 0;
+
#ifdef TUXMATH_DEBUG
printf("\nbonus_comet_counter is %d\n",bonus_comet_counter);
#endif
- if (bonus_comet_counter == 1) {
+
+ if (bonus_comet_counter == 1)
+ {
bonus_comet_counter = 0;
comets[found].bonus = 1;
playsound(SND_BONUS_COMET);
#ifdef TUXMATH_DEBUG
printf("\nCreated bonus comet");
#endif
- }
+ }
#ifdef TUXMATH_DEBUG
- printf ("\nadd_comet(): formula string is: %s", comets[found].flashcard.formula_string);
+ printf ("\nadd_comet(): formula string is: %s", comets[found].flashcard.formula_string);
#endif
- /* Record the time at which this comet was created */
- comets[found].time_started = SDL_GetTicks();
+ /* Record the time at which this comet was created */
+ comets[found].time_started = SDL_GetTicks();
}
/* comet slot found and question found so return successfully: */
return 1;
}
+
+
/* Draw numbers/symbols over the attacker: */
/* This draws the numbers related to the comets */
void draw_nums(const char* str, int x, int y)
@@ -2901,8 +2891,9 @@
-/* Draw a line: */
+/* FIXME these ought to be in SDL_extras - DSB */
+/* Draw a line: */
void draw_line(int x1, int y1, int x2, int y2, int red, int grn, int blu)
{
int dx, dy, tmp;
Modified: tuxmath/branches/lan/src/network.c
===================================================================
--- tuxmath/branches/lan/src/network.c 2009-07-11 18:01:24 UTC (rev 1181)
+++ tuxmath/branches/lan/src/network.c 2009-07-11 20:17:52 UTC (rev 1182)
@@ -125,7 +125,7 @@
int check_messages(char buf[NET_BUF_LEN])
{
- int x = 0,numready;
+ int x = 0, numready;
//This is supposed to check to see if there is activity:
numready = SDLNet_CheckSockets(set, 0);
More information about the Tux4kids-commits
mailing list