最新文章 (全部类别)
安装DevExpress V22.1.13
官方VS2022下载,VS2022密钥
C/S快速开发框架旗舰版CSFrameworkV6.0 - VS开发环境配置
运行.NET8 Winform程序弹窗用户账户控制解决方案
使用Xlight FTP文件服务器
CSFramework试用版定制用户软件信息
DevExpress TreeList树形表格组件使用
DevExpress GridView表格不启用/禁用主从表模式(Master/Detail)
CSFrameworkV6开发框架集成GZUpdate.Client自动升级程序
FastReport.NET2023破解版去除水印DEMO VERSION (2023.1.8/2023.2.18版本)
.NET8调用存储过程传入DataTable表类型解决方案
使用DeepSeek生成DevExpress表格、窗体、C#模型代码并集成到开发框架
C# EF+LINQ 查询主表明细表数据查询条件写法
C/S架构软件开发平台 - 旗舰版V6.1 - 序列号管理
塑木地板行业ERP - 用户操作手册 - 物料类别管理
QMS五金制品行业报价系统 - 用户操作手册 - 成本基础资料表
QMS五金制品行业报价系统 - 用户操作手册 - 采购评估
QMS五金制品行业报价系统 - 用户操作手册 - 设备登记
QMS五金制品行业报价系统 - 用户操作手册 - 新品可行性评估
QMS五金制品行业报价系统 - 用户操作手册 - 工艺工序维护
QMS五金制品行业报价系统 - 用户操作手册 - 业务员管理
QMS五金制品行业报价系统 - 用户操作手册 - 客户管理
塑木地板行业ERP - 用户操作手册 - 组织架构(部门)
塑木地板行业ERP - 用户操作手册 - 系统初始化
塑木地板行业ERP - 用户操作手册 - 付款AP
塑木地板行业ERP - 用户操作手册 - 供应商对账单
塑木地板行业ERP - 用户操作手册 - 收款AR
塑木地板行业ERP - 用户操作手册 - 客户对账
塑木地板行业ERP - 用户操作手册 - 销售退货
塑木地板行业ERP - 用户操作手册 - 采购入库
塑木地板行业ERP - 用户操作手册 - 采购退货
塑木地板行业ERP - 用户操作手册 - 采购订单
塑木地板行业ERP - 用户操作手册 - 供应商管理
CSFrameworkV6.0 - 快速开发平台 - 增加字段操作步骤
录入基础资料数据,编码自动生成,自动编号
塑木地板行业ERP - 用户操作手册 - 客户送货单(成品出库)
塑木地板行业ERP - 用户操作手册 - 客户管理
VS2022项目自动刷新依赖项程序集引用(出现黄色叹号)
.NETCore WebApi服务器提供本地文件服务(通过URL访问图片)
C/S架构软件开发平台 - 旗舰版V6.0 - 底层框架迭代开发
.NET8 Winform桌面应用程序禁用dpi缩放
GIT改了密码导致无法提交代码解决方案
OneDrive安装闪退解决方案
VS2022正在加载设计器,连接到已命名的管道时发生超时
客户端部署.NET7程序 | 客户端安装环境
DevExpress.XtraTreeList.TreeList 组件自动定位当前记录
塑木地板行业ERP - 用户操作手册 - 软件安装&部署
塑木地板行业ERP - 用户操作手册 - 用户管理
塑木地板行业ERP - 用户操作手册 - 角色管理
塑木地板行业ERP - 用户操作手册 - 成品出入库历史记录
.net敏捷开发,创造卓越

C#版智能五子棋游戏(4)-主窗体


C#版智能五子棋游戏(4)-主窗体贴图图片

MainForm 布局局部类,随便拉起来的,由VS生成

namespace QiuQiu.ChessForm
{
   partial class MainForm
   {
      /// <summary>
      /// 必需的设计器变量。
      /// </summary>
      private System.ComponentModel.IContainer components = null;
      
      /// <summary>
      /// 清理所有正在使用的资源。
      /// </summary>
      /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
      protected override void Dispose(bool disposing)
      {
         if (disposing && (components != null))
         {
            components.Dispose();
         }
         base.Dispose(disposing);
      }
      
