Advice for my game.

closed account (23h0pfjN)
http://pastebin.com/9UnCPPW3


Here is the code i realy would like some advice what should i make in this game?
I know its short but still i hope you will give me some ideas to put into this game.
What do you have different strings getHelp, getStatus, ect. if you use them all interchangeably?
closed account (23h0pfjN)
Could you explain it a bit more i cant understand?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    string getStats;
    string getLoot;
//...
    string getHelp;
    string Aselection;

//...

    cout << "Your selection: ";
    cin >> getHelp;
    if(getHelp=="/help"){
        help();
    }
    if(getHelp=="/con"){}

//...

    cout << "To see your stats write in /stats." << endl;
    Sleep(2500);
    cin >> getStats;
    if(getStats == "/stats"){
        stats(HP, atk, def, str, inte);
    }
    if(getStats == "/con"){}

//...

    cout << "You could loot it white the command: /loot" << endl;
    cin >> getLoot;
    if(getLoot == "/loot"){
        lootdef("dress", def);
    }
    if(getLoot == "/con"){}

//...

    cout << "Write the number of your choise: ";
    cin >> getSelection;
    if(getSelection == 1){
        Skebattle(HP, atk, def, "Skeleton");
    }
    if(getSelection == 2){
        RunAway();
        cout << "You have no choice, you must attack" << endl;
        Skebattle(HP, atk, def, "Skeleton");
    }

//...

    cout << "If you want to look the skeleton, write /loot" << endl;
    cin >> getLoot;
    if(getLoot=="/loot"){
        lootatk("short sword", atk);
        cout << "You got +25 xp" << endl;
        cin >> getLoot;
        if(getLoot=="/equip"){
            lootatk("short sword", atk);
        }
    }
    if(getLoot=="/con"){}


You use all of them the same way, you only need one string, so why do you have four strings to do one thing?
Last edited on
closed account (23h0pfjN)
Ok i get that, i just liked that it was easy to read and modify.
closed account (23h0pfjN)
Anymore interestings i could add?
You've made this very hard to add things. Better to break things into pieces. I'm going to focus on one function: levelUp(). First off, you aren't using it correctly, but here we go:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Functions to return numbers
double getNum(){
  double num;
  while (!(cin >> num){
    cin.clear(); cin.ignore(80, '\n');
    cout << "Numbers Only.  Try Again: ";
  }
  cin.ignore(80,\n);
  return num;
}
int getInt();
  double num;
  do {
    num = getNum();
    if (num != static_cast<int>(num)) cout << "Integers Only.  Try again: ";
  } while  (num != static_cast<int>(num));
  return static_cast<int>(num);
}
int getIntInRange(int low, int high){
  int num;
  do {
  num = getInt();
  if (num < low || num > high) cout << "Not a Valid Choice.  Try Again: ";
  }
  while (num < low || num > high);
  return num;
}

// Level Up Function
int levelUp(string abilities[], const int SIZE){
  cout << "You can chose 1 out of these traits:" << endl;
  for (int i = 0; i < SIZE; i++) cout << i + 1 << ": " << abilities[i] << endl;
  cout << "Now type the number of your choice:";
  return getIntInRange(1, SIZE);
}

int main(){
  const int SIZE_ABILITIES = 3;
  string abilities[SIZE_ABILITIES] = {"Strength", "Intelligence", "Dexterity"};
  int playerStats[SIZE_ABILITIES] = {15, 14, 17};
  
  int choice = levelUp(abilities, SIZE_ABILITIES);
  playerStats[choice - 1]++;

  //  You actually don't need "choice" at all
  // playerStats[levelUp(abilities, SIZE_ABILITIES) - 1]++;
  return 0;
}  


Now, to add an ability, all you have to do is increase SIZE_ABILITY, and then add a value to the two arrays.

Edit: Now you've got me thinking..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Include the other functions

void printOptions(string options[], int SIZE){
  cout << "Your Options:" << endl;
  for (int i =0;i <SIZE; i++) cout << i + 1 << ": " << options[i] << endl;
}

void printStats(string abilities[], int playerStats[], int SIZE){
  cout << "Player Stats:" << endl;
  for (int i = 0; i < SIZE; i++) cout << "\t" << abilities[i] << ": " << playerStats << endl;
}

