#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#ifdef _WIN32
#define __WIN32__
#endif
#include "util/nstring.h"
#include "util/nlist.h"
void GoOn()
{
printf ("Press a key for continue...\n");
getch();
printf("\n");
}
void Demo()
{
const int NQ2WEAPON = 11;
nString q2WeaponNames[NQ2WEAPON] =
{
"Shotgun",
"Blaster",
"Super Shotgun",
"Hyperblaster",
"Machine Gun",
"Chain Gun",
"Rocket Launcher",
"Grenade",
"Grenade Launcher",
"Railgun",
"BFG"
};
printf ("Demo - q2 weapons for demonstration nList class\n"
"------------------------------------------------\n\n");
nList pickedWeapons;
srand((int) time(0));
for (int i = 0; i < 5; i++)
{
int nIndex = (int)(((float)rand() / (float)RAND_MAX) * NQ2WEAPON);
bool fWeaponPicked = false;
for (nNode* n = pickedWeapons.GetHead(); n != 0; n = n->GetSucc())
{
nString* pStr = (nString*)n->GetPtr();
if (q2WeaponNames[nIndex] == (*pStr))
{
fWeaponPicked = true;
break;
}
}
if (!fWeaponPicked) pickedWeapons.AddHead(new nNode((void*)&q2WeaponNames[nIndex]));
}
printf ("Player picked this weapons:\n");
for (nNode* n = pickedWeapons.GetHead(); n != 0; n = n->GetSucc())
{
nString* pStr = (nString*)n->GetPtr();
printf ("%s;\n", pStr->Get());
}
GoOn();
printf("Clear resources of demo...\n");
while (!pickedWeapons.IsEmpty())
{
delete pickedWeapons.RemHead();
}
}
int main()
{
Demo();
printf("Press any key to quit...");
getch();
return 0;
}