Advertisement
zynamo

Untitled

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