[Tux4kids-commits] r1368 - in tuxmath/branches/lan: server src

David Bruce dbruce-guest at alioth.debian.org
Wed Aug 5 15:39:07 UTC 2009


Author: dbruce-guest
Date: 2009-08-05 15:39:06 +0000 (Wed, 05 Aug 2009)
New Revision: 1368

Modified:
   tuxmath/branches/lan/server/server.c
   tuxmath/branches/lan/server/testclient.c
   tuxmath/branches/lan/src/game.c
   tuxmath/branches/lan/src/mathcards.c
   tuxmath/branches/lan/src/mathcards.h
   tuxmath/branches/lan/src/network.c
   tuxmath/branches/lan/src/network.h
Log:
changed MC_AnsweredCorrectly() and LAN_AnsweredCorrectly() to take int arg for question id rather than MC_FlashCard* pointer arg

Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c	2009-08-05 14:11:27 UTC (rev 1367)
+++ tuxmath/branches/lan/server/server.c	2009-08-05 15:39:06 UTC (rev 1368)
@@ -714,7 +714,7 @@
   id = atoi(p);
 
   //Tell mathcards so lists get updated:
-  if(!MC_AnsweredCorrectly_id(id))
+  if(!MC_AnsweredCorrectly(id))
     return;
   //If we get to here, the id was successfully parsed out of inbuf
   //and the corresponding question was found.

Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c	2009-08-05 14:11:27 UTC (rev 1367)
+++ tuxmath/branches/lan/server/testclient.c	2009-08-05 15:39:06 UTC (rev 1368)
@@ -410,7 +410,7 @@
         {  
           printf("%s is correct!\nAwait next question...\n>\n", buf);
           //Tell server we answered it right:
-          LAN_AnsweredCorrectly(fc);
+          LAN_AnsweredCorrectly(fc->question_id);
           erase_flashcard(fc);  
           print_current_quests();
         }

Modified: tuxmath/branches/lan/src/game.c
===================================================================
--- tuxmath/branches/lan/src/game.c	2009-08-05 14:11:27 UTC (rev 1367)
+++ tuxmath/branches/lan/src/game.c	2009-08-05 15:39:06 UTC (rev 1368)
@@ -1373,9 +1373,9 @@
   if (lowest != -1)  /* -1 means no comet had this answer */
   {
 #ifdef HAVE_LIBSDL_NET
-    LAN_AnsweredCorrectly(&(comets[lowest].flashcard));
+    LAN_AnsweredCorrectly(comets[lowest].flashcard.question_id);
 #else
-    MC_AnsweredCorrectly(&(comets[lowest].flashcard));
+    MC_AnsweredCorrectly(comets[lowest].flashcard.question_id);
 #endif
     /* Store the time the question was present on screen (do this */
     /* in a way that avoids storing it if the time wrapped around */

Modified: tuxmath/branches/lan/src/mathcards.c
===================================================================
--- tuxmath/branches/lan/src/mathcards.c	2009-08-05 14:11:27 UTC (rev 1367)
+++ tuxmath/branches/lan/src/mathcards.c	2009-08-05 15:39:06 UTC (rev 1368)
@@ -530,56 +530,41 @@
 /*  MC_AnsweredCorrectly() is how the user interface      */
 /*  tells MathCards that the question has been answered   */
 /*  correctly. Returns 1 if no errors.                    */
-int MC_AnsweredCorrectly(MC_FlashCard* fc)
+int MC_AnsweredCorrectly(int id)
 {
   mcdprintf("\nEntering MC_AnsweredCorrectly()");
 
   MC_MathQuestion* quest = NULL;
 
-  if (!fc)
-  {
-    fprintf(stderr, "\nMC_AnsweredCorrectly() passed invalid pointer as argument!\n");
-
-    mcdprintf("\nInvalid MC_FlashCard* argument!");
-    mcdprintf("\nLeaving MC_AnsweredCorrectly()\n");
-
-    return 0;
-  }
-
   if(!active_quests) // No questions currently "in play" - something is wrong:
   {
     fprintf(stderr, "MC_AnsweredCorrectly() - active_quests empty\n");
     return 0;
   }
 
-  #ifdef MC_DEBUG
-  printf("\nQuestion was:");
-  print_card(*fc);
-  #endif
+  mcdprintf("\nQuestion id was: %d\n", id);
 
-
   //First take the question out of the active_quests list
   quest = active_quests;  
   // Loop until quest is NULL or we find card with same id:
-  while(quest && (fc->question_id != quest->card.question_id))
+  while(quest && (id != quest->card.question_id))
     quest = quest->next;
   if(!quest) // Means we didn't find matching card - something is wrong:
   {
     fprintf(stderr, "MC_AnsweredCorrectly() - matching question not found!\n");
     return 0;
   }
-  #ifdef MC_DEBUG
+
+#ifdef MC_DEBUG
   printf("\nMatching question is:");
   print_card(quest->card);
-  #endif
+#endif
 
   //We found a matching question, now we take it out of the 
   //"active_quests" list and either put it back into the 
   //main question list in a random location, or delete it:
   active_quests = remove_node(active_quests, quest);
   questions_pending--;  //the length of the 'active_quests' list
-
-
   answered_correctly++;
 
   if (!math_opts->iopts[PLAY_THROUGH_LIST])
@@ -603,47 +588,18 @@
     unanswered--;
   }
 
-  #ifdef MC_DEBUG
+#ifdef MC_DEBUG
   print_counters();
   printf("\nLeaving MC_AnsweredCorrectly()\n");
-  #endif
+#endif
 
   return 1;
 }
 
 
 
