俄罗斯方块分步程序

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

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);
        }
    }
}

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值