Advertisement
WillWill56

Seecret

Feb 13th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.21 KB | None | 0 0
  1. int main(int argc, char *argv[]) {
  2.  
  3.   printf("Hello World!\n\n");
  4.  
  5.   GameCategory *TestGameCategory = NewGameCategory();
  6.   TestGameCategory->GID = 0;
  7.   TestGameCategory->Name = malloc(strlen("MPDots") + 1); // The + 1 makes room for a null character at the end of the string
  8.   printf("Game category name length: %d\n", strlen("MPDots") + 1);
  9.   strcpy(TestGameCategory->Name, "MPDots");
  10.  
  11.   printf("The test game category \"%s\" has been successfully created!\n", TestGameCategory->Name);
  12.  
  13.   User *TestUser = NewUser();
  14.   TestUser->UID = 0;
  15.   TestUser->Name = malloc(strlen("WillWill56") + 1);
  16.   printf("User name length: %d\n", strlen("WillWill56") + 1);
  17.   strcpy(TestUser->Name, "WillWill56");
  18.  
  19.   printf("The test user \"%s\" has been successfully created!\n", TestUser->Name);
  20.  
  21.   UserPtr *UserPtrA = NewUserPtrInGameCategory(TestGameCategory);
  22.   UserPtrA->User = TestUser;
  23.   TestUser->GameCategory = TestGameCategory;
  24.  
  25.   printf("\"%s\" successfully joined game category \"%s\"!\n", TestUser->Name, TestUser->GameCategory->Name);
  26.  
  27.   GameRoom *TestGameRoom = NewGameRoomInGameCategory(TestGameCategory);
  28.   TestGameRoom->RID = 0;
  29.   TestGameRoom->Name = malloc(strlen("Dotville") + 1);
  30.   printf("Game room name length: %d\n", strlen("Dotville") + 1);
  31.   strcpy(TestGameRoom->Name, "Dotville");
  32.   TestGameRoom->Owner = TestUser;
  33.   TestGameRoom->UserLimit = 4;
  34.   /************* INTERMISSION - this bit has two steps *************/
  35.   UserPtr *UserPtrB = NewUserPtrInGameRoom(TestGameRoom);
  36.   UserPtrB->User = TestUser;
  37.   TestUser->GameRoom = TestGameRoom;
  38.  
  39.   printf("\"%s\" successfully created and joined game room \"%s\"!\n", TestUser->Name, TestUser->GameRoom->Name);
  40.  
  41.   sleep(10); // Lets use a function that only works on Linux, cause I feel like it. This isn't a professional piece of software or anything, I can do what I want! :P
  42.  
  43.   printf("\"%s\" is leaving and deleting game room \"%s\"!\n", TestUser->Name, TestUser->GameRoom->Name);
  44.  
  45.   DeleteUserPtrFromGameRoom(UserPtrB); // The function follows a trail of pointers to find out which game room to delete the UserPtr from (same for DeleteUserPtrFromGameCategory())
  46.   UserPtrB = NULL;
  47.   free(TestUser->GameRoom->Name); // We can use any pointer to the room
  48.   TestUser->GameRoom->Name = NULL;
  49.   DeleteGameRoomFromGameCategory(TestUser->GameRoom, TestUser->GameCategory); // See previous comment
  50.   TestUser->GameRoom = NULL;
  51.   TestGameRoom = NULL; // GameRoom deletion will be handled differently in high-level functions, such that only one pointer will have to be set to NULL (kind of)
  52.  
  53.   printf("\"%s\" is leaving game category \"%s\"!\n", TestUser->Name, TestUser->GameCategory->Name);
  54.  
  55.   DeleteUserPtrFromGameCategory(UserPtrA);
  56.   UserPtrA = NULL;
  57.   TestUser->GameCategory = NULL;
  58.  
  59.   printf("\"%s\" is disconnecting!\n", TestUser->Name);
  60.  
  61.   free(TestUser->Name);
  62.   TestUser->Name = NULL;
  63.   DeleteUser(TestUser);
  64.   TestUser = NULL;
  65.  
  66.   printf("Demo shutting down, removing game category \"%s\"!\n\n", TestGameCategory->Name);
  67.  
  68.   free(TestGameCategory->Name);
  69.   TestGameCategory->Name = NULL;
  70.   DeleteGameCategory(TestGameCategory);
  71.   TestGameCategory = NULL;
  72.  
  73.   printf("Have a nice day! (:\n\n");
  74.  
  75.   return 0;
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement