做个玩玩

public Form1()
{
InitializeComponent();
} #region 定义砖块int[i,j,y,x] Tricks:i为那块砖,j为状态,y为列,x为行
private int[, , ,] Tricks = {{
{
{,,,},
{,,,},
{,,,},
{,,,}
},
{
{,,,},
{,,,},
{,,,},
{,,,}
},
{
{,,,},
{,,,},
{,,,},
{,,,}
},
{
{,,,},
{,,,},
{,,,},
{,,,}
}
},
{
{
{,,,},
{,,,},
{,,,},
{,,,}
},
{
{,,,},
{,,,},
{,,,},
{,,,}
},
{
{,,,},
{,,,},
{,,,},
{,,,}
},
{
{,,,},
{,,,},
{,,,},
{,,,}
}
},
{
{
{,,,},
{,,,},
{,,,},
{,,,}
},
{
{,,,},
{,,,},
{,,,},
{,,,}
},
{
{,,,},
{,,,},
{,,,},
{,,,}
},
{
{,,,},
{,,,},
{,,,},
{,,,}
}
},
{
{
{,,,},
{,,,},
{,,,},
{,,,}
},
{
{,,,},
{,,,},
{,,,},
{,,,}
},
{
{,,,},
{,,,},
{,,,},
{,,,}
},
{
{,,,},
{,,,},
{,,,},
{,,,}
}
}}; #endregion private Color[] TrickColor = { Color.Red, Color.Blue, Color.Orange, Color.Green }; private int[,] CurrentTrick = new int[, ]; //当前的砖块
//CurrentTrickNum当前砖块的数目, CurrentStatusNum当前状态 CurrentColor当前颜色
private int CurrentTrickNum, CurrentStatusNum, CurrentColor;
private int TricksNum = ;//方块种类
private int StatusNum = ;//方块状态
private int ColorNum = ;//颜色种类
private Image myImage;
private Random rand = new Random(); private void Form1_Load(object sender, EventArgs e)
{
//初始化
myImage = new Bitmap(panel1.Width, panel1.Height);
for (int y = ; y < ; y++)
{
for (int x = ; x < ; x++)
{
CurrentTrick[y, x] = ;
}
}
Draw();
} protected override void OnPaint(PaintEventArgs e)
{
Draw();
base.OnPaint(e);
} private void Draw()
{
Graphics g = Graphics.FromImage(myImage);
g.Clear(Color.Black);
//绘制当前的图片
for (int y = ; y < ; y++)
{
for (int x = ; x < ; x++)
{
if (CurrentTrick[y, x] == )
{
g.FillRectangle(new SolidBrush(TrickColor[CurrentColor]), x * , y * , , );
g.DrawRectangle(Pens.White, x * , y * , , );
}
}
}
Graphics gg = panel1.CreateGraphics();
gg.DrawImage(myImage, , );
} //随机生成方块
private void BeginTricks()
{
//随机生成砖码和状态码和颜色
CurrentTrickNum = rand.Next(, TricksNum);
CurrentStatusNum = rand.Next(, StatusNum);
CurrentColor = rand.Next(, ColorNum);
//分配数组
for (int y = ; y < ; y++)
{
for (int x = ; x < ; x++)
{
CurrentTrick[y, x] = Tricks[CurrentTrickNum, CurrentStatusNum, y, x];
}
}
} //控制方向
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.W)
{
ChangeTricks();
Draw();
}
} //变换方块
private void ChangeTricks()
{
if (CurrentStatusNum < )
{
CurrentStatusNum++;
}
else
{
CurrentStatusNum = ;
}
for (int y = ; y < ; y++)
{
for (int x = ; x < ; x++)
{
CurrentTrick[y, x] = Tricks[CurrentTrickNum, CurrentStatusNum, y, x];
}
}
} private void button1_Click(object sender, EventArgs e)
{
BeginTricks();
Draw();
}

