Skip to content

Instantly share code, notes, and snippets.

@phibr0
Created February 13, 2025 17:41
Show Gist options
  • Save phibr0/b9dc7028090211a3103fa6432843d9e2 to your computer and use it in GitHub Desktop.
Save phibr0/b9dc7028090211a3103fa6432843d9e2 to your computer and use it in GitHub Desktop.

Textuelle Methodenbeschreibung

PlayerActionService

startTurn(): Unit

General Information:
Change to screen that displays the calling player as current player and shows the card deck of that player.

Preconditions:

  • Game must be started and a game is currently running.
  • The game was showing the NextPlayerScreen.

Postconditions:

  • The game screen is shown.
  • The NextPlayerScreen is hidden.

Errors:

  • IllegalStateException: Thrown when the game is not active or when the preconditions aren’t met.

endTurn(): Unit

General Information:
Ends the turn, changes to NextPlayerScreen.

Preconditions:

  • A valid turn has been made.
  • A game is currently running.

Postconditions:

  • The next player screen is shown.
  • The next player is set.

Errors:

  • IllegalStateException: Thrown when no valid turn has been made before.

drawCard(): Card

General Information:
Gives the single card from the top of the draw stack.

Preconditions:

  • The game has started.
  • The card stack is not empty.
  • The calling player has no more than 9 cards in hand.

Postconditions:

  • The returned card is given to the calling player.

Results:
Returns the drawn card.

Errors:

  • IllegalStateException: draw stack empty

mixCardsIn(): List<Card>

General Information:
Player mixes hand cards into the draw stack, shuffles them, and draws 5 cards.

Preconditions:

  • The hand contains at least 8 cards.
  • The draw stack is not empty.
  • The game is started and running.

Postconditions:

  • The hand was mixed into the draw stack.
  • 5 new cards were drawn into the hand.

Results:
Returns the new hand.

Errors:

  • IllegalStateException: Thrown when the game is not active or when the preconditions aren’t met.

passTurn(lastRoundPassed: Boolean): Unit

General Information:
Passes the turn. If 2 passes occur in a row, the game ends.

Preconditions:

  • The game has started.
  • It is not possible to mix cards in.
  • It is not possible to draw cards.
  • It is not possible to play cards.

Parameter:

  • lastroundpassed: Boolean indicating if it is the last round.

Postconditions:

  • Either the game end screen is shown if lastroundpassed is set to true or the turn ends.

Errors:

  • IllegalStateException: Thrown when the game is not active or when the preconditions aren’t met.

playCard(card: Card): Unit

General Information:
Enables a player to play one card from their hand. The playing card is placed on top of the central deck as long as it is valid.

Preconditions:

  • The game must be started and hasn’t ended yet.
  • The player has at least one card in their hand.

Postconditions:

  • The playing card is on top of one of the central decks.
  • The playing card is no longer in the player’s hand.

Parameter:

  • card: The card that will be played.

    Valid Range for Parameter Value:

    • The card must have a value of +1 or -1 compared to at least one of the two cards in the central deck.
    • The card must have a value of +2 or -2 compared to at least one of the two cards in the central deck if it has the same suit as one of the two cards in the central deck.

Errors:

  • IllegalStateException: Thrown if the game hasn’t started yet or the player is not in the game.
  • IllegalArgumentException: Thrown if the playing card is invalid.

GameService

startNewGame(): Unit

General Information:
Prepares the game after being launched by the player.

Preconditions:

  • The game must be launched and no game is currently being played.

Postconditions:

  • Both players have chosen a name.
  • Both players have 5 hand cards.
  • Both players have a draw stack of 20 cards each.
  • There are two central stacks in the middle with 1 card each.
  • The screen shows the "next-turn-screen" with the player's name on it.

Errors:

  • IllegalStateException: Name not provided

endCurrentGame(): Unit

General Information:
Allows stopping the game and displays a final end screen to the users.

Preconditions:

  • A second pass in a row occurs, or one player doesn’t have any cards in their hand and their draw stack is empty.

Postconditions:

  • The end scene is displayed, showing either the winning player or “Draw.”

Errors:

  • IllegalStateException: Thrown when the game is not active or when the preconditions aren’t met.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment