Thursday, 10 November 2011

Java: Texas Hold Em (1)

Welp, let's do this. I'm basically looking at someone else's source code, which is incomplete. So I hope to get my framework from this other person's work, while being forced to do the actual building myself! I should mention that since I don't have a working copy, if I fuck up, there'll be a lot of going back to find things. Programming isn't very good as a linear progression, unless you're beyond amazing at it. There'll always be small errors that you missed, or that require some odd fix that doesn't seem to make sense.

Having said that, we should get going!

Okay, so...there'll definitely be a GUI. Probably several, combined into one, to stick with the OOP nature of Java. That looks icky, so we won't start with that. We could have bots, I suppose, but if we do, that'll be at the very end. It appears we're getting ahead of ourselves, so let's go down to a more basic level. What's needed to play the game, not thinking in terms of programming.

1) Players
2) Table
3) Deck of Cards
4) Cards to put in the deck
5) Dealer, to handle...dealing. Also, shuffling.
6) Hand of cards, for each Player

I think that`s enough to think about for now. Hopefully, you`ll agree that a Card is probably the simplest object here, so let`s work on that today. It`s a simple class, since it`s such a basic object, with only a rank and suit:

Ah, you remember enumerations, right? The guy who's (open source) work I'm jacking didn't, so this is probably a BIG sign that there'll be jumping back and other technical difficulties, but fuckit, I'm here to learn!

There, now we have both enumerations complete, we just put in our constructor. Normally you'd have a couple of if-statements to error check, but eh.

And here's all the methods. Simple things to return the suit and rank, and a basic toString() method. I might have to put a comparison in there later, but I'm not sure, yet! For now though, it looks like we're done with our card class.

Class adjourned! See you tomorrow! Questions/comments welcome, as always.


  1. Good to know! Texas hold em rules!

  2. Isn't there a complete version out there that you could refer to? I'm pretty sure that be of more help to you.

  3. Im from Tx and still dont know how to play Tx Hold Em

  4. Woot! Here we go, looking forward to this. Although I'm fuzzy on the actual rules of the game so I might have to re-learn them before I look into the coding process.

  5. I like where this is going. (:

  6. Yay! I'm printing your java walkthrough to start learning hard mode in february :D