]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Added quests
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 8 Sep 2015 21:01:40 +0000 (17:01 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 8 Sep 2015 21:01:40 +0000 (17:01 -0400)
Makefile
include/Quest.h [new file with mode: 0644]
src/Quest.cpp [new file with mode: 0644]

index d2fe513ecd748d06e04f02550bf6529396bccda8..13a7119654c4d3a39d14bcbb0d0a96f6bedf6e25 100644 (file)
--- 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 (file)
index 0000000..169124e
--- /dev/null
@@ -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 (file)
index 0000000..52ab3a8
--- /dev/null
@@ -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;
+}