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代码生成器界面
加载后显示指定模块
CSFramework开发框架模块容器界面介绍
模块图标顺序设置-CS框架网
.Net Core SignalR简介-用SignalR撸个游戏
企业V4.5代码生成器自动生成原型及二次加工界面参考
C/S快速开发框架旗舰V5.1 - 数据字典编写的代码
运行程序,显示指定的模块
隐藏工具栏的功能按钮(方法二)
C/S快速开发框架旗舰V5.1 - 业务单据开发步骤
新建的上看不到Toolbar?
CS开发框架禁用Toolbar的按钮
的导航菜单及树结构菜单实现多语言(翻译英文越南文)
C#积木游戏(改编自DevExpress GridTetris)
C/S快速开发框架旗舰V5.1 - 业务单据基类介绍

热门标签
.NET5 .NET6 .NET7 APP Auth-软件授权注册系统 Axios B/S B/S开发框架 Bug Bug记录 C#加密解密 C#源码 C/S CHATGPT CMS系统 CodeGenerator CSFramework.DB CSFramework.EF CSFrameworkV1学习版 CSFrameworkV2标准版 CSFrameworkV3高级版 CSFrameworkV4企业版 CSFrameworkV5旗舰版 CSFrameworkV6.0 DAL数据访问层 Database datalock DbFramework Demo教学 Demo下载 DevExpress教程 DOM EF框架 Element-UI EntityFramework ERP ES6 Excel FastReport GIT HR IDatabase IIS JavaScript LINQ MES MiniFramework MIS NavBarControl Node.JS NPM OMS ORM PaaS POS Promise API Redis SAP SEO SQL SQLConnector TMS系统 Token令牌 VS2022 VSCode VUE WCF WebApi WebApi NETCore WebApi框架 WEB开发框架 Windows服务 Winform 开发框架 Winform 开发平台 WinFramework Workflow工作流 Workflow流程引擎 版本区别 报表 踩坑日记 操作手册 代码生成器 迭代开发记录 基础资料窗体 架构设计 角色权限 开发sce 开发技巧 开发教程 开发框架 开发平台 开发指南 客户案例 快速搭站系统 快速开发平台 秘钥 密钥 权限设计 软件报价 软件测试报告 软件简介 软件开发框架 软件开发平台 软件开发文档 软件体系架构 软件下载 软著证书 三层架构 设计模式 生成代码 实用小技巧 收钱音箱 数据锁 数据同步 微信小程序 未解决问题 文档下载 喜鹊ERP 喜鹊软件 系统对接 详细设计说明书 行政区域数据库 需求分析 疑难杂症 蝇量级框架 蝇量框架 用户管理 用户开发手册 用户控件 在线支付 纸箱ERP 智能语音收款机 自定义窗体 自定义组件 自动升级程序