Example #1
0
        public override string pcPlay(int[,] grid, int turn)
        {
            string result = "normal";

            result   = NormalPlay.play(grid, pcMark);
            countPC += 1;
            return(result);
        }
Example #2
0
        private void lbl20_Click(object sender, EventArgs e)
        {
            if (grid[2, 0] == 0)
            {
                playModel.userPlay(2, 0, grid, playModel.userMark);
                this.gameDecision(NormalPlay.checkStatus(grid, playModel.userMark), false);
                this.refreshVal();

                playModel.pcPlay(grid, playModel.pcMark);
                this.gameDecision(NormalPlay.checkStatus(grid, playModel.pcMark), true);
                this.refreshVal();
            }
        }
Example #3
0
 private void labelClick(int X, int Y)
 {
     if (isPlayer1)
     {
         playModel.userPlay(X, Y, grid, playModel.user1Mark);
         this.gameDecision(NormalPlay.checkStatus(grid, playModel.user1Mark), false);
         this.refreshVal();
         isPlayer1          = false;
         lbluser2.ForeColor = Color.White;
         lbluser1.ForeColor = Color.DimGray;
     }
     else
     {
         playModel.userPlay(X, Y, grid, playModel.user2Mark);
         this.gameDecision(NormalPlay.checkStatus(grid, playModel.user2Mark), true);
         this.refreshVal();
         isPlayer1          = true;
         lbluser2.ForeColor = Color.DimGray;
         lbluser1.ForeColor = Color.White;
     }
 }
Example #4
0
        public override string pcPlay(int[,] grid, int turn)
        {
            string result = "normal";

            if (isStartedByPC)
            {
                if (countPC == 0)
                {
                    grid[1, 1] = turn;
                    pcTurn1X   = 1;
                    pcTurn1Y   = 1;
                }
                else if (countPC == 1)
                {
                    if ((userTurn1X + userTurn1Y) % 2 == 0)
                    {
                        grid[2 - userTurn1X, 2 - userTurn1Y] = turn;
                        pcTurn2X = 2 - userTurn1X;
                        pcTurn2Y = 2 - userTurn1Y;
                    }
                    else
                    {
                        if (userTurn1X == 1)
                        {
                            grid[2, userTurn1Y] = turn;
                            pcTurn2X            = 2;
                            pcTurn2Y            = userTurn1Y;
                        }
                        else
                        {
                            grid[userTurn1X, 2] = turn;
                            pcTurn2X            = userTurn1X;
                            pcTurn2Y            = 2;
                        }
                    }
                }
                else if (countPC == 2)
                {
                    if ((userTurn1X + userTurn1Y) % 2 == 0)
                    {
                        if ((userTurn2X + userTurn2Y) % 2 == 0)
                        {
                            result = NormalPlay.play(grid, pcMark);
                        }
                        else
                        {
                            if (userTurn1X - userTurn2X == 1 && userTurn1Y == userTurn2Y || userTurn1X == userTurn2X && userTurn1Y - userTurn2Y == 1)
                            {
                                grid[2 * userTurn2X - userTurn1X, 2 * userTurn2Y - userTurn1Y] = turn;
                            }
                            else
                            {
                                grid[2 - (2 * userTurn2X - pcTurn2X), 2 - (2 * userTurn2Y - pcTurn2Y)] = turn;
                            }
                        }
                    }
                    else
                    {
                        if (grid[2 - (userTurn1X * 2 - pcTurn2X), 2 - (2 * userTurn1Y - pcTurn2Y)] == 0)
                        {
                            grid[2 - (userTurn1X * 2 - pcTurn2X), 2 - (2 * userTurn1Y - pcTurn2Y)] = turn;
                        }
                        else
                        {
                            grid[2 - pcTurn2X, 2 - pcTurn2Y] = turn;
                        }
                    }
                }
                else
                {
                    result = NormalPlay.play(grid, pcMark);
                }
            }
            else
            {
                if (countPC == 0)
                {
                    if (grid[1, 1] == 0)
                    {
                        grid[1, 1] = turn;
                        pcTurn1X   = 1;
                        pcTurn1Y   = 1;
                    }
                    else
                    {
                        grid[0, 2] = turn;
                        pcTurn1X   = 0;
                        pcTurn1Y   = 2;
                    }
                }
                else if (countPC == 1)
                {
                    if (userTurn1X == 1 && userTurn1Y == 1)
                    {
                        if (userTurn2X == 2 && userTurn2Y == 0)
                        {
                            grid[0, 0] = turn;
                            pcTurn1X   = 0;
                            pcTurn1Y   = 0;
                        }
                        else
                        {
                            result = NormalPlay.play(grid, pcMark);
                        }
                    }
                    else
                    {
                        if (userTurn1X + userTurn2X == 2 && userTurn1Y + userTurn2Y == 2)
                        {
                            grid[0, 1] = turn;
                            pcTurn1X   = 0;
                            pcTurn1Y   = 1;
                        }
                        else
                        {
                            result = NormalPlay.play(grid, pcMark);
                        }
                    }
                }
                else
                {
                    result = NormalPlay.play(grid, pcMark);
                }
            }
            countPC += 1;
            return(result);
        }
