[Tut] Final Fantasy Encounter Simulator with explainations
I know the spacing gets weird at the bottom. when cutting up blocks with seperate code tags it gets strange.
I posted code in the C++ section. That post describes how old FFs 1-6 calculated when to use randoms.
1. Includes. windows.h for the Sleep and Key functions
ctime and cstdlib for the rand and time functions
2. encounter class
Public contains Set and Get functions, so we can set the rate with a random number(see later)
Get is just so we can see how many we have to go until fight and used later to set a new value for set
Simple get and set functions, you should know what they do.
3. The entry point
int main blah blah you know.
Then we set int tiles to be a random number between 1-23. seed it to time so it wont be pseudo-random
we make an instance(it is an instance, right?) of encounter.
Then we use our set function with the random number 1-23 as the param.
4. The loop.
infinite loop.
Sleep is used so it only checks every 150 ms, enough to tap an arrow key without it registering multiple times.
If statement for the keys..blahblah
We cout the remaining steps with the get functions
and we set to the get functions value - 1 so each key press, it goes down.
5. conclusion. if the get functions value = -1...
we use -1 so the encounter happens when get = 0.
and rest.
I posted code in the C++ section. That post describes how old FFs 1-6 calculated when to use randoms.
1. Includes. windows.h for the Sleep and Key functions
ctime and cstdlib for the rand and time functions
Code:
#include <iostream> #include <windows.h> #include <ctime> #include <cstdlib> using namespace std;
2. encounter class
Public contains Set and Get functions, so we can set the rate with a random number(see later)
Get is just so we can see how many we have to go until fight and used later to set a new value for set
Simple get and set functions, you should know what they do.
Code:
class encounter
{
public:
void SetEncounter(int SE) {cSE = SE;}
int GetEncounter() {return cSE;}
private:
int cSE;
};
3. The entry point
int main blah blah you know.
Then we set int tiles to be a random number between 1-23. seed it to time so it wont be pseudo-random
we make an instance(it is an instance, right?) of encounter.
Then we use our set function with the random number 1-23 as the param.
Code:
int main()
{
srand(time(0));
int tiles = (rand() % 23)+1;
encounter e1;
cout << "Welcome to the Final Fantasy Random Encounter Simulator by Patrick\n";
cout << "Controls: Up, Down, Left, Right Keys\n";
e1.SetEncounter(tiles);
infinite loop.
Sleep is used so it only checks every 150 ms, enough to tap an arrow key without it registering multiple times.
If statement for the keys..blahblah
We cout the remaining steps with the get functions
and we set to the get functions value - 1 so each key press, it goes down.
Code:
while(1)
{
Sleep(150);
if ((GetAsyncKeyState(VK_UP)) || (GetAsyncKeyState(VK_DOWN)) || (GetAsyncKeyState(VK_LEFT)) || (GetAsyncKeyState(VK_RIGHT))) //<3
{
cout << e1.GetEncounter() << " steps until a fight\n";
e1.SetEncounter(e1.GetEncounter()-1);
we use -1 so the encounter happens when get = 0.
and rest.
Code:
if(e1.GetEncounter() == -1)
{
cout << "Fight! Press Enter";
cin.get();
cout << "You died. Game over\n";
return 0;
}
}
}
return 0;
}



