/// <summary> /// Deletes the currently selected move from the list of moves /// public void DeleteMove() { foreach (SelectionPanelBahviour panel in selectedMovesPanels) { panel.RemovePanelWithMove(moveToBeDeleted.GetName()); } AvailableMoves.DeleteMove(moveToBeDeleted); foreach (MovePanelBehaviour panel in listItems) { Destroy(panel.gameObject); } if (selectedListIndex < listItems.Length - 1) { selectedListIndex = Mathf.Max(selectedListIndex, 0); } else { selectedListIndex = Mathf.Max(selectedListIndex - 1, 0); } InputSettings.Deregister(moveToBeDeleted.GetName()); hasDeleted = true; controlsActive = true; SaveLoad.Save(moves); Init(); }
public AvailableMove MakeMove(string identifier) { var move = AvailableMoves.FirstOrDefault(m => m.Identifier == identifier); if (move is null) { return(null); } var piece = GetPiece(move.From); var to = move.To; SetPiece(move.From, null); var promote = (piece.Side == Side.Black && to.Y == Size - 1) || (piece.Side == Side.White && to.Y == 0); SetPiece(to, piece.Move(to, promote)); foreach (var taken in move.Takes) { SetPiece(taken.Pos, null); } CurrentTurn = CurrentTurn == Side.Black ? Side.White : Side.Black; AvailableMoves = GetAvailableMoves(); return(move); }
public void AvailableMovesTest_2( sbyte directionRight1, sbyte directionDown1, sbyte directionRight2, sbyte directionDown2, bool isCapture, byte x0, byte y0, byte x11, byte y11, byte x12, byte y12) { var availableMoves = new AvailableMoves(); availableMoves.AddDirection(directionRight1, directionDown1, isCapture); availableMoves.AddDirection(directionRight2, directionDown2, isCapture); var cells = availableMoves.ToCells(x0, y0); cells[0].X.Should().Be(x11); cells[0].Y.Should().Be(y11); cells[1].X.Should().Be(x12); cells[1].Y.Should().Be(y12); cells[2].Should().Be(_emptyCell); cells[3].Should().Be(_emptyCell); }
private void CellSelected(object sender, RoutedEventArgs e) { var cell = e.ButtonTag <Cell>(); if (cell.Figure.Side == Core.Board.Side.Empty) { MakeMove(this, null); } else { AvailableMoves.Clear(); if (WalkMoves.TryGetValue(cell.Figure, out var figureMoves) && figureMoves.Length > 0) { foreach (var move in figureMoves.Select((gameMove, i) => new MovesModel($"{i + 1}", i, gameMove))) { AvailableMoves.Add(move); } } } SelectedFigure = cell.Figure; foreach (var c in Cells) { if (c.Type == PieceType.None) { c.Active = false; } } }
public void ValidateName() { name = inputField.text; validName = !AvailableMoves.ContainsName(name); validName &= !name.Equals(string.Empty); alreadyUsedText.SetActive(AvailableMoves.ContainsName(name)); }
// switch current lane one to the left public void MoveLeft() { switch (currLane) { case AvailableMoves.Idle: { currLane = AvailableMoves.IdleLeft; PlayFile(AvailableMoves.WalkLeft); } break; case AvailableMoves.IdleLeft: break; case AvailableMoves.IdleRight: { currLane = AvailableMoves.Idle; PlayFile(AvailableMoves.WalkRightBack); } break; default: break; } }
private void CheckerBtn_Click(object sender, EventArgs e) { CheckerButton checkerBtn = sender as CheckerButton; bool clickedState = checkerBtn.Clicked, playerIsClickingOnASquareThatHasHisSoldier = checkerBtn.Square.Color == GameManager.ActivePlayer.Color, playerIsclickingAnAvailableMoveSquare = checkerBtn.IsAnAvailableMove; // First, make sure you are able to click that button if (!playerIsClickingOnASquareThatHasHisSoldier && !playerIsclickingAnAvailableMoveSquare) { return; } if (playerIsClickingOnASquareThatHasHisSoldier) { // Unclick all the other buttons. m_Board.UnclickallButtons(); clickedState = !clickedState; // We have to toggle the state now. // This line also triggeres the Available Moves part. Please take a look at the CheckerCheckerButton Setter for more information CheckedCheckerButton = clickedState ? checkerBtn : null; } else { // Player has clicked on an available move square Move move = AvailableMoves.First(m => m.Destination == checkerBtn.LocationOnMatrix); CheckedCheckerButton = null; GameManager.HandleMove(move); } }
public bool CanMoveToSquare(Vector2Int squareIndex) { if (AvailableMoves.Any(move => move.TargetSquare == squareIndex)) { return(true); } return(false); }
public Rook Move(Coordinates newCoordinates) { if (AvailableMoves.Contains(newCoordinates)) { return(new Rook(newCoordinates, _chessboard)); } throw new InvalidMoveException(); }
public override IEnumerable <Square> GetAvailableMoves(Board board) { AvailableMoves moves = new AvailableMoves(board.FindPiece(this)); moves.AddLateralSquares(); moves.RemoveCurrentSquare(); return(moves.Squares); }
public Knight Move(Coordinates newCoordinates) { if (!AvailableMoves.Contains(newCoordinates)) { throw new InvalidMoveException(); } return(new Knight(newCoordinates, _chessboard, _movementTracker)); }
private void RedrawBoard() { UpdateGameBoardCells(_game); AvailableMoves.Clear(); SelectedMoveModel = null; SelectedFigure = Figure.Nop; Info = $"Status: {_game.Status}{Environment.NewLine}Turn: {_game.Turn}{Environment.NewLine}Side move now: {_game.CurrentPlayer.Side}"; }
public static void Load() { if (File.Exists(Application.persistentDataPath + "/savedMoves.mvs")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/savedMoves.mvs", FileMode.Open); AvailableMoves.SetMoves((List <Move>)bf.Deserialize(file)); file.Close(); } }
// selects and plays a move public void PlayFile(AvailableMoves move) { // if file set, play file if (m_FilePaths.TryGetValue(move, out currFilePath)) { // stop previous file, start new file StopPlaying(); StartPlaying(); } }
public override IEnumerable <Square> GetAvailableMoves(Board board) { AvailableMoves moves = new AvailableMoves(board.FindPiece(this)); // create 2D array of move adjustments int[,] adjustments = new int[, ] { { 1, 1 }, { 1, 0 }, { 1, -1 }, { 0, 1 }, { 0, -1 }, { -1, 1 }, { -1, 0 }, { -1, -1 } }; moves.AddAdjustedSquares(adjustments); return(moves.Squares); }
public override List <BattleMove> GetExecutableMoves(Team enemyTeam) { List <BattleMove> executableMoves = AvailableMoves.Where(bm => bm.MoveType != BattleMoveType.Attack).ToList(); executableMoves.RemoveAll(m => _getViableTargets(m, enemyTeam).ToList().Count == 0); if (_malevolenceCounter >= MaxMalevolenceLevel) { executableMoves.RemoveAll(m => m.MoveType == BattleMoveType.Special); } return(executableMoves.ToList()); }
/// <summary> /// Adds the move in list of available moves for the specific match /// </summary> /// <returns><c>true</c>, if move was added, <c>false</c> otherwise.</returns> /// <param name="move">Move.</param> public bool AddMove(Move move) { if (AvailableMoves.FindIndex(a => a.Label.ToLower() == move.Label.ToLower()) == -1) { AvailableMoves.Add(move); return(true); } else { WriteLine("Move with label {0} exists!", move.Label); } return(false); }
public void SaveMove() { if (!AvailableMoves.ContainsName(move.GetName()) && !move.GetName().Equals(string.Empty)) { AvailableMoves.AddMove((Move)move.Clone()); SaveLoad.Save(AvailableMoves.GetMoves()); //Save every time save button is clicked in case game crashes while still in scene. ResetMoveEditor(); } else { saveButton.interactable = false; } }
/// <summary> /// Generates a valid name. Names take the form Move0, Move1, etc. The first one that is not used is returned. /// </summary> /// <returns>A valid name.</returns> public string GenerateValidName() { //Start from 0 and go to the highest possible value. Break loop and return as soon as a valid name is found. for (int i = 0; i < Int32.MaxValue; i++) { string name = "Move" + i; if (!AvailableMoves.ContainsName(name)) { return(name); } } return("NO_VALID_NAME"); }
public KnightV2 Move(Coordinates newCoordinates) { if (!AvailableMoves.Contains(newCoordinates)) { throw new InvalidMoveException(); } if (_isStartPosition) { PublishMovement(Location); } return(new KnightV2(newCoordinates, _chessboard, _observers)); }
public override void GeneratePossibleMoves(ChessGridInfo grid, ChessGridInfo gridCopy, ChessPlayer playerCopy, ChessPlayer enemyCopy, bool checkMovesValidity, bool checkSpecialMoves) { AvailableMoves.Clear(); Vector2Int newSquare = Vector2Int.zero; for (int i = 0; i < possibleDirections.GetLength(0); i++) { if (i == 1 && MovedFirstTime) { break; } int newX = SquareIndex.x + possibleDirections[i, 0]; int newY = SquareIndex.y + possibleDirections[i, 1]; newSquare.Set(newX, newY); if (grid.CheckIfSquareIndexIsValid(newSquare)) { Piece piece = grid.GetPieceOnSquareIndex(newSquare); Move move = CheckPromotionFlag(newSquare, piece); if (checkMovesValidity && piece == null) { Piece attackedPieceCopy = piece == null ? null : gridCopy.GetPieceOnSquareIndex(piece.SquareIndex); Move moveCopy = new Move(gridCopy.GetPieceOnSquareIndex(SquareIndex), newSquare, attackedPieceCopy, move.PromotionFlag); bool areMovesValid = CheckIfMoveIsValid(gridCopy, playerCopy, enemyCopy, moveCopy); if (!areMovesValid) { continue; } } if (piece == null) { AvailableMoves.Add(move); } else { break; } } } PieceAttack(grid, gridCopy, playerCopy, enemyCopy, checkMovesValidity); EnPassant(grid, gridCopy, playerCopy, enemyCopy, checkMovesValidity); }
public void MoveTo(int x, int y) { //TODO: remove hack for avoid switch weapons button var mousePosition = Mouse.GetState().Position; var scaledMousePosition = new Point((int)Math.Round(mousePosition.X / CurrentDisplay.Scale), (int)Math.Round(mousePosition.Y / CurrentDisplay.Scale)); if (scaledMousePosition.X > 700 && scaledMousePosition.Y < 900 && scaledMousePosition.Y > 850) { return; } if (AvailableMoves.Any(move => move.Last().X == x && move.Last().Y == y)) { Event.Publish(new MovementConfirmed(AvailableMoves.First(move => move.Last().X == x && move.Last().Y == y))); } }
public void AddMove(CheckMovesData checkMovesData, int offset) { if (!checkMovesData._valid) { return; } Move thisMove = new Move(); thisMove.startPosition = position; thisMove.endPosition = position + checkMovesData.i * offset; thisMove.piece = this; AvailableMoves.Add(thisMove); }
public void AvailableMovesTest_4() { var availableMoves = new AvailableMoves(); availableMoves.AddDirection(-1, 1, false); availableMoves.AddDirection(-1, 1, true); var cells = availableMoves.ToCells(7, 5); cells[0].X.Should().Be(5); cells[0].Y.Should().Be(7); cells[1].Should().Be(_emptyCell); cells[2].Should().Be(_emptyCell); cells[3].Should().Be(_emptyCell); }
private void MoveSelected(object sender, MouseEventArgs e) { SelectedMoveModel = e.ButtonTag <MovesModel>(); var selectedMoveSequence = SelectedMoveModel.Sequence; var allFigureMovePoints = AvailableMoves.SelectMany(x => x.Sequence).Select(x => x.Target); foreach (var point in allFigureMovePoints) { if (point == Point.Nop) { continue; } var cell = Cells.FirstOrDefault(x => x.Pos == point); cell.Active = selectedMoveSequence.Contains(point); } }
/// <summary> /// If the scene stack is non empty, pops the stack and loads the top scene. /// If the current scene is the MoveEditor, a "Are you sure"-dialog is opened to not discard the move. /// </summary> public static void GoBack() { if (sceneStack.Count > 0) { float fadeTime = GameObject.Find("Canvas").GetComponent <SceneFade>().BeginFade(1); Wait(fadeTime); if (SceneManager.GetActiveScene().name == "MoveEditorScene") { SaveLoad.Save(AvailableMoves.GetMoves()); } string previousSceneName = (string)sceneStack.Pop(); if (scenePathsList.Contains(previousSceneName)) { SceneManager.LoadScene(previousSceneName); } } }
public override void GeneratePossibleMoves(ChessGridInfo grid, ChessGridInfo gridCopy, ChessPlayer playerCopy, ChessPlayer enemyCopy, bool checkMovesValidity, bool checkSpecialMoves) { AvailableMoves.Clear(); Vector2Int newSquare = Vector2Int.zero; for (int i = 0; i < possibleDirections.GetLength(0); i++) { int newX = SquareIndex.x + possibleDirections[i, 0]; int newY = SquareIndex.y + possibleDirections[i, 1]; newSquare.Set(newX, newY); if (grid.CheckIfSquareIndexIsValid(newSquare)) { Piece piece = grid.GetPieceOnSquareIndex(newSquare); Move move = new Move(this, newSquare, piece); if (checkMovesValidity && piece != null && piece.PieceType == PieceType.King) { continue; } if (checkMovesValidity && (piece == null || (piece != null && piece.TeamColor != TeamColor))) { Piece attackedPieceCopy = piece == null ? null : gridCopy.GetPieceOnSquareIndex(piece.SquareIndex); Move moveCopy = new Move(gridCopy.GetPieceOnSquareIndex(SquareIndex), newSquare, attackedPieceCopy); bool areMovesValid = CheckIfMoveIsValid(gridCopy, playerCopy, enemyCopy, moveCopy); if (!areMovesValid) { continue; } } if (piece == null) { AvailableMoves.Add(move); } else if (piece != null && TeamColor != piece.TeamColor) { AvailableMoves.Add(move); } } } }
public ShieldGuy(int level, IChanceService chanceService, string name = null) : base(name ?? "Shield Guy" , level , LevelUpManager.GetHealthByLevel <ShieldGuy>(level) , LevelUpManager.GetManaByLevel <ShieldGuy>(level) , LevelUpManager.GetStrengthByLevel <ShieldGuy>(level) , LevelUpManager.GetDefenseByLevel <ShieldGuy>(level) , LevelUpManager.GetSpeedByLevel <ShieldGuy>(level) , LevelUpManager.GetEvadeByLevel <ShieldGuy>(level) , LevelUpManager.GetLuckByLevel <ShieldGuy>(level) , chanceService , SpellFactory.GetSpellsByLevel <ShieldGuy>(level) , MoveFactory.GetMovesByLevel <ShieldGuy>(level)) { _basicAttack = AvailableMoves.FirstOrDefault(bm => bm.MoveType == BattleMoveType.Attack); _ironShieldMove = AvailableMoves.FirstOrDefault(bm => bm is ShieldMove) as ShieldMove; _healShield = AvailableMoves.FirstOrDefault(bm => bm is ShieldFortifyingMove && ((ShieldFortifyingMove)bm).FortifyingType == ShieldFortifyingType.Health) as ShieldFortifyingMove; _fortifyShield = AvailableMoves.FirstOrDefault(bm => bm is ShieldFortifyingMove && ((ShieldFortifyingMove)bm).FortifyingType == ShieldFortifyingType.Defense) as ShieldFortifyingMove; }
public Shade(int level, IChanceService chanceService, int shadeExperience) : base("Shade", level, LevelUpManager.GetHealthByLevel <Shade>(level), LevelUpManager.GetManaByLevel <Shade>(level), LevelUpManager.GetStrengthByLevel <Shade>(level), LevelUpManager.GetDefenseByLevel <Shade>(level), LevelUpManager.GetSpeedByLevel <Shade>(level), LevelUpManager.GetEvadeByLevel <Shade>(level), LevelUpManager.GetLuckByLevel <Shade>(level), chanceService, SpellFactory.GetSpellsByLevel <Shade>(level) , MoveFactory.GetMovesByLevel <Shade>(level)) { ShadeExperience = shadeExperience; _malevolenceCounter = 0; _chargeMove = AvailableMoves.FirstOrDefault(bm => bm.MoveType == BattleMoveType.Special); _malevolenceAttackMove = AvailableMoves.FirstOrDefault(bm => bm.MoveType == BattleMoveType.ConditionalPowerAttack); }
private void PieceAttack(ChessGridInfo grid, ChessGridInfo gridCopy, ChessPlayer playerCopy, ChessPlayer enemyCopy, bool checkMovesValidity) { Vector2Int newSquare = Vector2Int.zero; for (int i = 0; i < possibleAttacks.GetLength(0); i++) { int newX = SquareIndex.x + possibleAttacks[i, 0]; int newY = SquareIndex.y + possibleAttacks[i, 1]; newSquare.Set(newX, newY); if (grid.CheckIfSquareIndexIsValid(newSquare)) { Piece piece = grid.GetPieceOnSquareIndex(newSquare); Move move = CheckPromotionFlag(newSquare, piece); if (checkMovesValidity && piece != null && piece.PieceType == PieceType.King) { continue; } if (checkMovesValidity && (piece != null && piece.TeamColor != TeamColor)) { Piece attackedPieceCopy = piece == null ? null : gridCopy.GetPieceOnSquareIndex(piece.SquareIndex); Move moveCopy = new Move(gridCopy.GetPieceOnSquareIndex(SquareIndex), newSquare, attackedPieceCopy, move.PromotionFlag); bool areMovesValid = CheckIfMoveIsValid(gridCopy, playerCopy, enemyCopy, moveCopy); if (!areMovesValid) { continue; } } if (piece != null && TeamColor != piece.TeamColor) { AvailableMoves.Add(move); } } } }