Example #5
0
        public void refreshVal()
        {
            if (lbl00.InvokeRequired)
            {
                refreshValCallback d = new refreshValCallback(refreshVal);
                this.Invoke(d);
            }
            else
            {
                if (grid[0, 0] == 0)
                {
                    lbl00.Text = "";
                }
                else if (grid[0, 0] == 1)
                {
                    lbl00.Text = "X";
                }
                else if (grid[0, 0] == -1)
                {
                    lbl00.Text = "O";
                }
                if (grid[0, 1] == 0)
                {
                    lbl01.Text = "";
                }
                else if (grid[0, 1] == 1)
                {
                    lbl01.Text = "X";
                }
                else if (grid[0, 1] == -1)
                {
                    lbl01.Text = "O";
                }
                if (grid[0, 2] == 0)
                {
                    lbl02.Text = "";
                }
                else if (grid[0, 2] == 1)
                {
                    lbl02.Text = "X";
                }
                else if (grid[0, 2] == -1)
                {
                    lbl02.Text = "O";
                }
                if (grid[1, 0] == 0)
                {
                    lbl10.Text = "";
                }
                else if (grid[1, 0] == 1)
                {
                    lbl10.Text = "X";
                }
                else if (grid[1, 0] == -1)
                {
                    lbl10.Text = "O";
                }
                if (grid[1, 1] == 0)
                {
                    lbl11.Text = "";
                }
                else if (grid[1, 1] == 1)
                {
                    lbl11.Text = "X";
                }
                else if (grid[1, 1] == -1)
                {
                    lbl11.Text = "O";
                }
                if (grid[1, 2] == 0)
                {
                    lbl12.Text = "";
                }
                else if (grid[1, 2] == 1)
                {
                    lbl12.Text = "X";
                }
                else if (grid[1, 2] == -1)
                {
                    lbl12.Text = "O";
                }
                if (grid[2, 0] == 0)
                {
                    lbl20.Text = "";
                }
                else if (grid[2, 0] == 1)
                {
                    lbl20.Text = "X";
                }
                else if (grid[2, 0] == -1)
                {
                    lbl20.Text = "O";
                }
                if (grid[2, 1] == 0)
                {
                    lbl21.Text = "";
                }
                else if (grid[2, 1] == 1)
                {
                    lbl21.Text = "X";
                }
                else if (grid[2, 1] == -1)
                {
                    lbl21.Text = "O";
                }
                if (grid[2, 2] == 0)
                {
                    lbl22.Text = "";
                }
                else if (grid[2, 2] == 1)
                {
                    lbl22.Text = "X";
                }
                else if (grid[2, 2] == -1)
                {
                    lbl22.Text = "O";
                }

                if (myTurn)
                {
                    lbluser2.ForeColor = Color.DimGray;
                    lbluser1.ForeColor = Color.White;
                }
                else
                {
                    lbluser2.ForeColor = Color.White;
                    lbluser1.ForeColor = Color.DimGray;
                }

                //check if one of them won
                //user1=false, user2=true
                this.gameDecision(NormalPlay.checkStatus(grid, playModel.user1Mark), false);
                this.gameDecision(NormalPlay.checkStatus(grid, playModel.user2Mark), true);
            }
        }