Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Object-oriented Programming / 06-Practice-05.04.2022 / Player.cpp
diff options
context:
space:
mode:
Commit2cf8d711c3dd110555c16913941f865841aa3175 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-04-06 08:40:07 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-04-06 08:40:07 +0300
Filesf9822151e8c05911cc6919e7a8a9c4daee1e929a /Year 1/Object-oriented Programming/06-Practice-05.04.2022/Player.cpp
uni-projects-2cf8d711c3dd110555c16913941f865841aa3175.tar
uni-projects-2cf8d711c3dd110555c16913941f865841aa3175.tar.gz
uni-projects-2cf8d711c3dd110555c16913941f865841aa3175.zip
Parente9f62e28a4de3f9051da9b437bd6130328de2d90 (diff)
Fixed folder naming from yesterdays oop practice
1 files changed, 0 insertions, 103 deletions
-rw-r--r--Year 1/Object-oriented Programming/06-Practice-05.04.2022/Player.cpp103
diff --git a/Year 1/Object-oriented Programming/06-Practice-05.04.2022/Player.cpp b/Year 1/Object-oriented Programming/06-Practice-05.04.2022/Player.cpp
deleted file mode 100644
index eaca839..0000000
--- a/Year 1/Object-oriented Programming/06-Practice-05.04.2022/Player.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-#include "Player.h"
-#include <cstring>
-
-/* Private */
-
-void Player::copyFrom(const Player& other) {
- this->name = new char[strlen(other.name) + 1];
- strcpy(this->name, other.name);
- this->pass = new char[strlen(other.pass) + 1];
- strcpy(this->pass, other.pass);
- this->age = other.age;
- this->balance = other.balance;
-}
-
-void Player::free() const {
- delete[] this->name;
- delete[] this->pass;
-}
-
-bool Player::isValidPassword(const char* passwordAttempt) {
- return strcmp(this->pass, passwordAttempt) == 0;
-}
-
-/* Public */
-
-Player::Player(const char* name, const char* pass, unsigned age, double currentBalance) {
- this->name = new char[strlen(name) + 1];
- strcpy(this->name, name);
- this->pass = new char[strlen(pass) + 1];
- strcpy(this->pass, pass);
- this->age = age;
- this->balance = balance;
-}
-
-Player::Player(const Player& other) {
- this->copyFrom(other);
-}
-
-Player& Player::operator=(const Player& other) {
- if (this != &other) {
- this->free();
- this->copyFrom(other);
- }
- return *this;
-}
-
-Player::~Player() {
- this->free();
-}
-
-const char* Player::get_name() const {
- return this->name;
-}
-bool Player::set_name(const char* password, const char* name) {
- if (!this->isValidPassword(password))
- return false;
-
- delete[] this->name;
- this->name = new char[strlen(name) + 1];
- strcpy(this->name, name);
- return true;
-}
-
-bool Player::set_password(const char* password, const char* newPassword) {
- if (!this->isValidPassword(password))
- return false;
-
- delete[] this->pass;
- this->pass = new char[strlen(newPassword) + 1];
- strcpy(this->pass, newPassword);
- return true;
-}
-
-unsigned Player::get_age() const {
- return this->age;
-}
-bool Player::set_age(const char* password, unsigned value) {
- if (!this->isValidPassword(password))
- return false;
-
- this->age = value;
- return true;
-}
-
-double Player::get_balance() const {
- return this->balance;
-}
-
-bool Player::addToBalance(const char* password, double value) {
- if (!this->isValidPassword(password))
- return false;
-
- this->balance += value;
- return true;
-}
-
-bool Player::deductFromBalance(const char* password, double value) {
- if (!this->isValidPassword(password))
- return false;
-
- this->balance -= value;
- return true;
-}