-int MC_AnsweredCorrectly_id(int id)
-{
-  MC_MathQuestion* mq;
-  MC_FlashCard* fc;
 
-  if(!active_quests)
-  {
-    mcdprintf("MC_AnsweredCorrectly_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_AnsweredCorrectly_id() - matching question not found for id = %d!\n", id);
-    return 0;
-  }
-  //Now just pass address of card field to MC_AnsweredCorrectly():
-  fc = &(mq->card);
-  return MC_AnsweredCorrectly(fc);
-}
 
-
-
 /*  MC_NotAnsweredCorrectly() is how the user interface    */
 /*  tells MathCards that the player failed to answer the  */
 /*  question correctly. Returns 1 if no errors.           */
@@ -691,6 +647,7 @@
   printf("\nMatching question is:");
   print_card(quest->card);
   #endif
+
   /* if desired, put question back in list so student sees it again */
   if (math_opts->iopts[REPEAT_WRONGS])
   {
@@ -739,15 +696,7 @@
   }
   else /* avoid memory leak */
   {
-#ifdef MC_DEBUG
-    printf("\nBefore free() *fc is:");
-    print_card(*fc);
-#endif
     free_node(quest);
-#ifdef MC_DEBUG
-    printf("\n After free() *fc is:");
-    print_card(*fc);
-#endif
   }
 
 
@@ -757,7 +706,6 @@
   #endif
 
   return 1;
-
 }
 
 

Modified: tuxmath/branches/lan/src/mathcards.h
===================================================================
--- tuxmath/branches/lan/src/mathcards.h	2009-08-05 14:11:27 UTC (rev 1367)
+++ tuxmath/branches/lan/src/mathcards.h	2009-08-05 15:39:06 UTC (rev 1368)
@@ -210,8 +210,8 @@
 /*  MC_AnsweredCorrectly() is how the user interface      */
 /*  tells MathCards that the question has been answered   */
 /*  correctly. Returns 1 if no errors.                    */
-int MC_AnsweredCorrectly(MC_FlashCard* q);
-int MC_AnsweredCorrectly_id(int id);
+int MC_AnsweredCorrectly(int id);
+//int MC_AnsweredCorrectly_id(int id);
 
 /*  MC_NotAnsweredCorrectly() is how the user interface    */
 /*  tells MathCards that the question has not been        */

Modified: tuxmath/branches/lan/src/network.c
===================================================================
--- tuxmath/branches/lan/src/network.c	2009-08-05 14:11:27 UTC (rev 1367)
+++ tuxmath/branches/lan/src/network.c	2009-08-05 15:39:06 UTC (rev 1368)
@@ -410,10 +410,10 @@
 }
 
 
-int LAN_AnsweredCorrectly(MC_FlashCard* fc)
+int LAN_AnsweredCorrectly(int id)
 {
   char buffer[NET_BUF_LEN];
-  snprintf(buffer, NET_BUF_LEN, "%s\t%d", "CORRECT_ANSWER", fc->question_id);
+  snprintf(buffer, NET_BUF_LEN, "%s\t%d", "CORRECT_ANSWER", id);
   return say_to_server(buffer);
 }
 

Modified: tuxmath/branches/lan/src/network.h
===================================================================
--- tuxmath/branches/lan/src/network.h	2009-08-05 14:11:27 UTC (rev 1367)
+++ tuxmath/branches/lan/src/network.h	2009-08-05 15:39:06 UTC (rev 1368)
@@ -38,7 +38,7 @@
 /* Network replacement functions for mathcards "API": */
 /* These functions are how the client tells things to the server: */
 int LAN_StartGame(void);
-int LAN_AnsweredCorrectly(MC_FlashCard* fc);
+int LAN_AnsweredCorrectly(int id);
 int LAN_NotAnsweredCorrectly(MC_FlashCard* fc);
 int LAN_LeaveGame(void);
 /* This is how the client receives messages from the server: */




More information about the Tux4kids-commits mailing list