Thursday, 29 September 2011

Java: Enumerated Types ( The Player )

    Not much else to go! Let's think about what our player consists of. Not in a philosophical sense, mind, but only as far as the game gives a crap. The player consists of...a name (To differentiate them from each other) and a hand of cards. This is what I've then got for a player class (If you have something different, share it!):

First in this class, I've got some variables, straightforward enough. Since the size of the player's hand will change, I used an ArrayList to hold them, instead of the standard array I used for the deck. This might cause some problems with empty slots, so best to nip the problem in the bud. We can also, as a bonus, now use this class in other programs that don't require a set number of cards per hand. Next up is the constructor which is there to actually initialize the name. Next, we have newCard, to be used when being dealt cards, since cards are dealt 1 at a time, instead of a huge clump of 13 at once. the toString method is there so the players' hands can be represented, too. That's about it for the player, fairly straightforward.

So we have a player, the deck and the cards that the players will use. We need a table, at this point, as you may have astutely guessed. Y'know, from the title.

We'll want an enumeration for the compass directions of the table, To make sure the program goes in the correct (clockwise) order, we should probably also have some way to tell the program, in the enumeration, which direction is next. We need an array of players, the deck of cards and to specify where the dealer sits. We need a way to seat players where we want and we need to be able to deal cards out.

Go think about this. Try to make one yourself, and tomorrow, I'll show you my version. It's a fairly large class, at least relative to what we've seen up until this point, so I don't want to throw it at you directly after the player class.


That's all, folks!.Questions welcome! Comment, follow, subscribe, share etc, and see you tomorrow!


    And as part of a shameless plug for a friend, if you're interested in classic movies/books/music, visit his site here (fixed), and feel free to throw loads of criticism at us. 

9 comments:

  1. I have a tendency to name my player really horrible things. I think that may make me a bad person.

    ReplyDelete
  2. You are doing a great job teaching and explaining bit by bit, I'm still trying to catch up as I've started quite a few posts back :).

    ReplyDelete
  3. These are really great little lessons here. Keep it up!

    ReplyDelete
  4. We'll all be coding java in no time xD

    ReplyDelete
  5. I wish i had more time to sit and experiment with all that stuff you post here.

    ReplyDelete
  6. I have the same problem than that plumber.

    ReplyDelete
  7. I've never used Java before, only C++ and Javascript/HTML... this blog looks like a great source of info.

    ReplyDelete
  8. This is fucking my brain everytime.

    ReplyDelete