private void NotifyBoardChanged() { if (!_suppressChangeEvents) { BoardChanged?.Invoke(this); } }
public void OnBoardChanged(int i_X, int i_Y) { if (BoardChanged != null) { BoardChanged.Invoke(i_X, i_Y); } }
/// <summary> /// Start a new game with the two players of the session and continue until the game is over. /// </summary> /// <returns>return the chess game log with all draws etc.</returns> public ChessGame ExecuteGame() { // initialize new chess game Game = new ChessGame(); // continue until the game is over while (!Game.GameStatus.IsGameOver()) { // determin the drawing player var drawingPlayer = Game.SideToDraw == ChessColor.White ? WhitePlayer : BlackPlayer; // init loop variables bool isDrawValid; ChessDraw draw; do { // get the draw from the player draw = drawingPlayer.GetNextDraw(Game.Board, Game.LastDrawOrDefault); isDrawValid = Game.ApplyDraw(draw, true); }while (!isDrawValid); // raise board changed event BoardChanged?.Invoke(Game.Board); } // return the chess game, so it can be logged, etc. return(Game); }
/// <summary> /// Reverts the <see cref="Game"/> back to the <see cref="LastMove"/>'s state. /// </summary> public void Undo() { if (!CanUndo) { return; } Tile removedTile = _history.Pop(); BoardChanging?.Invoke( this, new BoardChangingEventArgs( new Tile[0], new Tile[] { removedTile })); removedTile.Piece = new Piece(Pieces.None); Manager.Turn.MoveBack(); if (IsOver) { IsOver = false; Manager.Turn.ShiftStartBackwards(); } BoardChanged?.Invoke( this, new BoardChangedEventArgs( new Tile[0], new Tile[] { removedTile })); }
public void place(Ship s) { if (Check_placeable(s, s.X, s.Y)) { if ((int)s.orientation == 0) { for (int i = 0; i < s.Lives; i++) { board[s.Y + i, s.X].type = s.type; board[s.Y + i, s.X].ship = s; s.positions.Add(board[s.Y + i, s.X]); BoardChanged?.Invoke(s.X, s.Y + i); } } if ((int)s.orientation == 1) { for (int i = 0; i < s.Lives; i++) { board[s.Y, s.X + i].type = s.type; board[s.Y, s.X + i].ship = s; s.positions.Add(board[s.Y, s.X + i]); BoardChanged?.Invoke(s.X + i, s.Y); } } } }
/// <summary> /// 盤上に駒を配置します。 /// ゲームがすでに終了している場合、指定した位置にすでに駒が置かれている場合は何もしません。 /// </summary> /// <param name="row">配置する行</param> /// <param name="column">配置する列</param> /// <param name="player">配置する駒</param> public void PutPiece(int row, int column, PlayerForm player) { if (GameStatus == GameStatus.Finished) { return; } if (this.board.BoardStatuses[row, column] != PlayerForm.None) { return; } this.board.PutPiece(row, column, player); BoardChanged?.Invoke(this, EventArgs.Empty); SwitchCurrentPleyer(); (bool isGameEnded, PlayerForm winner) = CheckIfGameEnded(BoardSize, AlignNumber); if (isGameEnded) { this.GameStatus = GameStatus.Finished; } this.Winner = winner; if (isGameEnded) { GameEnded.Invoke(this, new GameEndedEventArgs(this.Winner)); } }
protected virtual void OnBoardChange(int i_Row, int i_Column) { if (BoardChanged != null) { BoardChanged.Invoke(i_Row, i_Column); } }
/// <summary> /// ゲームをリセットします。 /// </summary> public void ResetGame() { this.board.ResetBoard(PlayerForm.None); CurrentPlayer = PlayerForm.Circle; CurrentPlayerChanged?.Invoke(this, EventArgs.Empty); BoardChanged?.Invoke(this, EventArgs.Empty); this.GameStatus = GameStatus.BeforeStart; Winner = PlayerForm.None; }
public void Go(Board board) { lock (_locker) { if (_board != board) { _board = board; BoardChanged?.Invoke(this, board); } } }
public void PaintTile(float x, float y) { if (!EnablePainting) { return; } var point = new Point( (int)(x / Board.TileSize.Width), (int)(y / Board.TileSize.Height)); Board.Tiles[point.X + point.Y * Board.Size.Width] = Tile.Block; BoardChanged?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Sets the current state of the board to the one specified by the data string /// </summary> public async void SetByDataString(string dataString, Version boardVersion = null) { // Check if the version is provided. If not, assume it is the current version. if (boardVersion == null) { boardVersion = BingoVersion; } await InitBoard(); ResetBoard(); BingoGrid.Children.Clear(); // NOTE: When making significant changes to this algorithm, // don't delete the code. Create an if branch to run the // previous version of the algorithm. byte[] tileData = dataString.Replace("\r", String.Empty).Replace("\n", String.Empty).TakeEvery(2) .Select(s => byte.Parse(s, System.Globalization.NumberStyles.HexNumber)).ToArray(); for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { var data = tileData[5 * x + y]; int textIndex = (data >> 1) - 1; if (textIndex == -1 || (x == 2 && y == 2)) { // Tile is free space BingoGrid.Children.Add(GenerateFreeTile()); continue; } string text = AllTiles[textIndex]; bool isFilled = (data & 1) == 1; AddTile(text, isFilled); } } BoardChanged?.Invoke(dataString); }
public async void ResetBoard() { await InitBoard(); // Clear the board of tiles var items = BingoGrid.Children.ToList(); foreach (UIElement item in items) { if (item is ToggleButton) { BingoGrid.Children.Remove(item); } } // Randomly choose 24 tiles var newTiles = GetRandom(AllTiles, 24); for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { // Check if the tile is the free space if (x == 2 && y == 2) { continue; } int boardIndex = 5 * x + y; if (boardIndex > 12) { boardIndex--; } SetTile(newTiles.ElementAt(boardIndex), x, y); } } BoardChanged?.Invoke(ToDataString()); }
public PlayResponse Play(PlayRequest request) { if (currentPlayer == null) { return(null); } PlayResponse response = currentPlayer.Play(request, victoryValidator); if (response.IsValidMove) { BoardChanged?.Invoke(request.Row, request.Col, currentPlayer.Mark); if (response.Result != Enums.GameState.Playing) { GameOver?.Invoke(response.Result, response.Result == Enums.GameState.Draw ? Enums.MarkType.None : currentPlayer.Mark); } currentPlayer = NextPlayer; } return(response); }
/// <summary> /// Resets the <see cref="Game"/> to its original state. /// </summary> public void Restart() { Tile[] history = _history.ToArray(); BoardChanging?.Invoke( this, new BoardChangingEventArgs( new Tile[0], history)); foreach (Tile tile in _history) { tile.Piece = new Piece(Pieces.None); } Manager.Turn.Reset(); _history.Clear(); IsOver = false; BoardChanged?.Invoke( this, new BoardChangedEventArgs( new Tile[0], history)); }
private void OnBoardChanged() { bool whiteQueenSurrounded = (CountNeighbors(PieceName.WhiteQueenBee) == 6); bool blackQueenSurrounded = (CountNeighbors(PieceName.BlackQueenBee) == 6); if (whiteQueenSurrounded && blackQueenSurrounded) { BoardState = BoardState.Draw; } else if (whiteQueenSurrounded) { BoardState = BoardState.BlackWins; } else if (blackQueenSurrounded) { BoardState = BoardState.WhiteWins; } else { BoardState = CurrentTurn == 0 ? BoardState.NotStarted : BoardState.InProgress; } BoardChanged?.Invoke(this, null); }
/// <summary> /// Puts a <see cref="Tile"/> corresponding to <see cref="CurrentPlayer"/> /// and advances the <see cref="Game"/> to the next state. at position /// <paramref name="x"/>, <paramref name="y"/>. /// </summary> /// <param name="x">x-axis position</param> /// <param name="y">y-axis position</param> /// <exception cref="ArgumentException"></exception> public void Play(int x, int y) { if (x < 0 || x > Board.Width) { throw new ArgumentException("Value is out of range", nameof(x)); } if (y < 0 || y > Board.Height) { throw new ArgumentException("Value is out of range", nameof(y)); } // Check if game is over if (IsOver) { return; } Tile tile = Board[x, y]; // Check for already placed tile if (tile.Piece.Type != Pieces.None) { return; } Player oldPlayer = Manager.CurrentPlayer; tile.Piece = oldPlayer.Piece; Tile previousTile = LastMove; _history.Push(tile); BoardChanging?.Invoke( this, new BoardChangingEventArgs( new Tile[] { tile }, new Tile[0])); // Check for game over if (CheckGameOver(x, y, out IList <Tile> winningLine)) { IsOver = true; if (ShiftPlayersOnGameOver) { Manager.Turn.ShiftStartForwards(); } } // Increment turn Manager.Turn.MoveNext(); BoardChanged?.Invoke( this, new BoardChangedEventArgs( new Tile[] { tile }, new Tile[0])); if (IsOver) { GameOver?.Invoke( this, new GameOverEventArgs( Manager.Turn.Current, oldPlayer, winningLine)); } }
public TrackerBoard() { TileChanged += (o, e) => BoardChanged?.Invoke(this, new EventArgs()); }
private void HandleChangedBoard(string fenBoard) => BoardChanged?.Invoke(this, new BoardChangedEventArgs(EditBoard(fenBoard)));
public void RandomFill(int seed, Difficulty diff) { if (Populated) { tiles = new PrimaryTile[10, 10]; } Random r = new Random(seed); CoordSet filled; int i = 0; switch (diff) { case Difficulty.Easy: while (i < 5) { Ship s = Ship.CreateRandom(r, ClassicShipLengths[i]); if (TryAddShip(s)) { i++; } } break; case Difficulty.Medium: filled = new CoordSet(); while (i < 5) { Ship s = Ship.CreateRandom(r, ClassicShipLengths[i]); if (filled.Overlaps(s.GetOccupiedArea(0))) { continue; } filled.Add(s.GetOccupiedArea(1)); TryAddShip(s); i++; } break; case Difficulty.Hard: filled = new CoordSet(); var border = new CoordSet(); for (int j = 0; j < 10; j++) { border.Add(new CoordPair(0, j)); border.Add(new CoordPair(j, 0)); border.Add(new CoordPair(9, j)); border.Add(new CoordPair(j, 9)); } while (i < 5) { Ship s = Ship.CreateRandom(r, ClassicShipLengths[i]); var shipArea = s.GetOccupiedArea(0); if (shipArea.Overlaps(filled)) { continue; } var weakArea = new CoordSet(border); weakArea.IntersectWith(shipArea); if (r.NextDouble() < weakArea.Count * 0.4) { continue; } border.Add(s.GetOccupiedArea(1)); filled.Add(shipArea); TryAddShip(s); i++; } break; } Populated = true; BoardChanged?.Invoke(this, new EventArgs()); }
public PrimaryBoard() { TileChanged += (o, e) => BoardChanged?.Invoke(this, new EventArgs()); }
/// <summary> /// Raise the BoardChanged event /// </summary> /// <param name="board"></param> protected virtual void OnBoardChanged(TBoard board) { BoardChanged?.Invoke(this, board); }
/// <summary> /// 局面変更イベントを発行します。 /// </summary> internal void FireBoardChanged(object sender, BoardChangedEventArgs e) { BoardChanged.SafeRaiseEvent(sender, e); }