C++ C++;Cootie游戏错误

C++ C++;Cootie游戏错误,c++,C++,大部分代码我都完成了,我应该创建一个cootie游戏,根据每个玩家掷的骰子将手臂、腿、头等添加到cootie中。然而,当我试图编译它的时候,我一直在犯错误,我不确定应该怎么做才能消除它们。我在编程方面非常糟糕,但我会尽力理解你的回答,非常感谢你的帮助 以下是错误: In file included from main.cpp:8: Player.h:14: error: ‘cootie’ does not name a type Player.h:15: error: ‘Dice’ does n

大部分代码我都完成了,我应该创建一个cootie游戏,根据每个玩家掷的骰子将手臂、腿、头等添加到cootie中。然而,当我试图编译它的时候,我一直在犯错误,我不确定应该怎么做才能消除它们。我在编程方面非常糟糕,但我会尽力理解你的回答,非常感谢你的帮助

以下是错误:

In file included from main.cpp:8:
Player.h:14: error: ‘cootie’ does not name a type
Player.h:15: error: ‘Dice’ does not name a type
In file included from Player.cpp:1:
Player.h:14: error: ‘cootie’ does not name a type
Player.h:15: error: ‘Dice’ does not name a type
Player.cpp: In member function ‘void Player::takeTurn()’:
Player.cpp:24: error: ‘dice’ was not declared in this scope
Player.cpp:25: error: ‘getRoll’ was not declared in this scope
Player.cpp:27: error: ‘monster’ was not declared in this scope
Player.cpp:29: error: expected `}' before ‘else’
Player.cpp: At global scope:
Player.cpp:29: error: expected unqualified-id before ‘else’
Player.cpp:31: error: expected constructor, destructor, or type conversion before ‘<<’ token
Player.cpp:32: error: expected unqualified-id before ‘else’
Player.cpp:34: error: expected constructor, destructor, or type conversion before ‘<<’ token
Player.cpp:35: error: expected unqualified-id before ‘else’
Player.cpp:37: error: expected constructor, destructor, or type conversion before ‘<<’ token
Player.cpp:38: error: expected unqualified-id before ‘else’
Player.cpp:40: error: expected constructor, destructor, or type conversion before ‘<<’ token
Player.cpp:41: error: expected unqualified-id before ‘else’
Player.cpp:43: error: expected constructor, destructor, or type conversion before ‘<<’ token
Player.cpp:44: error: expected declaration before ‘}’ token
Player.h:14: error: ‘cootie’ does not name a type
Player.h:15: error: ‘Dice’ does not name a type
Player.cpp:

#include "Player.h"
#include "cootie.cpp"
#include "Dice.h"
#include <iostream>
#include <string>
using namespace std;
//Player::Player(string name)
//{
  //  name = n;
  //ctor
//}

//accessors
//string Player::getName(){
//return name;
//}
//mutators
//void Player::setName(string n){
//    name = n;
 //   }

void Player::takeTurn()
{
    dice.randomize();
    float f = getRoll();
    if (f == 1)
    monster.setLegs(monster.getLegs()+1);
    cout << "add a leg to cootie"<< endl;
    else if (f == 2)
    monster.setHeads(monster.getHeads()+1);
    cout << "add a head to cootie"<< endl;
    else if (f == 3)
    monster.setEyes(monster.getEyes()+1);
    cout << "add an eye to cootie"<< endl;
    else if (f == 4)
    monster.setWings(monster.getWings()+1);
    cout << "add a wing to cootie"<< endl;
    else if (f == 5)
    monster.setBodies(monster.getBodies()+1);
    cout << "add a body to cootie"<< endl;
    else if (f == 6)
    monster.setAntennas(monster.getAntennas()+1);
    cout << "add an antenna to cootie"<< endl;
}
main.cpp:

#include "Player.h"
#include "cootie.h"
#include "Dice.h"
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>

using namespace std;

int main (){
   // cootie c("R2D2", 1, 1,0,2,1,0);
cootie c;
int x;


    //Dice d(6);
    //cout << "regular dice" << d.getRoll() << endl;
    //Dice d20(20);
   // cout << "20 size dice" <<d20.getRoll() << endl;
    //Dice percentile(100);
    //cout << "Percentile size dice"<< percentile.getRoll() << endl;
    Player playerArray [2];// 2 player game
    while (x<3)
{
    for (x=0;x<2;x++)
    {
        playerArray[x].takeTurn();
        cout <<"Player "<< x;
    cout << "Cootie " << x << endl;
    cout << c.getLegs() << " Leg(s)" << endl;
    cout << c.getHeads() << " Head(s)" << endl;
    cout << c.getEyes() << " Eye(s)" << endl;
    cout << c.getWings() << " Wing(s)" << endl;
    cout << c.getBodies() << " Bodie(s)" << endl;
    cout << c.getAntennas() << " Antenna(s)" << endl;

    }
}
cout << "im done here" <<endl;

    return 0;
}
#包括“Player.h”
#包括“cootie.h”
#包括“Dice.h”
#包括
#包括
#包括
#包括
使用名称空间std;
int main(){
//cootie c(“R2D2”,1,1,0,2,1,0);
库蒂c;
int x;
//骰子d(6);

//显然有很多问题需要解决

第一个问题,

Player.h:14:错误:“cootie”未命名类型


表明
cootie.h
应包含在
Player.h
中,因此
类cootie
的声明在使用时可见。

显然有很多问题需要解决

第一个问题,

Player.h:14:错误:“cootie”未命名类型


指示
cootie.h
应包含在
Player.h
中,因此
类cootie
的声明在使用时可见。

从错误判断,您忘记导入一些头文件


后来似乎还出现了另一个涉及else语句的错误。我认为这可能是您犯的语法错误。您的编译器应该使您能够相当容易地隔离此错误。

从错误判断,您忘记导入一些头文件


后来似乎还有另一个错误涉及到else语句。我想这可能是你犯的语法错误。你的编译器应该可以让你很容易地隔离出这个错误。

伙计,没有人会费力地阅读所有这些代码。@OldProgrammer,尽管我怀疑这与它使用的代码无关self.
#包括“cootie.cpp”
在标题中使用名称空间std;
只会导致悲伤。@OldProgrammer这一切都在堆栈跟踪中。第二行很明显,玩家不知道cootie.hDude,没有人会涉猎所有这些代码。@OldProgrammer,尽管我怀疑这与代码本身无关。
包括“cootie.cpp”
在标题中使用namespace std;
只会导致悲伤。@这一切都在堆栈跟踪中。第二行很明显,玩家不知道cootie.h
#include "Dice.h"

#include <cstdlib>
#include <ctime>
//#include "cootie.h"
#include <iostream>
//#include <string>
using namespace std;

Dice::Dice(int sides) :
    sides(sides)
{}


float Dice::getRoll() {
    return ((rand() % sides) + 1);
}

void Dice::randomize (){
    srand((unsigned)time(NULL)); // or is it null?
}
#ifndef DICE_H
#define DICE_H


class Dice
{
    public:
        Dice(int sides);
        float getRoll();

        static void randomize(); //called once
    protected:
    private:
        int sides;
};

#endif // DICE_H
#include "Player.h"
#include "cootie.cpp"
#include "Dice.h"
#include <iostream>
#include <string>
using namespace std;
//Player::Player(string name)
//{
  //  name = n;
  //ctor
//}

//accessors
//string Player::getName(){
//return name;
//}
//mutators
//void Player::setName(string n){
//    name = n;
 //   }

void Player::takeTurn()
{
    dice.randomize();
    float f = getRoll();
    if (f == 1)
    monster.setLegs(monster.getLegs()+1);
    cout << "add a leg to cootie"<< endl;
    else if (f == 2)
    monster.setHeads(monster.getHeads()+1);
    cout << "add a head to cootie"<< endl;
    else if (f == 3)
    monster.setEyes(monster.getEyes()+1);
    cout << "add an eye to cootie"<< endl;
    else if (f == 4)
    monster.setWings(monster.getWings()+1);
    cout << "add a wing to cootie"<< endl;
    else if (f == 5)
    monster.setBodies(monster.getBodies()+1);
    cout << "add a body to cootie"<< endl;
    else if (f == 6)
    monster.setAntennas(monster.getAntennas()+1);
    cout << "add an antenna to cootie"<< endl;
}
#ifndef PLAYER_H
#define PLAYER_H


class Player
{
    public:
        Player();
        void takeTurn();
 //       void getName(string na);
 //       void setName();
    protected:
    private:
       cootie monster;
       Dice dice(6);
 //       string name;
};

#endif // PLAYER_H
#include "Player.h"
#include "cootie.h"
#include "Dice.h"
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>

using namespace std;

int main (){
   // cootie c("R2D2", 1, 1,0,2,1,0);
cootie c;
int x;


    //Dice d(6);
    //cout << "regular dice" << d.getRoll() << endl;
    //Dice d20(20);
   // cout << "20 size dice" <<d20.getRoll() << endl;
    //Dice percentile(100);
    //cout << "Percentile size dice"<< percentile.getRoll() << endl;
    Player playerArray [2];// 2 player game
    while (x<3)
{
    for (x=0;x<2;x++)
    {
        playerArray[x].takeTurn();
        cout <<"Player "<< x;
    cout << "Cootie " << x << endl;
    cout << c.getLegs() << " Leg(s)" << endl;
    cout << c.getHeads() << " Head(s)" << endl;
    cout << c.getEyes() << " Eye(s)" << endl;
    cout << c.getWings() << " Wing(s)" << endl;
    cout << c.getBodies() << " Bodie(s)" << endl;
    cout << c.getAntennas() << " Antenna(s)" << endl;

    }
}
cout << "im done here" <<endl;

    return 0;
}