C#五子棋人人对战完整代码

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)

{

// 确认是否重新开始

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值