private void PaintSymbol(MoveMetadata moveMetadata, Point coordinate) { _graphics.DrawString((moveMetadata.Player == PlayerType.Zero ? "0" : "X"), new Font("Arial", 30F), new SolidBrush((moveMetadata.Player == PlayerType.Zero ? Color.Blue : Color.Red)), coordinate.X, coordinate.Y); }
public void Moved(MoveMetadata moveMetadata, bool isYourTurn) { this.Store(moveMetadata); Invalidate(); this.CheckGameStatus(moveMetadata); this._isYourTurn = isYourTurn; toolStripStatus.Text = isYourTurn ? "Your turn" : "Not your turn"; }
private void PaintSymbols() { // Horizontal for (byte c = 0; c <= 2; c++) { // Vertical for (byte r = 0; r <= 2; r++) { MoveMetadata moveMetadata = this._moveMatrix[c, r]; if (moveMetadata != null) { switch (moveMetadata.CellNumber) { case CellNumber.First: PaintSymbol(moveMetadata, GetPointToPaint(moveMetadata.CellNumber)); break; case CellNumber.Second: PaintSymbol(moveMetadata, GetPointToPaint(moveMetadata.CellNumber)); break; case CellNumber.Third: PaintSymbol(moveMetadata, GetPointToPaint(moveMetadata.CellNumber)); break; case CellNumber.Forth: PaintSymbol(moveMetadata, GetPointToPaint(moveMetadata.CellNumber)); break; case CellNumber.Fifth: PaintSymbol(moveMetadata, GetPointToPaint(moveMetadata.CellNumber)); break; case CellNumber.Sixth: PaintSymbol(moveMetadata, GetPointToPaint(moveMetadata.CellNumber)); break; case CellNumber.Seventh: PaintSymbol(moveMetadata, GetPointToPaint(moveMetadata.CellNumber)); break; case CellNumber.Eighth: PaintSymbol(moveMetadata, GetPointToPaint(moveMetadata.CellNumber)); break; case CellNumber.Ninth: PaintSymbol(moveMetadata, GetPointToPaint(moveMetadata.CellNumber)); break; } } } } }
public void Move(MoveMetadata moveMetadata) { ITicTacToeCallback sender = OperationContext.Current.GetCallbackChannel <ITicTacToeCallback>(); foreach (KeyValuePair <PlayerType, ITicTacToeCallback> pair in _dictionary) { if (((ICommunicationObject)pair.Value).State == CommunicationState.Opened) { pair.Value.Moved(moveMetadata, !pair.Value.Equals(sender)); } } }
public void AddMove(Move move) { var meta = new MoveMetadata() { MaxUses = move.Uses.MaxUses, CurrentUses = move.Uses.MaxUses, TimesBoosted = 0, Slot = Moves[Moves.Keys.ToList()[-1]].Slot - 1 }; Moves.Add(move, meta); }
private bool HasValueInCell(Point clickedPoint) { MoveMetadata hasValueInCell = null; CellNumber cellNumber = GetCellNumber(clickedPoint); switch (cellNumber) { case CellNumber.First: hasValueInCell = this._moveMatrix[0, 0]; break; case CellNumber.Second: hasValueInCell = this._moveMatrix[0, 1]; break; case CellNumber.Third: hasValueInCell = this._moveMatrix[0, 2]; break; case CellNumber.Forth: hasValueInCell = this._moveMatrix[1, 0]; break; case CellNumber.Fifth: hasValueInCell = this._moveMatrix[1, 1]; break; case CellNumber.Sixth: hasValueInCell = this._moveMatrix[1, 2]; break; case CellNumber.Seventh: hasValueInCell = this._moveMatrix[2, 0]; break; case CellNumber.Eighth: hasValueInCell = this._moveMatrix[2, 1]; break; case CellNumber.Ninth: hasValueInCell = this._moveMatrix[2, 2]; break; case CellNumber.None: break; } return(hasValueInCell != null); }
private void StoreGameState(GameState gameState, MoveMetadata moveMetadata) { MoveMetadata[][] moveMatrix = gameState.Matrix; switch (moveMetadata.CellNumber) { case CellNumber.First: moveMatrix[0][0] = moveMetadata; break; case CellNumber.Second: moveMatrix[0][1] = moveMetadata; break; case CellNumber.Third: moveMatrix[0][2] = moveMetadata; break; case CellNumber.Forth: moveMatrix[1][0] = moveMetadata; break; case CellNumber.Fifth: moveMatrix[1][1] = moveMetadata; break; case CellNumber.Sixth: moveMatrix[1][2] = moveMetadata; break; case CellNumber.Seventh: moveMatrix[2][0] = moveMetadata; break; case CellNumber.Eighth: moveMatrix[2][1] = moveMetadata; break; case CellNumber.Ninth: moveMatrix[2][2] = moveMetadata; break; } gameState.NextPlayer = (moveMetadata.Player == PlayerType.Cross) ? PlayerType.Zero : PlayerType.Cross; }
// Moves a directory. This method may be called for versioned and unversioned // files. The default implementetions performs a system file move. public async Task MoveDirectoryAsync(FilePath localSrcPath, FilePath localDestPath, bool force, ProgressMonitor monitor) { ClearCachedVersionInfo(localSrcPath, localDestPath); var metadata = new MoveMetadata(VersionControlSystem) { Force = force, OperationType = MoveMetadata.MoveType.Directory }; using (var tracker = Instrumentation.MoveCounter.BeginTiming(metadata, monitor.CancellationToken)) { try { await OnMoveDirectoryAsync(localSrcPath, localDestPath, force, monitor); } catch (Exception e) { LoggingService.LogError("Failed to move directory", e); metadata.SetFailure(); FileService.SystemDirectoryRename(localSrcPath, localDestPath); } } }
// Moves a file. This method may be called for versioned and unversioned // files. The default implementetions performs a system file move. // It's up to the implementation to decide how smart the MoveFile method is. // For example, when moving a file to an unversioned directory, the implementation // might just throw an exception, or it could version the directory, or it could // ask the user what to do. public void MoveFile(FilePath localSrcPath, FilePath localDestPath, bool force, ProgressMonitor monitor) { ClearCachedVersionInfo(localSrcPath, localDestPath); var metadata = new MoveMetadata(VersionControlSystem) { Force = force, OperationType = MoveMetadata.MoveType.File }; using (var tracker = Instrumentation.MoveCounter.BeginTiming(metadata, monitor.CancellationToken)) { try { OnMoveFile(localSrcPath, localDestPath, force, monitor); } catch (Exception e) { LoggingService.LogError("Failed to move file", e); metadata.SetFailure(); File.Move(localSrcPath, localDestPath); } } }
public async Task <bool> Move(MoveMetadata moveMetadata) { var gameState = await StateManager.GetStateAsync <GameState>("GameState"); if (moveMetadata.Player != gameState.NextPlayer) { return(await Task.FromResult(false)); } StoreGameState(gameState, moveMetadata); RaiseMovedEvent(moveMetadata, gameState); await StateManager.SetStateAsync("GameState", gameState); await RaiseGameEndedEvent(); return(await Task.FromResult(true)); }
private void Store(MoveMetadata moveMetadata) { switch (moveMetadata.CellNumber) { case CellNumber.First: this._moveMatrix[0, 0] = moveMetadata; break; case CellNumber.Second: this._moveMatrix[0, 1] = moveMetadata; break; case CellNumber.Third: this._moveMatrix[0, 2] = moveMetadata; break; case CellNumber.Forth: this._moveMatrix[1, 0] = moveMetadata; break; case CellNumber.Fifth: this._moveMatrix[1, 1] = moveMetadata; break; case CellNumber.Sixth: this._moveMatrix[1, 2] = moveMetadata; break; case CellNumber.Seventh: this._moveMatrix[2, 0] = moveMetadata; break; case CellNumber.Eighth: this._moveMatrix[2, 1] = moveMetadata; break; case CellNumber.Ninth: this._moveMatrix[2, 2] = moveMetadata; break; } }
private void frmTicTacToe_Click(object sender, EventArgs e) { if (!this._gameStated) { MessageBox.Show("Other Player has not joined yet.", "TicTacToe", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (this._isYourTurn) { MouseEventArgs eargs = e as MouseEventArgs; Point clickedPoint = new Point(eargs.X, eargs.Y); if (!HasValueInCell(clickedPoint)) { MoveMetadata moveMetadata = new MoveMetadata(this._playerType, GetCellNumber(clickedPoint)); Store(moveMetadata); this._ticTacToeChannel.Move(moveMetadata); this._isYourTurn = false; } else { MessageBox.Show("Click on a blank region.", "TicTacToe", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Not your turn.", "TicTacToe", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private async void frmTicTacToe_Click(object sender, EventArgs e) { if (!_gameStated) { MessageBox.Show("Plese wait for other player to join", "TicTacToe", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (_isYourTurn) { MouseEventArgs eargs = e as MouseEventArgs; Point clickedPoint = new Point(eargs.X, eargs.Y); if (!HasValueInCell(clickedPoint)) { MoveMetadata moveMetadata = new MoveMetadata(PlayerChoice.Value, GetCellNumber(clickedPoint)); await ActorProxy.Move(moveMetadata); } else { MessageBox.Show("Click on a blank region.", "TicTacToe", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Not your turn.", "TicTacToe", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void RaiseMovedEvent(MoveMetadata moveMetadata, GameState gameState) { var events = GetEvent <ITicTacToeEvents>(); events.Moved(moveMetadata.Player, gameState.Matrix); }
private void CheckGameStatus(MoveMetadata moveMetadata) { WinVector winVector = WinVector.NONE; // Horizontal for (byte i = 0; i <= 2; i++) { if ((this._moveMatrix[i, 0] != null && this._moveMatrix[i, 0].Player == moveMetadata.Player) && (this._moveMatrix[i, 1] != null && this._moveMatrix[i, 1].Player == moveMetadata.Player) && (this._moveMatrix[i, 2] != null && this._moveMatrix[i, 2].Player == moveMetadata.Player)) { if (i == 0) { winVector = WinVector.TOP; } else if (i == 1) { winVector = WinVector.CENTER; } else if (i == 2) { winVector = WinVector.BOTTOM; } this._winVectorsToPaint.Add(winVector); // There can't be move than one filled horizontal rows. break; } } // Vertical for (byte i = 0; i <= 2; i++) { if ((this._moveMatrix[0, i] != null && this._moveMatrix[0, i].Player == moveMetadata.Player) && (this._moveMatrix[1, i] != null && this._moveMatrix[1, i].Player == moveMetadata.Player) && (this._moveMatrix[2, i] != null && this._moveMatrix[2, i].Player == moveMetadata.Player)) { if (i == 0) { winVector = WinVector.LEFT; } else if (i == 1) { winVector = WinVector.MIDDLE; } else if (i == 2) { winVector = WinVector.RIGHT; } this._winVectorsToPaint.Add(winVector); // There can't be move than one filled vertical rows. break; } } // Diagonal if ((this._moveMatrix[0, 0] != null && this._moveMatrix[0, 0].Player == moveMetadata.Player) && (this._moveMatrix[1, 1] != null && this._moveMatrix[1, 1].Player == moveMetadata.Player) && (this._moveMatrix[2, 2] != null && this._moveMatrix[2, 2].Player == moveMetadata.Player)) { winVector = WinVector.BACK_DIAGONAL; this._winVectorsToPaint.Add(winVector); } if ((this._moveMatrix[0, 2] != null && this._moveMatrix[0, 2].Player == moveMetadata.Player) && (this._moveMatrix[1, 1] != null && this._moveMatrix[1, 1].Player == moveMetadata.Player) && (this._moveMatrix[2, 0] != null && this._moveMatrix[2, 0].Player == moveMetadata.Player)) { winVector = WinVector.FORWARD_DIAGONAL; this._winVectorsToPaint.Add(winVector); } if (this._winVectorsToPaint.Count > 0) { Won(moveMetadata.Player); return; } // Draw if (this._moveMatrix[0, 0] != null & this._moveMatrix[0, 1] != null & this._moveMatrix[0, 2] != null & this._moveMatrix[1, 0] != null & this._moveMatrix[1, 1] != null & this._moveMatrix[1, 2] != null & this._moveMatrix[2, 0] != null & this._moveMatrix[2, 1] != null & this._moveMatrix[2, 2] != null & this._winVectorsToPaint.Count == 0) { Draw(); } }