各位程序员!我正在寻找进入游戏开发,所以我正在尝试编写自己的,非常简单的文本战斗模拟器。您可以选择玩家名称并与您选择的怪物战斗。无论如何,我的目标是首先编写简单的代码,然后扩展并添加更多类。这是我现在唯一的两个文件:
播放器.h
#ifndef PLAYER_H
#define PLAYER_H
#include <string>
using std::string;
class player
{
public:
player();
const int maxHealth = 100;
int armorModifier = 0;
int playerLevel = 1;
int gold = 0;
int currentHealth = maxHealth;
string Name;
~player();
};
#endif // PLAYER_H
BattlesMain.cpp
/* GAME FEATURES THAT ARE COMMENTED WILL BE IMPLEMENTED AT A LATER TIME */
#include <iostream>
#include "player.h"
using std::cout;
using std::cin;
int main()
{
/* MAIN MENU */
cout << "Monster Battles: Text Action, v0.1\n";
cout << "Welcome, fighter!\n";
cout << "1.New Game\n";
// cout << "2.Load Game\n";
cout << "3.Quit Game\n";
char choice;
cin >> choice;
/* GAME LOOP */
while (choice !='4')
{
if (choice == '1')
{
player Player1;
cout << "Arena Host: Hello, fighter. What is your name?\n";
cin >> Player1.Name;
cout << "Welcome to the arena, " << Player1.Name << ". Here, you will \n";
cout << "be given the chance to battle fearsome monsters for fortune and \n";
cout << "fame. With the gold you win, you can visit our shop to buy new weapons, \n";
cout << "armor and other useful items. Since you are unarmed, here's a THIEF'S DAGGER. \n";
cout << "It's not much, but you'll hopefully be able to buy better items later! Good luck!\n";
}
return 0;}
请注意,这是我第一次尝试创建一个小项目,所以请容忍我任何糟糕的编码风格(非常欢迎反馈)。正如我在评论中所说的那样,这是我想做的精简版。问题是,当我尝试执行文件时,无论我在何处使用 Player1.Name,都会收到错误消息“错误:未定义对 'player()' 的引用。我目前正在使用适用于 Windows 7 的 Code::Blocks。
谢谢!