📄 downslow.cs
字号:
using System;
using System.Windows.Forms;
using DiamondPet.UserLayer;
namespace DiamondPet.LogicLayer.GameStateRunLogic
{
/// <summary>
/// DownSlow 的摘要说明。
/// 慢下状态
/// </summary>
public class DownSlow : RunningState
{
public bool leftKeyDown;
public bool rightKeyDown;
public DownSlowCommand.DownSlowCommand leftDownCmd;
public DownSlowCommand.DownSlowCommand rightDownCmd;
public DownSlowCommand.DownSlowCommand downDownCmd;
public DownSlowCommand.DownSlowCommand upDownCmd;
public DownSlowCommand.DownSlowCommand enterDownCmd;
public DownSlowCommand.DownSlowCommand leftUpCmd;
public DownSlowCommand.DownSlowCommand rightUpCmd;
public DownSlowCommand.NextPropertyCommand nextPropertyCmd;
public DownSlowCommand.PrePropertyCommand prePropertyCmd;
public DownSlowCommand.UsePropertyCommand usePropertyCmd;
/// <summary>
/// 时间间隔记录
/// </summary>
public int tickLast;
/// <summary>
/// 左键按下时间
/// </summary>
public int leftCount;
/// <summary>
/// 右键按下时间
/// </summary>
public int rightCount;
#region 构造函数
/// <summary>
/// 默认构造函数
/// </summary>
public DownSlow()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 构造函数
/// </summary>
/// <param name="r"></param>
public DownSlow(RunStateManager r) : base(r)
{
Initialize();
InitializeCommand();
}
#endregion
#region 初始化部分
private void InitializeCommand()
{
leftDownCmd = new DownSlowCommand.LeftKeyDownCommand(this);
rightDownCmd = new DownSlowCommand.RightKeyDownCommand(this);
downDownCmd = new DownSlowCommand.DownKeyDownCommand(this);
upDownCmd = new DownSlowCommand.UpKeyDownCommand(this);
enterDownCmd = new DownSlowCommand.EnterKeyDownCommand(this);
leftUpCmd = new DownSlowCommand.LeftKeyUpCommand(this);
rightUpCmd = new DownSlowCommand.RightKeyUpCommand(this);
nextPropertyCmd = new DownSlowCommand.NextPropertyCommand(this);
prePropertyCmd = new DownSlowCommand.PrePropertyCommand(this);
usePropertyCmd = new DownSlowCommand.UsePropertyCommand(this);
}
public override void Initialize()
{
runCommandQueue.Clear();
//是否需要呢?
//
//runStateManager.gameDate.propertyQueue.Reset();
//
leftKeyDown = false;
rightKeyDown = false;
tickLast = Environment.TickCount;
leftCount = 0;//Environment.TickCount - GameConstResource.LeftRightTimeSpan;
rightCount = 0;//Environment.TickCount - GameConstResource.LeftRightTimeSpan;
}
#endregion
#region 绘图部分
protected override void DrawAll()
{
Draw.DrawTempToImage();
this.DrawScore();
this.DrawPropetyBar();
this.DrawLevel();
this.DrawMoveBlock();
}
#endregion
#region 程序逻辑部分
public override void RunStateLogic()
{
this.CheckSlowSpeed();
//时间更新
this.runStateManager.gameDate.timeControl.RenewTime(System.Environment.TickCount);
DrawAll();
//for test
int curTick = Environment.TickCount;
// //左移逻辑
if ( leftCount != 0 )
{
while ( curTick - leftCount >= GameConstResource.LeftRightTimeSpan )
{
//改变数据结构
runStateManager.gameDate.curGameItems.MoveItems(0,-1);
leftCount = leftCount + GameConstResource.LeftRightTimeSpan;
}
}
//右移逻辑
if ( rightCount != 0 )
{
while ( curTick - rightCount >= GameConstResource.LeftRightTimeSpan )
{
runStateManager.gameDate.curGameItems.MoveItems(0,1);
rightCount = rightCount + GameConstResource.LeftRightTimeSpan;
}
}
//下移逻辑
if ( runStateManager.gameDate.curGameItems.CheckCouldMove(1,0))
{
//tickLast 在按“下”以后至为零,以后没有再置回,所以这段程序一直在跑,建议向下落的时间间隔与向左,向右分开设置
while ( curTick - tickLast >= GameConstResource.currentSpeed )
{
runStateManager.gameDate.curGameItems.MoveItems(1,0);
tickLast = tickLast + GameConstResource.currentSpeed;
}
}
else
{
CombineBlock();
//粘住后合并
if ( CheckClearBlock() == true)
{
//清连击累计变量
this.runStateManager.gameDate.gameScore.CleanNum();
runStateManager.ChangeState(RunStateManager.CLEARBLOCK);
}
else
{
runStateManager.ChangeState(RunStateManager.SELECTBLOCK);
}
}
CheckCommand();
//判断时间是否已经到了
base.JudgeTimeOver();
}
/// <summary>
/// 将界面命令加入队列
/// </summary>
/// <param name="key"></param>
/// <param name="isdown">push down</param>
public override void AddKeyCommand(System.Windows.Forms.Keys key, bool isdown)
{
if (isdown)
{
switch(key)
{
//数字键
case Keys.D4:
this.leftDownCmd.ExecuteCommand();
break;
case Keys.D6:
this.rightDownCmd.ExecuteCommand();
break;
case Keys.D2:
this.upDownCmd.ExecuteCommand();
break;
case Keys.D8:
this.downDownCmd.ExecuteCommand();
break;
case Keys.D5:
this.runCommandQueue.AddElement(this.enterDownCmd);
break;
//方向键和控制键
case Keys.Left:
this.leftDownCmd.ExecuteCommand();
break;
case Keys.Right:
this.rightDownCmd.ExecuteCommand();
break;
case Keys.Up:
this.upDownCmd.ExecuteCommand();
break;
case Keys.Down:
this.downDownCmd.ExecuteCommand();
break;
case Keys.Enter:
this.runCommandQueue.AddElement(this.enterDownCmd);
break;
//道具相关按键
case Keys.F8: //#
this.runCommandQueue.AddElement(this.prePropertyCmd);
break;
case Keys.F9: //*
this.runCommandQueue.AddElement(this.nextPropertyCmd);
break;
case Keys.D0:
this.runCommandQueue.AddElement(this.usePropertyCmd);
break;
}
}
else
{
switch(key)
{
case Keys.D4:
this.leftUpCmd.ExecuteCommand();
break;
case Keys.D6:
this.rightUpCmd.ExecuteCommand();
break;
case Keys.Left:
this.leftUpCmd.ExecuteCommand();
break;
case Keys.Right:
this.rightUpCmd.ExecuteCommand();
break;
}
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -