关闭

俄罗斯方块分步程序

428人阅读 评论(0) 收藏 举报

 按照面向对象方法,对游戏进行细分,可以分为小区域和大块,大块由小区域组成.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;

namespace TT
{
    class Square
    {
        //属性
        public Point Location;    //方块出现的位置
        public Size size;         //方块大小
        public Color ForeColor;
        public Color BackColor;

        //构造方法,由于大小和颜色是固定的,所以可以在开始时就初始化
        public Square(Size InitialSize, Color InitialBackColor, Color InitialForeColor)
        {
            size = InitialSize;
            BackColor = InitialBackColor;
            ForeColor = InitialForeColor;
        }

        //用前景色画方块
        public void Show(System.IntPtr WinHandle)
        {
            Graphics GameGraphics;
            GraphicsPath graphPath;
            PathGradientBrush brushSqure;
            Color[] surroundColor;
            Rectangle rectSquare;

            GameGraphics = Graphics.FromHwnd(WinHandle);
            //梯度颜色
            graphPath = new GraphicsPath();
            rectSquare = new Rectangle(Location.X, Location.Y, size.Width, size.Height);
            graphPath.AddRectangle(rectSquare);

            brushSqure = new PathGradientBrush(graphPath);
            brushSqure.CenterColor = ForeColor;
            surroundColor = new Color[] { BackColor };
            brushSqure.SurroundColors = surroundColor;

            GameGraphics.FillPath(brushSqure, graphPath);
        }
        //用背景色画方块
        public void Hide(System.IntPtr WinHandle)
        {
            Graphics GameGraphics;
            Rectangle rectSquare;

            GameGraphics = Graphics.FromHwnd(WinHandle);

            rectSquare = new Rectangle(Location.X, Location.Y, size.Width, size.Height);
            GameGraphics.FillRectangle(new SolidBrush(GameField.BackColor), rectSquare);
        }
    }
}

 

注:这个为最新类,添加了梯度路径画笔,便方块更加美观.

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:84188次
    • 积分:1459
    • 等级:
    • 排名:千里之外
    • 原创:58篇
    • 转载:8篇
    • 译文:0篇
    • 评论:11条
    文章分类
    最新评论