Set程序的游戏,需要帮助进行循环嵌套等等 [英] Game of Set program, need help with for loop nesting and more

查看:79
本文介绍了Set程序的游戏,需要帮助进行循环嵌套等等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一款名为Set的游戏,它是一款纸牌游戏:这里是规则的简要说明:


Set的游戏是用81张牌进行的,每张牌都是它有4个属性(数量,模式,

颜色和形状)。对象的数量是1,2或3. 3种可能的模式是实心的,

条纹和打开。 3种可能的颜色是红色,绿色和紫色。 3种可能的

形状是钻石,波浪形和椭圆形。 81张牌包含所有可能的组合

的图案,颜色和形状。一些示例卡是:

? 1条纹红色椭圆

? 2纯绿色波浪

? 3打开紫色钻石


好​​了我现在遇到的麻烦就是创建我的81张牌。我试图这样做的方法是创建一个嵌套的for循环(应该只有4),它遍历每个数组并获得数字,颜色,形状和模式。如果嵌套正确我应该能够创建一组卡片,其中包含数字,颜色,形状和图案的81种可能组合。

展开 | 选择 | Wrap | 行号

解决方案

一个名为getDeckOfCards的方法不应该是空的。它必须返回List< Card>相反。
枚举将有助于清理代码和逻辑


现在我想为该方法创建一副81张牌。我不确定我是否还应该归还任何东西。此外,我对Enums链接感到困惑,以帮助清理代码。我会继续看它。


假设你有一个名为Color的枚举。

Color.values()方法为你提供了一个包含所有颜色的数组

I am making a game called Set, it is a card game: here is a brief description of the rules:

The game of Set is played with 81 cards, each of which has 4 properties (number, pattern,
color and shape). The number of objects is 1, 2, or 3. The 3 possible patterns are solid,
striped, and open. The 3 possible colors are red, green, and purple. The 3 possible
shapes are diamond, squiggle, and oval. The 81 cards comprise all possible combinations
of patterns, colors and shapes. Some example cards are:
? 1 Striped red oval
? 2 Solid green squiggle
? 3 Open purple diamond

Ok now what I am having trouble with is creating my deck of 81 cards. The way I am trying to do it is by creating a buch of nested for loops (should only be 4) that goes through each array and gets a number, color, shape and pattern. If nested right I should be able to create a deck of cards that has 81 possible combination''s of numbers, colors, shapes and patterns.

Expand|Select|Wrap|Line Numbers

解决方案

A method called getDeckOfCards should not be void. It must be returning a List<Card> instead.
Enums will help to clean up the code and logic


Right now I want to just create a deck of 81 cards for that method. Im not sure If i should be returning anything yet. Also I am confused on the Enums link to help clean up the code. I will continue looking at it though.


Suppose you have an enum called Color.
The Color.values() method gives you an array of all the colors.


这篇关于Set程序的游戏,需要帮助进行循环嵌套等等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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