예제 #1
0
        public bool SetUpChessPieces(RealTimeChessDbContext context, int nNumPlayers, int nBoardWidth, int nBoardHeight)
        {
            bool bSuccess = true;

            if (2 == nNumPlayers)
            {
                switch (PlayerTypeId)
                {
                case 1:
                    SetPawnRow(context, 2, nBoardWidth);
                    SetRoyalRow(context, 1, nBoardWidth);
                    break;

                case 2:
                    SetPawnRow(context, 7, nBoardWidth);
                    SetRoyalRow(context, 8, nBoardWidth);
                    break;

                case 3:
                    SetPawnColumn(context, 2, nBoardHeight);
                    SetRoyalColumn(context, 1, nBoardHeight);
                    break;

                case 4:
                    SetPawnColumn(context, 7, nBoardHeight);
                    SetRoyalColumn(context, 8, nBoardHeight);
                    break;
                }
            }
            return(bSuccess);
        }
예제 #2
0
        public void SetPawnColumn(RealTimeChessDbContext context, int nFileNumber, int nBoardHeight)
        {
            ChessPieceType typePawn    = context.ChessPieceType.SingleOrDefault(t => t.ChessPieceTypeName == "Pawn");
            int            nPawnTypeId = typePawn.ChessPieceTypeId;

            for (int i = 1; i < 9; i++)
            {
                ChessPiece pawn = new ChessPiece(this.MatchPlayerId, nPawnTypeId, i, nFileNumber);
                context.ChessPiece.Add(pawn);
            }
            context.SaveChanges();
        }
예제 #3
0
        public void NotifyOpponents(RealTimeChessDbContext dbContext)
        {
            ChessPiece  piece  = dbContext.ChessPiece.Single(chessPiece => chessPiece.ChessPieceId == ChessPieceId);
            MatchPlayer player = dbContext.MatchPlayers.SingleOrDefault(matchPlayer => matchPlayer.MatchPlayerId == piece.MatchPlayerId);
            //ChessMatch match = dbContext.Matches.SingleOrDefault(chessMatch => chessMatch.ChessMatchId == player.ChessMatchId);
            ChessMatch match = dbContext.Matches.Include(chessMatch => chessMatch.MatchPlayers).Single <ChessMatch>(chessMatch => chessMatch.ChessMatchId == player.ChessMatchId);

            foreach (MatchPlayer opponent in match.MatchPlayers)
            {
                if (opponent.MatchPlayerId != piece.MatchPlayerId)
                {
                    opponent.PostOpponentMove(this);
                }
            }
        }
예제 #4
0
        public void SetRoyalColumn(RealTimeChessDbContext context, int nFileNum, int nBoardWidth)
        {
            int nTypeIdKing    = (context.ChessPieceType.SingleOrDefault(t => t.ChessPieceTypeName == "King")).ChessPieceTypeId;
            int nTypeIdQueen   = (context.ChessPieceType.SingleOrDefault(t => t.ChessPieceTypeName == "Queen")).ChessPieceTypeId;
            int nTypeIdBishop  = (context.ChessPieceType.SingleOrDefault(t => t.ChessPieceTypeName == "Bishop")).ChessPieceTypeId;
            int nKTypeIdKnight = (context.ChessPieceType.SingleOrDefault(t => t.ChessPieceTypeName == "Knight")).ChessPieceTypeId;
            int nTypeIdRook    = (context.ChessPieceType.SingleOrDefault(t => t.ChessPieceTypeName == "Rook")).ChessPieceTypeId;

            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nTypeIdRook, 8, nFileNum));       // ChessPiece RookLeft
            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nKTypeIdKnight, 7, nFileNum));    // ChessPiece KnightLeft
            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nTypeIdBishop, 6, nFileNum));     // ChessPiece BishopLeft
            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nTypeIdKing, 5, nFileNum));       // ChessPiece King
            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nTypeIdQueen, 4, nFileNum));      // ChessPiece Queen
            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nTypeIdBishop, 3, nFileNum));     // ChessPiece BishopRight
            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nKTypeIdKnight, 2, nFileNum));    // ChessPiece KnightRight
            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nTypeIdRook, 1, nFileNum));       // ChessPiece RookRight
            context.SaveChanges();
        }
예제 #5
0
        public void SetRoyalRow(RealTimeChessDbContext context, int nRankNumber, int nBoardWidth)
        {
            int nTypeIdKing    = context.ChessPieceType.SingleOrDefault(t => t.ChessPieceTypeName == "King").ChessPieceTypeId;
            int nTypeIdQueen   = context.ChessPieceType.SingleOrDefault(t => t.ChessPieceTypeName == "Queen").ChessPieceTypeId;
            int nTypeIdBishop  = context.ChessPieceType.SingleOrDefault(t => t.ChessPieceTypeName == "Bishop").ChessPieceTypeId;
            int nKTypeIdKnight = context.ChessPieceType.SingleOrDefault(t => t.ChessPieceTypeName == "Knight").ChessPieceTypeId;
            int nTypeIdRook    = context.ChessPieceType.SingleOrDefault(t => t.ChessPieceTypeName == "Rook").ChessPieceTypeId;

            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nTypeIdRook, nRankNumber, 8));
            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nKTypeIdKnight, nRankNumber, 7));
            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nTypeIdBishop, nRankNumber, 6));
            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nTypeIdKing, nRankNumber, 5));
            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nTypeIdQueen, nRankNumber, 4));
            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nTypeIdBishop, nRankNumber, 3));
            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nKTypeIdKnight, nRankNumber, 2));
            context.ChessPiece.Add(new ChessPiece(MatchPlayerId, nTypeIdRook, nRankNumber, 1));
            context.SaveChanges();
        }
예제 #6
0
        public bool SetUpChessBoard(RealTimeChessDbContext context, int nBoardWidth, int nBoardHeight)
        {
            bool bSuccess = true;

            if (false == IsSetup)
            {
                foreach (MatchPlayer matchPlayer in this.MatchPlayers)
                {
                    IsSetup = matchPlayer.SetUpChessPieces(context, this.NumPlayers, nBoardWidth, nBoardHeight);
                    //context.Entry(matchPlayer).Collection(p => p.Pieces).Load();
                }
                IsSetup = true;
                context.SaveChanges();
            }
            else
            {
                bSuccess = false;
            }
            return(bSuccess);
        }
예제 #7
0
        public void Begin(RealTimeChessDbContext dbContext)
        {
            ChessPiece piece = dbContext.ChessPiece.SingleOrDefault(chessPiece => chessPiece.ChessPieceId == ChessPieceId);

            PositionBeginX = piece.LocationX;
            PositionBeginY = piece.LocationY;

            // calculate legs of right triangle
            int nDistanceX = (int)PositionEndX - (int)PositionBeginX;
            int nDistanceY = (int)PositionEndY - (int)PositionBeginY;

            // Calculate Hypotenuse of right triangle
            Distance = Math.Sqrt((nDistanceX * nDistanceX) + (nDistanceY * nDistanceY));

            TravelTime         = TimeSpan.FromSeconds((double)Distance / (double)Velocity);
            GameClockBeginMove = DateTime.Now;
            GameClockEndMove   = GameClockBeginMove + TravelTime;

            piece.LocationX = PositionEndX;
            piece.LocationY = PositionEndY;

            NotifyOpponents(dbContext);
        }