我是编程中的一个完整的菜鸟,我有多个错误,表示"期待一个声明" 我们分配了一个项目,需要创建一个文字基础游戏,角色攻击对手。 我们要制作角色,当我们告诉他们攻击时,我们必须输入正确的攻击密钥。
这是我到目前为止所做的:
#include <cstdlib>
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;
int Opponent;
int showOpponentHealth(int OpponentHealth, int Attack);
int showHealth(int Health, int OpponentAttack);
int showMagic(int Magic);
{ //Error: expected a declaration
public:
Opponent() : OpponentAttack(0), OpponentHealth(3);
{
OpponentAttack = rand() % 100;
OpponentHealth = rand() % 6 + 10;
}
}
int getAttack(Opponent);
{ //Error: expected a declaration
AttRoll = Rand() % 100
if (AttRoll < getAtt)
hit
{
AttType = 1 - 3
if (AttType == 1)
return 30
else if (AttType == 2)
return 50
else if (AttType == 3)
return 70
}
float character::getHeal()
{
magicCost = magic - 6;
Heal = rand() % 3 + 5;
cout << "Heal value= " << heal << ".\n";
return Heal;
}
}
void Battle()
{
int Health = rand() % 6 + 10;
int OpponentHealth = rand() % 6 + 10;
int hit;
}
long timeTest()
{
//seed the random number generator
srand(GetTickCount64());
//rand will give a number between 0 and max integer value
int waitTime = rand() % 5 + 1;
for (int i = waitTime; i>0; i--)
{
cout << "*";
Sleep(1000); //wait for 1 second
}
char typeThis = rand() % 26 + 97;
cout << typeThis << ":";
char playerResponse;
//this is the window function I'm using to get the time: ULONGLONG WINAPI GetTickCount64(void);
ULONGLONG startTime = GetTickCount64();
cin >> playerResponse;
ULONGLONG endTime = GetTickCount64();
if (playerResponse != typeThis)
return -1;
long deltaTime = endTime - startTime;
return deltaTime;
}
do //syntax error
{ //Error: expected a declaration
cout << " Attack Opponent? \n Yes = 1\n"
cin >> Attack Opponent;
if (AttackOpponent == 1)
{
OpponentHealth = showOpponentHealth(OpponentHealth, Attack);
Health = showHealth(health, OpponentAttack);
cout << "You attacked the Opponent with a light attack.";
cout << "The Opponent now has " << OpponentHealth << "health left.";
if (OpponentHealth <= 0)
{
cout << "You Win!";
}
else if (OpponentHealth > 0)
{
cout << "Opponent attacks back";
cout << "You have" << Health << "health left,";
}
else if (AttackOpponent == 2)
cout << "You attacked the Opponent with a medium attack.";
cout << "The Opponent now has " << OpponentHealth << "health left.";
{ //Error: expected a declaration
else if (AttackOpponent == 3)
cout << "You attadcked the Opponent with a heavy attack.";
cout << "The Opponent now has " << Opponent Health << "health left.";
}
} //Error: expected a declaration
int showOpponentHealth(int OpponentHealth, int Attack)
{
OpponentHealth = OpponentHealth - Attack;
return OpponentHealth;
}
int showHealth(int Health, int OpponentAttack)
{
Health = Health - OpponentAttack;
return Health;
}
}
int main()
{
cout << "Try the timeTest: " << timeTest() << endl;
int Health = rand() % 6 + 10;
if (Health <= 0)
cout << "You Died. Game Over." << endl;
int Magic = 10
else (Magic <= 0)
cout << "No more Magic." << endl;
system("Pause");
return0;
}
错误会在方括号和&#34; do&#34;
上弹出答案 0 :(得分:2)
你的do {...}循环不在任何函数之内。它必须在函数内部 - 编译器告诉你它需要声明一个函数,如:
long timeTest()
你的意思是把do循环放在timeTest()中吗?