/// <inheritdoc/> public void OnNavigatedTo(NavigationContext navigationContext) { IsGameEnded = false; GameLog = string.Empty; MasterFactory.CheckedPlayer = null; var callback = _gameServiceProvider.ServiceCallback; var gameInfo = callback.GameInfo; var field = callback.GameInfo.GameField; var playerColor = callback.GameInfo.PlayerColor; TurnColor = gameInfo.TurnColor; YourColor = gameInfo.PlayerColor; GameField = new VirtualField(field.ToMultiDimensionalArray(), playerColor); OpponentName = gameInfo.OpponentName; callback.FieldUpdated -= OnFieldUpdated; callback.GameEnded -= OnGameEnded; callback.FieldUpdated += OnFieldUpdated; callback.GameEnded += OnGameEnded; }
private VirtualField CreateQueenKingField() { var defaultField = VirtualFieldUtils.CreateEmptyField(); var field = new VirtualField(defaultField); /*************** * _ _ _ _ P * _ Q _ _ _ P * _ _ _ _ K * P P _ P * */ field[4, 2] = ChessPiece.WhiteKing; field[1, 1] = ChessPiece.WhiteQueen; field[0, 3] = ChessPiece.WhitePawn; field[1, 3] = ChessPiece.WhitePawn; field[3, 3] = ChessPiece.WhitePawn; field[4, 0] = ChessPiece.WhitePawn; field[5, 1] = ChessPiece.WhitePawn; return(field); }
private void DrawGrid(VirtualField field) { var lineColor = Brushes.Black; // Rows for (int j = 0; j <= field.Height; j++) { var horizontalLine = CreateLine(0, j * CellY, field.Width * CellX, j * CellY); horizontalLine.Stroke = lineColor; CanvasRef.Children.Add(horizontalLine); SetZIndex(horizontalLine, 1); } // Columns for (int i = 0; i <= field.Width; i++) { var verticalLine = CreateLine(i * CellX, 0, i * CellX, field.Height * CellY); verticalLine.Stroke = lineColor; CanvasRef.Children.Add(verticalLine); SetZIndex(verticalLine, 1); } }
bool CanWeReplaceFieldInternal( SqlTableSource table, VirtualField field, HashSet <int> excludeSourceIds, int testedSourceIndex, HashSet <VirtualField> visited) { if (visited.Contains(field)) { return(false); } if (!excludeSourceIds.Contains(field.SourceID) && !IsSourceRemoved(field.SourceID)) { return(true); } visited.Add(field); if (_equalityMap == null) { return(false); } if (testedSourceIndex < 0) { return(false); } if (_equalityMap.TryGetValue(field, out var sameFields)) { foreach (var pair in sameFields) { if ((testedSourceIndex == 0 || GetSourceIndex(table, pair.Item1) > testedSourceIndex) && CanWeReplaceFieldInternal(table, pair.Item2, excludeSourceIds, testedSourceIndex, visited)) { return(true); } } } return(false); }
public void Initialize() { if (_isInitialized) { return; } var randomColor = DateTime.Now.Millisecond % 2 == 0 ? PlayerColor.White : PlayerColor.Black; var player1Color = randomColor; var player2Color = player1Color.Invert(); Player.SetColor(Player1, player1Color); Player.SetColor(Player2, player2Color); var chessGameField = VirtualFieldUtils.CreateDefaultField(); _turnColor = PlayerColor.White; _virtualField = new VirtualField(chessGameField); var p1GameInfo = new WcfGameInfo( player1Color, Player2.PlayerName, chessGameField.ToJaggedArray(), _turnColor); var p2GameInfo = new WcfGameInfo( player2Color, Player1.PlayerName, chessGameField.ToJaggedArray(), _turnColor); // TODO Если теряется связь то надо отдавать победу Player1.Callback.GameHasStarted(p1GameInfo); Player2.Callback.GameHasStarted(p2GameInfo); _isInitialized = true; }
bool CanWeReplaceField(SelectQuery.TableSource table, VirtualField field, HashSet <int> excludeSourceId, int testedSourceId) { var visited = new HashSet <VirtualField>(); return(CanWeReplaceFieldInternal(table, field, excludeSourceId, GetSourceIndex(table, testedSourceId), visited)); }
protected bool Equals(VirtualField other) { return(Equals(Field, other.Field) && Equals(Column, other.Column)); }
/// <summary> /// Constructor for <see cref="PawnMaster"/>. /// </summary> public PawnMaster(VirtualField field, ChessPoint point, IPieceMasterFactory master) : base(field, point, master, ChessPiece.BlackPawn, ChessPiece.WhitePawn) { }
/// <summary> /// Constructor for <see cref="QueenMaster"/>. /// </summary> public QueenMaster(VirtualField field, ChessPoint point, IPieceMasterFactory master) : base(field, point, master, ChessPiece.BlackQueen, ChessPiece.WhiteQueen) { }
/// <summary> /// Constructor for <see cref="BishopMaster"/>. /// </summary> public BishopMaster(VirtualField field, ChessPoint point, IPieceMasterFactory master) : base(field, point, master, ChessPiece.BlackBishop, ChessPiece.WhiteBishop) { }
bool MatchFields(SelectQuery.TableSource manySource, SelectQuery.TableSource oneSource, VirtualField field1, VirtualField field2, FoundEquality equality) { if (field1 == null || field2 == null) { return(false); } DetectField(manySource, oneSource, field1, equality); DetectField(manySource, oneSource, field2, equality); return(equality.OneField != null && equality.ManyField != null); }
/// <summary> /// Constructor for <see cref="RookMaster"/>. /// </summary> public RookMaster(VirtualField field, ChessPoint point, IPieceMasterFactory master) : base(field, point, master, ChessPiece.BlackRook, ChessPiece.WhiteRook) { }
public void SetIncorrectMovement() { var field = new VirtualField(); field[-1, 8] = ChessPiece.BlackRook; }
public void GetIncorrectMovement() { var field = new VirtualField(); var test = field[100, 100]; }
/// <summary> /// Constructor for <see cref="KingMaster"/>. /// </summary> public KingMaster(VirtualField field, ChessPoint point, IPieceMasterFactory master) : base(field, point, master, ChessPiece.BlackKing, ChessPiece.WhiteKing) { }
private void FillVirtualField(VirtualField virt) { virt.ObjectToRemovePath = ObjectToRemovePath; virt.Path = VirtualPath; }
VirtualField MapToSource(SelectQuery.TableSource table, VirtualField field, int sourceId) { var visited = new HashSet <VirtualField>(); return(MapToSourceInternal(table, field, sourceId, visited)); }
void DetectField(SelectQuery.TableSource manySource, SelectQuery.TableSource oneSource, VirtualField field, FoundEquality equality) { field = GetNewField(field); if (oneSource.Source.SourceID == field.SourceID) { equality.OneField = field; } else if (manySource.Source.SourceID == field.SourceID) { equality.ManyField = field; } else { equality.ManyField = MapToSource(manySource, field, manySource.Source.SourceID); } }
private static IEnumerable <ChessPoint> FindPieces(Func <ChessPiece, bool> checker, VirtualField field) { for (int x = 0; x < field.Width; x++) { for (int y = 0; y < field.Height; y++) { if (checker(field[x, y])) { yield return(new ChessPoint(x, y)); } } } }
/// <summary> /// /// </summary> /// <param name="_DBAdapter"></param> /// <param name="usePrefix">是否使用字段前辍 如 t1.Name</param> /// <param name="withTablePrefix">是否生按表生成前辍,关联时用 如Table__Name</param> /// <param name="mapingName">别名,空则按字段名,没有AS</param> /// <param name="fieldName">自定义查询字段名,空则按Name</param> internal void SetFieldQueryScript2(DBAdapter.DBAdapterBase _DBAdapter, string usePrefix, bool withTablePrefix, string mapingName, string fieldName = "") { string query = ""; if (!string.IsNullOrEmpty(usePrefix)) { //query += "{" + ModelType.FullName + "}"; query += usePrefix; } this.FieldMapping = new FieldMapping() { QueryName = MapingName, MappingName = mapingName }; if (!string.IsNullOrEmpty(mapingName)) { FieldMapping.QueryName = mapingName; FieldMapping.MappingName = mapingName; } else { FieldMapping.QueryName = MapingName; FieldMapping.MappingName = MemberName; } if (string.IsNullOrEmpty(fieldName)) { fieldName = withTablePrefix ? MapingName : _DBAdapter.KeyWordFormat(MapingName); } //判断虚拟字段 if (FieldType == Attribute.FieldType.虚拟字段) { query = VirtualField.Replace("{" + ModelType.FullName + "}", usePrefix);//替换前辍 mapingName = MemberName; } else { query += fieldName; } QueryField = query; var mappNameFull = fieldName; if (!string.IsNullOrEmpty(mapingName)) { //MapingName = mapingName; mappNameFull = mapingName; } if (withTablePrefix) { FieldMapping.MappingName = mappNameFull; mappNameFull = GetTableFieldFormat(TableName, mappNameFull); FieldMapping.QueryName = mappNameFull; } //MapingName = mappNameFull; //别名不为空或有表前辍 if (!string.IsNullOrEmpty(mapingName) || withTablePrefix) { QueryFullScript = string.Format("{0} as {1}", query, mappNameFull); } else { QueryFullScript = query; } }
/// <summary> /// Constructor for <see cref="KnightMaster"/>. /// </summary> public KnightMaster(VirtualField field, ChessPoint point, IPieceMasterFactory master) : base(field, point, master, ChessPiece.BlackKnight, ChessPiece.WhiteKnight) { }