Ejemplo n.º 1
0
        private bool PerformMove(int userId, int gameId, int figureId, int toRow, int toCol)
        {
            GameRepository gameRepository = data.GetGameRepository();
            Game           game           = gameRepository.Get(gameId);

            if (game.UserIdInTurn != userId)
            {
                return(false);
            }

            FigureRepository figureRepository = data.GetFigureRepository();
            Figure           figure           = figureRepository.Get(figureId);

            if (!ValidateMove(figure, toRow, toCol))
            {
                return(false);
            }

            Figure hitFigure = figureRepository.GetFigureByGameAndPosition(gameId, toRow, toCol);

            if (hitFigure != null && hitFigure.IsWhite != figure.IsWhite)
            {
                figureRepository.Delete(hitFigure);
            }
            else if (hitFigure != null && hitFigure.IsWhite == figure.IsWhite)
            {
                return(false);
            }

            figure.PositionRow = toRow;
            figure.PositionCol = toCol;
            figureRepository.Update(figureId, figure);

            if (game.WhitePlayerId == game.UserIdInTurn)
            {
                game.UserIdInTurn = game.BlackPlayerId;
            }
            else
            {
                game.UserIdInTurn = game.WhitePlayerId;
            }

            gameRepository.Update(game.Id, game);

            UserRepository userRepository = data.GetUserRepository();
            User           userInTurn     = userRepository.Get(game.UserIdInTurn.GetValueOrDefault(0));

            var gameStartedMessageText = string.Format("{0} it is your move {1}", userInTurn.Nickname, game.Name);

            MessagesRepository messageRepository = data.GetMessagesRepository();

            messageRepository.CreateGameMessage(game.Id, game.UserIdInTurn.GetValueOrDefault(0), gameStartedMessageText, UserMessageTypeGameMove);

            return(true);
        }
Ejemplo n.º 2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if ((lblID.Text == "") || (lblID.Text == "0"))
            {
                MessageBox.Show("Bạn hãy chọn phác đồ thuốc cần xóa!");
                return;
            }
            DialogResult dr = MessageBox.Show("Bạn có muốn xóa phác đồ này không?", "Xóa phác đồ thuốc", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (dr == DialogResult.OK)
            {
                figureRepository.Delete(int.Parse(lblID.Text.Trim()));
            }
            FillToGrid();
        }