资源预览内容
第1页 / 共31页
第2页 / 共31页
第3页 / 共31页
第4页 / 共31页
第5页 / 共31页
第6页 / 共31页
第7页 / 共31页
第8页 / 共31页
第9页 / 共31页
第10页 / 共31页
亲,该文档总共31页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
第一部分是概述,第二部分为代码,第三部分为联络。一、概述一、概述VS 打开后如下图所示,由于不能直接上传 C#文件,就做成这个 Word 文档。运行后效果图:(1).得分显示区域,消除 1 个豆豆后可得 10 分,但若点击豆豆却不可消除,扣除 30 分。分数图片资源文件:ForFunPictures(2).测试用。CheckBox 勾上时,会将 Log 输出到 exe 所在文件夹下。(3).勾上时,即使豆豆上升到最大时,游戏也不会结束。(4).勾上时,每次得分都将自动保存到本地 exe 所在文件夹下。(5).勾上时,豆豆才会自动往上增长。(6).可点击六个 Button 设置增长豆豆的颜色。若不勾上则不会使用设置的颜色,而使用游戏预设的颜色。(7).点击“开始游戏”时,游戏界面出现的豆豆行数。(8).“自增长模式”勾上时才有效。豆豆增长间隔时间,ms 单位。(9).开始游戏(10).游戏界面。鼠标点击豆豆,即打豆豆。二、代码二、代码1. ForFunClassFBlock.cs (FBlock 代表的是一个个颜色的豆豆。代表的是一个个颜色的豆豆。 )using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using System.Drawing.Drawing2D;namespace ForFun.Classpublic class FBlock/ / Block的长宽值/ public const int BlockSize = 25;/ / 长宽值半数/ public const int HalfSize = 12;/ / 随机数生成器/ private static Random rand = new Random();private Color showColor;/ / 显示的主颜色/ public Color ShowColorget return showColor; set showColor = value; / / 初始化FBlock/ / public FBlock(Color colors)int index = rand.Next(0, colors.Length);this.showColor = colorsindex;/ / 初始化FBlock/ / public FBlock(Color color)this.showColor = color;/ / 填充颜色/ / / public void Draw(Graphics graphics, Point pointMatrix)/ 渐变色Brush生成LinearGradientBrush brush = CreateTheBrush(pointMatrix);/ 绘制DrawTheBlock(graphics, brush, pointMatrix);/ / 填充Block颜色/ / / / private void DrawTheBlock(Graphics graphics, Brush brush, Point pointMatrix)/ 获得左上坐标(PictureBox中的坐标)Point location = FPointTranslator.GetLeftTopPoint(pointMatrix);/ 绘制区域大小Size size = new Size(FBlock.BlockSize, FBlock.BlockSize);Rectangle rect = new Rectangle(location, size);graphics.FillEllipse(brush, rect);/ / 获得渐变色的Brush/ / / private LinearGradientBrush CreateTheBrush(Point pointMatrix)/ 渐变色起点:左下Point pointLB = FPointTranslator.GetLeftButtomPoint(pointMatrix);/ 渐变色终点:右上Point pointRT = FPointTranslator.GetRightTopPoint(pointMatrix);return new LinearGradientBrush(pointLB, pointRT, this.ShowColor, Color.White);2. ForFunClassFGrid.cs (FGrid 代表的是整个游戏主区域,包含了代表的是整个游戏主区域,包含了 m*n 个个 Block)using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using System.IO;namespace ForFun.Classpublic class FGrid/ / 测试Log输出/ public bool LogOutputFlg = false;/ / Block项目矩阵/ private FBlock, matrix = new FBlock14, 18;/ / 获取行数/ public int AllRowCountget return matrix.GetLength(0); / / 获取列数/ public int AllColCountget return matrix.GetLength(1); private Color colors = new Color Color.Red, Color.Green, Color.Yellow, Color.Blue ;/ / 可能颜色集/ public Color Colorsget return colors; set colors = value; / / 根据行数生成Matrix的随机颜色值。/ / public FGrid(int rowCount)/ 行数限制if (rowCount matrix.GetLength(0)throw new Exception(“Please set the rowCount: “ + rowCount);/ 随机生成指定行数、固定列数的Blockfor (int row = 0; row / 根据行数生成Matrix的随机颜色值。/ / public FGrid(int rowCount, Color clrs)/ 行数限制if (rowCount matrix.GetLength(0)throw new Exception(“Please set the rowCount: “ + rowCount);/ 用户设置颜色集更新this.colors = clrs;/ 随机生成指定行数、固定列数的Blockfor (int row = 0; row / 填充颜色/ / / public void Draw(Graphics graphics, Color backColor)/ 准备重新绘制graphics.Clear(backColor);FBlock theBlock = null;for (int row = 0; row / 增加行数/ / / 无敌模式Flgpublic int AddRow(int count, bool finishFlg)/ 非无敌模式时,检查是否已经游戏结束if (!finishFlg)for (int col = 0; col = count; row-)for (int column = 0; column / 释放内存/ public void Dispose()for (int row = 0; row / 与被Click的Block颜色相同的Block坐标集合/ private List lstPtsForFindNeighbors;/ / Block被点击/ / / public int Click(Point ptMatrix)int ret = 0;/ 点击的Block不为空时if (matrixptMatrix.X, ptMatrix.Y != null)/ 同色标记bool, neighborsFlg = new boolAllRowCount, AllColCount;/ 根据颜色生成同色标记ret = FindNeighbors(ptMatrix, ref neighborsFlg);if (ret 1)/ 如果返回的值大于1,则被点击的Block周围存在同色Block,则重铸GridCollapseBlock(neighborsFlg);return ret = 1 ? -3 : ret;/ / 根据基准点,查找其同色邻居/ / / / private int FindNeighbors(Point ptMatrix, ref bool, neighborsFlg)int ret = 0;/ 初始化同色标记矩阵for (int row = 0; row ();/ 基准点加入同色集合lstPtsForFindNeighbors.Add(ptMatrix);/ 同色集合非空时while (lstPtsForFindNeighbors.Count != 0)/ 获取同色集合最末一个坐标,再消除Point ptBase = lstPtsForFindNeighbors.Last();ret+;lstPtsForFindNeighbors.RemoveAt(lstPtsForFindNeighbors.Count - 1);/ 获取该坐标的同色邻居DoFind(ptBase, ref neighborsFlg); if (this.LogOutputFlg)/ Log需输出时,则输出OutputLogs(neighborsFlg);return ret; ;/ / 根据基准点,查找其同色邻居(详细方法)/ / / private void DoFind(Point ptBase, ref bool, neighborsFlg)if (matrixptBase.X, ptBase.Y = null)return;/ 基准颜色Color colorBase = matrixptBase.X, ptBase.Y.ShowColor;/ 查找基准点上方if (ptBase.Y 0)Point pt = new Point(ptBase.X, ptBase.Y - 1);DoJudge(colorBase, pt, ref neighborsFlg);/ 查找基准点左侧if (ptBase.X 0)Point pt = new Point(ptBase.X - 1, ptBase.Y);DoJudge(colorBase, pt, ref neighborsFlg);/ / 判断是否为同色/ / / / private void DoJudg
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号