在C中玩纸牌游戏需要帮助 [英] Need help with a card game in C.

查看:108
本文介绍了在C中玩纸牌游戏需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要C中的纸牌游戏帮助。

首先,我必须创建两种数据类型。第一个是卡片,使用结构来模拟单张卡片,并使用两个单独的枚举作为套装和等级。第二种数据类型是Card Deck,它支持用户输入的任意数量的卡包(必须使用动态内存分配)。需要CardDeck操作,如随机播放,分类,添加或删除卡等。



如果我完成了这笔金额,我想我可以做到实际游戏开发自己。感谢任何帮助



c



我的尝试:



这是我到目前为止所拥有的......



Need help with a card game in C.
First of all I have to create two data types. The first is "Card" using a struct to model a single card and using two seperate enum's for the suit and rank. The second data type is Card Deck which supports any number of packs of cards entered by the user(Must use dynamic memory allocation). Need CardDeck Operations such as shuffle, sorting, adding or removing cards, etc..

If i got this amount done, I think I would be able to do the actual game development myself. Any help is appreciated

c

What I have tried:

This is what I have so far..

#include <stdio.h>



// Data Type "Card"

struct Card
{
	char suit;
	char rank;
};


enum suit  { Club, Spade, Heart, Diamond};

enum rank { Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace};

推荐答案

嗯,您定义了枚举和数据结构。现在你需要添加一些真正的代码(即功能)。例如,尝试在卡组中实现卡片分类。我们很乐意为您提供帮助,一旦您开始并可能卡住。
Well, you defined the enumerations and a data structure. Now you need to add some real code (that is functionality). Try, for instance, to implement card sorting in the deck. We would be glad to help on that, once you started and possible get stuck.


在您的结构中定义 suit rank as char types。然后在下面定义两个枚举类型套装等级这只会让人感到困惑。首先定义枚举,然后使用这些类型(但名称不同)作为结构中的变量。然后,您可以在您创建的每张卡片中设置两种类型。



因此,您可以创建 CardDeck ,两者都包含的数组( CardDeck <52 ,以及Hand的任何数字)。洗牌需要一个随机发生器来选择52中的一个并创建一个新的洗牌卡阵列准备交易。



其他功能应该不会太难弄清楚。
In your struct you define suit and rank as char types. Then below that you define two enum types suit and rank which just serves to confuse. Define your enums first, and then use those types (but with different names) as the variables in your structure. You can then set both types inside each card that you create.

So from that you can create CardDeck and Hand, both of which would contain arrays of Cards (52 for the CardDeck, and whatever number for the Hand). Shuffling the deck just needs a randomiser to select one of the 52 and create a new array of shuffled cards ready to deal.

The other functions should not be too difficult to figure out.


这篇关于在C中玩纸牌游戏需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