📄 gameform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
namespace CardGame
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class GameForm : System.Windows.Forms.Form
{
private System.Windows.Forms.MenuItem menuItem_Game;
private System.Windows.Forms.MenuItem menuItem_Game_Deal;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem_Game_Undo;
private System.Windows.Forms.MenuItem menuItem_Game_BackImage;
private System.Windows.Forms.MenuItem menuItem_Game_Option;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem_Game_Exit;
private System.Windows.Forms.StatusBar statusBar;
private System.Windows.Forms.MainMenu mainMenu;
private System.Windows.Forms.StatusBarPanel status_score;
private System.Windows.Forms.StatusBarPanel status_time;
private System.Windows.Forms.StatusBarPanel status_copyright;
private CardGame.GamePlace gPlace;
private System.ComponentModel.IContainer components=null;
public GameForm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(GameForm));
this.statusBar = new System.Windows.Forms.StatusBar();
this.status_copyright = new System.Windows.Forms.StatusBarPanel();
this.status_score = new System.Windows.Forms.StatusBarPanel();
this.status_time = new System.Windows.Forms.StatusBarPanel();
this.mainMenu = new System.Windows.Forms.MainMenu();
this.menuItem_Game = new System.Windows.Forms.MenuItem();
this.menuItem_Game_Deal = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem_Game_Undo = new System.Windows.Forms.MenuItem();
this.menuItem_Game_BackImage = new System.Windows.Forms.MenuItem();
this.menuItem_Game_Option = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem_Game_Exit = new System.Windows.Forms.MenuItem();
this.gPlace = new CardGame.GamePlace();
((System.ComponentModel.ISupportInitialize)(this.status_copyright)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.status_score)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.status_time)).BeginInit();
this.SuspendLayout();
//
// statusBar
//
this.statusBar.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.statusBar.Location = new System.Drawing.Point(0, 387);
this.statusBar.Name = "statusBar";
this.statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.status_copyright,
this.status_score,
this.status_time});
this.statusBar.ShowPanels = true;
this.statusBar.Size = new System.Drawing.Size(592, 22);
this.statusBar.SizingGrip = false;
this.statusBar.TabIndex = 0;
//
// status_copyright
//
this.status_copyright.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.status_copyright.Text = " .Net版纸牌游戏--作者:周灿";
this.status_copyright.Width = 426;
//
// status_score
//
this.status_score.Alignment = System.Windows.Forms.HorizontalAlignment.Right;
this.status_score.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
this.status_score.Text = " 得分:0 ";
this.status_score.Width = 58;
//
// status_time
//
this.status_time.Alignment = System.Windows.Forms.HorizontalAlignment.Right;
this.status_time.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
this.status_time.Text = " 时间:00:00:00 ";
this.status_time.Width = 108;
//
// mainMenu
//
this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem_Game});
//
// menuItem_Game
//
this.menuItem_Game.Index = 0;
this.menuItem_Game.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem_Game_Deal,
this.menuItem3,
this.menuItem_Game_Undo,
this.menuItem_Game_BackImage,
this.menuItem_Game_Option,
this.menuItem7,
this.menuItem_Game_Exit});
this.menuItem_Game.Text = "游戏(&G)";
this.menuItem_Game.Popup += new System.EventHandler(this.menuItem_Game_Popup);
//
// menuItem_Game_Deal
//
this.menuItem_Game_Deal.Index = 0;
this.menuItem_Game_Deal.Shortcut = System.Windows.Forms.Shortcut.F2;
this.menuItem_Game_Deal.Text = "发牌(&D)";
this.menuItem_Game_Deal.Click += new System.EventHandler(this.menuItem_Game_Deal_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "-";
//
// menuItem_Game_Undo
//
this.menuItem_Game_Undo.Index = 2;
this.menuItem_Game_Undo.Shortcut = System.Windows.Forms.Shortcut.CtrlZ;
this.menuItem_Game_Undo.Text = "撤销(&U)";
this.menuItem_Game_Undo.Click += new System.EventHandler(this.menuItem_Game_Undo_Click);
//
// menuItem_Game_BackImage
//
this.menuItem_Game_BackImage.Index = 3;
this.menuItem_Game_BackImage.Text = "背面图案(&C)...";
this.menuItem_Game_BackImage.Click += new System.EventHandler(this.menuItem_Game_BackImage_Click);
//
// menuItem_Game_Option
//
this.menuItem_Game_Option.Index = 4;
this.menuItem_Game_Option.Text = "选项(&O)...";
this.menuItem_Game_Option.Click += new System.EventHandler(this.menuItem_Game_Option_Click);
//
// menuItem7
//
this.menuItem7.Index = 5;
this.menuItem7.Text = "-";
//
// menuItem_Game_Exit
//
this.menuItem_Game_Exit.Index = 6;
this.menuItem_Game_Exit.Text = "退出(&X)";
this.menuItem_Game_Exit.Click += new System.EventHandler(this.menuItem_Game_Exit_Click);
//
// gPlace
//
this.gPlace.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel_Game.BackgroundImage")));
this.gPlace.Dock = System.Windows.Forms.DockStyle.Fill;
this.gPlace.Location = new System.Drawing.Point(0, 0);
this.gPlace.Name = "gPlace";
this.gPlace.TabIndex = 0;
//
// GameForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.Green;
this.ClientSize = new System.Drawing.Size(592, 409);
this.Controls.Add(this.statusBar);
this.Controls.Add(this.gPlace);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.mainMenu;
this.Name = "GameForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "纸牌游戏";
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.GameForm_KeyDown);
this.Load += new System.EventHandler(this.GameForm_Load);
((System.ComponentModel.ISupportInitialize)(this.status_copyright)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.status_score)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.status_time)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void GameForm_Load(object sender, System.EventArgs e)
{
gPlace.InitPlace();
gPlace.Shuffle();
gPlace.StateTrigger+=new CardGame.GamePlace.StateTriggerDelegate(gPlace_StateTrigger);
}
private void menuItem_Game_BackImage_Click(object sender, System.EventArgs e)
{
BackImageForm bf=new BackImageForm();
if(bf.ShowDialog(this)==DialogResult.OK)
{
gPlace.RefreshCardBack();
}
bf.Dispose();
}
private void menuItem_Game_Exit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void menuItem_Game_Deal_Click(object sender, System.EventArgs e)
{
gPlace.Visible=false;
gPlace.Shuffle();
}
private void menuItem_Game_Undo_Click(object sender, System.EventArgs e)
{
if(CardCollections.CanUndo)
{
CardCollections.Undo();
}
}
private void menuItem_Game_Popup(object sender, System.EventArgs e)
{
if(CardCollections.CanUndo)
{
menuItem_Game_Undo.Enabled=true;
}
else
{
menuItem_Game_Undo.Enabled=false;
}
}
private void menuItem_Game_Option_Click(object sender, System.EventArgs e)
{
OptionForm of=new OptionForm(statusBar.Visible,gPlace.IsRecord,gPlace.IsScore,gPlace.CanLoop);
if(of.ShowDialog(this)==DialogResult.OK)
{
statusBar.Visible=of.State;
gPlace.IsRecord=of.Record;
gPlace.IsScore=of.Score;
gPlace.CanLoop=of.Loop;
if(of.ReStartGame)
{
gPlace.Shuffle();
}
}
of.Dispose();
}
private void gPlace_StateTrigger(string timeStr, int score)
{
if(!gPlace.IsRecord)
{
status_time.Text="";
}
else if(timeStr!=null)
{
//status_time.Text=" 时间:"+timeStr+" ";
}
if(gPlace.IsScore)
{
if(score>=0)status_score.Text=" 得分:"+score+" ";
}
else
{
status_score.Text="";
}
}
private void GameForm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode==Keys.Enter)
{
if(gPlace!=null)gPlace.TurnSenderCard();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -