3、核心控制类
UIControl.cs
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using YYTetris.Piece;
using System.Windows.Threading;
using System.Collections.Generic;
using System.ComponentModel;
namespace YYTetris
{
public class UIControl : INotifyPropertyChanged
{
/**//// <summary>
/// 俄罗斯方块容器
/// </summary>
public Block[,] Container { get; set; }
/**//// <summary>
/// 下一个形状的容器(4×4)
/// </summary>
public Block[,] NextContainer { get; set; }
/**//// <summary>
/// 游戏状态(Ready, Play, Pause, Over)
/// </summary>
public GameStatus GameStatus { get; set; }
private int _rows = 20; // 行数(Y 方向)
private int _columns = 10; // 列数(X 方向)
private int _positionX = 3; // 形状所属的 4×4 容器的 X 坐标
private int _positionY = 0; // 形状所属的 4×4 容器的 Y 坐标
private List<PieceBase> _pieces; // 形状集合
private PieceBase _currentPiece; // 当前形状
private PieceBase _nextPiece; // 下一个形状
private int _initSpeed = 400; // 初始速率(毫秒)
private int _levelSpeed = 50; // 每增加一个级别所需增加的速率(毫秒)
private DispatcherTimer _timer;
/**//// <summary>
/// 构造函数
/// </summary>
public UIControl()
{
// 初始化形状集合,共七种形状
_pieces = new List<PieceBase>() { new I(), new L(), new L2(), new N(), new N2(), new O(), new T() };
// 初始化方块容器(用 Block 对象填满整个容器)
Container = new Block[_rows, _columns];
for (int i = 0; i < _rows; i++)
{
for (int j = 0; j < _columns; j++)
{
var block = new Block();
block.Top = i * block.rectangle.ActualHeight;
block.Left = j * block.rectangle.ActualWidth;
block.Color = null;
Container[i, j] = block;
}
}
// 初始化下一个形状的容器(用 Block 对象将其填满)
NextContainer = new Block[4, 4];
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
var block = new Block();
block.Top = i * block.rectangle.ActualHeight;
block.Left = j * block.rectangle.ActualWidth;
block.Color = null;
NextContainer[i, j] = block;
}
}
上一页 [1] [2] [3] [4] [5] [6] [7] 下一页
责任编辑:小草