Make me an RPG game coded in C
- User
Make me an RPG game coded in C
Assistant
Certainly! Here's a simple RPG game coded in C:
c#include <stdio.h> #include <stdlib.h> #include <time.h> #define MAX_PLAYER_HEALTH 100 #define MAX_ENEMY_HEALTH 50 #define MAX_ENEMY_ATTACK 10 typedef struct { int health; int attack; } Character; void printStatus(Character player, Character enemy) { printf("Player Health: %d\n", player.health); printf("Enemy Health: %d\n", enemy.health); } int main() { Character player = {MAX_PLAYER_HEALTH, 0}; Character enemy = {MAX_ENEMY_HEALTH, 0}; int choice; srand(time(NULL)); printf("Welcome to the RPG Game!\n"); while (player.health > 0 && enemy.health > 0) { printStatus(player, enemy); printf("Choose an action:\n"); printf("1. Attack\n"); printf("2. Heal\n"); scanf("%d", &choice); switch (choice) { case 1: enemy.health -= rand() % 20 + 10; printf("You attacked the enemy!\n"); break; case 2: player.health += rand() % 20 + 10; if (player.health > MAX_PLAYER_HEALTH) player.health = MAX_PLAYER_HEALTH; printf("You healed yourself!\n"); break; default: printf("Invalid choice. Skipping turn.\n"); break; } if (enemy.health > 0) { player.health -= rand() % MAX_ENEMY_ATTACK + 1; printf("The enemy attacked you!\n"); } printf("\n"); } if (player.health <= 0) printf("Game Over! You lost.\n"); else printf("Congratulations! You won the game.\n"); return 0; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.