public algorithm(byte[,] arr, coors point) { this.size = Convert.ToInt16(Math.Sqrt(arr.Length)) - 1; this.arr = arr; this.point = point; this.playerSymbol = this.arr[this.point.y, this.point.x]; }
void pb_DoubleClick(object sender, EventArgs e) { PictureBox pb = sender as PictureBox; int row = Convert.ToInt16(pb.Name.Substring(2, 2)); int col = Convert.ToInt16(pb.Name.Substring(4, 2)); if (this.arrCaro[row, col] != 0) { return; } pb.BackgroundImage = this.player1 ? param.image.player1 : param.image.player2; this.arrCaro[row, col] = Convert.ToByte(this.player1 ? 1 : 2); this.nowPoint = new coors(col, row); bool checkWin = new algorithm(this.arrCaro, this.nowPoint).checkWin(); if (!checkWin) { this.player1 = !this.player1; this.Controls["player1"].Visible = this.player1; this.Controls["player2"].Visible = !this.player1; return; } MessageBox.Show("Player " + (this.player1 ? "Red" : "Blue") + " is winner"); this.Close(); }
private void setDefaultValue() { this.Width = param.window.width; this.Height = param.window.height; this.StartPosition = FormStartPosition.CenterScreen; this.AutoSizeMode = AutoSizeMode.GrowAndShrink; this.oldPoint = new coors(); bool heightIsBigger = this.ClientSize.Height > this.ClientSize.Width; this.sizeCaro = heightIsBigger ? this.ClientSize.Width : this.ClientSize.Height; // without margin this.numOfLine = sizeCaro / param.size; this.marginCaro = (sizeCaro - (param.size * numOfLine)) / 2; this.sizeCaro = param.size * numOfLine++; this.paddingLeftRight = heightIsBigger ? 0 : (this.ClientSize.Width - this.ClientSize.Height) / 2; this.paddingTopBottom = !heightIsBigger ? 0 : (this.ClientSize.Height - this.ClientSize.Width) / 2; this.arrCaro = new byte[this.numOfLine - 2, this.numOfLine - 2]; this.player1 = true; }