using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 五子棋
{
// 窗体程序
public partial class Form1 : Form
{
private bool start; // 游戏是否开始
private bool ChessCheck = true; // 白子黑子回合
private const int size = 15; // 棋盘大小
private int[,] CheckBoard = new int[size, size]; // 棋盘点位数组
public Form1()
{
InitializeComponent();
}
// 窗口加载事件
private void Form1_Load_1(object sender, EventArgs e)
{
initializeGame(); // 初始化游戏
this.Width = MainSize.FormWidth; // 宽度
this.Height = MainSize.FormHeight; // 高度
this.Location = new Point(400, 75); // 设置窗口位置
}
// 初始化
private void initializeGame()
{
// 棋盘点位数组 重置
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
CheckBoard[i, j] = 0;
}
}
start = false; // 未开始
label1.Text = "游戏未开始";
button1.Visible = true; // 显示开始游戏
button2.Visible = false; // 隐藏重新开始
}
// "棋盘"Paint事件
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics g = panel1.CreateGraphics(); // 创建面板画布
ChessBoard.DrawCB(g,panel1); // 调用画棋盘方法
Chess.ReDrawC(panel1, CheckBoard); // 调用重新加载棋子
}
// "控制界面"Paint事件
private void panel2_Paint(object sender, PaintEventArgs e)
{
// 设置控制界面的大小
panel2.Size = new Size(MainSize.FormWidth - MainSize.CBoardWidth -20, MainSize.FormHeight);
}
// "开始游戏"CLick事件
private void button1_Click_1(object sender, EventArgs e)
{
start = true; // 开始
ChessCheck = true; // 黑子回合
label1.Text = "黑子回合"; // 提示文本改为 黑子回合
button1.Visible = false; // 隐藏开始游戏
button2.Visible = true; // 显示重新开始
panel1.Invalidate(); // 重绘面板棋盘
//开始游戏时,启动计时器
count = 0;
timer1.Start();
}
// 按钮"重新开始"CLick事件
private void button2_Click_1(object sender, EventArgs e)
{
// 确认是否重新开始