-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cpp
157 lines (142 loc) · 3.98 KB
/
Player.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//Julian Worn
//07/17/2023
//Player.cpp
//Source File for the Player Class in the Scheduling system
//for pre/post conditions as well as class/implementation invariants, check header file Player.h
#include "Player.h"
using namespace std;
Player::Player(string n, unsigned lN, string**& a) {
name = n;
lessonNeed = lN;
if (a==nullptr){
a = new string*[7];
for (int i=0; i<7; i++){
a[i] = nullptr;
}
}
practiceSchedule = a;
a = nullptr;
}
Player::Player(string n, unsigned p, unsigned lN, string**& a){
name = n;
priority = p;
if (lN>=7) lN=7;
lessonNeed = lN;
if (a==nullptr){
a = new string*[7];
for (int i=0; i<7; i++){
a[i] = nullptr;
}
}
practiceSchedule = a;
a = nullptr;
}
void Player::copy(const Player& source)
{
name = source.name;
priority = source.priority;
lessonNeed = source.lessonNeed;
lessonReceived = source.lessonReceived;
scheduleFail = source.scheduleFail;
if (source.practiceDays){
practiceDays = new int[7];
for (int i=0; i<7; i++){
practiceDays[i] = source.practiceDays[i];
}
}
if (source.practiceSchedule){
practiceSchedule = new string*[7];
for (int i=0; i<7; i++){
if (source.practiceSchedule[i]){
practiceSchedule[i] = new string[24];
for(int j=0; j<24; j++){
practiceSchedule[i][j] = source.practiceSchedule[i][j];
}
}
else practiceSchedule[i] = nullptr;
}
}
}
Player::Player(shared_ptr<Player>& player) {
if (!player) return;
*this = *player;
}
Player::Player(const Player& source)
{
copy(source);
}
void Player::operator=(const Player& source)
{
if (this == &source) {return;}
if (practiceDays) delete[] practiceDays;
if (practiceSchedule){
for (int i=0; i<7; i++){
delete[] practiceSchedule[i];
}
delete[] practiceSchedule;
}
copy(source);
}
Player::Player(Player&& source)
{
name = source.name;
priority = source.priority;
lessonNeed = source.lessonNeed;
lessonReceived = source.lessonReceived;
scheduleFail = source.scheduleFail;
practiceDays = source.practiceDays;
practiceSchedule = source.practiceSchedule;
source.name = "";
source.priority = 0;
source.lessonNeed = 0;
source.lessonReceived = 0;
source.scheduleFail = false;
source.practiceDays = 0;
source.practiceSchedule = 0;
}
void Player::operator=(Player&& source)
{
swap(name, source.name);
swap(priority, source.priority);
swap(lessonNeed, source.lessonNeed);
swap(lessonReceived, source.lessonReceived);
swap(scheduleFail, source.scheduleFail);
swap(practiceDays, source.practiceDays);
swap(practiceSchedule, source.practiceSchedule);
}
Player::~Player()
{
if (practiceDays) delete[] practiceDays;
if (practiceSchedule){
for (int i=0; i<7; i++){
delete[] practiceSchedule[i];
}
delete[] practiceSchedule;
}
}
string Player::getName(){ return name;}
unsigned Player::getPriority(){ return priority;}
void Player::setPriority(unsigned p) { priority = p;}
void Player::setPracticeSchedule(string**& a){
if (a==nullptr){
a = new string*[7];
for (int i=0; i<7; i++){
a[i] = nullptr;
}
}
practiceSchedule = a;
a = nullptr;
}
string** Player::getPracticeSchedule(){return practiceSchedule;}
unsigned Player::getLessonNeed(){return lessonNeed;}
void Player::decLessonNeed(){lessonNeed --;}
void Player::setLessonNeed(unsigned lN) { lessonNeed = lN;}
void Player::incLessonReceived(){lessonReceived ++;}
int Player::getLessonReceived(){return lessonReceived;}
void Player::lessonAdd(){
incLessonReceived();
decLessonNeed();
}
void Player::setScheduleFail(bool f) {scheduleFail = f;}
bool Player::getScheduleFail() {return scheduleFail;}
int* Player::getPracticeDays() {return practiceDays;}