예제 #1
0
        private void BtnUpdateClick(object sender, EventArgs e)
        {
            try
            {
                var result = MessageDialog.Instance.ShowMessage(this, "Q011");
                if (result == DialogResult.No)
                {
                    return;
                }

                if (_figure.Id == 0)
                {
                    figureRepository.Insert(_figure);
                    return;
                }

                figureRepository.Update(_figure);
            }
            catch (Exception ex)
            {
                // MessageDialog.Instance.ShowMessage(this, "ERR0002", ex.Message);
                ExceptionHandler.Instance.HandlerException(ex);
            }
            finally
            {
                this.Close();
            }
        }
예제 #2
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);
        }
예제 #3
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("Bạn có muốn cập nhật không?", "Cập nhật", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (dr == DialogResult.OK)
            {
                // Figure ent = FillToEntity();
                if (_figure.Id == 0)
                {
                    figureRepository.Insert(_figure);
                }
                else
                {
                    figureRepository.Update(_figure);
                }

                this.Close();
            }
        }