0
\$\begingroup\$

I am creating a Yugioh java game with MVC. I was wondering wich is the better way to manage game states with MVC? I tought maybe I can use State Pattern in Model section with DrawPhase, InvocationPhase and BattlePhase as states, but in this way I won't know wich player has invoked a card or do something. Is there another way that allow me to know the whole game state and have control over the turns?
Also I'm not sure about using Threads with a Computer bot to play with so the idea of a game loop is almost discarded.

This Yugioh game is a little more simple:

On each turn you:

-Pick a card from your Deck and add it to your Hand

-Invoke monsters and spells to the board

-Battle Phase: atack to the opponent with your monsters that are in the board or use your spells that are in the board to: damage the opponent, gain life points, increase damage of monsters, etc. Monsters that fight can die and go to the gaveyard. (each player has a gaveyard)

-Next turn and repeat.

\$\endgroup\$
2
  • \$\begingroup\$ You'd likely get more/better help if you explained the game. Tell yourself that most of us have never played Yugioh and so we don't know the rules. \$\endgroup\$
    – Vaillancourt
    Commented Oct 28, 2022 at 21:31
  • \$\begingroup\$ It's not clear to me why using a state pattern would forbid you from storing the ID of the player who is acting. It is not clear to me why "the idea of a game loop is almost discarded" or what it would even mean to "almost" discard something. Can you edit your question to clarify? Consider walking us through your thinking step-by-step, illustrated with pseudocode if it helps you convey concrete details about the implementation you have in mind. \$\endgroup\$
    – DMGregory
    Commented Oct 28, 2022 at 21:53

1 Answer 1

1
\$\begingroup\$

From what I've understood, you want to use the States pattern to convey/control the overall game flow of the card game. You have defined 3 logical game states, Pick a card(s1), Invoke Monster(s2), and Battle Phase(s3).

Assuming your manager/controller class has an entity that is managing the transitions b/w these logical game states (s1,s2,s3), you can also have another entity that is storing/managing the current player state P1 or P2.

now the overall state of the game is defined as the combination of both logical game states and the current player state for eg.

{p1, s1}, {p1, s2}, {p1, s3} or {p2, s1}, {p2, s2}, {p2, s3}.

Now your View logic will be observing the overall state of the game, It will know which player turn is this, and what actions are allowed and will update accordingly.

Your View will also expose Action buttons to transition the logical game state using the controller. In the case of a bot, your bot script will directly use the controller to transition the state using the API provided by the controller.

The overall idea is to have different state machines instead of a single large one to represent the overall state of the game. Otherwise, permutation and combination will be high for the total number of states.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .