Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Object-oriented Programming / 12-Practice-17.05.2022 / ex1
diff options
context:
space:
mode:
Commitff171c3bc508e4a82e2329c550532f60a8be2e38 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-17 21:14:55 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-17 21:14:55 +0300
Files0d6542c85b32a0b439fc540735214e5a8264c051 /Year 1/Object-oriented Programming/12-Practice-17.05.2022/ex1
uni-projects-ff171c3bc508e4a82e2329c550532f60a8be2e38.tar
uni-projects-ff171c3bc508e4a82e2329c550532f60a8be2e38.tar.gz
uni-projects-ff171c3bc508e4a82e2329c550532f60a8be2e38.zip
Parent2a8bf5b484ae5eb05bbaaeaf613089dc4a15f73a (diff)
Added work from today's practice
diff --git a/Year 1/Object-oriented Programming/12-Practice-17.05.2022/ex1/Guest.h b/Year 1/Object-oriented Programming/12-Practice-17.05.2022/ex1/Guest.h
new file mode 100644
index 0000000..1032bbe
--- /dev/null
+++ b/Year 1/Object-oriented Programming/12-Practice-17.05.2022/ex1/Guest.h
@@ -0,0 +1,11 @@
+#include "Player.h"
+
+class Guest : public Player {
+ unsigned demoDuration;
+
+public:
+
+ bool levelUp() {
+ return false;
+ }
+};
diff --git a/Year 1/Object-oriented Programming/12-Practice-17.05.2022/ex1/LoggedInPlayer.h b/Year 1/Object-oriented Programming/12-Practice-17.05.2022/ex1/LoggedInPlayer.h
new file mode 100644
index 0000000..1a33433
--- /dev/null
+++ b/Year 1/Object-oriented Programming/12-Practice-17.05.2022/ex1/LoggedInPlayer.h
@@ -0,0 +1,5 @@
+#include "Player.h"
+
+class LoggedInPlayer : public Player {
+ char password[9]; // 8 chars + '\0'
+};
diff --git a/Year 1/Object-oriented Programming/12-Practice-17.05.2022/ex1/Player.h b/Year 1/Object-oriented Programming/12-Practice-17.05.2022/ex1/Player.h
new file mode 100644
index 0000000..e57eea2
--- /dev/null
+++ b/Year 1/Object-oriented Programming/12-Practice-17.05.2022/ex1/Player.h
@@ -0,0 +1,29 @@
+enum Star {
+ One = 128,
+ Two = 256,
+ Three = 512,
+ Four = 1024,
+ Five = 2048,
+};
+
+class Player {
+protected:
+ int ID;
+ short points;
+ Star star;
+
+public:
+ Player() {
+ ID = 0;
+ points = 0;
+ star = One;
+ }
+ virtual bool levelUp() {
+ bool can = star < Five && points >= (star << 1);
+ if (can) {
+ star = (Star)(star << 1);
+ points -= star;
+ }
+ return can;
+ }
+};
diff --git a/Year 1/Object-oriented Programming/12-Practice-17.05.2022/ex1/PremiumPlayer.h b/Year 1/Object-oriented Programming/12-Practice-17.05.2022/ex1/PremiumPlayer.h
new file mode 100644
index 0000000..0c8e9e1
--- /dev/null
+++ b/Year 1/Object-oriented Programming/12-Practice-17.05.2022/ex1/PremiumPlayer.h
@@ -0,0 +1,15 @@
+#include "LoggedInPlayer.h"
+
+class PremiumPlayer : public LoggedInPlayer {
+ char name[1024];
+
+public:
+ bool levelUp() {
+ bool can = points >= 256;
+ if (can) {
+ points -= 256;
+ star = (Star)(star << 1);
+ }
+ return can;
+ }
+};