Advertisement
zynamo

DracView-2:13-21/1

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