写一个斗地主玩,不知道处理游戏逻辑的方法放在哪里好
本帖最后由 nigelleith 于 2013-04-11 16:23:58 编辑 小弟新手,
写了个斗地主,
就两个类,头文件和main文件如下:
main.cpp:
int main()
{
DDZLogicCenter one_game;
one_game.GameInit();//初始化牌桌
one_game.PlayOneGame();//玩一局,地主赢返回true,农民赢返回false
one_game.GameCount();//结算并打印结果
return 0;
}
DDZLogicCenter.h:
typedef multimap<int,int> PokeBuf;
class DDZLogicCenter
{
public:
bool GameInit();//初始化牌桌
bool PlayOneGame();//玩一局,地主赢返回true,农民赢返回false
int GameCount();//结算并打印结果
bool PushPoke();
private:
PokeBuf poke_buf_in_round_;//桌面上的牌
PokeBuf *poke_buf_in_hand_;//当前轮到的玩家手上的牌
PokeBufpoke_to_desk;//出的牌
PokeBufdizhu_,nongmin_a_,nongmin_b_;//三个玩家手上的牌
//PokeBuf *present_pointer[3] = {&dizhu_,&nongmin_a_,&nongmin_b_};//构建一个指针数组,用来做循环处理出牌权
int win_flag_;
};
DDZPokeType.h:
typedef pair<int,int> Poke;//<面值,花色>,面值为3-14,为了将2和大小鬼除在顺子外,2的number为16,小鬼为18,大鬼20
typedef multimap<int,int> PokeBuf;//一堆牌
typedef pair<int,pair<int,int>> PokeType;
const static int g_smalljoker = 18;
const static int g_bigjoker = 20;
class Cards
{
public:
Cards(PokeBuf poke_buf_);
//返回列表:张数为0:-2, 类型错误:-1, 单张:1, 对子:2, 三张不带:3, 三带一:4, 三带二:5, 四带二:6,
//顺子:7, 连对:8, aaa飞机:9, aaab飞机:10, aaabb飞机:11, 同时是两种三飞:12 炸弹:13, 火箭:14,
int GetType();
int GetLevelInType();//返回类型中的值,比如77788826则返回8
int GetConsecutiveNumber();//返回顺子,连对,飞机的几连
private:
PokeType IsOne();//返回consecutive_number_,即几连的连数,无连返回1
PokeType IsDouble();
PokeType IsTriple();
PokeType IsTripleAndOne();
PokeType IsTripleAndDouble();
PokeType IsQuadrupleAndTwo();
PokeType IsQuadruple();
PokeType IsRocket();
PokeType IsStraight();
PokeType IsDoubleStraight();
PokeType IsPlaneLikeAaa();
PokeType IsPlaneLikeAaa(PokeBuf);
PokeType IsPlaneLikeAaab();
PokeType IsPlaneLikeAaabb();
PokeBuf poke_buf_;
PokeType poke_type_;
}
大概就是这些方法.游戏是勉强能运行了,但是还是很别扭,牌型判定的class显得功能很独立,但是另外一个DDZLogicCenter感觉很乱,完全是有什么都往里面丢.不知道这些方法到底应该怎么安排.请问像这个游戏的话,到底应该怎么设计,哪些方法放在哪个类?望指教一下
(另外请教一下怎么怎么把代码弄成有行号的那种显示,感谢) 面向对象
[解决办法]
前年无聊也搞了一个斗地主,lz需要的话有空可以传给你,不过我都没用到类,完全是一摊子,不过不支持人机对战(AI不好搞啊),三个人联机的,不过后来扩展成游戏大厅,多个桌子的形式了。
[解决办法]