Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.12 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////
  2. // COMP2521 18x1 ... the Fury of Dracula
  3. // DracView.c: the DracView ADT implementation
  4. //
  5. // 2014-07-01   v1.0    Team Dracula <cs2521@cse.unsw.edu.au>
  6. // 2017-12-01   v1.1    Team Dracula <cs2521@cse.unsw.edu.au>
  7.  
  8. #include <assert.h>
  9. #include <err.h>
  10. #include <stdbool.h>
  11. #include <stdlib.h>
  12. #include <sysexits.h>
  13. #include <string.h>
  14. #include "DracView.h"
  15. #include "Game.h"
  16. #include "GameView.h"
  17. #include "Globals.h"
  18. #include "Map.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #define LINE_LEN 40 //... if you decide to use the Map ADT
  22.      
  23. struct dracView {
  24.     int dracLife;
  25.     char *dracPlist;
  26.     int roundNumber;
  27.     int currPlayer;
  28.    
  29.     int godLoca;
  30.     int drsLoca;
  31.     int vanLoca;
  32.     int minLoca;
  33.     int draLoca;
  34.    
  35.     int godLife;
  36.     int drsLife;
  37.     int vanLife;
  38.     int minLife;
  39.     int draLife;
  40.    
  41.     Map dracMap;
  42. };
  43.      
  44.  
  45. // Creates a new DracView to summarise the current state of the game
  46. DracView
  47. newDracView (char *pastPlays, PlayerMessage messages[])
  48. {
  49.     // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
  50.     DracView new = malloc (sizeof *new);
  51.     GameView dragame = newGameView(pastPlays, messages);
  52.     if (new == NULL) err (EX_OSERR, "couldn't allocate DracView)");
  53.         new->dracLife = getHealth(dragame, PLAYER_DRACULA);
  54.         new->dracPlist = pastPlays;
  55.         new->roundNumber = getRound(dragame)-1;
  56.         if (new->roundNumber < 0) new->roundNumber = 0;
  57.        
  58.         new->godLoca = getLocation(dragame, PLAYER_LORD_GODALMING);
  59.         new->drsLoca = getLocation(dragame, PLAYER_DR_SEWARD);
  60.         new->vanLoca = getLocation(dragame, PLAYER_VAN_HELSING);
  61.         new->minLoca = getLocation(dragame, PLAYER_MINA_HARKER);
  62.         new->draLoca = getLocation(dragame, PLAYER_DRACULA);
  63.         printf("%d is draculaLoca\n", new->draLoca);
  64.        
  65.         new->godLife = getHealth (dragame, PLAYER_LORD_GODALMING);
  66.         new->drsLife = getHealth (dragame, PLAYER_DR_SEWARD);
  67.         new->vanLife = getHealth (dragame, PLAYER_VAN_HELSING);
  68.         new->minLife = getHealth (dragame, PLAYER_MINA_HARKER);
  69.         new->draLife = getHealth (dragame, PLAYER_DRACULA);
  70.         printf("%d is new->draLife\n", new->draLife);
  71.         new->dracMap = newMap();
  72.        
  73.    
  74.  
  75.     return new;
  76. }
  77.  
  78. // Frees all memory previously allocated for the DracView toBeDeleted
  79. void
  80. disposeDracView (DracView toBeDeleted)
  81. {
  82.     // COMPLETE THIS IMPLEMENTATION
  83.     free (toBeDeleted);
  84. }
  85.  
  86. //// Functions to return simple information about the current state of the game
  87.  
  88. // Get the current round
  89. Round
  90. giveMeTheRound (DracView dv)
  91. {
  92.     return dv->roundNumber;
  93. }
  94.  
  95. // Get the current score
  96. int
  97. giveMeTheScore (DracView dv)
  98. {
  99.     // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
  100.     return 0;
  101. }
  102.  
  103. // Get the current health points for a given player
  104. int
  105. howHealthyIs (DracView dv, PlayerID player)
  106. {
  107.     if (player == PLAYER_LORD_GODALMING) return dv->godLife;
  108.     if (player == PLAYER_MINA_HARKER) return dv->minLife;
  109.     if (player == PLAYER_VAN_HELSING) return dv->vanLife;
  110.     if (player == PLAYER_DR_SEWARD) return dv->drsLife;
  111.     printf("%d is dralife\n", dv->draLife);
  112.     if (player == PLAYER_DRACULA) return dv->draLife;
  113.     return 0;
  114. }
  115.  
  116. // Get the current location id of a given player
  117. LocationID
  118. whereIs (DracView dv, PlayerID player)
  119. {
  120.     if (player == PLAYER_LORD_GODALMING) return dv->godLoca;
  121.     if (player == PLAYER_MINA_HARKER) return dv->minLoca;
  122.     if (player == PLAYER_VAN_HELSING) return dv->vanLoca;
  123.     if (player == PLAYER_DR_SEWARD) return dv->drsLoca;
  124.     if (player == PLAYER_DRACULA) return dv->draLoca;
  125.     return 0;
  126. }
  127.  
  128. // Get the most recent move of a given player
  129. void
  130. lastMove (DracView dv, PlayerID player,
  131.     LocationID *start, LocationID *end)
  132. {
  133.     // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
  134.     return;
  135. }
  136.  
  137. // Find out what minions are placed at the specified location
  138. void
  139. whatsThere (DracView dv, LocationID where,
  140.     int *numTraps, int *numVamps)
  141. {
  142.     // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
  143.     return;
  144. }
  145.  
  146. //// Functions that return information about the history of the game
  147.  
  148. // Fills the trail array with the location ids of the last 6 turns
  149. void
  150. giveMeTheTrail (DracView dv, PlayerID player,
  151.     LocationID trail[TRAIL_SIZE])
  152. {
  153.     // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
  154. }
  155.  
  156. //// Functions that query the map to find information about connectivity
  157.  
  158. // What are my (Dracula's) possible next moves (locations)
  159. LocationID *
  160. whereCanIgo (DracView dv, int *numLocations, bool road, bool sea)
  161. {
  162.     // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
  163.     return NULL;
  164. }
  165.  
  166. // What are the specified player's next possible moves
  167. LocationID *
  168. whereCanTheyGo (DracView dv, int *numLocations, PlayerID player,
  169.     bool road, bool rail, bool sea)
  170. {
  171.    
  172.     LocationID *b;
  173.     LocationID from = whereIs(dv, player);
  174.    
  175.     b = locationsConnected(dv->dracMap, from, 100, road, rail, sea);
  176.     //int i = 0;
  177.     int connCount = numberOfConnections(dv->dracMap, from, road, rail, sea);
  178.  
  179.     *numLocations = connCount;
  180.  
  181.    
  182.     //LocationID locArr[numLocations];
  183.     // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
  184.     return b;
  185.  
  186.  
  187.  
  188.     *numLocations = 0;
  189.     return NULL;
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement