Programming Technique: How to create a simple card game

前端 未结 6 1169
自闭症患者
自闭症患者 2020-12-24 00:10

as I am learning the Ruby language, I am getting closer to actual programming. I was thinking of creating a simple card game. My question isn\'t Ruby oriented, but I do kno

6条回答
  •  爱一瞬间的悲伤
    2020-12-24 00:24

    Macek's answer is good as far as for setting up a deck.

    You also asked about other entities.

    You probably want four "Players". Each player might be either human or machine controlled.

    To implement a human player, you interface with the screen/mouse/keyboard; to implement the machine controlled players, you have a hand and you can see some central cards on a table (all the players need to know of a central table that holds any cards that would be on the table).

    From there the logic is based on what game you are playing.

    Once your "Player" (AI) gets the turn (for instance, a takeTurn method is called on your player object), it should examine its cards and make the proper decisions--taking cards from stacks on the table or placing cards from its hand onto the table. (The table almost certainly has at least two stacks a player can access--"Draw" and "Discard".)

    When a Human player has his takeTurn method called, it should interface with the screen--updating the player's hand, allowing him to draw and discard.

    When each player is done with his turn, it should return. It can't directly call the next player (otherwise you'd start to build up a stack), so you need some form of turn control that can call the players in order. This centralized control also prevents players from knowing about each other, they shouldn't really need to (one of the best OO design tactics is that each object should know as little about other objects as possible).

    ...Still thinking... I may add more...

提交回复
热议问题