-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVIPCustomer.cpp
More file actions
147 lines (124 loc) · 5.64 KB
/
VIPCustomer.cpp
File metadata and controls
147 lines (124 loc) · 5.64 KB
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
#include "VIPCustomer.h"
#include <iostream>
// VIPCustomer is a child class of CustomerEntity
// Constructor that initializes a VIPCustomer with an ID and a specific position
VIPCustomer::VIPCustomer(std::string fID, Position position)
: tipAmount(0),
CustomerEntity(fID, position, 20, 2000, 150, 30, 30) { // Call the parent class (CustomerEntity) constructor to initialize common attributes
circle.setFillColor(sf::Color(255, 215, 0)); // Golden color
}
// Method to update the Customer's ordering and behaviour over time
void VIPCustomer::update() {
// If the customer is seated and waiting for an appetizer
if (seated && !appetizerOrdered && !waitingForFood) {
// Start the timer for ordering after seating
if (seatedClock.getElapsedTime().asSeconds() >= 5) {
orderAppetizer();
}
}
// If the appetizer is received, now ask for the main course
if (appetizerOrdered && !mainCourseOrdered && !waitingForFood && assignedFood != nullptr) {
// Start asking for the main course after a delay
if (seatedClock.getElapsedTime().asSeconds() >= 5) {
orderMainCourse();
}
}
// If the main course is received, now ask for the dessert
if (mainCourseOrdered && !dessertOrdered && !waitingForFood && assignedFood != nullptr) {
// Start asking for the dessert after a delay
if (seatedClock.getElapsedTime().asSeconds() >= 5) {
orderDessert();
}
}
// If the dessert is received, now ask for champagne
if (dessertOrdered && !champagneOrdered && !waitingForFood && assignedFood != nullptr) {
// Start asking for the dessert after a delay
if (seatedClock.getElapsedTime().asSeconds() >= 5) {
orderChampagne();
}
}
// Check if all courses are completed, mark the meal as finished
if (appetizerOrdered && mainCourseOrdered && dessertOrdered && champagneOrdered && !waitingForFood && assignedFood != nullptr) {
finishMeal();
}
}
// Method to handle the assignment of Food to a Customer and to set appropriate messages
// based on the timing and correctness of the food served
void VIPCustomer::assignFood(Food* food) {
if (food == nullptr) {
std::cerr << "Error: Null food pointer\n" << std::endl;
return;
}
float elapsedTime = foodClock.getElapsedTime().asSeconds();
bool servedOnTime = (elapsedTime <= 5); // the 5 second timer starts when the customer orders the food
// If served On Time && food served is Correct
if (servedOnTime && food->getFoodType() == expectedFoodType) {
fMessage = "IncreaseCurrentHappiness 50";
std::cout << "Customer " << fID << " received correct food within " << elapsedTime << " seconds.\n" << std::endl;
}
// If served Not On Time && food served is Correct
else if (!servedOnTime && food->getFoodType() == expectedFoodType) {
fMessage = "IncreaseCurrentHappiness 25";
std::cout << "Customer " << fID << " received correct food late after " << elapsedTime << " seconds.\n" << std::endl;
}
// If served On Time && food served is Incorrect
else if (servedOnTime && food->getFoodType() != expectedFoodType) {
fMessage = "DecreaseCurrentHappiness 50";
std::cout << "Customer " << fID << " received incorrect food within " << elapsedTime << " seconds.\n" << std::endl;
}
// If served Not On Time && food served is Incorrect
else if (!servedOnTime && food->getFoodType() != expectedFoodType) {
fMessage = "DecreaseCurrentHappiness 75";
std::cout << "Customer " << fID << " received incorrect food late after " << elapsedTime << " seconds.\n" << std::endl;
}
waitingForFood = false;
assignedFood = food; // Assign the food to the customer
seatedClock.restart();
}
// Method to call after customer is done with all the services
void VIPCustomer::finishMeal() {
std::cout << fID << " has finished their meal!\n" << std::endl;
// Call the tip function once the meal is complete
tip();
// Mark the meal as finished
finishedMeal = true;
// Reset the table's availability back to true (available)
if (assignedTable) {
assignedTable->setAvailability(true);
}
else {
std::cout << "Pointer is null " << std::endl;
}
// Clear the table:
seated = false; // Mark the customer as not seated
assignedFood = nullptr; // Clear the assigned food
setPosition(-1000, -1000); // Move the customer off-screen
}
// Method to tip the player
void VIPCustomer::tip() {
// Calculate tipAmount based on 10% of currentHappiness
tipAmount = static_cast<int>(fCurrentHappiness * 0.10); // static_cast is basically to truncate the decimal part of the tipAmount
// Display the tipping message
if (tipAmount > 0) {
std::cout << "VIPCustomer gives a tip of " << tipAmount << " points ~\n";
// Increase player's reputation by the tipAmount
Player* player = Player::getInstance(); // Get the singleton instance of Player
if (player) {
int currentReputation = player->getPlayerReputation();
player->setPlayerReputation(currentReputation + tipAmount);
std::cout << "Customer " << fID << " tipped to the player's reputation by " << tipAmount << "\n" << std::endl;
}
else {
std::cerr << "Error: Unable to access Player instance.\n" << std::endl;
}
}
else {
std::cout << "VIPCustomer is unhappy and gives no tip :(\n";
}
}
void VIPCustomer::complain() {
// VIPCustomer doesn't use this method
}
void VIPCustomer::chitChat() {
// VIPCustomer doesn't use this method
}