My first game programmed with C++
No tutorial was followed, just all my knowledge from 17 online lessons
People that do know C++, feedback on the source and what I can do better to improve
my programming skills would be appreciated.
source code:
SPOILER: (click to show)
Code:
#include <iostream>
#include <ctime>
void RollDice(int iPlayerGuess);
void GiveGold(int iAmount);
void TakeGold(int iAmount);
void PlayerWin(int iDie1, int iDie2);
int iPlayerGold;
void main() {
int iPlayerGuess;
std::cout << "\tPick a number between 1 - 12" << std::endl;
std::cin >> iPlayerGuess;
RollDice(iPlayerGuess);
}
void RollDice(int iPlayerGuess) {
time_t t;
time(&t);
srand(t);
int iDie1;
int iDie2;
if (iPlayerGuess < 0 || iPlayerGuess > 12){
main();
}
std::cout << "\n\tRolling dice.." << std::endl;
iDie1 = (rand() % 7);
iDie2 = (rand() % 7);
std::cout << "\t\t[ " << iDie1 << " ] [ " << iDie2 << " ]" << std::endl;
if (iPlayerGuess == (iDie1 + iDie2)) {
PlayerWin(iDie1, iDie2);
} else {
TakeGold(200);
main();
}
}
void PlayerWin(int iDie1, int iDie2) {
int iAmountOfGold;
iAmountOfGold = 20 * (iDie1 * iDie2);
GiveGold(iAmountOfGold);
std::cout << "+" << iAmountOfGold << "G!\n" << std::endl;
main();
}
void GiveGold(int iAmount) {
iPlayerGold = iPlayerGold + iAmount;
std::cout << "You now have " << iPlayerGold << " gold." << std::endl;
}
void TakeGold(int iAmount) {
iPlayerGold = iPlayerGold - iAmount;
std::cout << "-" << iAmount << " gold" << std::endl;
std::cout << "You now have " << iPlayerGold << " gold.\n" << std::endl;
}