C#语言俄罗斯方块源代码(据陈广老师视频)
以下是我根据陈广老师视频,自己敲的代码,日后会不断更新。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Tetris
{
public partial class FrmConfig : Form
{
public FrmConfig()
{
InitializeComponent();
}
private bool[,] struArr=new bool[5,5]; //此处bool值数组应用不明白,怎么会返回一个bull值呢?
private Color blockColor = Color.Red;
private void lblMode_Click(object sender, EventArgs e)
{
}
private void lblMode_Paint(object sender, PaintEventArgs e)
{
Graphics gp = e.Graphics;
gp.Clear(Color.Black);
Pen p = new Pen(Color.White);
for (int i = 31; i < 155; i = i + 31)
gp.DrawLine(p, 1, i, 155, i);
for (int i = 31; i < 155; i = i + 31)
gp.DrawLine(p, i, 1, i, 155);
SolidBrush s = new SolidBrush(blockColor);
for (int x = 0; x < 5;x++ )
{
for (int y = 0; y < 5;y++ )
{
if (struArr[x,y])
{
gp.FillRectangle(s, 31 * x + 1, 30 * y + 1, 30, 30);
}
}
}
}
private void lblMode_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;
int xPos, yPos;
xPos = e.X / 31;
yPos = e.Y / 31;
struArr[xPos, yPos] = !struArr[xPos, yPos];
bool b = struArr[xPos, yPos]; // 此处不解?
Graphics gp = lblMode.CreateGraphics();
SolidBrush s = new SolidBrush(b?blockColor:Color.Black);
gp.FillRectangle(s, 31 * xPos + 1, 30 * yPos + 1, 30, 30);
gp.Dispose();
}
private void lblColor_Click(object sender, EventArgs e)
{
colorDialog1.ShowDialog();
blockColor = colorDialog1.Color;
lblColor.BackColor = colorDialog1.Color;
lblMode.Invalidate();
}
private void btnAdd_Click(object sender, EventArgs e)
{
bool isEmpty = false;
foreach (bool i in struArr)
{
if (i)
{
isEmpty = true;
break;
}
}
if (!isEmpty)
{
MessageBox.Show("图案为空","提示窗口",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
StringBuilder sb = new StringBuilder(25);
foreach (bool i in struArr)
{
sb.Append(i?"1":"0");
}
string blockString = sb.ToString();
foreach (ListViewItem item in lsvBlockSet.Items)
{
if(item.SubItems[0].Text==blockString)
{
MessageBox.Show("图案已经存在", "提示窗口", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
ListViewItem myItem = new ListViewItem();
myItem = lsvBlockSet.Items.Add(blockString);
myItem.SubItems.Add(Convert.ToString(blockColor.ToArgb()));
}
private void lsvBlockSet_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
if (e.IsSelected)
{
blockColor = Color.FromArgb(int.Parse(e.Item.SubItems[1].Text));
lblColor.BackColor = blockColor;
string s = e.Item.SubItems[0].Text;
for (int i = 0; i < s.Length;i++ )
{
struArr[i / 5, i % 5] = (s[i] == '1') ? true : false;
}
lblMode.Invalidate();
}
}
private void btnDel_Click(object sender, EventArgs e)
{
if(lsvBlockSet.SelectedItems.Count==0)
{
MessageBox.Show("请在右边选择一个条目进行删除!", "提示窗口", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
lsvBlockSet.Items.Remove(lsvBlockSet.SelectedItems[0]);
btnClear.PerformClick();
}
private void btnClear_Click(object sender, EventArgs e)
{
for (int x = 0; x < 5;x++ )
{
for (int y = 0; y < 5; y++)
{
struArr[x, y] = false;
}
}
lblMode.Invalidate();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
if (lsvBlockSet.SelectedItems.Count == 0) //判断是否有项目被选中
{
MessageBox.Show("请在右边选择一个条目进行修改!", "提示窗口", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
bool isEmpty = false; //判断图案是否为空
foreach(bool i in struArr)
{
if(i)
{
isEmpty = true;
break;
}
}
if(!isEmpty)
{
MessageBox.Show("图案为空,请先用鼠标点击左边图案再进行修改!", "提示窗口", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
StringBuilder sb = new StringBuilder(25);
foreach(bool i in struArr) //把图案的字符串信息转换为二维数组信息
{
sb.Append(i?"1":"0");
}
lsvBlockSet.SelectedItems[0].SubItems[0].Text = sb.ToString(); //改变图案信息
lsvBlockSet.SelectedItems[0].SubItems[0].Text = Convert.ToString(blockColor.ToArgb()); //改变颜色信息
}
}
}
转载于:https://www.cnblogs.com/vincent316/archive/2008/08/01/1258460.html
C#语言俄罗斯方块源代码(据陈广老师视频)相关推荐
- C#语言俄罗斯方块源代码(据陈广老师视频) 第1-6集
写到第六集,出现了很多错误,都是照着上面写的也不知道怎么回事,先不解决了,以后学习的过程中慢慢解决吧. 代码就先写前6集吧,估计已经写到整个代码的70%了,呵呵 整个项目代码:C#语言俄罗斯方块源代码 ...
- 观看 陈广 老师视频做的图像管理器,代码打包,给需要的朋友。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 陈广老师 C#语言参考视频打包下载地址
陈广老师 C#语言参考视频下载地址 http://dl.getdropbox.com/u/97203/chenguang.zip 转载于:https://www.cnblogs.com/ycxyyzw ...
- 根据陈广老师的视频,做了一个俄罗斯方块
暑假在家里学习C#基础编程,边听陈广老师的视频,边学习C#基础知识.接下来准备做一下Windows中的计算器.加油! PS:第一篇博客,居然写成了日记形式的流水账.update at 2014/3/3 ...
- c#俄罗斯方块视频教程下载地址[陈广老师]
开发平台 c#.net winforms应用程序 俄罗斯方块视频教程下载地址 http://cimg3.163.com/tech/school/doc/c/Tetris(01).swf http:// ...
- 陈广老师C#参考视频 方法的参数传递 总结
方法的参数传递有三种: 1.值参数 方法名称(参数类型,参数名称) 2.引用参数 方法名称(ref 参数类型,参数名称) 3.输出参数 方法名称(out 参数类型,参数名称) 运行结果: i=0 j ...
- 看陈广老师c#参考视频总结(第十篇 完)
日期:<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /> ...
- 看陈广老师c#参考视频总结(第三篇)
日期:<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /> ...
- 看陈广老师c#参考视频总结
http://xiaoshu838.blog.51cto.com/433568/89243 转载于:https://blog.51cto.com/1724802/592450
最新文章
- webpack组织模块的原理 - 基础篇
- 30分钟从工作电脑入侵公司内网!Win11:更新强制要求有TPM2.0,知道为啥了吧?...
- SVN中 “containing working copy admin area is missin
- 电为啥要分交流、直流?
- js几种常见排序的实现
- Java、Javascript、Javaweb三者的区别
- 计算机算法设计与分析 单峰序列
- Hosts文件与钓鱼网站
- Linux下的shell编程(二)BY 四喜三顺
- 同一个网络下怎样在两台机器之间传输文件
- ubuntu 黑体_linux ubuntu 思源黑体安装
- 循环系统疾病病人的护理题库【2】
- 非负矩阵分解 NMF 总结
- SoftEther 介绍
- Cocos独立游戏精品|高自由度地牢探险《贪婪洞窟​》
- 如何确定产品生命周期
- 7-13 打印金字塔图案
- 域名的DA值和PA值用什么工具查询?
- 中国计算机学会会刊变动公告
- AI工程师认证,看这一篇就够了
热门文章
- PTA 10-45 查询zgda表中的工号,姓名,性别,职称4项信息,显示结果时首先按照女性在前的顺序,如果性别相同则按照职称的 升序排列。
- python 角点检测_python 实现Harris角点检测算法
- 大端小端模式及其判别方式
- 视频截图Failed to execute ‘toDataURL‘ on ‘HTMLCanvasElement‘: Tainted canvas处理
- 【PTE】SQL注入(二)
- 十二个“一”的扩展延伸文艺创作
- 把字符型转为数字型4种方式
- Java开发初体验:第一个Java程序:HelloWorld
- CSS设置div高度自适应
- javascript轮播插件的使用(TouchSlide)