Advertisement
zynamo

DracView.c

Jan 21st, 2018
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.45 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.     int gameScore;
  29.    
  30.     int godLoca;
  31.     int drsLoca;
  32.     int vanLoca;
  33.     int minLoca;
  34.     int draLoca;
  35.    
  36.     int godLife;
  37.     int drsLife;
  38.     int vanLife;
  39.     int minLife;
  40.     int draLife;
  41.    
  42.     Map dracMap;
  43. };
  44.      
  45.  
  46. // Creates a new DracView to summarise the current state of the game
  47. DracView
  48. newDracView (char *pastPlays, PlayerMessage messages[])
  49. {
  50.     // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
  51.     DracView new = malloc (sizeof *new);
  52.     GameView dragame = newGameView(pastPlays, messages);
  53.     if (new == NULL) err (EX_OSERR, "couldn't allocate DracView)");
  54.         new->dracLife = getHealth(dragame, PLAYER_DRACULA);
  55.         new->dracPlist = pastPlays;
  56.         new->roundNumber = getRound(dragame)-1;
  57.         if (new->roundNumber < 0) new->roundNumber = 0;
  58.        
  59.         new->godLoca = getLocation(dragame, PLAYER_LORD_GODALMING);
  60.         new->drsLoca = getLocation(dragame, PLAYER_DR_SEWARD);
  61.         new->vanLoca = getLocation(dragame, PLAYER_VAN_HELSING);
  62.         new->minLoca = getLocation(dragame, PLAYER_MINA_HARKER);
  63.         new->draLoca = getLocation(dragame, PLAYER_DRACULA);
  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.         new->gameScore = getScore(dragame);
  71.        
  72.         new->dracMap = newMap();
  73.         disposeGameView(dragame);
  74.        
  75.    
  76.  
  77.     return new;
  78. }
  79.  
  80. // Frees all memory previously allocated for the DracView toBeDeleted
  81. void
  82. disposeDracView (DracView toBeDeleted)
  83. {
  84.     disposeMap(toBeDeleted->dracMap);
  85.     free (toBeDeleted);
  86. }
  87.  
  88. //// Functions to return simple information about the current state of the game
  89.  
  90. // Get the current round
  91. Round
  92. giveMeTheRound (DracView dv)
  93. {
  94.     return dv->roundNumber;
  95. }
  96.  
  97. // Get the current score
  98. int
  99. giveMeTheScore (DracView dv)
  100. {
  101.     return dv->gameScore;
  102. }
  103.  
  104. // Get the current health points for a given player
  105. int
  106. howHealthyIs (DracView dv, PlayerID player)
  107. {
  108.     if (player == PLAYER_LORD_GODALMING) return dv->godLife;
  109.     if (player == PLAYER_MINA_HARKER) return dv->minLife;
  110.     if (player == PLAYER_VAN_HELSING) return dv->vanLife;
  111.     if (player == PLAYER_DR_SEWARD) return dv->drsLife;
  112.     printf("%d is dralife\n", dv->draLife);
  113.     if (player == PLAYER_DRACULA) return dv->draLife;
  114.     return 0;
  115. }
  116.  
  117. // Get the current location id of a given player
  118. LocationID
  119. whereIs (DracView dv, PlayerID player)
  120. {
  121.     if (player == PLAYER_LORD_GODALMING) return dv->godLoca;
  122.     if (player == PLAYER_MINA_HARKER) return dv->minLoca;
  123.     if (player == PLAYER_VAN_HELSING) return dv->vanLoca;
  124.     if (player == PLAYER_DR_SEWARD) return dv->drsLoca;
  125.     if (player == PLAYER_DRACULA) return dv->draLoca;
  126.     return 0;
  127. }
  128.  
  129. // Get the most recent move of a given player
  130. void
  131. lastMove (DracView dv, PlayerID player,
  132.     LocationID *start, LocationID *end)
  133. {
  134. /*    int i;
  135.     giveMeTheTrail(dv, player, trail);
  136.     end = trail[0];
  137.     for (i = 0; trail[i + 1] != 'UNKNOWN_LOCATION'; i++);
  138.     start = trail[i]; */
  139. }
  140.  
  141. // Find out what minions are placed at the specified location
  142. void
  143. whatsThere (DracView dv, LocationID where,
  144.     int *numTraps, int *numVamps)
  145. {
  146.     *numTraps = 5;
  147.     *numVamps = 6;
  148.    
  149.     return;
  150. }
  151.  
  152. //// Functions that return information about the history of the game
  153.  
  154. // Fills the trail array with the location ids of the last 6 turns
  155. void
  156. giveMeTheTrail (DracView dv, PlayerID player,
  157.     LocationID trail[TRAIL_SIZE])
  158. {
  159.     PlayerMessage messages[LINE_LEN] = { " ", " ", " "};//arbitrary and just a dummy
  160.     GameView batGame = newGameView(dv->dracPlist, messages);
  161.     if (batGame == NULL) err (EX_OSERR, "couldn't allocate DracView)");
  162.    
  163.     getHistory(batGame, player, trail);//should fill the trail of any player
  164. }
  165.  
  166. //// Functions that query the map to find information about connectivity
  167.  
  168. // What are my (Dracula's) possible next moves (locations)
  169. LocationID *
  170. whereCanIgo (DracView dv, int *numLocations, bool road, bool sea)
  171. {
  172.     LocationID *b;
  173.     LocationID from = whereIs(dv, PLAYER_DRACULA);
  174.    
  175.     b = locationsConnected(dv->dracMap, from, 100, road, 0 , sea);
  176.     int connCount = numberOfConnections(dv->dracMap, from, road, 0 , sea);
  177.  
  178.     *numLocations = connCount;
  179.     return b;
  180.  
  181. }
  182.  
  183. // What are the specified player's next possible moves
  184. LocationID *
  185. whereCanTheyGo (DracView dv, int *numLocations, PlayerID player,
  186.     bool road, bool rail, bool sea)
  187. {
  188.    
  189.     LocationID *b;
  190.     LocationID from = whereIs(dv, player);
  191.    
  192.     b = locationsConnected(dv->dracMap, from, 100, road, rail, sea);
  193.     //int i = 0;
  194.     int connCount = numberOfConnections(dv->dracMap, from, road, rail, sea);
  195.  
  196.     *numLocations = connCount;
  197.     return b;
  198.  
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement