Looks like good code. Better than the first game I ever made! :D
Only thing you could add at this point, is validation of input. i.e. Make sure the user inputs what makes the program work.
1 2 3 4 5
|
cout << "\nPlayer 1's Turn.\n" << potionNUM1 << " potions left." << "\nY = Attack, N = Potion: ";
char player1Attack;
cin >> player1Attack;
//Player 1 Attacks
if(player1Attack == 'y')
|
Here, a user could see that you ask for 'Y'( UPPER case ). But then you check for 'y'( lower case ).
Here's a function that could be useful:
http://www.cplusplus.com/reference/clibrary/cctype/tolower/
Also, other validation, if the user enter's something other than expected, i.e. a number. Maybe catch it and output an error saying incorrect data entered.
And, here's a function I use to clear a console screen:
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
|
void cls()
{
//include windows in a header file:
//#include <windows.h>
//get the HANDLE for the console window
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordScreen = { 0, 0 }; // home for the cursor
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
// Get the number of character cells in the current buffer.
if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
return;
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
// Fill the entire screen with blanks.
if( !FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten ))
return;
// Get the current text attribute.
if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
return;
// Set the buffer's attributes accordingly.
if( !FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten ))
return;
// Put the cursor at its home coordinates.
SetConsoleCursorPosition( hConsole, coordScreen );
}
|
Personally, I think that tolower example looks a bit, uhmmm... Well, I don't see the need for the extra 'c' char and putchar( I've never used putchar )... lol
I just wrote this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream> //cout
#include <conio.h> // _kbhit()
int main()
{
char text[] = "I'M UPPER CASE TEXT";
std::cout << "This is the text before conversion:\n" << text << '\n';
for( int i = 0; i < 20; ++i )
{
//access each element and convert to lower case
text[ i ] = tolower( text[ i ] );
}
std::cout << "\nThis is the text now:\n" << text << '\n';
//press a key to continue...
//while there isn't a key being pressed
while( ! _kbhit() )
{ /* do nothing - wait for a key press, before exiting */ }
return 0;
}
|
A few future updates I'd like to make would be to turn this into a RPG of sorts, as this would allow me to build upon it etc as I learn more and more C++. |
I've found, that when I learn more C++ / the use of extra, before unknown functions, I usually end up re-writing the program. I find( sometimes ), it's easier to re-write instead of sitting there replacing code. As, again, sometimes, you can be replacing code and you are not able to compile and run because functions/variables etc. don't match up yet. And when you finish, you could be at a loss.
But this is just from personal experience! I like to learn by doing, rather than reading 5 chapters then trying stuff out.