public GameSession(int id, string name, Player player, ChessDotNet.Player side, string gamePassword = null)
        {
            if (string.IsNullOrWhiteSpace(name) | player == null)
            {
                throw new ArgumentNullException();
            }

            Description = new GameDescription()
            {
                Id       = id,
                Name     = name,
                Password = gamePassword
            };
            if (side == ChessDotNet.Player.Black)
            {
                Description.BlackPlayer = player;
            }
            else
            {
                Description.WhitePlayer = player;
            }
            State          = new Waiting(this);
            Turn           = new WhiteTurn(this);
            ChessLogicCore = new ChessDotNet.ChessGame();
        }
示例#2
0
        public void CreateNewGame(string username, string password, string gamename, ChessDotNet.Player side, string gamePassword)
        {
            gamePassword = string.IsNullOrWhiteSpace(gamePassword) ? null : gamePassword;

            if (CurrentGame == null & !string.IsNullOrWhiteSpace(gamename))
            {
                if (TryCreatePlayer(username, password))
                {
                    CurrentGame = new GameSession(GetNextGameId(), gamename, CurrentPlayer, side, gamePassword);
                    _games.Add(CurrentGame);
                    CurrentGame.NotifyAboutDeletingTheGame += CurrentGame_NotifyAboutDeletingTheGame;
                    try
                    {
                        var callback = OperationContext.Current.GetCallbackChannel <IGameSessionEstablishmentCallback>();
                        callback.SuccesfullConnectionToTheGame(CurrentGame.Description);
                    }
                    catch (Exception)
                    {
                        DisconnectFromTheGame();
                    }
                    WriteInfo();
                }
                else
                {
                    SendCallbackMessage("Не удалось создать игру");
                }
            }
            else
            {
                SendCallbackMessage("Не удалось создать игру");
            }
        }
示例#3
0
 public Board(ChessDotNet.Player side)
 {
     Cells = new BindingList <Cell>();
     InitializeCells(side);
     InitializeFigures(side);
     State      = new PieceDroped();
     Side       = side;
     ChessLogic = new ChessDotNet.ChessGame();
 }
示例#4
0
        public void EnemyMoved(string originalPosition, string newPosition)
        {
            ChessDotNet.Player enemySide = Side == ChessDotNet.Player.White ? ChessDotNet.Player.Black : ChessDotNet.Player.White;
            SelectedCell = Cells.Single(item => item.Position == originalPosition);
            var move     = new ChessDotNet.Move(originalPosition, newPosition, enemySide, 'Q');
            var moveType = ChessLogic.MakeMove(move, true);

            UpdateSourceIfPromotion(moveType, newPosition, enemySide);
            SelectedCell.Source = null;
            UpdateSourceIfEnPassant(moveType, newPosition, enemySide);
            UpdateSourceIfCastling(moveType, newPosition);
        }
示例#5
0
 public async void CreateNewGame(string gameName, ChessDotNet.Player side, string gamePassword)
 {
     CommandExecutionStarted();
     try
     {
         await _instance.client.CreateNewGameAsync(Username, Password, gameName, side, gamePassword);
     }
     catch (Exception ex)
     {
         CommandExecutionStoped();
         ShowInfo(ex);
     }
 }
        private void InitializeBoard(GameDesc desc)
        {
            _state = desc.State;
            ChessDotNet.Player side =
                TcpChessClient.getInstance().Username == desc.WhiteUsername ?
                ChessDotNet.Player.White : ChessDotNet.Player.Black;
            Board             = new Board(side);
            Cells             = Board.Cells;
            HorizontalIndexes = Board.HorizontalIndexes;
            VerticalIndexes   = Board.VerticalIndexes;

            MoveCommand = new DelegateCommand <string>((move) => { if (_state == "Playing")
                                                                   {
                                                                       Board.MakeMove(move);
                                                                   }
                                                       });
        }
示例#7
0
        private void InitializeIndexes(ChessDotNet.Player side)
        {
            List <char> hIndexes = new List <char>()
            {
                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'
            };

            List <char> vIndexes = new List <char>()
            {
                '8', '7', '6', '5', '4', '3', '2', '1'
            };

            if (side == ChessDotNet.Player.Black)
            {
                hIndexes.Reverse();
                vIndexes.Reverse();
            }

            HorizontalIndexes = new BindingList <char>(hIndexes);

            VerticalIndexes = new BindingList <char>(vIndexes);
        }
示例#8
0
        private void InitializeFigures(ChessDotNet.Player side)
        {
            List <string> whitePieces = new List <string>()
            {
                "wR", "wN", "wB", "wK", "wQ", "wB", "wN", "wR",
                "wP", "wP", "wP", "wP", "wP", "wP", "wP", "wP"
            };

            List <string> blackPieces = new List <string>()
            {
                "bR", "bN", "bB", "bQ", "bK", "bB", "bN", "bR",
                "bP", "bP", "bP", "bP", "bP", "bP", "bP", "bP"
            };

            if (side == ChessDotNet.Player.Black)
            {
                List <string> tempPieces = new List <string>(whitePieces);
                whitePieces = new List <string>(blackPieces);
                blackPieces = new List <string>(tempPieces);
            }

            int count = 0;

            for (int i = Cells.Count - 1; i > Cells.Count - whitePieces.Count - 1; i--)
            {
                Cells[i].Source = "/Resources/Pieces/" + whitePieces[count] + ".png";
                count++;
            }

            count = 0;

            for (int i = 0; i < blackPieces.Count; i++)
            {
                Cells[i].Source = "/Resources/Pieces/" + blackPieces[count] + ".png";
                count++;
            }
        }
示例#9
0
 public System.Threading.Tasks.Task CreateNewGameAsync(string username, string password, string gamename, ChessDotNet.Player side, string gamePassword)
 {
     return(base.Channel.CreateNewGameAsync(username, password, gamename, side, gamePassword));
 }
示例#10
0
 public void CreateNewGame(string username, string password, string gamename, ChessDotNet.Player side, string gamePassword)
 {
     base.Channel.CreateNewGame(username, password, gamename, side, gamePassword);
 }
示例#11
0
 public void UpdateSourceIfEnPassant(ChessDotNet.MoveType moveType, string newPosition, ChessDotNet.Player side)
 {
     if (moveType == (ChessDotNet.MoveType.Move | ChessDotNet.MoveType.EnPassant | ChessDotNet.MoveType.Capture))
     {
         char c             = newPosition.ElementAt(0);
         int  verticalIndex = (int)Char.GetNumericValue(newPosition.ElementAt(1));
         if (side == ChessDotNet.Player.White)
         {
             verticalIndex--;
         }
         else
         {
             verticalIndex++;
         }
         newPosition = c.ToString() + verticalIndex.ToString();
         Cells.Single(item => item.Position == newPosition).Source = null;
     }
 }
示例#12
0
 public void UpdateSourceIfPromotion(ChessDotNet.MoveType moveType, string newPosition, ChessDotNet.Player side)
 {
     if (moveType == (ChessDotNet.MoveType.Capture | ChessDotNet.MoveType.Promotion | ChessDotNet.MoveType.Move))
     {
         string sourceForPromotion = side == ChessDotNet.Player.White ? "/Resources/Pieces/wQ.png" : "/Resources/Pieces/bQ.png";
         Cells.Single(item => item.Position == newPosition).Source = sourceForPromotion;
     }
     else
     {
         Cells.Single(item => item.Position == newPosition).Source = SelectedCell.Source;
     }
 }
示例#13
0
 private void InitializeCells(ChessDotNet.Player side)
 {
     InitializeColor();
     InitializeIndexes(side);
     InitializeNames();
 }