This is how the in-game menu will look like, I have added just three functions.
1) Fight an enemy so the character can level up
2) See your character's Information (level,gold,health etc...)
3) Save your progress and exit the game
You can add others if you want...
Function 3) is the only one working for now and this is the
Source Code:
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
void new_game(char name[40]);
void fight(int r_p,int b_p,int hp,int mp,int gold,int level);
void show_info(int r_p,int b_p,int hp,int mp,int gold,int level);
void save(int r_p,int b_p,int hp,int mp,int gold,int level,char name[40]);
int main()
{
cout << "\t \t Welcome to My-Game!" << endl;
cout << "\t Please choose one of the options below: " << endl;
cout << "\t 1)New Game " << endl;
cout << "\t 2)Load Game " << endl;
cout << "\t 0)Exit " << endl << endl;
cout << "Choice: ";
int answer=0;
cin >> answer;
char name[40];
if (answer == 1)
{
system("cls");
cout << "\t Please Type in your character's Name (Max. 40 chars)" <
new_game(name);
}
else if (answer == 0)
{
return 0;
}
else if (answer == 2)
{
system("cls");
cout << "\t Please Type in your character's Name" <
}
int r_p,b_p,hp,mp,gold,level;
ifstream file;
file.open(name);
file >> r_p >> b_p >> hp >> mp >> gold >> level;
cout << r_p << " " << b_p << " " << hp << " " << mp << " " << gold << " " << level;
while (1)
{
system("cls");
cout << "\t " << name << endl;
cout << " What do you want to do now?" << endl << " 1) Fight \n 2) See Info \n 0)Save & Exit" << endl;
cin >> answer;
if (answer == 1)
{
fight(r_p,b_p,hp,mp,gold,level);
}
else if (answer == 2)
{
show_info(r_p,b_p,hp,mp,gold,level);
}
else if (answer == 0)
{
save(r_p,b_p,hp,mp,gold,level,name);
return 0;
}
}
return 0;
}
void new_game(char name[40])
{
ofstream file;
file.open(name);
file << "1 1 100 100 250 1"; //r potions,blue potions,hp,mp,gold,lvl
file.close();
return;
}
void save(int r_p,int b_p,int hp,int mp,int gold,int level,char name[40])
{
ofstream file;
file.open(name);
file << r_p << " " << b_p << " " << hp << " " << mp << " " << gold << " " << level << endl;
file.close();
return;
}
void fight(int r_p,int b_p,int hp,int mp,int gold,int level)
{
return;
}
void show_info(int r_p,int b_p,int hp,int mp,int gold,int level)
{
return;
}
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου