/// <summary> /// 数字单元移动. /// </summary> /// <param name="step"></param> /// <param name="direction"></param> private void PlayerMoving(MoveStep step, MoveDirection direction) { // 恢复 原始位置图片。 SetPicImage(step.Row, step.Column); // 设置 目标位置图片. switch (direction) { case MoveDirection.Up: SetPicImage(step.Row - 1, step.Column); break; case MoveDirection.Down: SetPicImage(step.Row + 1, step.Column); break; case MoveDirection.Left: SetPicImage(step.Row, step.Column - 1); break; case MoveDirection.Right: SetPicImage(step.Row, step.Column + 1); break; } if (maze.IsFinish) { MessageBox.Show("完成!"); } }
public List <MoveStep> HandlerEvent(JSONObject r_move) { moveSteps.Clear(); MoveStep firstStep = new MoveStep() { Position_Cell = r_move.GetField("Position_Cell").str, Next_Cell = r_move.GetField("Next_Cell").str, TimeMoveNextCell = r_move.GetField("TimeMoveNextCell").n }; JSONObject listMove = r_move.GetField("ListMove"); //moveSteps = JsonUtility.FromJson<List<MoveStep>>(listMove.ToString()); //moveSteps.Insert(0, firstStep); moveSteps.Add(firstStep); for (int i = 0; i < listMove.Count; i++) { MoveStep step = JsonUtility.FromJson <MoveStep>(listMove[i].ToString()); moveSteps.Add(step); } ConvertMoveStepsToPath(moveSteps); return(moveSteps); }
bool SpeedUpShortCut() { if (mCurStep == null || mOwner == null) { return(false); } Vector3 calcPos = CalcDstPosition(); float curDis = GetDistanceOfCurToDst(calcPos); //当前位置到推算的目标点位置的距离 //float diff = Mathf.Abs(curDis-DBActor.SpeedUpMinDis); MoveStep step = mCurStep; float speed = step.speed; if (step.type == EActorStepType.AT_WALK_END) { AnimationOptions op = mOwner.GetWalkAniOptions(); if (op != null) { speed = op.Speed; } } bool drag = false; if (curDis <= DBActor.SpeedUpMinDis) { mOwner.MoveSpeed = speed; } else if (curDis > DBActor.SpeedUpMaxDis) { mOwner.MoveSpeed = speed; mOwner.SetPosition(step.pos); mOwner.TurnDir(mCurStep.dir); drag = true; } else { if (0 == speed) { GameDebug.LogError("zero speed"); speed = 0.5f; } float costTime = DBActor.SpeedUpMinDis / speed; float s = curDis / costTime; if (s > 0) { mOwner.MoveSpeed = s; } } if (mCurStep.type == EActorStepType.AT_WALK_BEGIN) { mCurStep.pos = calcPos; drag = true; } return(drag); }
public ActionStepHandler(ElementSelector elementSelector, int actionType) { TextBoxDict = new Dictionary <string, TextBox>(); var actionTypeValue = (EventAction)actionType; switch (actionTypeValue) { case EventAction.Add: ElementStep = new AddStep(elementSelector); break; case EventAction.Remove: ElementStep = new RemoveStep(elementSelector); break; case EventAction.Move: if (elementSelector.ElementType == ElementType.Event) { ElementStep = new MoveStep(elementSelector); } break; case EventAction.SetEffect: ElementStep = new SetEffectStep(elementSelector); break; } }
public Step Push(StepType type, bool copySelection = false) { if (type == StepType.Invalid) { return(null); } int previous = -1; if (currentType != StepType.Invalid) { previous = m_moveCurrent; } m_moveCurrent = (m_moveCurrent + 1) % m_moves.Length; m_moveHead = m_moveCurrent; if (m_moveTail == m_moveHead) { m_moveTail = (m_moveTail + 1) % m_moves.Length; } if (type == StepType.Selection) { m_moves[m_moveCurrent] = new Step(); } else { m_moves[m_moveCurrent] = new MoveStep(); } if (copySelection && previous != -1) { MoveStep step = m_moves[previous] as MoveStep; if (step != null) { if (step.clone) { foreach (Moveable instance in step.clones) { m_moves[m_moveCurrent].instances.Add(new Moveable(instance.id)); } } else { foreach (Moveable instance in m_moves[previous].instances) { m_moves[m_moveCurrent].instances.Add(new Moveable(instance.id)); } } } else { m_moves[m_moveCurrent].instances = m_moves[previous].instances; m_moves[m_moveCurrent].center = m_moves[previous].center; } } return(m_moves[m_moveCurrent]); }
/// <summary> /// 规定的移动时间结束 /// </summary> /// <param name="remainTime"></param> void OnTimerFinish(float remainTime) { if (mOwner.IsWalking()) { mOwner.Stand(); mCurStep = null; } }
private void LerpTo(Vector3 start, Vector3 end, MoveStep nextStep) { transform.position = Vector3.Lerp(start, end, _moveTimer); _moveTimer += LerpingModifier * Time.deltaTime; if (_moveTimer >= 1f) { _moveStep = nextStep; _moveTimer = 0f; } }
/// <summary> /// 数字单元移动. /// </summary> /// <param name="step"></param> /// <param name="direction"></param> private void NumberItemMoving(MoveStep step, MoveDirection direction) { Invoke(new Action(() => { // 取得指定坐标的 按钮控件. // 注意参数的顺序, 先列后行! Control ctl = this.tlpMain.GetControlFromPosition(step.J, step.I); // 将按钮从表格删除. this.tlpMain.Controls.Remove(ctl); // 根据移动方向,将按钮加到指定的位置. // 注意参数的顺序, 先列后行! switch (direction) { case MoveDirection.Left: // 左 this.tlpMain.Controls.Add(ctl, step.J - 1, step.I); break; case MoveDirection.Up: // 上 this.tlpMain.Controls.Add(ctl, step.J, step.I - 1); break; case MoveDirection.Right: // 右 this.tlpMain.Controls.Add(ctl, step.J + 1, step.I); break; case MoveDirection.Down: // 下 this.tlpMain.Controls.Add(ctl, step.J, step.I + 1); break; } this.Refresh(); Thread.Sleep(500); if (puzzle8.IsFinish) { // 停止计时! this.timer1.Stop(); EndAuto(); MessageBox.Show("完成拼图处理!"); } })); }
public void SetFieldId(int id) { _fieldId = id; if (_moveStep != MoveStep.Finish) { return; } _lastPosition = transform.position; _moveStep = MoveStep.RePosition; }
public IDictionary <Figure, MoveSequence[]> GetMoves(SquareBoard board, Side side) { //fake move to the same cell; always 2 cases are possible return(new Dictionary <Figure, MoveSequence[]> { { _figure, new MoveSequence[] { new MoveSequence(MoveStep.Move(_figure.Point)), new MoveSequence(MoveStep.Move(_figure.Point)) } } }); }
public void MoveFileTest_Negative() { TestHelper.DeleteFile(@"..\..\..\..\Test\BizUnit.TestSteps.Tests\TestData\PurchaseOrder001.testdel2xml"); TestHelper.DeleteFile(@"..\..\..\..\Test\BizUnit.TestSteps.Tests\TestData\PurchaseOrder001.testdel1xml"); System.IO.File.Copy(@"..\..\..\..\Test\BizUnit.TestSteps.Tests\TestData\PurchaseOrder001.xml", @"..\..\..\..\Test\BizUnit.TestSteps.Tests\TestData\PurchaseOrder001.testdel1xml"); var step = new MoveStep { SourcePath = string.Empty, DestinationPath = @"..\..\..\..\Test\BizUnit.TestSteps.Tests\TestData\PurchaseOrder001.testdel2xml" }; try { step.Validate(new Context()); } catch (ArgumentException ex) { Assert.IsTrue(ex.Message.Contains("SourcePath is either null or of zero length")); } step.SourcePath = @"..\..\..\..\Test\BizUnit.TestSteps.Tests\TestData\PurchaseOrder001.testdel1xml"; step.DestinationPath = string.Empty; try { step.Validate(new Context()); } catch (ArgumentException ex) { Assert.IsTrue(ex.Message.Contains("DestinationPath is either null or of zero length")); } step.SourcePath = @"..\..\..\..\Test\BizUnit.TestSteps.Tests\TestData\PurchaseOrder001.testdel1xmlerror"; step.DestinationPath = @"..\..\..\..\Test\BizUnit.TestSteps.Tests\TestData\PurchaseOrder001.testdel1xmlerror"; try { var context = new Context(); step.Validate(context); step.Execute(context); } catch (FileNotFoundException fex) { Assert.IsTrue(fex.Message.Contains("Could not find file")); } }
public Step Move(Direction direction, ref string failureInfo) { Step result = new MoveStep(controller, direction); if (result.CheckActionPrerequisites(ref failureInfo)) { return(result); } else { return(null); } }
public void MoveFileTest_Negative() { TestHelper.DeleteFile(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder001.testdel2xml")); TestHelper.DeleteFile(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder001.testdel1xml")); System.IO.File.Copy( Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder001.xml"), Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder001.testdel1xml")); var step = new MoveStep(); step.SourcePath = string.Empty; step.DestinationPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder001.testdel2xml"); try { step.Validate(new Context()); } catch (ArgumentException ex) { Assert.IsTrue(ex.Message.Contains("SourcePath is either null or of zero length")); } step.SourcePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder001.testdel1xml"); step.DestinationPath = string.Empty; try { step.Validate(new Context()); } catch (ArgumentException ex) { Assert.IsTrue(ex.Message.Contains("DestinationPath is either null or of zero length")); } step.SourcePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder001.testdel1xmlerror"); step.DestinationPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder001.testdel1xmlerror"); try { var context = new Context(); step.Validate(context); step.Execute(context); } catch (FileNotFoundException fex) { Assert.IsTrue(fex.Message.Contains("Could not find file")); } }
public void SetField(Field field) { if (_currentField) { _currentField.RemovePlayer(this); _lastPosition = transform.position; } _currentField = field; _moveStep = MoveStep.Lerp1; _moveTimer = 0; _fieldId = _currentField.AddPlayer(this); }
private void ChangeStepState(MoveStep step) { if (_step == step) { return; } _step = step; switch (step) { case MoveStep.None: { _speed = 0; _accSpeed = 0; _curIndex = _targetIndex; _circleCnt = 0; break; } case MoveStep.SpeedUp: { //开始匀减速运动 -- 降到指定的速度 float lastSpeed = _idleSpeed; _accSpeed = (lastSpeed - _speed) / _speedUpDuration; _stepElapsedTime = 0; break; } case MoveStep.Idle: { _accSpeed = 0; _stepElapsedTime = 0; break; } case MoveStep.Slowdown: { //开始计算加速度 // t = 2*s/(Vt+V0) // a = (V1 - V0)/t float y = _gridList[_targetIndex].Root.localPosition.y; //float duration = (2 * y) / Mathf.Abs((0 + _speed)); float duration = 4; _accSpeed = (0 - _speed) / duration; break; } } }
public void GetMoves_SingleSimpleMoveForward() { var figure = Figure.CreateSimple(2, 0, Side.Black); var board = new SquareBoard(3); board.Set(figure); var subject = GetSubject(); var moves = subject.GetMoves(board, Side.Black); var figureMoves = Assert.Contains(figure, moves); var move = Assert.Single(figureMoves); var step = Assert.Single(move); Assert.Equal(MoveStep.Move(Point.At(1, 1)), step); }
public void GetMoves_SingleJumpAndMakeKingSequence() { var board = new SquareBoard(3); board.Set(Figure.CreateSimple(2, 2, Side.Black)); board.Set(Figure.CreateSimple(1, 1, Side.Red)); testOutput.WriteLine(board.ToString()); var subject = GetSubject(); var moves = subject.GetMoves(board, Side.Black); var move = moves[Figure.CreateSimple(2, 2, Side.Black)].Single(); var expectedSequence = new MoveSequence(MoveStep.Jump(0, 0), MoveStep.King()); Assert.Equal(expectedSequence, move); }
Utils.Timer mEndTimer;// 移动结束的Timer public void ReceiveWalkBegin(PkgNwarMove moves) { if (false == mIsRecvMsg) { return; } // 移动时的位置和方向 Vector3 pos = Vector3.zero; Vector3 dir = Vector3.zero; pos.x = moves.pos.px * GlobalConst.UnitScale; pos.z = moves.pos.py * GlobalConst.UnitScale; // 如果速度为0,直接设置到目标点(移动时间太短的话也当作停止处理) if (moves.speed == 0 || (moves.time != 0 && moves.time <= 66)) { pos = RoleHelp.GetPositionInScene(mOwner.ActorId, pos.x, pos.z); mOwner.SetPosition(pos); mOwner.MoveSpeed = 0; return; } dir.x = moves.speed * Mathf.Cos(moves.dir); dir.z = moves.speed * Mathf.Sin(moves.dir); MoveStep step = new MoveStep(); step.type = EActorStepType.AT_WALK_BEGIN; step.pos = pos; step.dir = dir; step.speed = moves.speed * GlobalConst.UnitScale; mCurStep = step; mbDirty = true; // 如果移动时间不为0,则在规定的时间内自动停止 if (moves.time != 0) { if (mEndTimer != null) { mEndTimer.Destroy(); } mEndTimer = new Utils.Timer((int)moves.time, false, moves.time, OnTimerFinish); } }
public void MoveFileTest() { TestHelper.DeleteFile(@"..\..\TestData\PurchaseOrder001.testdel2xml"); TestHelper.DeleteFile(@"..\..\TestData\PurchaseOrder001.testdel1xml"); System.IO.File.Copy(@"..\..\TestData\PurchaseOrder001.xml", @"..\..\TestData\PurchaseOrder001.testdel1xml"); var step = new MoveStep(); step.SourcePath = @"..\..\TestData\PurchaseOrder001.testdel1xml"; step.DestinationPath = @"..\..\TestData\PurchaseOrder001.testdel2xml"; step.Execute(new Context()); Assert.IsTrue(System.IO.File.Exists(@"..\..\TestData\PurchaseOrder001.testdel2xml")); }
private void MoveText(TextFigure tf, Point pos) { if (_nowMoving == null) { _nowMoving = new MoveTextStep(tf, pos.X - _downPos.X, pos.Y - _downPos.Y); StepManager.InsertNext(_nowMoving); } else { var snapped = StepManager.Snap(pos, _nowMoving.Figure); Magnet snappedBy; if ((snapped != null) && ((snappedBy = StepManager.SnapTo(pos, _nowMoving.Figure.GetMagnets())) != null)) { if (snappedBy.EqualExprStrings(tf.Start)) { ((MoveTextStep)_nowMoving).Move( "(" + snapped.X.ExprString + ") - (" + _nowMoving.Figure.Name + ".x)", "(" + snapped.Y.ExprString + ") - (" + _nowMoving.Figure.Name + ".y)", snappedBy.Def, snapped.Def); } else if (snappedBy.EqualExprStrings(tf.Center)) { ((MoveTextStep)_nowMoving).Move( "((" + snapped.X.ExprString + ") - (" + tf.Name + ".width/2)) - (" + _nowMoving.Figure.Name + ".x)", "((" + snapped.Y.ExprString + ") - (" + tf.Name + ".height/2)) - (" + _nowMoving.Figure.Name + ".y)", snappedBy.Def, snapped.Def); } else if (snappedBy.EqualExprStrings(tf.End)) { ((MoveTextStep)_nowMoving).Move( "((" + snapped.X.ExprString + ") - (" + tf.Name + ".width)) - (" + _nowMoving.Figure.Name + ".x)", "((" + snapped.Y.ExprString + ") - (" + tf.Name + ".height)) - (" + _nowMoving.Figure.Name + ".y)", snappedBy.Def, snapped.Def); } } else { ((MoveTextStep)_nowMoving).Move(pos.X - _downPos.X, pos.Y - _downPos.Y); } } }
public void GetMoves_PresetBoard_SimpleShouldStopWhenPromoted() { var board = Board6x6Preset1(); testOutput.WriteLine(board.ToString()); var subject = GetSubject(); var moves = subject.GetMoves(board, Side.Black); var simpleMoves = moves[Figure.CreateSimple(4, 6, Side.Black)]; var jumpUntilPromotedToKing = new MoveSequence( MoveStep.Jump(2, 4), MoveStep.Jump(0, 2), MoveStep.King()); Assert.Contains(jumpUntilPromotedToKing, simpleMoves); }
private void Update() { if (_moveStep == MoveStep.Stopped) { return; } if (_moveStep == MoveStep.PlaySound) { Game.Instance.GetWalkAudio().Play(); _moveStep = MoveStep.Finish; } if (_moveStep == MoveStep.Finish) { _movementFinishedCallback?.Invoke(); return; } Debug.Assert(_lastPosition != null, nameof(_lastPosition) + " != null"); var pA = _lastPosition.Value; var pB = _currentField.transform.position + _currentField.GetOffset(_fieldId); var d = Vector3.Distance(pA, pB); var m = (pA + pB) / 2; var h = d * .3f; var q1 = m + new Vector3(0, h, 0); if (_moveStep == MoveStep.Lerp1) { LerpTo(pA, q1, MoveStep.Lerp2); return; } if (_moveStep == MoveStep.Lerp2) { LerpTo(q1, pB, MoveStep.PlaySound); } if (_moveStep == MoveStep.RePosition) { LerpTo(pA, pB, MoveStep.Finish); } }
public void GetMoves_PresetBoard_KingCanJumpBack() { var board = Board6x6Preset1(); testOutput.WriteLine(board.ToString()); var subject = GetSubject(); var moves = subject.GetMoves(board, Side.Black); var kingMoves = moves[Figure.CreateKing(2, 0, Side.Black)]; var expectedKingSequence = new MoveSequence( MoveStep.Jump(0, 2), MoveStep.Jump(2, 4), MoveStep.Jump(0, 6)); Assert.Equal(expectedKingSequence, kingMoves.Single()); }
private void moveToSelectedRecord(BaseEntity entity) { if (entity == null) { return; } while (!CurrentQueryset.Contains(entity)) { if (MoveStep.CanExecute("+")) { MoveStep.Execute("+"); } else { throw new NotImplementedException("DONT KNOW WHAT TO DO"); } } }
public void GetMoves_SingleSimple_PromoteToKing() { var figure = Figure.CreateSimple(1, 1, Side.Black); var board = new SquareBoard(3); board.Set(figure); var subject = GetSubject(); var moves = subject.GetMoves(board, Side.Black); var figureMoves = Assert.Contains(figure, moves); var expectedTopLeft = new MoveSequence(MoveStep.Move(0, 0), MoveStep.King()); var expectedBottomRight = new MoveSequence(MoveStep.Move(0, 2), MoveStep.King()); Assert.Contains(expectedTopLeft, figureMoves); Assert.Contains(expectedBottomRight, figureMoves); Assert.Equal(2, figureMoves.Length); }
public void GetMoves_SingleJumpMoveForward() { var figure = Figure.CreateSimple(3, 3, Side.Black); var board = new SquareBoard(4); board.Set(figure); board.Set(Figure.CreateSimple(2, 2, Side.Red)); testOutput.WriteLine(board.ToString()); var subject = GetSubject(); var moves = subject.GetMoves(board, Side.Black); var figureMoves = Assert.Contains(figure, moves); var move = Assert.Single(figureMoves); var step = Assert.Single(move); Assert.Equal(MoveStep.Jump(Point.At(1, 1)), step); }
public void MoveFileTest() { TestHelper.DeleteFile(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder001.testdel2xml")); TestHelper.DeleteFile(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder001.testdel1xml")); System.IO.File.Copy( Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder001.xml"), Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder001.testdel1xml")); var step = new MoveStep(); step.SourcePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder001.testdel1xml"); step.DestinationPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder001.testdel2xml"); step.Execute(new Context()); Assert.IsTrue(System.IO.File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder001.testdel2xml"))); }
private IMoveCommand CreateMoveCommand(MoveStep step) { switch (step.Type) { case MoveStepTypes.Move: return(new WalkMoveCommand { Step = step }); case MoveStepTypes.Jump: return(new JumpMoveCommand { Step = step }); case MoveStepTypes.PromoteKing: return(new PromoteKingMoveCommand { Step = step }); default: throw new NotImplementedException($"Unknown step type: {step.Type}"); } }
public void FindBestMove_ChooseToStrikeKing() { /* 0 1 2 3 4 * 0 . . . . . * 1 . r . R . Simple and King * 2 . . . . . * 3 . r . . . * 4 b . . . . */ var board = new SquareBoard(5); board.Set(Figure.CreateSimple(1, 1, Side.Red)); board.Set(Figure.CreateKing(1, 3, Side.Red)); board.Set(Figure.CreateSimple(3, 1, Side.Red)); board.Set(Figure.CreateSimple(4, 0, Side.Black)); var subject = GetSubject(); var move = subject.FindBestMove(board, Side.Black, CancellationToken.None, Options(maxDepth: 2)); Assert.Equal(Figure.CreateSimple(4, 0, Side.Black), move.Figure); Assert.Equal(new MoveSequence(MoveStep.Jump(2, 2), MoveStep.Jump(0, 4), MoveStep.King()), move.Sequence); }
public void GetMoves_SingleSimple_ForwardOnly() { /* . . . . * . . . . * . b . . * . . . . */ var board = new SquareBoard(4); board.Set(Figure.CreateSimple(2, 1, Side.Black)); var subject = GetSubject(); var moves = subject.GetMoves(board, Side.Black); var figureMoves = moves.Single().Value; var expectedTopLeft = new MoveSequence(MoveStep.Move(1, 0)); var expectedTopRight = new MoveSequence(MoveStep.Move(1, 2)); Assert.Contains(expectedTopLeft, figureMoves); Assert.Contains(expectedTopRight, figureMoves); Assert.Equal(2, figureMoves.Length); }
/// <summary> /// 初始化. /// </summary> protected override void InitOtherData() { // 初始化状态. moveStep = MoveStep.OnMoving; }