      #region Windows 窗体设计器生成的代码
      
      /// <summary>
      /// 设计器支持所需的方法 - 不要
      /// 使用代码编辑器修改此方法的内容。
      /// </summary>
      private void InitializeComponent()
      {
         this.button1 = new System.Windows.Forms.Button();
         this.chessboard1 = new QiuQiu.ChessEngine.Chessboard();
         this.label1 = new System.Windows.Forms.Label();
         this.lbNowPlaer = new System.Windows.Forms.Label();
         this.label3 = new System.Windows.Forms.Label();
         this.label4 = new System.Windows.Forms.Label();
         this.lbBlackTime = new System.Windows.Forms.Label();
         this.lbWhiteTime = new System.Windows.Forms.Label();
         this.button2 = new System.Windows.Forms.Button();
         this.label2 = new System.Windows.Forms.Label();
         this.label5 = new System.Windows.Forms.Label();
         this.player1ComboBox = new System.Windows.Forms.ComboBox();
         this.player2ComboBox = new System.Windows.Forms.ComboBox();
         this.SuspendLayout();
         //
         // button1
         //
         this.button1.Location = new System.Drawing.Point(457, 415);
         this.button1.Name = "button1";
         this.button1.Size = new System.Drawing.Size(59, 23);
         this.button1.TabIndex = 1;
         this.button1.Text = "开始";
         this.button1.UseVisualStyleBackColor = true;
         this.button1.Click += new System.EventHandler(this.button1_Click);
         //
         // chessboard1
         //
         this.chessboard1.CanManChess = false;
         this.chessboard1.Location = new System.Drawing.Point(0, -2);
         this.chessboard1.Name = "chessboard1";
         this.chessboard1.Size = new System.Drawing.Size(460, 460);
         this.chessboard1.TabIndex = 0;
         //
         // label1
         //
         this.label1.AutoSize = true;
         this.label1.Location = new System.Drawing.Point(466, 236);
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size(53, 12);
         this.label1.TabIndex = 9;
         this.label1.Text = "当前手:";
         //
         // lbNowPlaer
         //
         this.lbNowPlaer.AutoSize = true;
         this.lbNowPlaer.Location = new System.Drawing.Point(524, 236);
         this.lbNowPlaer.Name = "lbNowPlaer";
         this.lbNowPlaer.Size = new System.Drawing.Size(29, 12);
         this.lbNowPlaer.TabIndex = 10;
         this.lbNowPlaer.Text = "黑棋";
         //
         // label3
         //
         this.label3.AutoSize = true;
         this.label3.Location = new System.Drawing.Point(466, 277);
         this.label3.Name = "label3";
         this.label3.Size = new System.Drawing.Size(65, 12);
         this.label3.TabIndex = 11;
         this.label3.Text = "黑棋时间:";
         //
         // label4
         //
         this.label4.AutoSize = true;
         this.label4.Location = new System.Drawing.Point(466, 328);
         this.label4.Name = "label4";
         this.label4.Size = new System.Drawing.Size(65, 12);
         this.label4.TabIndex = 6;
         this.label4.Text = "白棋时间:";
         //
         // lbBlackTime
         //
         this.lbBlackTime.AutoSize = true;
         this.lbBlackTime.Location = new System.Drawing.Point(492, 300);
         this.lbBlackTime.Name = "lbBlackTime";
         this.lbBlackTime.Size = new System.Drawing.Size(53, 12);
         this.lbBlackTime.TabIndex = 7;
         this.lbBlackTime.Text = "00:00:00";
         //
         // lbWhiteTime
         //
         this.lbWhiteTime.AutoSize = true;
         this.lbWhiteTime.Location = new System.Drawing.Point(492, 354);
         this.lbWhiteTime.Name = "lbWhiteTime";
         this.lbWhiteTime.Size = new System.Drawing.Size(53, 12);
         this.lbWhiteTime.TabIndex = 8;
         this.lbWhiteTime.Text = "00:00:00";
         //
         // button2
         //
         this.button2.Location = new System.Drawing.Point(522, 415);
         this.button2.Name = "button2";
         this.button2.Size = new System.Drawing.Size(59, 23);
         this.button2.TabIndex = 1;
         this.button2.Text = "停止";
         this.button2.UseVisualStyleBackColor = true;
         this.button2.Click += new System.EventHandler(this.button2_Click);
         //
         // label2
         //
         this.label2.AutoSize = true;
         this.label2.Location = new System.Drawing.Point(463, 19);
         this.label2.Name = "label2";
         this.label2.Size = new System.Drawing.Size(41, 12);
         this.label2.TabIndex = 9;
         this.label2.Text = "黑棋:";
         //
         // label5
         //
         this.label5.AutoSize = true;
         this.label5.Location = new System.Drawing.Point(463, 97);
         this.label5.Name = "label5";
         this.label5.Size = new System.Drawing.Size(41, 12);
         this.label5.TabIndex = 9;
         this.label5.Text = "白棋:";
         //
         // player1ComboBox
         //
         this.player1ComboBox.FormattingEnabled = true;
         this.player1ComboBox.Location = new System.Drawing.Point(465, 52);
         this.player1ComboBox.Name = "player1ComboBox";
         this.player1ComboBox.Size = new System.Drawing.Size(121, 20);
         this.player1ComboBox.TabIndex = 12;
         //
         // player2ComboBox
         //
         this.player2ComboBox.FormattingEnabled = true;
         this.player2ComboBox.Location = new System.Drawing.Point(465, 131);
         this.player2ComboBox.Name = "player2ComboBox";
         this.player2ComboBox.Size = new System.Drawing.Size(121, 20);
         this.player2ComboBox.TabIndex = 13;
         //
         // MainForm
         //
         this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.ClientSize = new System.Drawing.Size(599, 467);
         this.Controls.Add(this.player2ComboBox);
         this.Controls.Add(this.player1ComboBox);
         this.Controls.Add(this.label5);
         this.Controls.Add(this.label2);
         this.Controls.Add(this.label1);
         this.Controls.Add(this.lbNowPlaer);
         this.Controls.Add(this.label3);
         this.Controls.Add(this.label4);
         this.Controls.Add(this.lbBlackTime);
         this.Controls.Add(this.lbWhiteTime);
         this.Controls.Add(this.button2);
         this.Controls.Add(this.button1);
         this.Controls.Add(this.chessboard1);
         this.Name = "MainForm";
         this.Text = "五子棋";
         this.Load += new System.EventHandler(this.MainForm_Load);
         this.ResumeLayout(false);
         this.PerformLayout();
         
      }
      
      #endregion
      internal QiuQiu.ChessEngine.Chessboard chessboard1;
      private System.Windows.Forms.Button button1;
      private System.Windows.Forms.Label label1;
      private System.Windows.Forms.Label lbNowPlaer;
      private System.Windows.Forms.Label label3;
      private System.Windows.Forms.Label label4;
      private System.Windows.Forms.Label lbBlackTime;
      private System.Windows.Forms.Label lbWhiteTime;
      private System.Windows.Forms.Button button2;
      private System.Windows.Forms.Label label2;
      private System.Windows.Forms.Label label5;
      private System.Windows.Forms.ComboBox player1ComboBox;
      private System.Windows.Forms.ComboBox player2ComboBox;
   }
}


MainForm类

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QiuQiu.ChessEngine;
using QiuQiu.QChessPlayer;

namespace QiuQiu.ChessForm
{
   public partial class MainForm : Form
   {
      private IChessEngine _engine;
      private ChessPlayers _chessPalyers;
      
      public MainForm()
      {
         InitializeComponent();
         
         _chessPalyers = new ChessPlayers();
         InitEngine();
      }
      
      private void InitEngine()
      {
         if (_engine != null)
         _engine.Dispose();
         _engine = new ChessEngine.ChessEngine();
         _engine.DataChange += new EventHandler(_engine_DataChange);
         _engine.PlayerChange += new EventHandler(_engine_PlayerChange);
         _engine.EventFire += new EngineEventHandle(_engine_EventFire);
         _engine.Timer.Elapsed += new ChessTimerElapsed(Timer_Elapsed);
         chessboard1.SetChessData(_engine.ChessData);
      }
      
      /// <summary>
      /// 计时器每秒触发
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      private void Timer_Elapsed(object sender, ChessTimerEventArgs e)
      {
         //时间
         try
         {
            Invoke(new EventHandler(timerAction), sender, e);
         }
         catch { }
      }
      
      /// <summary>
      /// 计时器触发动作
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      private void timerAction(object sender, EventArgs e)
      {
         this.lbBlackTime.Text = ((ChessTimerEventArgs)e).BlackPlayer.ToString().Substring(0, 8);
         this.lbWhiteTime.Text = ((ChessTimerEventArgs)e).WhitePlayer.ToString().Substring(0, 8);
      }
      
      void _engine_EventFire(IChessEngine sender, EngineEventArgs args)
      {
         switch (args.EventType)
         {
            case EventType.BlackWin:
            MessageBox.Show("黑棋胜!" + args.Message);
            break;
            case EventType.WhiteWin:
            MessageBox.Show("白棋胜!" + args.Message);
            break;
            case EventType.DataFull:
            MessageBox.Show("平局!" + args.Message);
            break;
            case EventType.Illegality:
            MessageBox.Show((sender.CurrentPlayer.ChessType == ChessType.Black?"黑棋":"白棋") + "犯规!" + args.Message);
            break;
            case EventType.Exceptions:
            MessageBox.Show((sender.CurrentPlayer.ChessType == ChessType.Black ? "黑棋" : "白棋") + "异常!" + args.Message);
            break;
         }
         
      }
      
      private void _engine_DataChange(object sender, EventArgs e)
      {
         try
         {
            chessboard1.SetChessData(_engine.ChessData);
            Invoke(new DeleGate(chessboard1.Refresh));
         }
         catch
         {
         }
      }
      
      void _engine_PlayerChange(object sender, EventArgs e)
      {
         Invoke(new DeleGate(PlayerChang));
      }
      
      private void PlayerChang()
      {
         lbNowPlaer.Text = _engine.CurrentPlayer.ChessType == ChessType.Black ? "黑棋" : "白棋";
      }
      
      private void MainForm_Load(object sender, EventArgs e)
      {
         _chessPalyers.LoadPlayer();
         player1ComboBox.DataSource = _chessPalyers.GetPlayerNames();
         player2ComboBox.DataSource = _chessPalyers.GetPlayerNames();
      }
      
      protected override void OnClosing(CancelEventArgs e)
      {
         _engine.Stop();
         base.OnClosing(e);
      }
      
      private void button1_Click(object sender, EventArgs e)
      {
         InitEngine();
         _engine.Plyer1 = _chessPalyers.GetPlayer(player1ComboBox.SelectedItem.ToString(), this);// new QiuQiu.QChessPlayer.Player();
         _engine.Plyer2 = _chessPalyers.GetPlayer(player2ComboBox.SelectedItem.ToString(), this);// new ManPlayer(chessboard1);
         if (_engine.Plyer1 == null)
         {
            MessageBox.Show("黑棋玩家加载失败!");
            return;
         }
         if (_engine.Plyer2 == null)
         {
            MessageBox.Show("白棋玩家加载失败!");
            return;
         }
         chessboard1.Refresh();
         _engine.Start();
      }
      
      void button2_Click(object sender, System.EventArgs e)
      {
         _engine.Stop();
      }
   }
}



最后是程序入口点,ChessForm结束,框架也结束

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace QiuQiu.ChessForm
{
   static class Program
   {
      /// <summary>
      /// 应用程序的主入口点。
      /// </summary>
      [STAThread]
      static void Main()
      {
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         Application.Run(new MainForm());
      }
      
   }
}




原帖CSDN: http://topic.csdn.net/u/20080425/12/4bbb0f82-f963-4743-ac0e-f806333ac5f9.html

本文来源:
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
C/S框架网
上一篇:C#版智能五子棋游戏(3)
下一篇:C# 更改网卡 IP 地址
评论列表

