Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////////////////
- // COMP2521 18x1 ... the Fury of Dracula
- // HunterView.c: the HunterView ADT implementation
- //
- // 2014-07-01 v1.0 Team Dracula <cs2521@cse.unsw.edu.au>
- // 2017-12-01 v1.1 Team Dracula <cs2521@cse.unsw.edu.au>
- #include <assert.h>
- #include <err.h>
- #include <stdbool.h>
- #include <stdlib.h>
- #include <sysexits.h>
- #include "Game.h"
- #include "GameView.h"
- #include "Globals.h"
- #include "HunterView.h"
- #include "Map.h" //... if you decide to use the Map ADT
- struct hunterView {
- int dracLife;
- char *dracPlist;
- int roundNumber;
- int currPlayer;
- int gameScore;
- int godLoca;
- int drsLoca;
- int vanLoca;
- int minLoca;
- int draLoca;
- int godLife;
- int drsLife;
- int vanLife;
- int minLife;
- int draLife;
- Map dracMap;
- };
- // Creates a new HunterView to summarise the current state of the game
- HunterView
- newHunterView (char *pastPlays, PlayerMessage messages[])
- {
- // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
- HunterView new = malloc (sizeof *new);
- GameView dragame = newGameView(pastPlays, messages);
- if (new == NULL) err (EX_OSERR, "couldn't allocate HunterView");
- new->dracLife = getHealth(dragame, PLAYER_DRACULA);
- new->dracPlist = pastPlays;
- new->roundNumber = getRound(dragame);
- if (new->roundNumber < 0) new->roundNumber = 0;
- new->godLoca = getLocation(dragame, PLAYER_LORD_GODALMING);
- new->drsLoca = getLocation(dragame, PLAYER_DR_SEWARD);
- new->vanLoca = getLocation(dragame, PLAYER_VAN_HELSING);
- new->minLoca = getLocation(dragame, PLAYER_MINA_HARKER);
- new->draLoca = getLocation(dragame, PLAYER_DRACULA);
- new->godLife = getHealth (dragame, PLAYER_LORD_GODALMING);
- new->drsLife = getHealth (dragame, PLAYER_DR_SEWARD);
- new->vanLife = getHealth (dragame, PLAYER_VAN_HELSING);
- new->minLife = getHealth (dragame, PLAYER_MINA_HARKER);
- new->draLife = getHealth (dragame, PLAYER_DRACULA);
- new->gameScore = getScore(dragame);
- new->dracMap = newMap();
- new->currPlayer = getCurrentPlayer(dragame);
- disposeGameView(dragame);
- return new;
- }
- // Frees all memory previously allocated for the HunterView toBeDeleted
- void
- disposeHunterView (HunterView toBeDeleted)
- {
- disposeMap(toBeDeleted->dracMap);
- free (toBeDeleted);
- }
- //// Functions to return simple information about the current state of the game
- // Get the current round
- Round
- giveMeTheRound (HunterView hv)
- {
- return hv->roundNumber;
- }
- // Get the id of current player
- PlayerID
- whoAmI (HunterView hv)
- {
- return hv->currPlayer;
- }
- // Get the current score
- int
- giveMeTheScore (HunterView hv)
- {
- return hv->gameScore;
- }
- // Get the current health points for a given player
- int
- howHealthyIs (HunterView hv, PlayerID player)
- {
- if (player == PLAYER_LORD_GODALMING) return hv->godLife;
- if (player == PLAYER_MINA_HARKER) return hv->minLife;
- if (player == PLAYER_VAN_HELSING) return hv->vanLife;
- if (player == PLAYER_DR_SEWARD) return hv->drsLife;
- if (player == PLAYER_DRACULA) return hv->draLife;
- return 0;
- }
- // Get the current location id of a given player
- LocationID
- whereIs (HunterView hv, PlayerID player)
- {
- if (player == PLAYER_LORD_GODALMING) return hv->godLoca;
- if (player == PLAYER_MINA_HARKER) return hv->minLoca;
- if (player == PLAYER_VAN_HELSING) return hv->vanLoca;
- if (player == PLAYER_DR_SEWARD) return hv->drsLoca;
- if (player == PLAYER_DRACULA) return hv->draLoca;
- return 0;
- }
- //// Functions that return information about the history of the game
- // Fills the trail array with the location ids of the last 6 turns
- void
- giveMeTheTrail (HunterView hv, PlayerID player,
- LocationID trail[TRAIL_SIZE])
- {
- // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
- }
- //// Functions that query the map to find information about connectivity
- // What are my possible next moves (locations)
- LocationID *
- whereCanIgo (HunterView hv, int *numLocations,
- bool road, bool rail, bool sea)
- {
- LocationID *b;
- PlayerID currPlayer = hv->currPlayer;
- LocationID from = whereIs(hv, currPlayer);
- b = locationsConnected(hv->dracMap, from, 10, road, rail, sea);
- int connCount = numberOfConnections(hv->dracMap, from, road, rail, sea);
- *numLocations = connCount;
- return b;
- }
- // What are the specified player's next possible moves
- LocationID *
- whereCanTheyGo (HunterView hv, int *numLocations, PlayerID player,
- bool road, bool rail, bool sea)
- {
- LocationID *b;
- LocationID from = whereIs(hv, player);
- b = locationsConnected(hv->dracMap, from, 10, road, rail, sea);
- //int i = 0;
- int connCount = numberOfConnections(hv->dracMap, from, road, rail, sea);
- *numLocations = connCount;
- //LocationID locArr[numLocations];
- // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
- return b;
- *numLocations = 0;
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement