|
|
---|---|
GameController.cs: Manages the overall game flow and player actions, including initiating the shuffle process: |
|
| |
| |
| |
This code is a collection of all the functions involved in the shuffle mechanic, though it doesn't exist as a single block in any one file. The complete shuffle logic is primarily found in GameModel.cs. | |
// 1. Initiate the shuffle process // In GameController.cs public void SomeGameAction() { // Other game logic... GameModel.ShuffleDeck(); // Call to shuffle the deck GameModel.GameStateActivate(GameState.GameStateType.mulliganDraw); // Activate the mulligan draw state } // 2. Shuffle the deck // In GameModel.cs public static void ShuffleDeck(int side) { List<Card> deck = model.players[side].deck; // Retrieve the cards from the deck Utility.ShuffleList(deck); // Call to the utility function to shuffle model.players[side].deck = deck; // Update the shuffled deck OnDeckShuffled(side); // Call the deck shuffled event } // 3. Handle the deck shuffled event // In GameModel.cs public static void OnDeckShuffled(int side) { // Notify that the deck has been shuffled CallbackOn(CallbackOnEnum.OnDeckShuffled, new object[] { side }); // Use a callback to handle the shuffle effect } // 4. Utility function for shuffling // In Utility.cs public static void ShuffleList<T>(List<T> list) { List<T> list2 = new List<T>(); while (list.Count > 0) { int num = UnityEngine.Random.Range(0, list.Count); list2.Add(list[num]); list.RemoveAt(num); // Remove the element from the original list } for (int i = 0; i < list2.Count; i++) { list.Add(list2[i]); // Put the shuffled elements back into the original list } } // 5. Drawing cards and checking the deck state // In GameModel.cs public static void Draw(int side) { // Check if the deck has cards before drawing if (DeckCount(side) == 0) { // Handle the case where the deck is empty (e.g., deal damage to the hero) HandleEmptyDeck(side); return; // Exit the function if the deck is empty } // Logic to draw a card ShadowEraCard card = GetDeck(side, DeckCount(side) - 1); // Get the last card from the deck AddHand(card); // Add the card to the player's hand // Notify that the card has been drawn OnCardDrawn(side); } // 6. Handling the consequences of an empty deck public static void HandleEmptyDeck(int side) { // Apply consequences, such as dealing damage to the hero // Example: model.players[side].hero.TakeDamage(damageAmount); } // 7. Callback calls // In SpecificCard.cs public void CallbackOn(CallbackOnEnum method, object[] param) { switch (method) { case CallbackOnEnum.OnDeckShuffled: OnDeckShuffled((int)param[0]); // Call the appropriate method when the deck is shuffled break; // Handle other game events... } } // 8. Other calls related to shuffling in gameplay // In Gameplay.cs public void ShuffleOurDeck() { GameModel.ShuffleDeck(); // Call to shuffle the current player's deck } |
*Explanation of `GameStateActivate(GameState.GameStateType.mulliganDraw):` In card games, a "mulligan" is a mechanism that allows players to redraw their initial cards before the game begins. This gives them the chance to improve their hand by exchanging unwanted cards or all cards in hand. |
---|