我的21场骰子游戏的C++错误,请帮忙
C++ error for my 21 game with dice help please
这是我的main.cpp
#include "DiceTwentyOne.h"
#include <string>
#include <iostream>
#include <conio.h>
using namespace std;
DiceTwentyOne game;
string play;
void playGame(string play)
{
int turns = 0;
while(play == "yes" && turns !=3)
{
cout << "Your score is: " << game.playGame(true);
cout << endl;
cout << "Would you like to roll?[yes,no]";
cin >> play;
cout << endl;
turns++;
}
cout << "Dealers score: " << game.playGame(false) << endl;
if(game.winLoss())
{
cout << "You win";
}
else
{
cout << "Dealer wins";
}
}
int main ()
{
cout << "Would you like to roll?[yes,no]";
cin >> play;
cout << endl;
if(play == "yes")
{
playGame(play);
}
else
{
cout << "Have a nice day.";
}
getch();
return 0;
}
die.h
#ifndef DIE.H
#define DIE.H
#include<stdlib.h>
#include<time.h>
#include<iostream>
using namespace std;
class Die
{
public:
Die();
void changeFace();
int getFace();
private:
int faceValue;
void rollDie();
};
#endif
die.cpp
#include "Die.h"
Die::Die()
{
faceValue;
}
void Die::rollDie()
{
int temp= (unsigned) time(0);
srand(rand()%temp*((unsigned) time (NULL)
*(unsigned)time(NULL)));
faceValue = (rand()%((6-1)+1)+1);
}
void Die::changeFace()
{
rollDie();
}
int Die::getFace()
{
return faceValue;
}
player.h
#ifndef PLAYER.H
#define PLAYER.H
class Player
{
private:
int turns, score;
public:
Player();
void setScore(int points);
int getScore();
void setTurns(int turns);
int getTurns();
};
#endif
player.cpp
#include "Player.h"
Player::Player()
{
score = 0;
turns = 0;
}
void Player::setScore(int points)
{
score = points + score;
}
int Player::getScore()
{
return score;
}
void Player::setTurns(int turn)
{
turns += turn;
}
dicetwentyone.h
#ifndef DICETWENTYONE.H
#define DICETWENTYONe.H
#include "Player.h"
#include "Die.h"
class DiceTwentyOne
{
private:
Player player;
Player dealer;
Die die;
public:
DiceTwentyOne();
int playGame(bool truth);
bool winLoss();
};
#endif
dicetwentyone.cpp
#include "DiceTwentyOne.h"
#include "Player.h"
DiceTwentyOne::DiceTwentyOne()
{
player;
dealer;
die;
}
int DiceTwentyOne::playGame(bool truth)
{
player.setTurns(1);
if(player.getScore()<21)
{
if(player.getTurns()<=3 && truth)
{
for(int i=0; i<2; i++)
{
die.changeFace();
player.setScore(die.getFace());
}
return player.getScore();
}
else
{
while(dealer.getScore()<15
&& dealer.getTurns()<=3)
{
dealer.setTurns(1);
for(int i=0; i<2; i++)
{
die.changeFace();
dealer.setScore(die.getFace());
}
}
int tempTurn = -1 * dealer.getTurns();
dealer.setTurns(tempTurn);
tempTurn = -1 * player.getTurns();
player.setTurns(tempTurn);
return dealer.getScore();
}
}
return -1;
}
bool DiceTwentyOne::winLoss()
{
if(dealer.getScore > 21)
{
return false;
}
else if(player.getScore() > dealer.getScore())
{
return true;
}
else
{
return false;
}
}
我收到了这个错误,我已经尝试为getTurns
赋值。有人知道如何解决这个问题吗?
错误1错误LNK2019:未解析的外部符号"public:int__thiscall Player::getTurns(void)"(?getTurns@Player@@QAEHXZ)在函数"public:int__thiscall DiceTwentOne::playGame(bool)"(?playGame@DiceTwentyOne@@QAEH_N@Z)C:\Users\will_000\Documents\Visual Studio 2012\Projects\ 21的游戏\ 21的游戏\DiceWentyOne.obj 21 的游戏
使用bool
调用playGame()
,但它被定义为playGame(std::string)
。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 错误:未在此范围内声明'reverse'