سؤال

I am trying to create a basic text-based adventure game in C++. Here is one of my classes.

#include "goblinFight.h"
#include <iostream>
#include <cmath>
#include <string>

using namespace std;


goblinFight::int fightGoblin()
{
cout << "A goblin attacks you! You: " << endl;
cout << "Raise your shield. (1)" << endl;
cout << "Take a step back. (2)" << endl;
cout << "Slash at it with your sword. (3)" << endl;
cin >> UI;
return UI;
}

goblinFight::void defendGoblin()
{
    switch(UI){
case 1: cout << "The goblin slashes at your with his " << goblinWeapon << ", but it bounces off your shield." << endl;
        playerShieldHealth -= 1;
        break;

case 2: cout << "The goblin steps forward..." << endl;
        switch(playerShieldHealth){
        case 0: playerShieldHealth += 2;
        break;
        case 1: playerShieldHealth += 1;
        break;}
        break;

case 3: srand(time(0));
        fightDice = rand() % 3;
        switch(fightDice){
        case 0: cout << "You strike the goblin! He bellows with rage!" << endl;
        goblinHealth -= 1;
        break;
        case 1: cout << "You strike the goblin! He screams in pain!" << endl;
        goblinHealth -= 1;
        break;
        case 2: cout << "You miss the goblin! He cackles at your ineptness." << endl;
        break;
        }
        break;
        }

The problem I am having is that it keeps giving me an error on line 9 that reads- error: expected unqualified-id before 'int'. It is giving me another error on line 19 that reads- error: expected unqualified-id before 'void'. I cannot figure out what the problem is, help would be appreciated.

هل كانت مفيدة؟

المحلول

You've got the return type and class name wrong ways.

goblinFight::int fightGoblin() Should be int goblinFight::fightGoblin()

ditto for goblinFight::void defendGoblin()

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top