Ejemplo n.º 1
0
        private void easy_Click(object sender, EventArgs e)
        {
            _ai.Depth = 1;
            Connect_4 f = new Connect_4(_u1, _ai, true);//Will open the game assigning the difficulty to the ai depending on which button the user clicked. Each number represents a different difficulty.

            f.Show();
            f.Closed += (s, args) => this.Close();
            this.Hide();
        }
Ejemplo n.º 2
0
        private void hard_Click(object sender, EventArgs e)
        {
            _ai.Depth = 3;
            Connect_4 f = new Connect_4(_u1, _ai, true);

            f.Show();
            f.Closed += (s, args) => this.Close();
            this.Hide();
        }
Ejemplo n.º 3
0
        private void ld_Click(object sender, EventArgs e)
        {
            OleDbConnection c = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='..\..\Resources\Saved Games.accdb'");

            c.Open();
            OleDbDataAdapter da1 = new OleDbDataAdapter(@"SELECT Columns FROM MoveHistory WHERE GameName = ?", c);//Loads all the movehistory from that game from the database.
            OleDbParameter   p1  = new OleDbParameter();

            p1.ParameterName = @"?";
            p1.Value         = textBox1.Text.ToString();
            da1.SelectCommand.Parameters.Add(p1);
            DataTable dt1 = new DataTable();

            da1.Fill(dt1);
            List <int> mh = new List <int>();

            foreach (DataRow r in dt1.Rows)
            {
                mh.Add((int)r["Columns"]);                                                             // Adds the movehistory into list as length is not fixed.
            }
            OleDbDataAdapter da2 = new OleDbDataAdapter(@"SELECT * FROM Game WHERE GameName = gn", c); // Gets all the other information needed to load the game.
            OleDbParameter   p2  = new OleDbParameter();

            p2.ParameterName = @"gn";
            p2.Value         = textBox1.Text.ToString();
            da2.SelectCommand.Parameters.Add(p2);
            DataTable dt2 = new DataTable();

            da2.Fill(dt2);
            c.Close();
            foreach (DataRow r in dt2.Rows)
            {
                bool isSP = (bool)r["isSP"];
                User u1   = new User((int)r[@"P1CounterNum"]);// Stores the values into the User classes so can be used in game.
                if (isSP)
                {
                    AI ai = new AI((int)r[@"P2CounterNum"]);
                    ai.Depth = (int)r[@"Difficulty"];
                    Connect_4 c4 = new Connect_4(u1, ai, 1, mh, true);//Opens the connect 4 game with the two users and movehistory if singleplayer.
                    this.Hide();
                    c4.Closed += (s, args) => this.Close();
                    c4.Show();
                }
                else
                {
                    User      u2 = new User((int)r[@"P2CounterNum"]);
                    int       pt = (int)r[@"PlayerTurn"];
                    Connect_4 c4 = new Connect_4(u1, u2, pt, mh, false);//Opens the connect 4 game with two users and movehistory when multiplayer.
                    this.Hide();
                    c4.Closed += (s, args) => this.Close();
                    c4.Show();
                }
            }
            gameName.Visible = true;
        }
Ejemplo n.º 4
0
        private void userChecker()
        {
            int userCounter = 0;

            if (_isMP && _playerCount == 1)
            {
                if (_otherUserColour == _colourNumber)
                {
                    AIU.Visible = true;
                    return;
                }
                User      p2 = new User(_colourNumber);
                Connect_4 f  = new Connect_4(_p1, p2, false);//If its the second user on multiplayer they will both be assigned the colours and the game will be open.
                f.Closed += (s, args) => this.Close();
                f.Show();
                this.Hide();
            }
            else if (_isMP && _playerCount == 0)
            {
                _playerCount++;
                User            p1 = new User(_colourNumber);
                Counter_Chooser c  = new Counter_Chooser(_isMP, _playerCount, p1, p1.CounterColour);//If its multiplayer but first user then player 1s counter colour assigned and counter chooser called again for player 2.
                c.Closed += (s, args) => this.Close();
                c.Show();
                this.Hide();
            }
            else
            {
                do
                {
                    Random r = new Random();
                    userCounter = r.Next(1, 6);
                } while (userCounter == _colourNumber);// Will choose a random colour for the ai making sure it doesn't clash with the users.
                User       player1 = new User(_colourNumber);
                AI         player2 = new AI(userCounter);
                Difficulty f       = new Difficulty(player1, player2);// The ai and user are assingned there colours then the difficulty form is called.
                f.Closed += (s, args) => this.Close();
                f.Show();
                this.Hide();
            }
        }