コード例 #1
0
ファイル: Board.cs プロジェクト: HeadBangZ/Connect4
 public void TheChampionIsPlayer(string playerColor)
 {
     MessageBox.Show(playerColor + " Player Wins!");
     InitializeBoard();
     Gfx.SetupCanvas();
     turn += 2;
 }
コード例 #2
0
ファイル: window.cs プロジェクト: HeadBangZ/Connect4
        private void Frame_Paint(object sender, PaintEventArgs e)
        {
            Graphics GfxToPass = Frame.CreateGraphics();

            engine = new Gfx(GfxToPass);

            ConnectFourBoard = new Board();
            ConnectFourBoard.InitializeBoard();
        }
コード例 #3
0
ファイル: Board.cs プロジェクト: HeadBangZ/Connect4
        public void DetectPosition(Point location)
        {
            int x = location.X / 100;
            int y = location.Y / 100;

            // Old Placement Detection
            #region Placement commented out
            //int x = 0;
            //int y = 0;

            //// Row value
            //if (location.X < 100)
            //{
            //	x = 0;
            //}
            //else if (location.X > 100 && location.X < 200)
            //{
            //	x = 1;
            //}
            //else if (location.X > 200 && location.X < 300)
            //{
            //	x = 2;
            //}
            //else if (location.X > 300 && location.X < 400)
            //{
            //	x = 3;
            //}
            //else if (location.X > 400 && location.X < 500)
            //{
            //	x = 4;
            //}
            //else if (location.X > 500 && location.X < 600)
            //{
            //	x = 5;
            //}
            //else if (location.X > 600 && location.X < 700)
            //{
            //	x = 6;
            //}

            //// Column Value
            //if (location.Y < 100)
            //{
            //	y = 0;
            //}
            //else if (location.Y > 100 && location.Y < 200)
            //{
            //	y = 1;
            //}
            //else if (location.Y > 200 && location.Y < 300)
            //{
            //	y = 2;
            //}
            //else if (location.Y > 300 && location.Y < 400)
            //{
            //	y = 3;
            //}
            //else if (location.Y > 400 && location.Y < 500)
            //{
            //	y = 4;
            //}
            //else if (location.Y > 500 && location.Y < 600)
            //{
            //	y = 5;
            //}
            #endregion

            // Turn check, and valid placement check
            if (BoardData[x, y].GetValue() == White)
            {
                //bool ColumnIsFilled = false;

                if (turn % 2 == 0)
                {
                    for (int col = BoardData.GetLength(1) - 1; col >= 0; col--)
                    {
                        if (BoardData[x, col].GetValue() == White)
                        {
                            Gfx.DrawRed(new Point(x, col));
                            BoardData[x, col].SetValue(Red);
                            DetectFourInARow(Red);
                            break;
                        }
                        //else if (col == BoardData.GetLength(1))
                        //{
                        //	ColumnIsFilled = true;
                        //}
                    }
                }
                else
                {
                    for (int col = BoardData.GetLength(1) - 1; col >= 0; col--)
                    {
                        if (BoardData[x, col].GetValue() == White)
                        {
                            Gfx.DrawYellow(new Point(x, col));
                            BoardData[x, col].SetValue(Yellow);
                            DetectFourInARow(Yellow);
                            break;
                        }
                        //else if (col == BoardData.GetLength(1))
                        //{
                        //	ColumnIsFilled = true;
                        //}
                    }
                }
                turn++;
            }
        }