I recently finished CS206 on Westwood Online. I had to scale way back from the original vision of said program. This was to be a simple text-based RPG.
In all reality the end result was indeed a textbased RPG, just not a very good one. As you can see from the original flowcharts it was sort of the text based equivalent of Diablo.
The end result was very far from what was listed here.
The project somehow managed to get a 599 out of 600 despite being coded in a rather messy and inconsistent manner.
for example:
versus later in the same program…
- //user Variable Data
- string playerName;
- int playerLevel = 1;
- playClass playerClass;
- playRace playerRace;
- int playerSTR=0;
- int playerINT=0;
- int playerDEX=0;
- int maxHP;
- int playerHP;
- int potionCount;
- int playerGold;
- int playerXP;
- int xpLevel;
- int playerLocation=0;
- bool mainGameLoop = true;
- const int MONSTERCOUNT = 6;
- struct monsterStruct
- {
- string monstername;
- int hitpoints;
- int attack;
- int xpValue;
- int goldValue;
- };
The bottom struct is a lot cleaner, and ties all the necessary data into one variable.
I’d show you my menu code, but all mortal men who lay eyes upon that mess will surely go mad!
what I can also show you though is my loadMonsters function.
- void loadMonsters()
- {
- int i;
- string strTest;
- ifstream monsterFile;
- monsterFile.open("Monsters.txt");
- for(i=0; i<MONSTERCOUNT;i++){
- getline(monsterFile,monsters[i].monstername);
- monsterFile >> monsters[i].hitpoints;
- monsterFile >> monsters[i].attack;
- monsterFile >> monsters[i].xpValue;
- monsterFile >> monsters[i].goldValue;
- getline (monsterFile,strTest);// Why did this fix the glitch????????
- }
- monsterFile.close();
- }
you may notice the second getline on the bottom… what data is it reading into strTest? NOTHING. for some reason on the next loop the getline was reading an empty string, but by placing that one down there, it somehow fixes it and makes sure on the next iteration of the loop the data is read properly, how? I have no idea but hey, it worked!
You can download the source code which requires visual studio 2008. You can also download the Release Version which should work on all windows PCs.
No comments:
Post a Comment