Programming a JAVA card game similar to "Oh, hell"

Started by
4 comments, last by Zahlman 14 years, 7 months ago
I am programming a JAVA card game called "Bankeren" and I cant figure out how to model the program. Anybody who can help me/give me some pointers. I have already programmed the Suit, Rank, Hand, Card and Deck classes. And I also have the Swing GUI ready, I just need the control structure. Obviously I want this to be a LAN/WAN game... Below is the rules of the game. Game: A Norwegian game very similar to "Oh, hell". Players: 5 players. Deck: Standard 52-card deck. Ace is high; 2 is low. Goal: To score the most points by accurately predicting how many tricks you'll win. Setup: Shuffle the cards. Choose a dealer. For each subsequent hand, the player to the left of the previous dealer becomes the new dealer. There is 20 hands in the game. For the first hand of the game, each player receives one card. For the second hand, each player receives two cards. The third hand, three cards, and so on until 10 cards, and the down to 1 card again. After the cards are dealt, the dealer turns the next card face up. The suit of this card establishes the trump suit. Remaining cards are set aside and not used in that hand. Bidding: All players bid simultaneously. Each player must bid; no one may pass. Legal bids range from 0 to the number of cards dealt for that round. EXAMPLE: If four cards are dealt, legal bids range from 0 to 4. Players are bidding on the number of tricks they think they'll win in that hand. Gameplay: The player with the highest bid plays first ("leads"), if more than one player has the highest bid, the player closest to the dealer (clockwise) leads. Play continues clockwise. Each player must follow suit (i.e. play the same suit that was led) if possible. Generally, each trick is won by the player who played the highest rank of the suit led. However, if the suit led was not trump, and one or more players played a trump card, then the trick is won by the player who played the highest rank of trump. When a trick is won, the winning player sets the trick in front of himself so that it's easy to tell how many tricks each player has won. Scoring: One player serves as the scorekeeper (this would be the computer). As each player makes his bid, the scorekeeper writes them down. All information about the bids is open, and any player can ask for a reminder of who bid what at any time during the game. Players only score points by precisely predicting the number of hands they would win. A bid that's either too high or too low scores zero points. Each player who makes his bid exactly scores 10 points plus the number of tricks won. EXAMPLE: Evelyn bid 4 and won 4 tricks. She scores 14 points (10+4). Frank bid 0 and won 0 tricks. He scores 10 points (10+0). Also if a player bids half or more of the dealt cards and wins, he gets a "double". EXAMPLE: Evelyn bid 4 on 8 cards and won 4 tricks. She scores 28 points ((10+4)*2) Winning: The player with the highest total score at the end of the game is the winner. Thanks in advance!
Advertisement
Quote:Original post by Krish88
I am programming a JAVA card game called "Bankeren" and I cant figure out how to model the program.


UML would probably work.
This sounds suspiciously like homework. What exactly are you having problems with? What have you tried so far?
Quote:Original post by Antheus
Quote:Original post by Krish88
I am programming a JAVA card game called "Bankeren" and I cant figure out how to model the program.


UML would probably work.


Yeah, but I can't figure out the relations between the classes and the server/client communication... BTW, do you know of any good UML freeware that can convert from diagram to code and vise versa
Quote:Original post by OrangyTang
This sounds suspiciously like homework. What exactly are you having problems with? What have you tried so far?


I can assure you that its not homework. It more of a hobby project. Its a game that me and some friends play.
To communicate with the server, you might add a Bid class, and make Bid and Card be Serializable - then just send the serialized forms down the wire. The server picks them up, deserializes, checks the type, checks validity, and records the response accordingly. Similarly, the server will need to communicate with the clients with StartBidding, StartPlaying, ItsYourTurn and RoundResults messages. (The client can add up the results from each round for itself.)

The server keeps track of every card in everyone's hand, and upon dealing, tells each client what the client's own hand is (and the trump card). You might use a state machine in the server (and probably similarly in the client too) to keep track of bidding and playing phases. In the bidding phase, the server waits for a response from each client; when it has them all, it sends ItsYourTurn to the player who leads (which also implies that play must have started), and StartPlaying to the others (so they can make any necessary updates to the GUI).

From there on, the server just keeps track of whose turn it is to play, sending ItsYourTurn as appropriate. (I guess it also sends a Card to each client so they know what was played.) If a message is received out of turn, or is invalid (e.g. the client sends a Card during bidding), the server logic should probably just ignore it, at least to start (i.e. you assume it's a cheating attempt, and that any subsequent error in the client is its own fault). :)

That should give the basic idea - of course there are lots of details missing, like setting up the connections to figure out who is playing (and giving the players names).

This topic is closed to new replies.

Advertisement