To develop my skills with lists, scroll views and special actions, I created a digital version of the card game Bananya.
This included managing the draw deck and litter deck, cards in the player hands, and completing special actions when cards were played.
At the start of the game, each player receives 7 cards. To give players their cards, I created a for loop that chooses a random card from the deck list, adds it to the player's hand, and removes it from the deck list until the player has 7 cards. The game can be played with 2-4 players, so it checks the player count before selecting cards for players 3 and 4.
On a player's turn, they can take a card from the draw deck or litter box, and then play a card.
When the player takes a card from the draw deck, the card is removed from the remaining cards list and added to their hand.
If the player takes a card from the litter box, the are not allowed to play the card on that turn. I made this by only giving the card to the player once they have played a card, if they took from the litter box.
After the player has drawn one card, the decks are not interactable, and the cards in the player's hand are enabled.
Once the player has taken a card, they must play one card in their hand. When a card is played, it is moved to the litter box list, removed from the player's hand, and the litter box image is set to the card's image to show which card is at the top of the pile.
10 of the 11 card types in Bananya have a special action that must be performed. After playing a card, the resolve power function is run. If the card is a standard Bananya, the turn is ended, which stops the player's cards from being interactable, and enables the next player button to switch the current player's turn.
The Baby Bananya card allows the player to discard one card. To make this, I added a discard bool that is set to true when the player uses this card, and end the turn once another card has been chosen without using its ability.
The Bananyako card swaps the player's hands. I created an empty list used to transfer the cards between the players. I moved one deck into this list, set the other decks to the deck of the next player in sequence, and set the last player's deck to the transfer list. I then reset the cards to their new parent object so they would be in the correct scroll view.
The Mouse card swaps one card from each player's hand. Similarly to the Bananyako, I used an empty object to move the transfer card into, and then swapped the cards before placing the transfer card into the last player's hand.
The Bananya Bunch card gives one card to every player. I created a for loop that draws a card for each player as if it were their turn to give them a card, and then sets the turn back to the original player's turn.
The Daddy Bananya card is similar to the bunch, but only gives a card to the current player. To make this I used the same setup as the bunch, but without cycling through each player.
The Calico Bananya card allows the player to choose any card currently in the litter box. If there is at least one card in the litter box, the player's cards are not interactable, and the litter pick menu appears, which displays every card that is currently in the litter. When a player chooses one, it is removed from the litter box and added to the player's hand.
The Long Haired Bananya card allows the player to choose another player to miss their next turn. When the player uses this card, buttons to select which player to choose appear, and the buttons for the current player and inactive players are removed. When a player button is chosen, it sets the nextToSkip variable, which is then used to skip over that player's turn.
The Tabby Bananya card allows the player to take one card from another player's hand. This uses a similar menu to the Long Haired Bananya, but when a target player is selected, a random card from their hand is chosen and added to the current player's hand.
The Pirate Bananya card allows the player to ask for a card type and receive that card from every player who owns it. When a player uses this card, the pirate card menu is displayed, showing all the card types. When the player chooses one, all the other player's decks are searched for that card type, and if they have that card it is added to the player's hand.
The Mackerel Tabby Bananya card allows the player to have their turn again. I created a go again function, which resets the turn without changing the player turn.
The player can click the button to call having all 10 bananya types during their turn. Every card type the player currently has is added to a list, and the list is checked to see if it contains every type. If it does, the game ends. If the player is missing one or more types, 2 cards are randomly removed from their hand.