int main(){
  const int SIZE_ABILITIES = 3, SIZE_OPTIONS = 3;
  string options[SIZE_OPTIONS] = {"Print Stats", "Level Up", "Quit");
  string abilities[SIZE_ABILITIES] = {"Strength", "Intelligence", "Dexterity"};
  int playerStats[SIZE_ABILITIES] = {15, 14, 17};

  
  
  int choice;
  do {
    
    printOptions(options, SIZE_OPTIONS);
    cout << "Please make a choice: ";
    choice = getIntInRange(1, SIZE_OPTIONS);

    switch (choice){
    case 1: printStats(abilities, playerStats, SIZE_ABILITIES); break;
    case 2: playerStats[levelUp(abilities, SIZE_ABILITIES) - 1]++; break;
    case 3: break;
    deafult: cout << "Invalid Choice"; // Though you never get here
    }
  } while (choice != SIZE_OPTIONS);
  cout << "Thanks for playing.  Hit enter to quit."; cin.get();


  return 0;
}



Edit: Actually compiling this, I found a few bugs. Nothing too serious, a ";" here, a ")" there.


Edit: Sorry board :), this is as pretty as I'm going to go :).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

double getNum();
int getInt();
int getIntInRange(int low, int high);
int levelUp(string abilities[], const int SIZE);
void printOptions(string options[], int SIZE);
void printStats(string abilities[], int playerStats[], const int SIZE);
int getLongestSrting(string str[],const int SIZE);
void printWelcome();

int main(){
	const int SIZE_ABILITIES = 4, SIZE_OPTIONS = 3;
	string options[SIZE_OPTIONS] = {"Print Stats", "Level Up", "Quit"};
	string abilities[SIZE_ABILITIES] = {"Strength", "Intelligence", "Dexterity", "Charisma"};
	int playerStats[SIZE_ABILITIES] = {15, 14, 17, 12};  



	int choice;
	
	printWelcome();
	do {
		printOptions(options, SIZE_OPTIONS);
		cout << "Please make a choice: ";
		choice = getIntInRange(1, SIZE_OPTIONS);
		cout << endl;
		switch (choice){
		case 1: printStats(abilities, playerStats, SIZE_ABILITIES); break;
		case 2: playerStats[levelUp(abilities, SIZE_ABILITIES) - 1]++; break;
		case 3: break;
		default: cout << "Invalid Choice"; // Though you never get here
		}
		cout << endl;
	} while (choice != SIZE_OPTIONS);
	cout << "Thanks for playing.  Hit enter to quit."; cin.get();


	return 0;
}

void printWelcome(){
	cout << "\t\tWelcome to my game :)\n\n";
}
double getNum(){
	double num;
	while (!(cin >> num)){
		cin.clear(); cin.ignore(80, '\n');
		cout << "Numbers Only.  Try Again: ";
	}
	cin.ignore(80,'\n');
	return num;
}
int getInt(){
	double num;
	do {
		num = getNum();
		if (num != static_cast<int>(num)) cout << "Integers Only.  Try again: ";
	} while  (num != static_cast<int>(num));
	return static_cast<int>(num);
}
int getIntInRange(int low, int high){
	int num;
	do {
		num = getInt();
		if (num < low || num > high) cout << "Not a Valid Choice.  Try Again: ";
	}
	while (num < low || num > high);
	return num;
}
int levelUp(string abilities[], const int SIZE){
	cout << "You can chose 1 out of these traits:" << endl;
	for (int i = 0; i < SIZE; i++) cout << i + 1 << ": " << abilities[i] << endl;
	cout << "Now type the number of your choice:";
	return getIntInRange(1, SIZE);
}
void printOptions(string options[], int SIZE){
	cout << "Your Options:" << endl;
	for (int i =0;i <SIZE; i++) cout << i + 1 << ": " << options[i] << endl;
}
void printStats(string abilities[], int playerStats[], const int SIZE){
	int longest = getLongestSrting(abilities, SIZE);
	cout << "Player Stats:" << endl;
	for (int i = 0; i < SIZE; i++) cout << left << setw(abilities[longest].length() + 1) << abilities[i] << ": " << right << playerStats[i] << endl;
}
int getLongestSrting(string str[],const int SIZE){
	int longest = 0;
	for (int i = 0; i < SIZE; i++)
		if (str[i].length() >= str[longest].length()) longest = i;
	return longest;
}
Last edited on
Topic archived. No new replies allowed.