Exemplo n.º 1
0
        // manipulation
        private void StartGame()
        {
            int             id;
            List <string[]> players;

            // grab the player names and algorithms for each player
            players = new List <string[]>();

            for (int i = 1; i <= AcquireConstants.MaxPlayers; i++)
            {
                string basename = Lstartbase + i;
                if (null != GetItem <ComboBox>(basename, Lstartlist).SelectedItem)
                {
                    string[] npair = new string[2];
                    npair[0] = (string)GetItem <ComboBox>(basename, Lstartlist).SelectedItem;
                    npair[1] = (string)GetItem <TextBox>(basename, Lstarttext).Text;
                    players.Add(npair);
                }
            }

            if (players.Count < 2)
            {
                GetItem <TextBlock>(Lstartstatus).Text = (string)GetItem <Label>(Lstarterr).Content;
                return;
            }

            // start Acquire game engine
            game = new AcquireGame();

            // init game state
            computers.Clear();
            cycleQueue.Clear();

            // add the players
            foreach (string[] npairs in players)
            {
                if (npairs.Length != 2)
                {
                    throw new ArgumentException("Wrong size of the internal data structure");
                }
                if (!playerNames.ContainsKey(npairs[0]))
                {
                    throw new ArgumentException("Missing a player implementation");
                }

                id = game.AddPlayer(npairs[1], playerNames[npairs[0]] != Oppenents.Human);

                switch (playerNames[npairs[0]])
                {
                case Oppenents.Random:
                    computers.Add(id, new Computer1());
                    break;

                case Oppenents.Computer2:
                    computers.Add(id, new Computer2());
                    break;

                case Oppenents.Computer3:
                    computers.Add(id, new Computer3());
                    break;
                }
            }

            // hide the UI
            StartGrid.Visibility        = System.Windows.Visibility.Collapsed;
            FinalDisplayGrid.Visibility = System.Windows.Visibility.Collapsed;
            if (lifetime.Count > 0 && (computers.Count == game.Players.Count))
            {
                // only display if there are computer players
                DisplayLifetime();
            }

            // start the game
            game.StartGame();

            // update the UI
            Refresh(game.CurrentPlayer);
        }