Creature player; // create a new creature object player.SetName("Bob"); player.SetMaxHealth(100); player.TakeDamage(20); // creature takes 20 damage CreatureInfo info = player.GetCreatureInfo(); // get information about the player std::cout << "Name: " << info.name << std::endl; // output: Name: Bob std::cout << "Health: " << info.health << "/" << info.maxHealth << std::endl; // output: Health: 80/100
for (int i = 0; i < numCreatures; i++) { Creature* creature = CreateRandomCreature(); // create a new random creature creatures.push_back(creature); // add creature to list of creatures } for (Creature* creature : creatures) { CreatureInfo info = creature->GetCreatureInfo(); // get info about each creature std::cout << "Name: " << info.name << std::endl; std::cout << "Health: " << info.health << "/" << info.maxHealth << std::endl; } for (Creature* creature : creatures) { delete creature; // free memory used by creatures }In this example, we simulate creating a list of random creatures and getting information about each one using GetCreatureInfo. We then output the name and current health for each creature. Finally, we free the memory used by the creatures. This code example likely belongs to a package or library related to simulation or artificial life.