Adding into J++ (jfw)

Status
Not open for further replies.

Adil

DevBest CEO
May 28, 2011
1,276
714
Hi. Today I'll be explaining how to add a simple quest prelude into J++ (jfw). First, open your favourite code editor or IDE. (Notepad++, Visual Studio (C++), Bluefish or GEdit is recommended).
Now, create a new file in your J++ 'core' directory. Name this file "quest1.cpp"
Now, we'll start coding. The most important lines of code are the following:
Code:
#include "Library.h" //this include includes the necessary header files to function.

bool questchoice(PLAYER* player); //this will be added into your global file.
Next, add these lines of code:
Code:
{
 int choice = 0; //declaring your choice variable

while (choice != 2); // this line means "while choice is not equal to 2"
{
cout << "What would you like to do?\n"; //displaying a line to the terminal/console
cout << "1: Carry on\n";
cout << "2: Stay and refuel\n";
 
cin >> choice //remembering the choice player made.
cin.clear();
cin.ignore(INT_MAX,'\n');
cout << endl;

Great! Now, let's add these lines:
[CODE]
switch (choice) //switch casing for the choice.
{
case 1:
{
cout << "You decide to carry on with your quest\n";
cin.get(); //press enter
Quest(); //calling the quest
break;
}
case 2:
{
cout << "You choose to stay\n";
cin.get();
cout << "\n(HP and MP restored)\n\n";
player->SetHealth(player->GetMaxHealth()); //calling the max health function
player->SetMana(player->GetMaxMana()); //calling the max mana function
Wait(); //returning to the crossroads.
}
default: break; //default choice
}
}
}
We're not done yet. You need to add the 'bool questchoice(PLAYER* player)' line to your globals.h file.
Locate your globals.h file, which should be found under the core folder.
It should look like this:
Code:
#ifndef GLOBAL_DEFINE
#define GLOBAL_DEFINE
// PROTOTYPES
void Wait();
void DisplayStats(PLAYER*);
bool Battle(PLAYER*,MONSTER*,int);
bool Crossroads();
bool Town(PLAYER*);
bool ArbekVillage(PLAYER*);
void DemonicQuest(PLAYER*);
bool SummonPortal(PLAYER*,int);
#endif
Add:
Code:
bool questchoice(PLAYER* player)
under the SummonPortal line.
The last part would be:
1. Editing the 'while (choice != 6)' to != 7
2. Adding a 7th case in, which points toward the questchoice.
Code:
case 7:
{
questchoice(&player);
break;
}
This should work. Please post any problems here. (Made in a short time)
 
Status
Not open for further replies.

Users who are viewing this thread

Top