Ejemplo n.º 1
0
        /// <summary>
        /// Start a new game
        /// </summary>
        /// <param name="mode"></param>
        public Connect4Game(GameSettings.GAMEMODE mode, int startingPlayer, GameSettings.DIFFICULTY difficulty, GameSettings settings)
        {
            startTime = DateTime.Now;

            RED_PLAYER = settings.RED_PLAYER;
            YELLOW_PLAYER = settings.YELLOW_PLAYER;

            COLUMNS = settings.COLUMNS;
            ROWS = settings.ROWS;

            this.aiStrength = difficulty;

            this.GameMode = mode;

            this.STARTING_PLAYER = startingPlayer;

            this.activePlayer = startingPlayer;

            map = new int[settings.COLUMNS, settings.ROWS];

            switch (GameMode)
            {
                case (GameSettings.GAMEMODE.SinglePlayer):
                    {
                        position = new Position();
                        zuege = new MoveList();
                        comp = new ComputerPlayer(Position.WHITE, "Machine", true, difficulty);

                        this.GameState = GameSettings.GAMESTATE.S_BeforeGame;

                        break;
                    }
                case (GameSettings.GAMEMODE.CPUvsCPU):
                    {
                        position = new Position();
                        zuege = new MoveList();
                        comp = new ComputerPlayer(Position.WHITE, "Machine1", true, difficulty);

                        if (this.STARTING_PLAYER == RED_PLAYER)
                        {
                            this.GameState = GameSettings.GAMESTATE.S_WaitForCPU;
                            this.HUMAN_PLAYER = RED_PLAYER;
                        }
                        else
                        {
                            this.GameState = GameSettings.GAMESTATE.S_WaitForCPU;
                            this.HUMAN_PLAYER = YELLOW_PLAYER;

                        }

                        break;
                    }
                case (GameSettings.GAMEMODE.LocalMultiPlayer):
                    {
                        position = new Position();
                        zuege = new MoveList();

                        this.GameState = GameSettings.GAMESTATE.S_BeforeGame;

                        break;
                    }
                case (GameSettings.GAMEMODE.NetworkGame):
                    {
                        position = new Position();
                        zuege = new MoveList();

                        /*string line = "";
                        using (StreamReader sr = new StreamReader("net.txt"))
                        {
                            string tmp;
                            while ((tmp = sr.ReadLine()) != null)
                            {
                                line = tmp;
                            }
                            sr.Close();
                        }

                        int port = Convert.ToInt32(line.Split(',')[0]);
                        string ip = line.Split(',')[1];

                        if (Convert.ToInt32(line.Split(',')[2]) == 2)
                        {
                            netStartPlayer = 1;
                        }
                        else
                        {
                            netStartPlayer = 2;
                        }

                        NetGame = new Networking(port, ip);*/
                        this.GameState = GameSettings.GAMESTATE.S_WaitForConnection;

                        break;
                    }
            }
        }
Ejemplo n.º 2
0
        // Free ressources
        public void Dispose()
        {
            position = null;
            comp = null;
            zuege = null;
            AIStarted = false;

            ClearGame();
        }