Exemplo n.º 1
0
        public void PrepareGame(string blackPlayerName, string whitePlayerName, string gameName)
        {
            if (GameStatus == ChessGameStatus.ChessGameStatus_NonStarted ||
                GameStatus == ChessGameStatus.ChessGameStatus_Finihed
                )
            {
                ChessBoardClock PlayerWhiteClock = new ChessBoardClock();
                ChessBoardClock PlayerBlackClock = new ChessBoardClock();
                PlayerWhiteClock.InitClock(defaultTimeAvailablePerPlayer);
                PlayerBlackClock.InitClock(defaultTimeAvailablePerPlayer);

                PlayerBlackClock.OnClockStop  += PlayerClock_OnClockStop;
                PlayerBlackClock.OnTimeFinish += PlayerClock_OnTimeFinish;

                PlayerWhiteClock.OnClockStop  += PlayerClock_OnClockStop;
                PlayerWhiteClock.OnTimeFinish += PlayerClock_OnTimeFinish;

                PlayerWhite = new ChessPlayer(whitePlayerName, ChessColor.ChessColor_White, this, PlayerWhiteClock);
                PlayerBlack = new ChessPlayer(blackPlayerName, ChessColor.ChessColor_Black, this, PlayerBlackClock);

                PlayerWhite.OnMoveRequested += Player_OnMoveRequested;
                PlayerBlack.OnMoveRequested += Player_OnMoveRequested;

                InitializeBoard();

                GameName = gameName;
            }
            else
            {
                throw new ChessExceptionInvalidGameAction(ExceptionCode.AnotherGameInProgress, "Cannot prepare a new game, another game is in progress");
            }
        }
Exemplo n.º 2
0
        // public event EventHandler<OnResignGameEventArgs> OnResignGame;

        public ChessPlayer(string nickName, ChessColor color, ChessGame game, ChessBoardClock clock)
        {
            NickName          = nickName;
            pieceColor        = color;
            Moves             = new LinkedList <ChessMove>();
            MyPiecesInBoard   = new List <ChessPiece>();
            game.OnTurnStart += Game_OnTurnStart;
            game.Board.OnNewPieceInserted += Board_OnNewPieceInserted;
            game.Board.OnNewPieceCaptured += Board_OnNewPieceCaptured;
            Game         = game;
            Clock        = clock;
            Clock.Player = this;
            Id           = Guid.NewGuid();
        }