Beispiel #1
0
 void SetKingdom_Click(object sender, EventArgs e)
 {
     StartGameButton.Text = "Start";
     SetKingdomPanel.Show();
     GamePanel.Hide();
     SettingsPanel.Hide();
     ShowCurrentKingdomCards();
     ShowExtensionCards();
 }
Beispiel #2
0
        void StartButton_Click(object sender, EventArgs e)
        {
            GamePanel.Show();
            SetKingdomPanel.Hide();
            SettingsPanel.Hide();
            LogTextBox.Text          = "";
            StartGameButton.Text     = "Restart";
            SetKingdomButton.Enabled = false;
            SettingsButton.Enabled   = false;
            PlayAreaPanel.Controls.Clear();
            PhaseLabel.Text       = "Loading";
            PhaseDescription.Text = "Please wait, game will be ready as soon as possible.";

            gameParams.Save();

            if (tokenSource != null)
            {
                tokenSource.Cancel();
                tokenSource = new CancellationTokenSource();
            }

            Task.Run(() =>
            {
                var human = new Human(PlayCard, GainCard, Choice, AlternativeChoice, job, gameParams.User1Name);
                BuyAgendaManager manager = null;

                switch (gameParams.AIType)
                {
                case AIType.Tens:
                    manager = new SimpleManager(directoryPath, "Tens_");
                    break;

                case AIType.Fives:
                    manager = new CachedManager(directoryPath, 5, "Fives_");
                    break;

                case AIType.Threes:
                    manager = new CachedManager(directoryPath, 3, "Threes43_");     // TODO
                    break;

                default:
                    break;
                }

                var agenda = manager.LoadBest(gameParams.Cards);
                if (agenda == null)
                {
                    Action function = () =>
                    {
                        MessageBox.Show("There is no suitable opponent for this kingdom. \n Please try different cards or" +
                                        " different type of opponent.");
                        StopButton_Click(sender, e);
                    };
                    this.Invoke(function);
                    return;
                }

                var ai = new ProvincialAI(agenda, gameParams.AIType.ToString());

                var source = new CancellationTokenSource();

                Game game = new Game(new User[] { ai, human }, gameParams.Cards.GetKingdom(2), new WindowLogger(Log), tokenSource);
                game.Play(int.MaxValue).ContinueWith((results) => EnableNextGame(results));
            });
        }
Beispiel #3
0
 void OpenSettings(object sender, EventArgs e)
 {
     SetKingdomPanel.Hide();
     GamePanel.Hide();
     SettingsPanel.Show();
 }