private void GameLogic(Move move) { //if (Anim.IsProcess) // return; bool isLeft = move == Move.Left; bool isRight = move == Move.Right; bool isUp = move == Move.Up; bool isDown = move == Move.Down; bool isMoveDone = false; for (int i = 0; isLeft || isRight ? i < CellSize.X : i < CellSize.Y; i++) { for (int j = isRight ? CellSize.Y - 1 : isDown ? CellSize.X - 1 : 0; isRight || isDown ? j >= 0 : isUp?j < CellSize.X : j < CellSize.Y; j += isRight || isDown ? -1 : 1) { Cage cage = Cages.Where(c => c.Position.X == (isUp || isDown ? i : j) && c.Position.Y == (isUp || isDown ? j : i)).FirstOrDefault(); if (cage != null && cage.Number != -1 && CheckCageCanMove(cage, move)) { for (int k = 1; isLeft || isRight ? k < CellSize.Y : k < CellSize.X; k++) { Cage nearlyCage = CheckCageNearly(cage, move); if (CheckCageCanMove(cage, move)) { if (nearlyCage?.Number == cage.Number && nearlyCage.CanMix) { cage.Position = new Point(cage.Position.X + (isLeft ? -1 : isRight ? 1 : 0), cage.Position.Y + (isUp ? -1 : isDown ? 1 : 0)); cage.Number *= 2; cage.CanMix = false; nearlyCage.Number = -1; nearlyCage.Name = cage.Name; nearlyCage.Position = new Point(-2, -2); Anim = new Animation(CageDistance, 20, IsAnimation, Animation_OnMix); Anim.Move(move, cage, true); Anim.Mix(cage); isMoveDone = true; break; } else if (nearlyCage == null) { cage.Position = new Point(cage.Position.X + (isLeft ? -1 : isRight ? 1 : 0), cage.Position.Y + (isUp ? -1 : isDown ? 1 : 0)); Anim = new Animation(CageDistance, 20, IsAnimation); Anim.Move(move, cage, false); isMoveDone = true; } else { break; } } else { break; } } } } } Cages.ForEach(c => c.CanMix = true); //Cages.ForEach(c=> { // args.History[args.History.Count - 1].Where(c2 => c2.Name == c.Name).FirstOrDefault().Position = c.Position; //}); if (isMoveDone) { AddRandomCage(); CountMove++; args.History.Add(new List <Cage>(Cages)); OnMove?.Invoke(args); } if (!CheckWays()) { OnNoWays?.Invoke(args); IsWin = false; GameOver(); } }
void ApplyMovement(Vector2 input) { rigidbody2D.AddForce(input * (speed * Time.deltaTime)); OnMove?.Invoke(Mathf.Abs(Vector2.Distance(transform.position, previousFramePosition))); previousFramePosition = transform.position; }
public void NotifyMove(Event e) => OnMove?.Invoke(this, e);
public static void ReportMove() { OnMove?.Invoke(); }
public void SetHandler(OnStart _s, OnEnd _e, OnMove _m) { _onStart = _s; _onEnd = _e; _onMove = _m; }
IEnumerator<ITask> OnMoveHandler(OnMove onMove) { if (onMove.DriveControl == _driveControl && _drivePort != null) { drive.SetDrivePowerRequest request = new drive.SetDrivePowerRequest(); request.LeftWheelPower = (double)onMove.Left * MOTOR_POWER_SCALE_FACTOR; request.RightWheelPower = (double)onMove.Right * MOTOR_POWER_SCALE_FACTOR; _drivePort.SetDrivePower(request); } yield break; }
public IEnumerator AnimateScan(InventoryCollection enable) { // Setup variables int comboCount = 0; bool isFormationFound = false; // Disable inventory enable.IsAllEnabled = false; // Drop blocks first; let them contribute to the combos DropNewBlocks(); yield return(StartCoroutine(AnimateBlocksDropping())); // Scan for any formations DiscoveredFormations formations = ScanFormations(comboCount, out isFormationFound); while (isFormationFound == true) { // Calculate the score formations.SortLists(); UpdateScore(formations, ref comboCount); // Update blocks to indicate they're now in combo state yield return(StartCoroutine(UpdateFormation(formations, Block.State.Combo))); // Wait for the combo animation to finish float waitTime = animationDelays.GetDelayBetweenComboAndElimination(formations.NumBlocks); if (waitTime > 0) { yield return(new WaitForSeconds(waitTime)); } // Update blocks to indicate they're eliminated yield return(StartCoroutine(UpdateFormation(formations, Block.State.Eliminated))); // Wait until the last block is hidden Block lastBlock = GetLastBlock(formations); while (lastBlock.CurrentState != Block.State.Hidden) { yield return(null); } // Remove all blocks RemoveFormations(formations); // Animate the blocks dropping yield return(StartCoroutine(AnimateBlocksDropping())); // Scan for the next formations isFormationFound = false; formations = ScanFormations(comboCount, out isFormationFound); } // Check if the player should end the game or not. bool isGameOver = CheckGameOver(); if (isGameOver == false) { // Re-enable inventory enable.IsAllEnabled = true; LastGameSettings.Instance.SaveSettings(); } else { // Reset all stats LastGameSettings.Instance.Reset(); } OnMove?.Invoke(this); }
private void HandleOnMove(Vector vector, bool isLeft) { OnMove?.Invoke(this, new LeapEvent((int)vector.x, (int)vector.y, isLeft)); }
public void Move(MouseEventArgs args) => OnMove?.Invoke(this, args);
public void RaisePositionChanged() { OnMove?.Invoke(_ownerId, PosX, PosY, PosZ, Angle, MoveMotion); }
/// <summary> /// <para>Invokes the OnMove event</para> /// </summary> /// <param name="direction"></param> public void Move(Vector2 direction) { OnMove?.Invoke(direction); }
// TODO Optimize movement methods /// <summary> /// Moves the piece and cleans it's path /// </summary> /// <param name="field">The field that was clicked</param> /// <param name="fields">the list of fields to use as board</param> /// <param name="player">the turn player</param> /// <param name="dieValue">the value of the die</param> public void Move(ref Field field, ref List <Field> fields, ref Player player, int dieValue) { Fields = fields; // Checks if there is any pieces to move if (field.GetPieces.Count != 0) { // The piece to move (Always chooses the first in the stack) Piece piece = (Piece)field.GetPieces.First(); homeField = player.GetPlayerFields[(piece.BasePosition)]; if (piece.GetPosition() + dieValue > 51 && piece.State != PieceState.Safe) { piece.SetPosition((piece.GetPosition() - 52)); } // The field to move to Field fieldToMove = fields[(piece.GetPosition() + dieValue)]; // TODO change from exception if (!piece.CanMove && player.Color != piece.Color) { LogControl.Log("The selected piece can't move", LogControl.LogLevel.Error); LogControl.Log(piece.CanMove.ToString() + ", COLOR: " + player.Color, LogControl.LogLevel.Error); throw new Exception("ERROR: Piece cannot move."); } else if (piece.Counter + dieValue > 55) { UpdateField(field, field.GetDefaultImage()); ResetField(field); piece.State = PieceState.Finished; OnMove?.Invoke(this, piece); // Fires the event only if there is any listeners } else if (piece.Counter + dieValue >= 50) { int tmpMath = piece.GetSafePosition + dieValue - 53; //int tmpz = fieldToMove = fields[(piece.GetSafePosition + tmpMath)]; PlacePiece(piece, fieldToMove, PieceState.Safe, dieValue); ResetField(field); } else if (piece.State == PieceState.Home) { fieldToMove = fields[(piece.StartPosition)]; UpdateField(fieldToMove, GetImage(piece.Color, fieldToMove)); PlacePiece(piece, fieldToMove, PieceState.InPlay, 0); ResetField(field); } else if (IsPiecePlaced(fieldToMove)) { if (fieldToMove.GetPieces.Count > 1 && fieldToMove.Color != piece.Color) { KillPiece(ref piece); return; } } else if (IsSpecialField(fieldToMove) != FieldType.BaseField) { MovementController dis = this; switch (fieldToMove) { case Globe glo: glo.Protec(ref piece, ref field, ref glo, ref dis, dieValue); break; case Start sta: sta.Protec(ref piece, ref field, ref sta, ref dis, dieValue); break; case Star star: star.Protec(ref piece, ref field, ref dis); break; } } else { ResetField(field); PlacePiece(piece, fieldToMove, PieceState.InPlay, dieValue); } } else { LogControl.Log("Player tried to move a token from an empty field: " + field, LogControl.LogLevel.Warning); } foreach (Piece piece in player.GetPieces()) { piece.CanMove = false; } }
public override void OnPointerUp(PointerEventData eventData) { base.OnPointerUp(eventData); input = Vector2.zero; OnMove?.Invoke(this, input); }
public override void OnDrag(PointerEventData eventData) { base.OnDrag(eventData); OnMove?.Invoke(this, input); }
public void DoOnMove(MoveDirection direction) => OnMove?.Invoke(direction);
public void Move(Vector2 direction, float deltaTime) { OnMove?.Invoke(direction, deltaTime); }
public static void AddOnMoved(OnMove handler) { PlayerMoved += handler; }
private Cursor() { RootElement.OnClick += (MouseButton mouseButton, MouseButtonState buttonState, Vector2 screenPosition, Vector3 worldPosition, PhysicalElement clickedElement) => { OnClick?.Invoke(mouseButton, buttonState, screenPosition, worldPosition, clickedElement); }; RootElement.OnDoubleClick += (MouseButton mouseButton, Vector2 screenPosition, Vector3 worldPosition, PhysicalElement clickedElement) => { OnDoubleClick?.Invoke(mouseButton, screenPosition, worldPosition, clickedElement); }; RootElement.OnCursorMove += (Vector2 relativePosition, Vector2 absolutePosition, Vector3 worldPosition) => { OnMove?.Invoke(relativePosition, absolutePosition, worldPosition); }; }
IEnumerator<ITask> OnMoveHandler(OnMove onMove) { if (onMove.DriveControl == _driveControl && _drivePort != null) { drive.SetDrivePowerRequest request = new drive.SetDrivePowerRequest(); request.LeftWheelPower = (double)onMove.Left * MOTOR_POWER_SCALE_FACTOR; request.RightWheelPower = (double)onMove.Right * MOTOR_POWER_SCALE_FACTOR; yield return Arbiter.Choice( _drivePort.SetDrivePower(request), delegate(DefaultUpdateResponseType response) { }, delegate(Fault f) { LogError(f); } ); } }
public void FireMove(InputAction.CallbackContext context) { OnMove?.Invoke(context); }