aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2015-09-08 17:01:40 -0400
committerClyne Sullivan <tullivan99@gmail.com>2015-09-08 17:01:40 -0400
commit60c7924097814686a2fb826b87fd7a3e1ff684de (patch)
tree3fd2c80bacf521960cbebcf48707c05c1bf0904e
parent51e40764ce718283c89422cd5e3d02d324c7d16c (diff)
Added quests
-rw-r--r--Makefile2
-rw-r--r--include/Quest.h30
-rw-r--r--src/Quest.cpp64
3 files changed, 95 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index d2fe513..13a7119 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ FLAGS_WIN32 = -lopengl32 -lmingw32 #-lSDL2_Image
FLAGS = -m32 -Iinclude -Wall -Werror -lSDL2main -lSDL2
all:
- @g++ src/main.cpp src/UIClass.cpp -o main $(FLAGS_LINUX) $(FLAGS)
+ @g++ src/main.cpp src/UIClass.cpp src/Quest.cpp -o main $(FLAGS_LINUX) $(FLAGS)
win32:
@g++ -L lib/ src/main.cpp src/UIClass.cpp -o main.exe $(FLAGS_WIN32) $(FLAGS)
diff --git a/include/Quest.h b/include/Quest.h
new file mode 100644
index 0000000..169124e
--- /dev/null
+++ b/include/Quest.h
@@ -0,0 +1,30 @@
+#ifndef QUEST_H
+#define QUEST_H
+
+#include <cstdlib>
+#include <cstring>
+
+#define QUEST_LIMIT 5
+#define TOTAL_QUESTS 1
+
+class Quest {
+public:
+ char *title,*desc;
+ unsigned int xp;
+ Quest();
+ Quest(const char *t,const char *d,unsigned int x);
+ ~Quest();
+};
+
+class QuestHandler {
+private:
+ unsigned char ccnt;
+ Quest *current[QUEST_LIMIT];
+public:
+ QuestHandler();
+ int assign(const char *t);
+ int drop(const char *t);
+ int finish(const char *t);
+};
+
+#endif // QUEST_H
diff --git a/src/Quest.cpp b/src/Quest.cpp
new file mode 100644
index 0000000..52ab3a8
--- /dev/null
+++ b/src/Quest.cpp
@@ -0,0 +1,64 @@
+#include <Quest.h>
+
+Quest QuestList[TOTAL_QUESTS]={
+ Quest("Test","A test quest",0)
+};
+
+Quest::Quest(){
+}
+Quest::Quest(const char *t,const char *d,unsigned int x){
+ size_t len;
+ title=(char *)malloc((len=strlen(t)));
+ strncpy(title,t,len);
+ desc=(char *)malloc((len=strlen(d)));
+ strncpy(desc,d,len);
+ xp=x;
+}
+Quest::~Quest(){
+ free(title);
+ free(desc);
+ xp=0;
+}
+
+QuestHandler::QuestHandler(){
+ ccnt=0;
+}
+int QuestHandler::assign(const char *t){
+ unsigned int i=0;
+ if(ccnt==QUEST_LIMIT)
+ return -1;
+ for(;i<TOTAL_QUESTS;i++){
+ if(!strcmp(QuestList[i].title,t)){
+ current[ccnt++]=&QuestList[i];
+ return ccnt;
+ }
+ }
+ return -1;
+}
+int QuestHandler::drop(const char *t){
+ unsigned char i=0;
+ for(;i<ccnt;i++){
+ if(!strcmp(current[i]->title,t)){
+ for(i++;i<ccnt;i++){
+ current[i-1]=current[i];
+ }
+ return (--ccnt);
+ }
+ }
+ return -1;
+}
+int QuestHandler::finish(const char *t){
+ unsigned char i=0;
+ unsigned int j;
+ for(;i<ccnt;i++){
+ if(!strcmp(current[i]->title,t)){
+ j=current[i]->xp;
+ for(i++;i<ccnt;i++){
+ current[i-1]=current[i];
+ }
+ ccnt--;
+ return j;
+ }
+ }
+ return -1;
+}