Sign in to follow this  
  • entries
    7
  • comments
    13
  • views
    1924

Basic code.

Sign in to follow this  
Kudu

153 views

Well at the end of each chapter of Beginning C++ Game Programming, I was hoping to do a largish piece of code with everything I learnt in the chapter included, I managed this for Chapter 1 but couldn't be assed for 2, I'm now half way through 3.

To make up for this, and to check that I can still remember all the correct syntax, I'm going to be creating some code and posting it here, for you to critisize at your own will =D.

Maybe if I have enough time, and schoolwork doesn't get in the way I'll create one large program combining all 3 pieces of code. This might be an idea for the beginning of the summer hols, and who knows, by September I may actually be decent at programming and have a bit of respect on these here boards!

I guess I may aswell post the Chapter 1 code here, this is all created by me, and is not a finished piece of code. Just a showcase of my progress:

//Testing what I learnt in Chapter 1.

#include
using namespace std;

int main()
{
cout << "Battle Aftermath.\n\n";

const int UNDEAD_EXP = 25;
int undeadKilled = 7;
int undeadPoints = UNDEAD_EXP * undeadKilled;
cout << "Undead Points: " << undeadPoints << ".\n";
cout << "Congratulations, you have slain " << undeadKilled << " undead beasts and gained " << undeadPoints << " Experience points!" << "\n\n";

const int HUMAN_EXP = 10;
int humansKilled = 16;
int humanPoints = HUMAN_EXP * humansKilled;
cout << "Human Points: " << humanPoints << endl;
cout << "Congratulations, you have slain " << humansKilled << " human gladiators and gained " << humanPoints << " Experience points!" << "\n\n";

const int ALLIES_EXP = -10;
int alliesKilled = 4;
int alliesPoints = ALLIES_EXP * alliesKilled;
cout << "Allies Points: " << alliesPoints << endl;
cout << "Although you battled well for your team, " << alliesKilled << " members were brutally massacred, putting a burden of " << alliesPoints << " experience on your team..." << "\n\n";

int totalPoints = undeadPoints + humanPoints + alliesPoints;

enum armour {LEATHER = 10, CHAINMAIL = 20, PLATEMAIL = 40};
armour myArmour = LEATHER;

cout << "You have earnt the right to a new set of armour.\n" << endl;
cout << "1 - I'll keep my armour thanks.\n";
cout << "2 - I'll upgrade to Chainmail please! (" << CHAINMAIL << " points)\n";
cout << "3 - I'll upgrade to Platemail please! (" << PLATEMAIL << " points)\n";

int choice;
cout << "Choice: ";
cin >> choice;

switch (choice)
{
case 1:
cout << "You have chosen to keep your current armour.\n";
break;
case 2:
cout << "You have chosen to upgrade to Chainmail!\n";
break;
case 3:
cout << "You have chosen to upgrade to Platemail!\n";
break;
default:
cout << "Please choose a number from 1-3\n";
}

return 0;
}
[/source]
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now