富旺配资 完整的策略游戏_UnitType_int_if
#include <stdio.h>富旺配资
#include <stdlib.h>
#include <time.h>
// 定义单位类型
typedef enum {
INFANTRY,
ARCHER,
CAVALRY,
NUM_UNIT_TYPES
}富旺配资富旺配资 UnitType;
// 定义单位结构体
typedef struct {
UnitType type;
int health;mlwine.com
int attack;
int defense;
展开剩余87%} Unit;
// 定义地图大小
#define MAP_WIDTH 5
#define MAP_HEIGHT 5
// 定义地图
int map[MAP_HEIGHT][MAP_WIDTH];
// 初始化地图
void initializeMap() {
for (int i = 0; i < MAP_HEIGHT; i++) {
for (int j = 0; j < MAP_WIDTH; j++) {
map[i][j] = 0; // 0 表示空地富旺配资
}
}
}
// 初始化单位
Unit createUnit(UnitType type) {
Unit unit;
unit.type = type;
switch (type) {
case INFANTRY:
unit.health = 100;
unit.attack = 15;
unit.defense = 10;
break;
case ARCHER:
unit.health = 80;
unit.attack = 20;
unit.defense = 5;
break;
case CAVALRY:
unit.health = 120;
unit.attack = 25;
unit.defense = 15;
break;
}
return unit;
}
// 简单的战斗机制
void battle(Unit* attacker, Unit* defender) {
int damage = attacker->attack - defender->defense;
if (damage < 1) damage = 1; // 确保至少造成1点伤害
defender->health -= damage;
printf("Attacker deals %d damage to defender.\n", damage);
if (defender->health <= 0) {
printf("Defender is defeated!\n");
}
}
// 主游戏循环
void gameLoop() {
Unit playerUnit = createUnit(INFANTRY);
Unit enemyUnit = createUnit(ARCHER);
printf("Welcome to Strategy & War!\n");
printf("Your unit: Infantry (Health: %d, Attack: %d, Defense: %d)\n",
playerUnit.health, playerUnit.attack, playerUnit.defense);
printf("Enemy unit: Archer (Health: %d, Attack: %d, Defense: %d)\n",
enemyUnit.health, enemyUnit.attack, enemyUnit.defense);
while (playerUnit.health > 0 && enemyUnit.health > 0) {
int choice;
printf("\nChoose your action:\n");
printf("1. Attack\n");
printf("2. Retreat\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
battle(&playerUnit, &enemyUnit);
if (enemyUnit.health > 0) {
battle(&enemyUnit, &playerUnit);
}
break;
case 2:
printf("You have retreated from the battle.\n");
return;
default:
printf("Invalid choice, try again.\n");
}
}
if (playerUnit.health <= 0) {
printf("You have been defeated!\n");
} else {
printf("You have won the battle!\n");
}
}
int main() {
srand(time(NULL)); // 初始化随机数生成器
initializeMap();
gameLoop();
return 0;
}
发布于:福建省易投投配资提示:文章来自网络,不代表本站观点。