So, here I am again, with my mass of code, albeit with more progress.
It's still got a long way to go, and I'm still not that good at coding, but man oh man have I learned a lot through this game.
I come with a few more questions than last time.
So to get to my first problem, You have to go to Select Character -> Create Character -> Enter Name -> Use all skill points. The problem is that it doesn't use all of the skill points. Any suggestions? (This is the setStats function, by the way)
And then another problem with that, is I can't really come up with a good way to end that loop - I was thinking maybe a finish selection(but I couldn't figure a way to implement that). Anything on this one either?
Also, I'm curious about how other people think I should go about adding spells/items to Character's class.
Another topic I'm curious of is how would I write/read creatures to/from files(say for saved characters).
The last one is I can't think of a good way other than an if statement per character in order to make them the character the player will use (unless I overload my select function).
The full program:
//RPG Game
#include <iostream>
#include <windows.h>
#include <string>
#include <conio.h>
#include <vector>
#include <dos.h>
#include <ctime>
#include <iomanip>
#include <sstream>
#include <fstream>
using namespace std;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
static string selection;
const int LINE_LENGTH = 75;
unsigned int srand();
void slowText(char c[]){
int len = strlen(c);
for(int i=0; i < len;i++) {
putchar(c[i]);
Sleep(30);
}
}
void hL(string s){
int highLight = 240;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, highLight);
cout << s << setw(10);
int nonHighLight = 15;
SetConsoleTextAttribute(hConsole, nonHighLight);
}
void nHL(string s){
int nonHighLight = 15;
SetConsoleTextAttribute(hConsole, nonHighLight);
cout << s << setw(10);
}
void bS(){
int blankSpace = 0;
SetConsoleTextAttribute(hConsole, blankSpace);
cout << " " << setw(3);
SetConsoleTextAttribute(hConsole, 15);
}
void borderDown()
{
const char o = 209;
for (int i = 0; i < LINE_LENGTH; i++)
cout << o;
cout << endl;
}
void borderUp()
{
const char o = 207;
for (int i = 0; i < LINE_LENGTH - 2; i++)
cout << o;
cout << endl;
}
void select(string s){
hL(s);
selection = s;
}
class Creature{
private:
int statArr[6];
string name;
public:
Creature(){
rollStats();
name = "Ciziten";
}
void rollStats()
{
int iniStat[4];
int temp = 6;
for(int i = 0; i < 6; i++){
for(int q = 0; q < 4; q++)
{
iniStat[q] = rand() % 6;
if(temp > iniStat[q]){temp = iniStat[q];}
}
statArr[i] = iniStat[0] + iniStat[1] + iniStat[2] + iniStat[3] - temp;
}
}
void setStats()
{
char a;
int y = 0;
stringstream ss;
int limit = 40;
vector<int> stat(6, 1);
vector<string> stats(6);
stats[0] = ("Strength");
stats[1] = ("Stamina");
stats[2] = ("Dexterity");
stats[3] = ("Willpower");
stats[4] = ("Intellect");
stats[5] = ("Luck");
stats.push_back("Finish");
for(char a = 'q'; a != ' ';)
{
if(a == 's' || a == 'S')
{
y += 1;
if(y < 0){y = (stats.size() - 1);}
}
if(a == 'w' || a == 'W')
{
y -= 1;
if(y > (stats.size() - 1)){y = 0;}
}
if(a == 'a' || a == 'A')
{
if(0 < (stat[y] - 1))
{
limit += 1;
stat[y] -= 1;
}
}
if(a == 'd' || a == 'D')
{
if(limit > (stat[y] - 1))
{
limit -= 1;
stat[y] += 1;
}
}
system("cls");
cout << endl << endl;
cout << "Name: " << name;
cout << endl << endl;
cout << "Now you must pick your attributes." << endl;
borderDown();
for (int j = 0; j < 6; j++)
{
bS();
cout << stats[j];
if(y == j){
cout << " : <" << stat[j] << ">" << endl;
}
else
{
cout << " : " << stat[j] << endl;
}
}
borderUp();
cout << "Amount of attribute points left to spend: " << limit;
a = getch();
}
}
void setName()
{
cin >> name;
cin.clear();
}
void viewName()
{
cout << name;
}
void viewStats()
{
for(int i = 0; i < 6; i++)
{
cout << statArr[i] << endl;
}
}
};
int main()
{
vector<Creature> characters;
Creature player;
string menuType;
int menu = 0;
char a ='q';
string hint;
vector<vector<string>> menOp(2, vector<string> (2));
int x = 0;
int y = 0;
int num = 0;
string displayTextBefore = "";
string displayTextAfter = "";
for(bool endgame = 1; endgame != 0;)
{
switch(menu)
{
case 0:
menuType = " |Main Menu|";
menOp[0][0] = "Start Game";
menOp[0][1] = "Game Options";
menOp[1][0] = "Select Character";
menOp[1][1] = "Exit";
hint = "W, A, S, D are to move and space to select";
break;
case 1:
menuType = " |Options Menu|";
menOp[0][0] = "Controls";
menOp[0][1] = "Color Scheme";
menOp[1][0] = "About";
menOp[1][1] = "Back";
hint = "Options are cool.";
break;
case 2:
menuType = " |Character Menu|";
menOp[0][0] = "Select Character";
menOp[0][1] = "Create Character";
menOp[1][0] = "Character Guide";
menOp[1][1] = "Back";
hint = "Dont have time to make a character? Use a prebuilt.";
break;
case 3:
menuType = " |!!!|";
menOp[0][0] = "Yes";
menOp[0][1] = "No";
hint = "Exit, if you must.";
break;
case 4:
menuType = " |Character Creation|";
menOp[0][0] = "Select Character";
menOp[0][1] = "Create Character";
menOp[1][0] = "Character Guide";
menOp[1][1] = "Back";
hint = "Dont have time to make a character? Use a prebuilt.";
break;
case 5:
menuType = " |Character|";
menOp[0][0] = "Enter Name";
menOp[0][1] = "Choose Stats";
menOp[1][0] = "Character Guide";
menOp[1][1] = "Back";
hint = "Dont have time to make a character? Use a prebuilt.";
break;
}
for(char a = 'q'; a != ' ';)
{
system("cls");
cout << x << "," << y;
if(a == 'd' || a == 'D')
{
y += 1;
if(y > (menOp.at(0).size() - 1)){y = 0;}
}
if(a == 's' || a == 'S')
{
x -= 1;
if(x < 0){x = (menOp.size() - 1);}
}
if(a == 'a' || a == 'A')
{
y -= 1;
if(y < 0){y = (menOp.at(0).size() - 1);}
}
if(a == 'w' || a == 'W')
{
x += 1;
if(x > (menOp.size() - 1)){x = 0;}
}
SetConsoleTextAttribute(hConsole, 15);
cout << endl << endl;
cout << displayTextBefore << endl << endl;
cout << " " << menuType << endl;
borderDown();
for (int i = 0; i < menOp.size(); i++)
{
for (int j = 0; j < menOp.at(0).size(); j++)
{ bS();
if(x == i && y == j){
select(menOp[i][j]);
}
else{nHL(menOp[i][j]);}
}
bS();
cout << endl;
}
borderUp();
cout << "Hint: " << hint;
cout << endl;
cout << displayTextAfter << endl;
a = getch();
}
if(selection == "Start Game"){cout << "Game Started";
system("pause");
}
if(selection == "Game Options"){menu = 1;}
if(selection == "Back" && menu == 1){menu = 0;}
if(selection == "Select Character"){menu = 2;}
if(selection == "Create Character")
{
int nameSet = 0;
for(bool charCreated = 0; charCreated != 1;)
{
if(nameSet != 1){
cout << "Reports show your name isn't in our records.\n Now what might it be? : ";
player.setName();
nameSet = 1;
}
else
{
player.viewName();
cout << endl;
}
player.setStats();
}
}
if(selection == "Back" && menu == 2){menu = 0;}
if(selection == "Exit")
{
menu = 3;
x = 0;
y = 0;
menOp.resize(1);
}
if(selection == "Yes" && menu == 3){
endgame = 0;
}
if(selection == "No" && menu == 3){
menu = 0;
menOp.resize(2);
menOp.at(1).push_back("DEFAULT");
menOp.at(1).push_back("DEFAULT");
}
}
system("pause");
return 0;
}