Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main() {
- // function that prints a random number from 1 - 50.
- void printRandomNumber() {
- srand(time(NULL));
- int randomNum = rand() % 50 + 1;
- printf("Random number: %d\n", randomNum);
- }
- // function that calculates the area of a rectangle.
- float calculateRectangleArea(float length, float width) {
- return length * width;
- }
- // function that applies a speed boost.
- void applySpeedBoost(float *speed) {
- // Increase speed by 10%
- *speed *= 1.1;
- }
- // function that simulates health regeneration.
- void regenerateHealth(int *health, int maxHealth) {
- // Add 5 health points (up to maxHealth)
- *health = (*health + 5 <= maxHealth) ? *health + 5 : maxHealth;
- }
- // function that calculates experience points.
- int calculateExperience(int level) {
- // Simple formula (you can customize this)
- return level * 100;
- }
- // function that adds an item to a players inventory.
- #define MAX_INVENTORY_SIZE 10
- typedef struct {
- char name[50];
- int quantity;
- } Item;
- void addItemToInventory(Item inventory[], const char *itemName, int quantity) {
- // Check if inventory is full.
- }
- // function that tracks quests completed by players.
- #define MAX_INVENTORY_SIZE 10
- typedef struct {
- char name[50];
- int quantity;
- } Item;
- void addItemToInventory(Item inventory[], const char *itemName, int quantity) {
- // Check if inventory is full
- }
- // function that simulates loot drops.
- typedef struct {
- char name[50];
- float dropChance; // chance of (0.0 to 1.0)
- } LootItem;
- LootItem lootTable[] = {
- {"Health Potion", 0.3},
- {"Gold Coin", 0.6},
- {"Rare Sword", 0.1}
- };
- void simulateLootDrop() {
- srand(time(NULL));
- float randomNum = (float)rand() / RAND_MAX; // between 0 and 1
- for (int i = 0; i < sizeof(lootTable) / sizeof(lootTable[0]); ++i) {
- if (randomNum < lootTable[i].dropChance) {
- printf("Loot dropped: %s\n", lootTable[i].name);
- break;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement