Skip to content

Instantly share code, notes, and snippets.

Created June 6, 2009 10:53
Show Gist options
  • Save anonymous/124805 to your computer and use it in GitHub Desktop.
Save anonymous/124805 to your computer and use it in GitHub Desktop.
// Sample army storage for Ressel:Arena
#include <iostream>
#include <list>
#include <string>
using namespace std;
// Setting up the Node data structure, in this case a clone of "soldier"
// From the Ressel:Arena game..
struct sSoldier
{
string name;
int hp;
int dmg;
};
list<sSoldier> deckshuffle( list<sSoldier> army )
{
srand ( time(NULL) );
list<sSoldier> playerdeck;
for ( int i = 0; i != 100; i++ )
{
int size = army.size();
int index = rand() % army.size();
list<sSoldier>::iterator it = army.begin();
for ( int i = 0; i < index; i++)
{
it++;
}
playerdeck.push_back ( *it );
army.erase ( it );
}
return playerdeck;
}
int main()
{
// Creating three type of soldiers: warrior, wizard, rogue
sSoldier warrior;
sSoldier wizard;
sSoldier rogue;
// Fleshing these guys out:
warrior.name = "Warrior";
warrior.hp = 30;
warrior.dmg = 5;
wizard.name = "Wizard";
wizard.hp = 10;
wizard.dmg = 15;
rogue.name = "Rogue";
rogue.hp = 15;
rogue.dmg = 10;
// Creating the pool of all the soldiers available in Ressel
// A dynamic array is the smartest for this since eventually
// We want to implement reading characters from a file..
// For right now though.. we just need to absorb the soldiers into
// Array of a known size..
sSoldier army[3] = { warrior, wizard, rogue };
// TEST 1: Outputting the contents off the array:
cout << "\n\nWelcome to the world of Ressel: Arena\n";
cout << "You are a new and noble King in Ressel..\n";
cout << "The world is still being created! So selection is limited!\n";
cout << "Here are the types of Soldiers that answered your call to arms:\n\n";
for ( int i = 0; i < 3; i++)
{
cout << i+1 << ". " << army[i].name << endl;
}
// Now lets prototype some selection (custom)
// CUSTOM SELECTION
int unitslots = 100; // The number of units available to fill
int unitchoice;
int unitamount;
sSoldier realunit;
list<sSoldier> playerarmy;
list<sSoldier> playerdeck;
// Need to create some sort of 'army counter' ..
// This is our best attempt using two lists..
list<int> armyunitcounter;
list<string> armyroster;
list<int>::iterator it1;
list<string>::iterator it2 = armyroster.begin();
while ( unitslots > 0 )
{
cout << "\nPlease m'lord, enter the number of the Solider you desire: ";
cin >> unitchoice;
cout << "A wise choice m'lord, how many shall I commission?: ";
cin >> unitamount;
// Check the requested amount vs. what is left in the total
// Number of soldier slots available.
if ( unitamount > unitslots )
{
cout << "\nI'm sorry m'lord but our Army is full!\n";
cout << "We currently have " << unitslots << " slots available.\n";
continue;
}
else
{
// Making an empty army and assigning it Xamount of Yunit
cout << "It shall be done!\n";
// Updating the counters..
armyunitcounter.push_back ( unitamount );
armyroster.push_back ( army[(unitchoice-1)].name );
// First we need to convert the index the player provided
// Into the actual unit they selected from the array
realunit = army[(unitchoice-1)];
// Instancing the players own army
while ( unitamount > 0 )
{
playerarmy.push_back ( realunit );
unitamount--;
unitslots--;
}
}
}
cout << "\nOur ranks are full m'lord!!\n";
cout << "Here's our current roster: \n";
for ( it1 = armyunitcounter.begin(); it1 != armyunitcounter.end(); it1++)
{
it2++;
cout << *it1 << " " << *it2 << endl;
}
/* TESTING SHUFFLING
playerdeck = deckshuffle( playerarmy );
list<sSoldier>::iterator it3 = playerdeck.begin();
cout << "\nWe've shuffled the deck! .. Or have we??\n";
cout << "Here's the whoolllleeee shebang (you wouldn't see this if we were really at war..)\n";
for ( int i = 0; i < 100; i++)
{
cout <<
*/
// Wrapping things up
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment