Newbie, in need of help.

Hey everyone. I know alot of you guys don't like giving direct answers, and that's perfectly ok. If someone could point me in the right direction, that would be fantastic.

I'm trying to emulate, a really basic pokemon battle, with C++. Here is what I have, and here is what I'm looking for.

//Battle with Samer
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;

const char* PokemonSamer[6] = {
"Charizard", "Umbreon", "Mew", "Arcanine", "Espurr", "Luxaray"
};

int main()
{
string mystr;
cout << "Musician Samer wants to battle!" "\n";
cout << "Go, ";
srand((unsigned)time(0));
cout << PokemonSamer[rand() % 6] << "!"<< "\n";
cout << "Please Choose your Pokemon: \n";
cout << "Charizard, Slowking, Weavile \n";
getline(cin, mystr);
cout << mystr << ", I choose you! \n";

system("PAUSE");

}

I would like to try and do some basic attacks (if yes, character takes x damage). I'm not sure if I need to create a list for the PokemonSamer, so I could assign values to each of the pokemon. If that is the case, will that interfere with the const char command, or is that already an array/list, and I'm making this harder than I need to be?

Any advice/guidance would be greatly appreciated.
How you handle hit points, attack points and health is up to your creativity as a programmer.

Since you seem to have an array of 6 different characters, I would suggest setting up arrays of 6 values for hit points and health.
1
2
3
 
  int hit_points[6] = { 10,10,15,20,10,10 };
  int health[6] = { 100, 100, 100, 100, 100, 100 };

In the simplest case, simply subtract the appropriate hit_points for one player from the health of the other player. When the health of either player goes to 0, the game is over.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on
Ok cool. That's kind of what I thought, but it seemed to make too much sense, and I second guessed. One more question, how do I assign a variable (hopefully that made sense)?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{
	string mystr;
	const char Samer;
	const char Trainer;

	cout << "Musician Samer wants to battle!" "\n";
	cout << "Go, ";
	srand((unsigned)time(0));
	cout << PokemonSamer[rand() % 6] << "!" << "\n";
	cout << "Please Choose your Pokemon: \n";
	cout << "Charizard, Slowking, Weavile \n";
	getline(cin, mystr);
	stringstream(mystr) >> Trainer;


In Javascript, it would just be "var Trainer". I have tried using char16_t, but when I actually run the program, my input is returned as a number. I can't find anything in this tutorial site that references that. Sorry about the format the first time around.
You have yo learn more with keyword const. :)

Why don't you use,
1
2
string Trainer;
getline(cin,Trainer);

Doesn't it make sense?

And for your samer, just char *Samer;, and use keyword word cstring (maybe in googling) to see what you're playing with.
Last edited on
lsk, I am not really sure what you're saying. there is no C++ keyword called "Cstring", and using or not using const has nothing to do with OP's questions.

OP, rather than using chars for Samer and Trainer i would use std::string (like you've done for your 'mystr' variable.
cstring is what we call string using in C language, you can also use in C++.
declared by char *var_name;

for example,
1
2
3
const char* PokemonSamer[6] = {
"Charizard", "Umbreon", "Mew", "Arcanine", "Espurr", "Luxaray"
};

This statement, you defined array of cstring(and defined as const).

Opps, maybe I shouldn't mention that's keyword.


1
2
const char Samer;
const char Trainer;
and stringstream(mystr) >> Trainer;
That's why I suggested about const.
Last edited on
oh, you meant a "c-style string".
yep, that's it.
Sorry if I used wrong word, stuck from lib's file name.

And I googled "cstring", I found something take me out of what I intend to do. LOL.
Last edited on
Thanks guys! I'm glad I got verification on this! I did end up changing it to use the strings below, and they (as of now) are working just fine. Thanks for the advice!

1
2
string Samer;
string Trainer;
Topic archived. No new replies allowed.