GDI学习之俄罗斯方块的更多相关文章

  1. GDI学习之俄罗斯方块续

    当前方块对象 #region 定义砖块int[i,j,y,x] Tricks:i为那块砖,j为状态,y为列,x为行 private int[, , ,] Tricks = {{ { {,,,}, {, ...

  2. C# GDI+学习笔记1

    —前言 本文是学习C# GDI+系列的第一篇文章,简单的介绍了GDI+的一些基本绘图内容,比较粗糙.但本文主要是让大家简单的回顾一下GDI+的基本概念.本篇文章的参考代码请在此下载 . GDIPTes ...

  3. Delphi7 GDI+学习

    Delphi7自带的绘图有锯齿,所以要学习GDI+ 主要是从这个网站学习 http://www.bianceng.com/Programming/Delphi/201212/34691.htm 相关控 ...

  4. GDI+学习笔记(六)渐变画笔

    刷,顾名思义,它是一样的刷.提请设备,还记得常唱歌曲,"我是一个画家.." 好吧.跑题了. 本系列博客希望尽可能简单的描写叙述每项功能,而不希望把每一个參数都介绍的详具体细,假设须 ...

  5. GDI+学习---2.GDI+编程模式及组成类

    在使用GDI+的时候,您不必像在GDI中那样关心设备场景句柄,只需简单地创建一个Graphics对象,然后以您熟悉的面向对象的方式(如myGraphicsObject.DrawLine(paramet ...

  6. GDI+学习---1.初识GDI+

    ---恢复内容开始--- GDI+: GDI+由一组C++类实现,是对于GDI的继承,GDI+不仅优化了大部分GDI性能而且提供了更多特性.允许应用程序开发者将信息显示在显示器或者打印机上,而无需考虑 ...

  7. GDI+学习笔记

    7.1.1 GDI+概述 GDI+是微软在Windows 2000以后操作系统中提供的新的图形设备接口,其通过一套部署为托管代码的类来展现, 这套类被称为GDI+的“托管类接口”,GDI+主要提供了以 ...

  8. GDI+学习笔记(九)带插件的排序算法演示器(MFC中的GDI+实例)

    带插件的排序算法演示器 请尊重本人的工作成果,转载请留言.并说明转载地址,谢谢. 地址例如以下: http://blog.csdn.net/fukainankai/article/details/27 ...

  9. GDI+学习之------ 画线、区域填充、写字

    <精通GDI编程>里的代码.在学习过程中对它加以总结,以防以后用到,全部代码都是在MFC 单文档中实现的,写在View::OnDraw(CDC */*pDC*/)中 画线/边框(Pen) ...

随机推荐

  1. html图片上下翻滚展示代码

    <marquee behavior="alternate" scrolldelay="1" direction="up" width= ...

  2. ASP.NET MVC使用jQuery无刷新上传

    昨晚网友有下载了一个jQuery无刷新上传的小功能,他尝试搬至ASP.NET MVC应用程序中去,在上传死活无效果.Insus.NET使用Teamviewer远程桌面,操作一下,果真是有问题.网友是说 ...

  3. 利用代码生成工具Database2Sharp设计数据编辑界面

    在Winform程序开发中,界面部分的开发工作量一般是比较大的,特别是表的字段数据比较多的情况下,数据编辑界面所需要的繁琐设计和后台逻辑处理工作量更是直线上升,而且稍不注意,可能很多处理有重复或者错误 ...

  4. Try out the latest C++ compiler toolset without waiting for the next update of Visual Studio

    Updated 22/Apr/2016: The NuGet package is now being uploaded daily. The payload doesn’t change every ...

  5. 正则表达式相关:C# 抓取网页类(获取网页中所有信息)

    类的代码: using System; using System.Data; using System.Configuration; using System.Net; using System.IO ...

  6. 【C++】第1章 在VS2015中用C++编写控制台应用程序

    分类:C++.VS2015 创建日期:2016-06-12 一.简介 看到不少人至今还在用VC 6.0开发工具学习C++,其实VC 6.0开发工具早就被淘汰了.这里仅介绍学习C++时推荐使用的两种开发 ...

  7. 记录一款不错的插件fullpage.js

    下载链接包括一些实例: http://www.dowebok.com/demo/2014/77/ 当然也可以从Github 上下载: https://github.com/alvarotrigo/fu ...

  8. JPA学习(1)基础认知

    JPA 是什么 Java Persistence API:用于对象持久化的API. Java EE 5.0 平台标准的 ORM 规范,使得应用程序以统一的方式访问持久层: JPA和Hibernate的 ...

  9. STL---Codeforces675D Tree Construction(二叉树节点的父亲节点)

    Description During the programming classes Vasya was assigned a difficult problem. However, he doesn ...

  10. K3Cloud开放数据模型

          金蝶K/3 Cloud是基于WEB2.0与云技术的一个开放式.社会化的新时代企业管理服务平台.整个产品采用SOA架构,完全基于BOS平台组建而成,业务架构上贯穿流程驱动与角色驱动思想,结合 ...