发表评论

评论内容
昵称:
关联文章

C#智能五子棋游戏(4)-
C#智能五子棋游戏(3)
C#智能五子棋游戏(1)
C#智能五子棋游戏(2)
V4.0-设置多语言,的菜单顺序乱了
企业V4.x代码生成器界面
C/S架构软件开发平台 - 旗舰V6.1 - 采购模块
C/S架构软件开发平台 - 旗舰V6.1 - 销售模块
C/S架构软件开发平台 - 旗舰V6.1 - 库存模块
C/S架构软件开发平台 - 旗舰V6.1 - 财务模块
C/S架构软件开发平台 - 旗舰V6.1 - 报表模块
C/S架构软件开发平台 - 旗舰V6.1 -人力资源模块
C/S架构软件开发平台 - 旗舰V6.1 - 系统管理模块
加载后显示指定模块
.Net Core SignalR简介-用SignalR撸个游戏
C/S架构软件开发平台 - 旗舰V6.1 - 数据字典模块
CSFramework开发框架模块容器界面介绍
模块图标顺序设置-CS框架网
企业V4.5代码生成器自动生成原型及二次加工界面参考
运行程序,显示指定的模块

热门标签
软件著作权登记证书 .NET .NET Reactor .NET5 .NET6 .NET7 .NET8 .NET9 .NETFramework AI编程 APP AspNetCore AuthV3 Auth-软件授权注册系统 Axios B/S B/S开发框架 B/S框架 BSFramework Bug Bug记录 C#加密解密 C#源码 C/S CHATGPT CMS系统 CodeGenerator CSFramework.DB CSFramework.EF CSFramework.License CSFrameworkV1学习版 CSFrameworkV2标准版 CSFrameworkV3高级版 CSFrameworkV4企业版 CSFrameworkV5旗舰版 CSFrameworkV6.0 CSFrameworkV6.1 CSFrameworkV6旗舰版 DAL数据访问层 Database datalock DbFramework DeepSeek Demo教学 Demo实例 Demo下载 DevExpress教程 Docker Desktop DOM ECS服务器 EFCore EF框架 Element-UI EntityFramework ERP ES6 Excel FastReport GIT HR IDatabase IIS JavaScript LINQ MES MiniFramework MIS MySql NavBarControl NETCore Node.JS NPM OMS Oracle资料 ORM PaaS POS Promise API PSD QMS RedGet Redis RSA SAP Schema SEO SEO文章 SQL SQLConnector SQLite SqlServer Swagger TMS系统 Token令牌 VS2022 VSCode VS升级 VUE WCF WebApi WebApi NETCore WebApi框架 WEB开发框架 Windows服务 Winform 开发框架 Winform 开发平台 WinFramework Workflow工作流 Workflow流程引擎 XtraReport 安装环境 版本区别 报表 备份还原 踩坑日记 操作手册 达梦数据库 代码生成器 迭代开发记录 功能介绍 官方软件下载 国际化 基础资料窗体 架构设计 角色权限 开发sce 开发工具 开发技巧 开发教程 开发框架 开发平台 开发指南 客户案例 快速搭站系统 快速开发平台 框架升级 毛衫行业ERP 秘钥 密钥 权限设计 软件报价 软件测试报告 软件加壳 软件简介 软件开发框架 软件开发平台 软件开发文档 软件授权 软件授权注册系统 软件体系架构 软件下载 软件著作权登记证书 软著证书 三层架构 设计模式 生成代码 实用小技巧 视频下载 收钱音箱 数据锁 数据同步 塑木地板行业ERP 微信小程序 未解决问题 文档下载 喜鹊ERP 喜鹊软件 系统对接 详细设计说明书 新功能 信创 行政区域数据库 需求分析 疑难杂症 蝇量级框架 蝇量框架 用户管理 用户开发手册 用户控件 在线支付 纸箱ERP 智能语音收款机 自定义窗体 自定义组件 自动升级程序
联系我们
联系电话:13923396219(微信同号)
电子邮箱:23404761@qq.com
站长微信二维码
微信二维码