示例#1
0
        public void refreshLabel1()
        {
            string X = "";
            string O = "";

            if (GameForm.aiGame == true)
            {
                log.Debug("It is one player game");
                X = OnePlayerForm.getPlayerXValue();
                O = "Computer";
            }
            else if (GameForm.aiGame == false)
            {
                log.Debug("It is two player game");
                X = TwoPlayersForm.getPlayerXValue();
                O = TwoPlayersForm.getPlayerOValue();
            }


            String newText = "It is ";

            if (theBoard.getPlayerForTurn() == Board.X)
            {
                newText += X;
                log.Debug("It is player X turn");
            }
            else
            {
                newText += O;
                log.Debug("It is player O turn");
            }
            newText    += "'s Turn\n";
            newText    += X + " has won " + theBoard.getXwins() + " times.\n" + O + " has Won " + theBoard.getOwins() + " times";
            label1.Text = newText;
        }
示例#2
0
        public void refreshtable(DataGridView d)
        {
            string X = "";
            string O = "";
            Player playerX;
            Player playerO;

            if (GameForm.aiGame == true)
            {
                X = OnePlayerForm.getPlayerXValue();
                O = "Computer";
            }
            else if (GameForm.aiGame == false)
            {
                X = TwoPlayersForm.getPlayerXValue();
                O = TwoPlayersForm.getPlayerOValue();
            }

            DataSet  ds = new DataSet();
            Database db;

            playerO = new Player(O);

            if (O != "Computer")
            {
                playerO.setWins(theBoard.getOwins());
                playerO.setLosses(theBoard.getXwins());
                playerO.setHighScore(theBoard.getOwins());
                db = new Database(playerO);
            }

            playerX = new Player(X);

            playerX.setWins(theBoard.getXwins());
            playerX.setLosses(theBoard.getOwins());
            playerX.setHighScore(theBoard.getXwins());
            db = new Database(playerX);

            db.fillTable(db.getConnection(), ds);

            d.DataSource = ds.Tables[0];
            d.Refresh();
        }
示例#3
0
        public void detectHit(Point loc)
        {
            //check if the board is clicked
            log.Debug("check if the board is clicked");
            if (loc.Y <= 500)
            {
                int x = 0;
                int y = 0;

                if (loc.X < 167)
                {
                    x = 0;
                }
                else if (loc.X > 167 && loc.X < 334)
                {
                    x = 1;
                }
                else if (loc.X > 334)
                {
                    x = 2;
                }


                if (loc.Y < 167)
                {
                    y = 0;
                }
                else if (loc.Y > 167 && loc.Y < 334)
                {
                    y = 1;
                }
                else if (loc.Y > 334 && loc.Y < 500)
                {
                    y = 2;
                }

                if (holders[x, y].getValue() == B && !isBoardFull())
                {
                    log.Debug("check player turn");

                    //it's X's turn
                    if (movesMade % 2 == 0 && holders[x, y].getValue() == B)
                    {
                        GFX.drawX(new Point(x, y));
                        holders[x, y].setValue(X);

                        if (detectRow())
                        {
                            if (GameForm.aiGame == true)
                            {
                                MessageBox.Show("you have won, " + OnePlayerForm.getPlayerXValue());
                            }
                            else if (GameForm.aiGame == false)
                            {
                                MessageBox.Show("you have won, " + TwoPlayersForm.getPlayerXValue());
                            }

                            Xwins++;
                            reset();
                            GFX.setUpCanvas();
                        }

                        if (GameForm.getAIgame() && !detectRow() && !isBoardFull())
                        {
                            Holder aiMove = ComputerLogic.determineAndPlaceMark(holders);
                            GFX.drawO(aiMove.getLocation());

                            holders[aiMove.getLocation().X, aiMove.getLocation().Y].setValue(O);


                            if (detectRow())
                            {
                                MessageBox.Show("Compuetr has won");
                                Owins++;
                                reset();
                                GFX.setUpCanvas();
                            }

                            movesMade++;
                            playersTurn = X;
                        }

                        playersTurn = O;
                    }

                    else
                    {
                        GFX.drawO(new Point(x, y));
                        holders[x, y].setValue(O);
                        if (detectRow())
                        {
                            MessageBox.Show("you have won, " + TwoPlayersForm.getPlayerOValue());
                            Owins++;
                            reset();
                            GFX.setUpCanvas();
                        }
                        playersTurn = X;
                    }

                    movesMade++;
                }
                if (isBoardFull())
                {
                    MessageBox.Show("It is tie, Play again");
                    reset();
                    GFX.setUpCanvas();
                }
            }
        }