Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////////////////
- // COMP2521 18x1 ... the Fury of Dracula
- // DracView.c: the DracView 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 <string.h>
- #include "DracView.h"
- #include "Game.h"
- #include "GameView.h"
- #include "Globals.h"
- #include "Map.h"
- #include <stdio.h>
- #include <stdlib.h>
- #define LINE_LEN 40 //... if you decide to use the Map ADT
- struct dracView {
- 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 DracView to summarise the current state of the game
- DracView
- newDracView (char *pastPlays, PlayerMessage messages[])
- {
- // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
- DracView new = malloc (sizeof *new);
- GameView dragame = newGameView(pastPlays, messages);
- if (new == NULL) err (EX_OSERR, "couldn't allocate DracView)");
- new->dracLife = getHealth(dragame, PLAYER_DRACULA);
- new->dracPlist = pastPlays;
- new->roundNumber = getRound(dragame)-1;
- 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);
- //printf("%d is draculaLoca\n", new->draLoca);
- 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);
- //printf("%d is new->draLife\n", new->draLife);
- new->dracMap = newMap();
- disposeGameView(dragame);
- return new;
- }
- // Frees all memory previously allocated for the DracView toBeDeleted
- void
- disposeDracView (DracView toBeDeleted)
- {
- disposeMap(toBeDeleted->dracMap);
- free (toBeDeleted);
- }
- //// Functions to return simple information about the current state of the game
- // Get the current round
- Round
- giveMeTheRound (DracView dv)
- {
- return dv->roundNumber;
- }
- // Get the current score
- int
- giveMeTheScore (DracView dv)
- {
- // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
- return dv->gameScore;
- }
- // Get the current health points for a given player
- int
- howHealthyIs (DracView dv, PlayerID player)
- {
- if (player == PLAYER_LORD_GODALMING) return dv->godLife;
- if (player == PLAYER_MINA_HARKER) return dv->minLife;
- if (player == PLAYER_VAN_HELSING) return dv->vanLife;
- if (player == PLAYER_DR_SEWARD) return dv->drsLife;
- printf("%d is dralife\n", dv->draLife);
- if (player == PLAYER_DRACULA) return dv->draLife;
- return 0;
- }
- // Get the current location id of a given player
- LocationID
- whereIs (DracView dv, PlayerID player)
- {
- if (player == PLAYER_LORD_GODALMING) return dv->godLoca;
- if (player == PLAYER_MINA_HARKER) return dv->minLoca;
- if (player == PLAYER_VAN_HELSING) return dv->vanLoca;
- if (player == PLAYER_DR_SEWARD) return dv->drsLoca;
- if (player == PLAYER_DRACULA) return dv->draLoca;
- return 0;
- }
- // Get the most recent move of a given player
- void
- lastMove (DracView dv, PlayerID player,
- LocationID *start, LocationID *end)
- {
- /* int i;
- giveMeTheTrail(dv, player, trail);
- end = trail[0];
- for (i = 0; trail[i + 1] != 'UNKNOWN_LOCATION'; i++);
- start = trail[i]; */
- }
- // Find out what minions are placed at the specified location
- void
- whatsThere (DracView dv, LocationID where,
- int *numTraps, int *numVamps)
- {
- *numTraps = 5;
- *numVamps = 6;
- // REPLACE THIS WITH YOUR OWN IMPLEMENTATION
- return;
- }
- //// 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 (DracView dv, PlayerID player,
- LocationID trail[TRAIL_SIZE])
- {
- PlayerMessage messages[LINE_LEN] = { " ", " ", " "};//arbitrary and just a dummy
- GameView batGame = newGameView(dv->dracPlist, messages);
- if (batGame == NULL) err (EX_OSERR, "couldn't allocate DracView)");
- getHistory(batGame, player, trail);//should fill the trail of any player
- }
- //// Functions that query the map to find information about connectivity
- // What are my (Dracula's) possible next moves (locations)
- LocationID *
- whereCanIgo (DracView dv, int *numLocations, bool road, bool sea)
- {
- LocationID *b;
- LocationID from = whereIs(dv, PLAYER_DRACULA);
- b = locationsConnected(dv->dracMap, from, 100, road, 0 , sea);
- int connCount = numberOfConnections(dv->dracMap, from, road, 0 , sea);
- *numLocations = connCount;
- return b;
- }
- // What are the specified player's next possible moves
- LocationID *
- whereCanTheyGo (DracView dv, int *numLocations, PlayerID player,
- bool road, bool rail, bool sea)
- {
- LocationID *b;
- LocationID from = whereIs(dv, player);
- b = locationsConnected(dv->dracMap, from, 100, road, rail, sea);
- //int i = 0;
- int connCount = numberOfConnections(dv->dracMap, from, road, rail, sea);
- *numLocations = connCount;
- return b;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement