JAVA:疯狂的八人模型游戏与抽象 [英] JAVA: crazy eights model game with abstraction

查看:104
本文介绍了JAVA:疯狂的八人模型游戏与抽象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

我正在尝试创建一个使用Player类抽象的Crazy Eights游戏的模型类。该模型遵循以下规则:



1.游戏开始时每个玩家从牌组中获得一定数量的牌。



2.从牌组中取出一张牌并放在弃牌堆的顶部(玩家可以看到)。



3一个玩家的回合包括从牌组中取出零张或多张牌(将它们添加到他们手中),然后在弃牌堆的顶部打一张牌(从手中取出)。



4.玩家总是可以从他们手牌中打出一张牌,与弃牌堆中的顶牌相同。



5 。玩家可以随时从手牌中打出与弃牌堆中的顶牌相同的牌。



6.玩家可以随时玩牌当玩家玩8时,他们可以将卡的套装改为他们选择的四种套装中的任何一套。 (你将通过从手中移除八个然后返回一个带有所需套装的新Card对象来完成此操作。)



7.允许玩家(反复)在将卡片放入弃牌堆之前从牌组中取出一张牌。如果你能够,你必须打牌。如果牌组用完牌,游戏结束。



8.首先丢弃所有牌的玩家是赢家。如果在任何玩家可以玩所有牌之前牌组已经耗尽,那么就没有赢家。



9.你没有实施一个疯狂的八人游戏。您正在构建此类游戏所需的类。你正在构建游戏模型。



10.玩家不应该在游戏方法中欺骗。



Hello!
I am trying to create a model class of a Crazy Eights game that uses abstraction from a Player class. The model follows these rules:

1. The game starts with each player being given some number of cards from the deck.

2. A single card is taken from the deck and placed on top of the discard pile (and is visible to the player).

3. A player's turn consists of taking zero or more cards from the deck (adding them to their hand) and then playing a card on the top of the discard pile (removing it from their hand).

4. A player can always play a card from their hand that has the same rank as the top card in the discard pile.

5. A player can always play a card from their hand that has the same suit as the top card in the discard pile.

6. A player can always play a card with rank 8. When a player plays an 8, they are allowed to change the suit of the card to any of the four suits of their choosing. (You will do this by removing the eight from your hand and then returning a new Card object with the desired suit.)

7. A player is allowed to (repeatedly) take a card from the deck before playing a card to the discard pile. You must play a card if you are able to. If the deck runs out of cards, the game ends.

8. The player that discards all their cards first is the winner. If the deck is exhausted before any player can play all their cards then there is no winner.

9. You are NOT implementing a crazy eights game. You are building the classes that would be needed for such a game. You are building the model for the game.

10. Player should NOT be "able to cheat" in the play method.

//This is my parent Player class that the CrazyEightsPlayer class works off of:

public abstract class Player{
  protected Hand hand;

  public Player(Hand hand){ this.hand = hand; }

  /* play a card from the player's hand */
  /* returns null if they cannot play a card and the deck becomes empty */
  /* do NOT return null unless you cannot play a card and the deck is empty 
  */
  public abstract Card play(Card top_of_discard_pile, Deck deck);

  public final int cardsLeft(){ return this.hand.numberOfCards(); }

 }



//This is my subclass CrazyEightsPlayer:

public class CrazyEightsPlayer extends Player {
  public CrazyEightsPlayer(Hand hand) {
    super(hand);
  }

  @Override
  public Card play(Card top_of_discard_pile, Deck deck) {
     while ((deck != null) && hand != null) {
        if ( ){

        } else {

        }
     }
     return ;
   }
 }





我的尝试:



我刚做了很多打字和退格,输入了许多不同的东西来试图让它发挥作用。我是编码的新手,所以我很努力想办法让事情顺利进行>。<

请帮助!



What I have tried:

I have just done a lot of typing and backspacing, inputting a bunch of different things to try to make it work. I am new to coding so I struggle a lot trying to come up with ways to make things work >.<
Please help!

推荐答案

Quote:

我刚刚完成了大量的输入和退格操作,输入了许多不同的东西,试图让它工作。

I have just done a lot of typing and backspacing, inputting a bunch of different things to try to make it work.

并且有你的问题。



停止输入。

不,严重 - 停止打字。改为开始思考。

查看规则,并找出他们在你玩游戏时要求你做的事情。然后给自己一副牌并手动遵守规则。写下 - 作为文字说明 - 您需要实际遵循规则,您需要采取的行动,您需要存储的数据。



当你是很高兴你有这个问题,你将有一个文本描述你需要实现的类来计算机化问题。



这是一个分析任务,而不是一个主要是编码任务:规则9非常非常清楚。因此,分析问题而不是跳入代码!

And there is your problem.

Stop typing.
No, seriously - stop typing. Start thinking instead.
Look at the rules, and work out what they require you to do when you play. Then get yourself a deck of cards and follow the rules manually. Write down - as a text description - what you need to actually do to follow the rules, what actions you need, what data you have to store.

When you are happy that you have that down pat, you will have a text description of the classes you need to implement to computerize the problem.

This is an analysis task, not a primarily coding task: Rule 9 makes that very, very clear. So analyse the problem instead of leaping into code!


这篇关于JAVA:疯狂的八人模型游戏与抽象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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