Pregunta

I've been at this for quite a while and I can't seem to solve the dynamic of the game.

So, basically, the game is a really popular card game in my Country called Truco. I'll try to explain it with the following bullet points, but anyways, the Bold paragraph after my explanation is pretty straightforward and simple as to what the game's structure is like, so, feel free to skip to that.

  • Each player alternates their turn, and in each turn Player 1 for example can play a card and play an action.
  • Action A is sort of like a poker bid, it raises the amount of points the winner would earn by winning the game and Player 2 must decide if they fold/loseTheGame, go along with the challenge or counter the bid, and raise the stakes.
  • There's also another type of action, lets call it Action B, if Player 1 calls it and Player 2 refuses to accept it, unlike Action A, the game isn't over, Player 2 simply loses some points at the end of the game. One can also counter this.
  • In a turn a Player can call a max of two actions, but never can he call an Action that has already been called in the game.
  • Each turn is ended with the Player playing a card of his.

All this must be REALLY confusing information for someone who does not know the game. So, to sum up, there a total of 6 turns, each turn is ended by a Player playing his card, and in each turn itself there is some exchanging of information between the two players consisting of challenges that the Player whose turn it is can call and the other must accept or refuse. Apart from all this, when the game ends the Match itself doesn't end, the Match is played until one of the two reaches 30 points, through the winning of games and challenges.

I started off trying to set it up with a while loop, but since the loops never pause and wait for onClickListeners, that failed quite easily. Then, I posted this question: How can I handle player turns in Android?

I started doing some research on the State Design Pattern and have be, n working on that for the past couple days. I have a class for the game itself: GameTruco. A TrucoState Class and 10 different implementations of that TrucoState. Inside GameTruco I have instances of all these different states and also all the different variables I need to keep track of, for the two actions the players can perform, whoseTurn it is and what round it is. So, all my options (be it different States and different methods that call these States) inside my GameTruco only consider the state of the game after the different Challenges that could be called, but DONT consider the playing of the cards themselves....I don't know quite how to handle this. And also, I don't quite get how I'm going to mix this up with my Button's onClickListeners when I finish designing this.

I would really appreciate it if anyone could advise me as to how to come up with a solution to this, either by recommeding a change in my State Pattern or another way of solving the dynamics of the card game.

¿Fue útil?

Solución

The State Pattern is probably a good solution to this problem.

my GameTruco only consider the state of the game after the different Challenges that could be called, but DONT consider the playing of the cards themselves

if the state is only considering whose turn it is and what the current bets are etc, then the cards could be considered separate from the state. You will need to have logic else where to track the cards and how to determine who won (which perhaps also updates the state)

also, I don't quite get how I'm going to mix this up with my Button's onClickListeners when I finish designing this.

Your click listener code should be the place where the states are changed.

Example:

//listener code implementation
//user has decided to raise...

int raiseAmount = ... // perhaps passed in thru listener or from UI objects
State currentState;  //current state before raise

currentState = currentState.player1Raises(raiseAmount);
//now state is for player 2 to decide what to do

//update UI to let player 2 decide what to do given current State
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top