private void Move() { Console.WriteLine("matrix[{0},{1}]-{2}", CurrentMove.X, CurrentMove.Y, CurrentMove.ShowDirection()); Console.ReadKey(); if (MoveRight()) { Move(); } if (MoveDown()) { Move(); } if (MoveLeft()) { Move(); } if (MoveUp()) { Move(); } }
private void Cell_Click(object sender, EventArgs e) { FieldCell clickedCell = (FieldCell)sender; if (clickedCell.Gem == null) { return; } if (_prevCell != null) { clickedCell.Gem.WasMoved = true; _prevCell.Gem.WasMoved = true; Move = new CurrentMove(clickedCell, _prevCell); GemsController.SwapGems(Move.FirstCell, Move.SecondCell); foreach (var cell in GameField) { if (cell.Gem != null) { cell.Gem.IsClicked = false; } GemsController.UpdateGemTexture(cell.Gem); } _prevCell = null; } else { clickedCell.Gem.IsClicked = true; GemsController.UpdateGemTexture(clickedCell.Gem); _prevCell = clickedCell; } }
} // CheckMoveWhite /// <inheritdoc /> /// <summary> /// Проверить ход для чёрных. /// </summary> /// <param name="button1">Кнопка 1.</param> /// <param name="button2">Кнопка 2.</param> public bool CheckMoveBlack(IFrameworkInputElement button1, IFrameworkInputElement button2) { var currentBoard = GetCurrentBoard(); var jumpMoves = currentBoard.CheckJumps("Black"); if (jumpMoves.Count > 0) { var invalid = true; foreach (var move in jumpMoves) if (CurrentMove.Equals(move)) invalid = false; if (invalid) { DisplayMessage("Шашка оппонента должна быть взята."); CurrentMove.Piece1 = null; CurrentMove.Piece2 = null; Console.WriteLine(Resources.GameWithAiViewModel_CheckMoveBlack_CheckMoveBlack__False); return false; } // if } // if if (button1.Name.Contains("Black")) if (button1.Name.Contains("King")) { if (CurrentMove.IsAdjacent("King") && !button2.Name.Contains("Black") && !button2.Name.Contains("White")) return true; var middlePiece = CurrentMove.CheckJump("King"); if (middlePiece != null && !button2.Name.Contains("Black") && !button2.Name.Contains("White")) { var middleStackPanel = (StackPanel)GetGridElement(View.CheckersGrid, middlePiece.Row, middlePiece.Column); var middleButton = (Button)middleStackPanel.Children[0]; if (middleButton.Name.Contains("White")) { View.CheckersGrid.Children.Remove(middleStackPanel); AddBlackButton(middlePiece); return true; } // if } // if } else { if (CurrentMove.IsAdjacent("Black") && !button2.Name.Contains("Black") && !button2.Name.Contains("White")) return true; var middlePiece = CurrentMove.CheckJump("Black"); if (middlePiece != null && !button2.Name.Contains("Black") && !button2.Name.Contains("White")) { var middleStackPanel = (StackPanel)GetGridElement(View.CheckersGrid, middlePiece.Row, middlePiece.Column); var middleButton = (Button)middleStackPanel.Children[0]; if (middleButton.Name.Contains("White")) { View.CheckersGrid.Children.Remove(middleStackPanel); AddBlackButton(middlePiece); return true; } // if } // if } // if-else CurrentMove = null; DisplayMessage("Недопустимый ход. Повторите снова."); return false; } // CheckMoveBlack
public void Stun() { //WeaverLog.Log("STUNNING"); if (CurrentMove != null) { //WeaverLog.Log("Current Move = " + CurrentMove.GetType().FullName); CurrentMove.OnStun(); } OnStun(); }
protected virtual void OnDeath() { if (CurrentMove != null) { //WeaverLog.Log("Current Move = " + CurrentMove.GetType().FullName); CurrentMove.OnDeath(); } StopAllBoundRoutines(); BossStage++; entityHealth.OnDeathEvent -= OnDeath; }
private void Transition(BarAnalyzerResult result, IBarDatum datum) { IMove prevMove = CurrentMove.Close(datum); var newMove = Move.Open(MoveList.Count, datum, (int)result.Trend); MoveList.Add(newMove); CurrentTrendType = result.Trend; MoveSubject.OnNext(prevMove); }
/// <summary> /// Makes pokemon use it's queued (current) move selection. /// The pokemon will call events before and after move usage. If /// an event nullifies the move, this coroutine will return immedietly. /// </summary> public IEnumerator UseMove() { if (CurrentMove == null) { yield break; } /* Call PP Changed Event */ CurrentMove.PP--; /* Use The Move */ yield return(CurrentMove.Use()); }
public void DeleteAllComentary() { for (int i = 0; i < Moves.Count; i++) { Move m = Moves[i]; m.Game = this; m.DeleteComments(); Notations.SetNotationView(m); } CurrentMove.DeleteComments(); Notations.SetNotation(CurrentMove, "", false, true); }
public void DeleteComentary(int moveId) { for (int i = 0; i < Moves.Count; i++) { Move m = Moves[i]; if (m.Id == moveId) { m.Game = this; m.DeleteComments(); Notations.SetNotationView(m); break; } } CurrentMove.DeleteComments(); }
public Form1() { InitializeComponent(); _grid = new Grid(); _gridPresenter = new GridPresenter(_grid, _cellSize); _pointToCellConverter = new PointToCellConverter(_cellSize); _currentMove = new CurrentMove(); _winnerValidator = new WinnerValidator(_grid); _tieValidator = new TieValidator(_grid); _gameState = new GameState(new IGameOverValidator[] { _winnerValidator, _tieValidator }); _grid.OnCellOccupied += pnl.Invalidate; _grid.OnCellOccupied += _currentMove.SwitchMove; _grid.OnCellOccupied += _gameState.ValidateGameOver; _winnerValidator.OnWinner += ShowWinnerMessage; _winnerValidator.OnWinner += _ => ResetGame(); _tieValidator.OnTie += ShowTieMessage; _tieValidator.OnTie += ResetGame; }
public override void Update(List <Rectangle> terrain, GameEntity[] entities, Door[] doors, Spike[] spikes) { Console.WriteLine($"Player pos: {destRec.X}"); collideBottom = false; collideTop = false; collideLeft = false; collideRight = false; anyMovement = false; //Gravity velocity.Y += GRAVITY; //Collision handling (with other entities) for (int i = 0; i < entities.Length; i++) { if (entities[i] != this) { entityCollision = GetCollisionType(entities[i].GetDestRec()); if (entityCollision == CollisionType.BottomCollision) { pos.Y = entities[i].GetDestRec().Y - destRec.Height + 1; if (velocity.Y > 0) { velocity.Y = 0; } break; } else if ((entityCollision == CollisionType.LeftCollision || entityCollision == CollisionType.RightCollision) && destRec.X % Main.TILE_SIZE != 0) { HandleTerrainCollision(entities[i].GetDestRec()); break; } } } //Collision handling (with terrain) terrainCollision = CollisionType.NoCollision; for (int i = 0; i < terrain.Count; i++) { HandleTerrainCollision(terrain[i]); } //Collision handling with doors for (int i = 0; i < doors.Length; i++) { if (destRec.Intersects(doors[i].GetDestRec()) && !doors[i].GetBeenOpened()) { HandleTerrainCollision(doors[i].GetDestRec()); } } //Collision handling with spikes for (int i = 0; i < spikes.Length; i++) { if (destRec.Intersects(spikes[i].GetDestRec())) { Main.playerFailed = true; } } if (velocity.X < 0) { facingRight = false; } else if (velocity.X > 0) { facingRight = true; } if (velocity.Y < 0) { spriteToUse = additionalSprites["jump"]; } else if (velocity.Y > 0) { spriteToUse = additionalSprites["fall"]; } else if (velocity.X != 0) { spriteToUse = additionalSprites["run"]; numFrameIntervals = 8; } else { spriteToUse = sprite; numFrameIntervals = 11; } //Checking if any entities are currently moving if (velocity.X != 0 || velocity.Y != 0) { anyMovement = true; } for (int i = 0; i < entities.Length; i++) { if (entities[i].GetVelocity().X != 0 || entities[i].GetVelocity().Y != 0) { anyMovement = true; } } //If there is no movement happening and the control sequence isn't empty, call the next command in the queue. if (currentMove == CurrentMove.None && !anyMovement && !currentControlSeq.IsEmpty()) { switch (currentControlSeq.Dequeue()) { //Move right case 'd': //Setting target position targetPosX = destRec.X + Main.TILE_SIZE; currentMove = CurrentMove.MoveRight; break; //Move left case 'a': //Setting target position targetPosX = destRec.X - Main.TILE_SIZE; currentMove = CurrentMove.MoveLeft; break; //Collect item case 'c': currentMove = CurrentMove.CollectItem; break; //Jump right case 'e': targetPosX = destRec.X + Main.TILE_SIZE; alreadyJumped = false; currentMove = CurrentMove.JumpRight; break; //Jump left case 'q': targetPosX = destRec.X - Main.TILE_SIZE; alreadyJumped = false; currentMove = CurrentMove.JumpLeft; break; //Push right case '+': targetPosX = destRec.X + Main.TILE_SIZE; currentMove = CurrentMove.PushRight; Main.isPlayerPushingCrate = true; break; //Push left case '-': targetPosX = destRec.X - Main.TILE_SIZE; currentMove = CurrentMove.PushLeft; Main.isPlayerPushingCrate = true; break; //Default is no movement default: currentMove = CurrentMove.None; break; } } //If there is no movement, then the horizontal velocity should be zero if (currentMove == CurrentMove.None) { velocity.X = 0; } //If the player is moving to the right (moving, pushing, jumping) set horizontal velocity to WALK_SPEED else if ((currentMove == CurrentMove.MoveRight || currentMove == CurrentMove.JumpRight || currentMove == CurrentMove.PushRight) && velocity.X != WALK_SPEED) { velocity.X = WALK_SPEED; } //If the player is moving to the left (moving, pushing, jumping) set horizontal velocity to -WALK_SPEED else if ((currentMove == CurrentMove.MoveLeft || currentMove == CurrentMove.JumpLeft || currentMove == CurrentMove.PushLeft) && velocity.X != -WALK_SPEED) { velocity.X = -WALK_SPEED; } if ((currentMove == CurrentMove.JumpLeft || currentMove == CurrentMove.JumpRight) && !alreadyJumped) { alreadyJumped = true; velocity.Y = JUMP_SPEED; } //Updating player's animation if (spriteToUse == sprite || spriteToUse == additionalSprites["run"]) { if (animationCounter == 0) { srcRec.X += DIST_BTWN_FRAMES; srcRec.X %= DIST_BTWN_FRAMES * numFrameIntervals; } animationCounter++; animationCounter %= 7; } else { srcRec.X = 9; } //Updating player position based on its velocity pos.Y += velocity.Y; pos.X += velocity.X; destRec.X = (int)pos.X; destRec.Y = (int)pos.Y; //Resetting currentMove and distanceTravelled so that they're ready for the next command in currentMoveSeq if (velocity.X == 0 && (targetPosX == destRec.X + Main.TILE_SIZE || targetPosX == destRec.X - Main.TILE_SIZE)) { currentMove = CurrentMove.None; Main.isPlayerPushingCrate = false; targetPosX = destRec.X; } if ((currentMove == CurrentMove.MoveRight || currentMove == CurrentMove.JumpRight || currentMove == CurrentMove.PushRight) && destRec.X == targetPosX) { currentMove = CurrentMove.None; Main.isPlayerPushingCrate = false; } else if ((currentMove == CurrentMove.MoveLeft || currentMove == CurrentMove.JumpLeft || currentMove == CurrentMove.PushLeft) && destRec.X == targetPosX) { currentMove = CurrentMove.None; Main.isPlayerPushingCrate = false; } else if (currentMove == CurrentMove.CollectItem) { currentMove = CurrentMove.None; } }