Advertisement
zynamo

11:30-hunterview.c

Jan 20th, 2018
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.07 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.         //printf("%d is draculaLoca\n", new->draLoca);
  61.        
  62.         new->godLife = getHealth (dragame, PLAYER_LORD_GODALMING);
  63.         new->drsLife = getHealth (dragame, PLAYER_DR_SEWARD);
  64.         new->vanLife = getHealth (dragame, PLAYER_VAN_HELSING);
  65.         new->minLife = getHealth (dragame, PLAYER_MINA_HARKER);
  66.         new->draLife = getHealth (dragame, PLAYER_DRACULA);
  67.         new->gameScore = getScore(dragame);
  68.         //printf("%d is new->draLife\n", new->draLife);
  69.         new->dracMap = newMap();
  70.         new->currPlayer = getCurrentPlayer(dragame);
  71.         disposeGameView(dragame);
  72.  
  73.     return new;
  74. }
  75.  
  76. // Frees all memory previously allocated for the HunterView toBeDeleted
  77. void
  78. disposeHunterView (HunterView toBeDeleted)
  79. {
  80.     disposeMap(toBeDeleted->dracMap);
  81.     free (toBeDeleted);
  82. }
  83.  
  84. //// Functions to return simple information about the current state of the game
  85.  
  86. // Get the current round
  87. Round
  88. giveMeTheRound (HunterView hv)
  89. {
  90.     return hv->roundNumber;
  91. }
  92.  
  93. // Get the id of current player
  94. PlayerID
  95. whoAmI (HunterView hv)
  96. {
  97.  
  98.     return hv->currPlayer;
  99. }
  100.  
  101. // Get the current score
  102. int
  103. giveMeTheScore (HunterView hv)
  104. {
  105.     return hv->gameScore;
  106. }
  107.  
  108. // Get the current health points for a given player
  109. int
  110. howHealthyIs (HunterView hv, PlayerID player)
  111. {
  112.     if (player == PLAYER_LORD_GODALMING) return hv->godLife;
  113.     if (player == PLAYER_MINA_HARKER) return hv->minLife;
  114.     if (player == PLAYER_VAN_HELSING) return hv->vanLife;
  115.     if (player == PLAYER_DR_SEWARD) return hv->drsLife;
  116.     //printf("%d is dralife\n", dv->draLife);
  117.     if (player == PLAYER_DRACULA) return hv->draLife;
  118.     return 0;
  119. }
  120.  
  121. // Get the current location id of a given player
  122. LocationID
  123. whereIs (HunterView hv, PlayerID player)
  124. {
  125.     if (player == PLAYER_LORD_GODALMING) return hv->godLoca;
  126.     if (player == PLAYER_MINA_HARKER) return hv->minLoca;
  127.     if (player == PLAYER_VAN_HELSING) return hv->vanLoca;
  128.     if (player == PLAYER_DR_SEWARD) return hv->drsLoca;
  129.     if (player == PLAYER_DRACULA) return hv->draLoca;
  130.     return 0;
  131. }
  132.  
  133. //// Functions that return information about the history of the game
  134.  
  135. // Fills the trail array with the location ids of the last 6 turns
  136. void
  137. giveMeTheTrail (HunterView hv, PlayerID player,
  138.     LocationID trail[TRAIL_SIZE])
  139. {
  140.     // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
  141. }
  142.  
  143. //// Functions that query the map to find information about connectivity
  144.  
  145. // What are my possible next moves (locations)
  146. LocationID *
  147. whereCanIgo (HunterView hv, int *numLocations,
  148.     bool road, bool rail, bool sea)
  149. {
  150.     LocationID *b;
  151.     PlayerID currPlayer = hv->currPlayer;
  152.     LocationID from = whereIs(hv, currPlayer);
  153.     b = locationsConnected(hv->dracMap, from, 10, road, rail, sea);
  154.     int connCount = numberOfConnections(hv->dracMap, from, road, rail, sea);
  155.    
  156.     *numLocations = connCount;
  157.    
  158.     return b;
  159. }
  160.  
  161. // What are the specified player's next possible moves
  162. LocationID *
  163. whereCanTheyGo (HunterView hv, int *numLocations, PlayerID player,
  164.     bool road, bool rail, bool sea)
  165. {
  166.        
  167.     LocationID *b;
  168.     LocationID from = whereIs(hv, player);
  169.    
  170.     b = locationsConnected(hv->dracMap, from, 10, road, rail, sea);
  171.     //int i = 0;
  172.     int connCount = numberOfConnections(hv->dracMap, from, road, rail, sea);
  173.  
  174.     *numLocations = connCount;
  175.  
  176.    
  177.     //LocationID locArr[numLocations];
  178.     // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
  179.     return b;
  180.     *numLocations = 0;
  181.     return NULL;
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement