本系列最后一篇,以后不会再以博文的方式呈现。
因为疫情的原因,再加上进入到大三,考证、学业繁忙。加上还要考研的目标,断更了很久。各位看我文章入坑的小伙伴,先说一声抱歉。我想做很多系列,列了很多规划,但这一切都被改变得太快。(本来打算大二上期复习考证等一些列计划全推到本学期,再加上本学期各种专业认知实习)所以后面有些系列更新很慢甚至几乎不会再更新了。在我规划好了时间后,我决定每周末来给大家更新,周末我是专门留着搞其他事情的,其他时间就专心学业和考试。我争取做到每周一更。觉得需要取关的可以取关,我理解。更新强度达不到之前的样子,不能实现之前的规划蓝图。总之,感谢大家的支持。
以下是本篇文章正文内容
俄罗斯方块是一款比较经典的游戏,即使没玩过是有听说过的,现在一些节目魔改了俄罗斯方块的玩法,给大家带来了更多的乐趣。现在,动动你的小脑袋,一起来写一个简易的俄罗斯方块游戏吧。
主函数代码如下:
namespace Tetris
{
partial class frmMain
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMain));
this.label4 = new System.Windows.Forms.Label();
this.btnStop = new System.Windows.Forms.Button();
this.btnStart = new System.Windows.Forms.Button();
this.lblScore = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.pbNextBlock = new System.Windows.Forms.PictureBox();
this.pbMain = new System.Windows.Forms.PictureBox();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.musicPlayer = new AxWMPLib.AxWindowsMediaPlayer();
((System.ComponentModel.ISupportInitialize)(this.pbNextBlock)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pbMain)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.musicPlayer)).BeginInit();
this.SuspendLayout();
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(228, 263);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(107, 12);
this.label4.TabIndex = 17;
this.label4.Text = "请选择速度(1-9):";
//
// btnStop
//
this.btnStop.Location = new System.Drawing.Point(230, 391);
this.btnStop.Name = "btnStop";
this.btnStop.Size = new System.Drawing.Size(119, 23);
this.btnStop.TabIndex = 16;
this.btnStop.Text = "暂停游戏";
this.btnStop.UseVisualStyleBackColor = true;
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
//
// btnStart
//
this.btnStart.Location = new System.Drawing.Point(228, 340);
this.btnStart.Name = "btnStart";
this.btnStart.Size = new System.Drawing.Size(121, 23);
this.btnStart.TabIndex = 15;
this.btnStart.Text = "开始游戏";
this.btnStart.UseVisualStyleBackColor = true;
this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
//
// lblScore
//
this.lblScore.AutoSize = true;
this.lblScore.Location = new System.Drawing.Point(299, 224);
this.lblScore.Name = "lblScore";
this.lblScore.Size = new System.Drawing.Size(11, 12);
this.lblScore.TabIndex = 13;
this.lblScore.Text = "0";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(228, 224);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(65, 12);
this.label2.TabIndex = 12;
this.label2.Text = "你的得分:";
//
// label1
//
this.label1.AutoSize = true;
this.label1.ForeColor = System.Drawing.Color.Black;
this.label1.Location = new System.Drawing.Point(228, 39);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(89, 12);
this.label1.TabIndex = 11;
this.label1.Text = "即将出场的是:";
//
// pbNextBlock
//
this.pbNextBlock.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.pbNextBlock.Location = new System.Drawing.Point(257, 65);
this.pbNextBlock.Name = "pbNextBlock";
this.pbNextBlock.Size = new System.Drawing.Size(120, 120);
this.pbNextBlock.TabIndex = 10;
this.pbNextBlock.TabStop = false;
this.pbNextBlock.Paint += new System.Windows.Forms.PaintEventHandler(this.pbNextBlock_Paint);
//
// pbMain
//
this.pbMain.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.pbMain.Location = new System.Drawing.Point(12, 12);
this.pbMain.Name = "pbMain";
this.pbMain.Size = new System.Drawing.Size(210, 420);
this.pbMain.TabIndex = 9;
this.pbMain.TabStop = false;
this.pbMain.Paint += new System.Windows.Forms.PaintEventHandler(this.pbMain_Paint);
//
// timer1
//
this.timer1.Interval = 200;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Items.AddRange(new object[] {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"});
this.comboBox1.Location = new System.Drawing.Point(230, 293);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 20);
this.comboBox1.TabIndex = 14;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// musicPlayer
//
this.musicPlayer.Enabled = true;
this.musicPlayer.Location = new System.Drawing.Point(341, 263);
this.musicPlayer.Name = "musicPlayer";
this.musicPlayer.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("musicPlayer.OcxState")));
this.musicPlayer.Size = new System.Drawing.Size(10, 12);
this.musicPlayer.TabIndex = 18;
//
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(386, 445);
this.Controls.Add(this.musicPlayer);
this.Controls.Add(this.label4);
this.Controls.Add(this.btnStop);
this.Controls.Add(this.btnStart);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.lblScore);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.pbNextBlock);
this.Controls.Add(this.pbMain);
this.KeyPreview = true;
this.Name = "frmMain";
this.Text = "俄罗斯方块";
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.frmMain_KeyDown);
((System.ComponentModel.ISupportInitialize)(this.pbNextBlock)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pbMain)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.musicPlayer)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button btnStop;
private System.Windows.Forms.Button btnStart;
private System.Windows.Forms.Label lblScore;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.PictureBox pbNextBlock;
private System.Windows.Forms.PictureBox pbMain;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.ComboBox comboBox1;
private AxWMPLib.AxWindowsMediaPlayer musicPlayer;
}
}
判断格子的状态
绘图只能在绘图时间里面才有效果,paint(绘图事件)
map[hang,lie]==1 //图形
map[hang,lie]==2 //边界
如果是边界颜色变化
else //其他
绘制三个边界
for(int hang = 0 ;hang
map[hang,0]=2;
//右边边界
map[hang,mapgetlength(1)-1]=2
是的,哎。代码虽然写了,但是由于是上学期的事情,很多东西都忘了。而且vs2019我已经卸载掉了。只能把这个代码整个搞出来给大家学习使用。所以也没办法展示截图,抱歉。
本次实例需要写五个窗体,整个的大致方法和流程可以参考前面我更新的有关C#的实例应用。这也是最后一次更新水 这个系列。我会把源代码传到平台上,关注一下就可以免费下载。代码里面的各种属性以及运行后的效果可以根据自己的需求修改。具体的方法和内容可以参考以前我写的内容以后大部分大项目我都会直接在文章底下发链接,供大家下载,当然需要找什么文件都可以在底下评论。之前的内容我会慢慢整理出来。
传送门1.简易计算器的实现
传送门2.学生系统管理系统
传送门3.小游戏设计
传送门4.数学测验器
传送门4.C#窗体应用基础(第1期)
其他的可以在主页查看哦。
觉得对你有帮助可以点个关注,点赞,收藏。有什么问题请在下面留言或者私聊。谢谢支持
点这里下载源代码.C#实现俄罗斯方块 (如果官方偷偷把资源积分调整了就私聊我,我发给你,本代码免费使用)
隐藏福利:最近在复习汇编语言,一些电子书分享给大家,下期也可能会更新汇编语言的相关内容。
1.汇编语言(第三版)清华大学出版社 链接:
提取码:g2pb
点这里下载.
2.微机原理与接口技术 人民邮电出版社出版
提取码:yfaj
点这里下载.
3.汇编语言编译器emu8086(汉化版)
点这里下载.
提取码:7jpa