-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.cpp
108 lines (97 loc) · 2.75 KB
/
game.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
Author: Gabrielle Niamat
Description: Implementation of Game class. Responsible for populating a JSON object representing a game match.
Date: Feb 6, 2023
*/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "json.hpp"
#include "request.hpp"
#include "game.hpp"
using namespace std;
using json = nlohmann::json;
/*
Name: Game constructor
Description: The Game class's constructor method
Parameters: None
Return: None
*/
Game::Game(){};
/*
Name: Game destructor
Description: The Game class's destructor method. Allows deallocation of used memory.
Parameters: None
Return: None
*/
Game::~Game(){};
/*
Name: setHomeScore method
Description: The Game class's setHomeScore method. Takes in an integer value and populates JSON object and class variable.
Parameters: int score: a number representing the home team's final score
Return: Void
*/
void Game::setHomeScore(int score)
{
// populate appropriate field in dictionary
gameDictionary["homeScore"] = score;
homeScore = score;
};
/*
Name: setAwayScore method
Description: The Game class's setAwayScore method. Takes in an integer value and populates JSON object and class variable.
Parameters: int score: a number representing the away team's final score
Return: Void
*/
void Game::setAwayScore(int score)
{
gameDictionary["awayScore"] = score;
awayScore = score;
};
/*
Name: setHomeName method
Description: The Game class's setHomeName method. Takes in an string memory address and populates JSON object and class variable.
Parameters: const string &name: a string representing the home team's name
Return: Void
*/
void Game::setHomeName(const string &name)
{
gameDictionary["homeName"] = name;
homeName = name;
};
/*
Name: setAwayName method
Description: The Game class's setAwayName method. Takes in an string memory address and populates JSON object and class variable.
Parameters: const string &name: a string representing the away team's name
Return: Void
*/
void Game::setAwayName(const string &name)
{
gameDictionary["awayName"] = name;
awayName = name;
};
/*
Name: printGame method
Description: The Game class's printGame method. Verifies that all 4 match variables have been initialized and then prints out the match data.
Parameters: None
Return: Void
*/
void Game::printGame()
{
// check if all data variables have been initialized
if (homeName != "" && awayName != "" && homeScore != -1 && awayScore != -1)
{
cout << homeName << " vs. " + awayName << " : " << homeScore << " - " << awayScore << endl;
}
};
/*
Name: getJSONObj method
Description: The Game class's getJSONObj method. Returns the populated JSON object containing all 4 data fields.
Parameters: None
Return: json object
*/
json Game::getJSONObj()
{
return gameDictionary;
};