As you can see there have been some changes on some functions...
Now the player is able to see his character's info from the menu...
Along with some other minor changes so that the program can be easier to be modified later on.
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,char name[40]);
void show_info(int r_p,int b_p,int hp,int mp,int gold,int level,char name[40]);
void save(int r_p,int b_p,int hp,int mp,int gold,int level,char name[40]);
bool menu(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=0,b_p=0,hp=0,mp=0,gold=0,level=0;
ifstream file;
file.open(name);
file >> r_p >> b_p >> hp >> mp >> gold >> level;
file.close();
bool close = false;
while (close == false) {close = menu(r_p,b_p,hp,mp,gold,level,name);}
return 0;}
bool menu(int r_p,int b_p,int hp,int mp,int gold,int level,char name[40]){
bool close = false;
int answer=0;
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,name);
}
else if (answer == 2)
{
show_info(r_p,b_p,hp,mp,gold,level,name);
}
else if (answer == 0)
{
save(r_p,b_p,hp,mp,gold,level,name);
close=true;
}
return close;
}
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,char name[40]){
return;
}
void show_info(int r_p,int b_p,int hp,int mp,int gold,int level,char name[40]){
system("cls");
cout << "\t " << name << endl;
cout << "You are " << level << " level(s)." << endl;
cout << "HP: " << hp << "/100" << endl;
cout << "MP: " << mp << "/100" << endl;
cout << "You have:\n" << r_p << " red potion(s)\n" << b_p << " blue potion(s)" << endl;
cout << "You have: " << gold << " gold coins." << endl;
system("pause");
return;
}
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου