计算机模拟“石头、剪子、布”游戏编程问题

来源:百度知道 编辑:UC知道 时间:2024/07/08 01:40:56
编程用计算机模拟“石头、剪子、布”游戏。在这个游戏中,两个人同时说“石头、剪子、布”,压过另一方的为胜者。规则为:布压过石头,石头压过剪子,剪子压过布。其中的选择和结果使用枚举类型。
(小弟刚学c++,对这个题毫无头绪,请大家出出思路。)
三楼回答太棒了,不过小弟初学,还没学这么深。
小弟把程序运行了一下,有点小错误,如果能改一下就更好了。
错误提示如图

楼上说的不错。不过忽略了一个问题。人家楼主说,要用枚举类型。

既然是C++,那就应该充分利用C++。

#include <iostream>
using namespace std;

typedef unsigned int BOOL;

#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 1
#endif

typedef enum _SSC
{
TYPE_NONE,
TYPE_STONE,
TYPE_SCISSORS,
TYPE_CLOTH,
}GAMETYPE;

class CStoneScissorsCloth
{
protected:
GAMETYPE m_type;

public:
CStoneScissorsCloth() : m_type( TYPE_NONE ) {}
~CStoneScissorsCloth(){}

public:
void Set( GAMETYPE set )
{
m_type = set;
}
void Init()
{
Set(( GAMETYPE ) ( rand() % 3 + 1 ));
}
GAMETYPE Get() const
{
return m_type;
}
BOOL operator > ( const CStoneScissorsCloth& other )
{
switch( m_type )