Example #1
0
        /// <summary>
        /// Return to the main menu after displaying a message.
        /// </summary>
        private void Game_End(object sender, GameLogEventArgs e)
        {
            // Clear everything.
            cpActiveCards.Reset();
            cpPlayerHand.Reset();
            cpAIHand.Reset();
            playerHand.Clear();
            aiHand.Clear();

            // Update stats.
            stats.NumberOfGames++;
            if (game.Fool == player)
            {
                stats.Losses++;

                MessageBox.Show("You're the fool!");
                Trace.WriteLine($"Game End! {stats.PlayerName} loses");
            }
            else
            {
                stats.Wins++;

                MessageBox.Show("You win!");
                Trace.WriteLine($"Game End! {stats.PlayerName} wins");
            }
            UpdateStats();

            // Print log.
            Trace.Flush();

            // Back to the main menu!
            tlpGameScreen.Hide();
            tlpMainMenu.Show();
        }
Example #2
0
        /// <summary>
        /// Sub to the correct events whenever a new bout happens.
        /// </summary>
        private void Game_NewBout(object sender, GameLogEventArgs e)
        {
            // A bug in the game lib makes it so that the first bout does not
            // fire a "bout end" event, so we clear the playing field on
            // "new bout" instead of "bout end".
            cpActiveCards.Reset();

            selectedCard = Player.NO_ACTION;

            // Sub to the new bout's events.
            game.CurrentBout.Report += PrepForTurn;

            Trace.WriteLine("New Bout\n--------");
        }
Example #3
0
        /// <summary>
        /// Determine whether the user is attacking or defending, disable cards they can't use.
        /// </summary>
        private void PrepForTurn(object sender, GameLogEventArgs e)
        {
            Bout bout = (Bout)sender;

            isAttacking = bout.Attacker == player;

            // When attacking, the concede button is disabled on the first turn, then enabled on
            // subsequent turns.
            if (isAttacking)
            {
                cpActiveCards.LabelText = "Attack!";

                if (bout.AttackCardsPlayed.Count == 0)
                {
                    btnGameConcede.Enabled = false;
                }
                else
                {
                    btnGameConcede.Enabled = true;
                }

                // Enable clicking only valid cards.
                for (int cardIndex = 0; cardIndex < player.Hand.Count; cardIndex++)
                {
                    playerHand[cardIndex].Enabled = bout.IsValidAttack(player.Hand[cardIndex]);
                }
            }
            else
            {
                cpActiveCards.LabelText = "Defend!";

                // The button should always be enabled when defending.
                btnGameConcede.Enabled = true;

                // Enable clicking only valid cards.
                // We need to be sure that the next player to go is the user
                // otherwise we could end up in a situation where the we try
                // to find out if a card can defend when there are no attacking
                // cards.
                if (bout.ActingPlayer == player)
                {
                    for (int cardIndex = 0; cardIndex < player.Hand.Count; cardIndex++)
                    {
                        playerHand[cardIndex].Enabled = bout.IsValidDefense(player.Hand[cardIndex]);
                    }
                }
            }
        }
Example #4
0
 private static void Core_GameLogEventDelegate(object sender, GameLogEventArgs e)
 {
     Console.WriteLine(e.Content);
 }