private void UpdateGameRoom(int gameId)
        {
            string username = labelSessionUser.Text;
            List <ClsScoreList> scoreList = ClsExtractData.GetGameRoomScoreList(gameId);

            if (scoreList.Any())
            {
                listViewScoreList.Items.Clear();
                foreach (ClsScoreList scoreEntry in scoreList)
                {
                    ListViewItem listViewItem = new ListViewItem(scoreEntry.Username);
                    listViewItem.SubItems.Add(scoreEntry.HighScore.ToString());
                    listViewScoreList.Items.Add(listViewItem);
                    if ("enable" == scoreEntry.UserTurn && username == scoreEntry.Username)
                    {
                        buttonRollDice.Enabled = true;
                    }

                    if ("enable" == scoreEntry.UserTurn)
                    {
                        labelUserTurnUpdate.Text = scoreEntry.Username;
                    }
                }
            }
        }
示例#2
0
        private void ResetPassword()
        {
            if (string.IsNullOrEmpty(textBoxPassword.Text))
            {
                MessageBox.Show(ClsConstants.FILL_DATA_MESSAGE, ClsConstants.DIALOG_ERROR, MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else
            {
                string dbMessage = ClsExtractData.ResetPassword(labelUsername.Text, textBoxPassword.Text);
                switch (dbMessage)
                {
                case "Password reset successfully.":
                    if (DialogResult.OK == MessageBox.Show(dbMessage, ClsConstants.DIALOG_INFORMATION,
                                                           MessageBoxButtons.OK, MessageBoxIcon.Information))
                    {
                        textBoxPassword.Clear();
                    }
                    Close();
                    break;

                default:
                    MessageBox.Show(dbMessage, ClsConstants.DIALOG_ERROR,
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
            }
        }
示例#3
0
        private void CheckUserNameExists(string inputUsername)
        {
            if (string.IsNullOrWhiteSpace(inputUsername))
            {
                labelUsernameError.Text = ClsConstants.INPUT_VALID_USERNAME_MESSAGE;
            }
            else
            {
                labelUsernameError.Text = string.Empty;
                String dbMesssage = ClsExtractData.CheckUserNameExistance(inputUsername);
                switch (dbMesssage)
                {
                case "user exists":
                    LoadPasswordInput();
                    break;

                case "register":
                    LoadRegistrationPage();
                    break;

                case "contact admin to unlock":
                    MessageBox.Show(ClsConstants.CONTACT_ADMIN, ClsConstants.DIALOG_ERROR,
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                default:
                    labelUsernameError.Text = dbMesssage;
                    break;
                }
            }
        }
示例#4
0
        private void CheckLogin()
        {
            labelLoginError.Text = string.Empty;
            String dbMessage = ClsExtractData.CheckUserAuthentication(textBoxUserName.Text, textBoxPassword.Text);

            switch (dbMessage)
            {
            case "admin login success":
                LoadGameDashboard("admin");
                break;

            case "user login success":
                LoadGameDashboard(string.Empty);
                break;

            case "contact admin to unlock":
                MessageBox.Show(ClsConstants.CONTACT_ADMIN, ClsConstants.DIALOG_ERROR,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case "locked":
                MessageBox.Show(ClsConstants.CONTACT_ADMIN, ClsConstants.DIALOG_ERROR,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case "login again":
                labelLoginError.Text = ClsConstants.AUTHENTICATION_FAILS_ERROR;
                break;

            default:
                labelLoginError.Text = dbMessage;
                break;
            }
        }
        private void JoinGame()
        {
            int gameId = Convert.ToInt32(listViewGameList.SelectedItems[0].SubItems[1].Text);
            DataRowCollection dataRows = ClsExtractData.JoinGame(gameId, labelUsername.Text);

            if (dataRows == null || dataRows.Count == 0)
            {
                MessageBox.Show(ClsConstants.SOMETHING_WRONG_MESSAGE, ClsConstants.DIALOG_INFORMATION,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if (dataRows[0].Table.Columns.Contains("message"))
                {
                    MessageBox.Show(dataRows[0]["message"].ToString(), ClsConstants.DIALOG_INFORMATION,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    this.Hide();
                    string tokenColor = dataRows[0][1].ToString();
                    string userTurn   = dataRows[0][2].ToString();
                    _GameRoom.ShowDialog(gameId, tokenColor, userTurn, labelUsername.Text);
                    this.Show();
                }
            }
        }
        private void UnlockUser()
        {
            string dbMessage = ClsExtractData.UnlockUser(listViewPlayerList.SelectedItems[0].Text);

            MessageBox.Show(dbMessage, ClsConstants.DIALOG_INFORMATION, MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
            LoadPlayerList();
        }
        private void TerminateGame()
        {
            int    gameId    = Convert.ToInt32(listViewGameList.SelectedItems[0].SubItems[1].Text);
            string dbMessage = ClsExtractData.TerminateGame(gameId);

            MessageBox.Show(dbMessage, ClsConstants.DIALOG_INFORMATION, MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
            UpdateGameList();
        }
 private void DeleteUser()
 {
     if (DialogResult.Yes == MessageBox.Show(ClsConstants.DELETE_USER_CONFIRM_MESSAGE, ClsConstants.DIALOG_WARNING,
                                             MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
     {
         string dbMessage = ClsExtractData.DeleteUser(listViewPlayerList.SelectedItems[0].Text);
         MessageBox.Show(dbMessage, ClsConstants.DIALOG_INFORMATION, MessageBoxButtons.OK,
                         MessageBoxIcon.Information);
     }
     LoadPlayerList();
 }
        private void UpdateScoreList()
        {
            listViewScoreList.Items.Clear();
            List <ClsScoreList> scoreList = ClsExtractData.GetOnlinePlayerList();

            if (scoreList != null && scoreList.Any())
            {
                foreach (ClsScoreList scoreEntry in scoreList)
                {
                    ListViewItem listViewItem = new ListViewItem(scoreEntry.Username);
                    listViewItem.SubItems.Add(scoreEntry.HighScore.ToString());
                    listViewScoreList.Items.Add(listViewItem);
                }
            }
        }
        private void LoadPlayerList()
        {
            listViewPlayerList.Items.Clear();
            List <ClsScoreList> scoreList = ClsExtractData.GetPalyerListForAdmin();

            if (scoreList != null && scoreList.Any())
            {
                foreach (ClsScoreList scoreEntry in scoreList)
                {
                    ListViewItem listViewItem = new ListViewItem(scoreEntry.Username);
                    listViewItem.SubItems.Add(scoreEntry.HighScore.ToString());
                    listViewItem.SubItems.Add(scoreEntry.AccountStatus.ToString());
                    listViewPlayerList.Items.Add(listViewItem);
                }
            }
        }
        private void UpdateGameList()
        {
            listViewGameList.Items.Clear();
            List <ClsGameList> gameList = ClsExtractData.GetGameList();

            if (gameList != null && gameList.Any())
            {
                foreach (ClsGameList gameEntry in gameList)
                {
                    ListViewItem listViewItem = new ListViewItem(gameEntry.GameHost);
                    listViewItem.SubItems.Add(gameEntry.GameId.ToString());
                    listViewItem.SubItems.Add(gameEntry.GameStatus.ToString());
                    listViewGameList.Items.Add(listViewItem);
                }
            }
        }
        private void RollDiceAndShowResult()
        {
            int    gameId     = Convert.ToInt32(labelGameId.Text);
            int    diceSide   = 0;
            string rollResult = ClsExtractData.GenerateDiceRollOutput(gameId, labelSessionUser.Text);

            if (rollResult.All(char.IsDigit))
            {
                diceSide = Convert.ToInt32(rollResult);
                UpdateDiceView(diceSide);
                GetAndIntiateMovement(gameId, diceSide, labelSessionUser.Text);
            }
            else
            {
                MessageBox.Show(rollResult, ClsConstants.DIALOG_INFORMATION, MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
        }
        private void ExitGame()
        {
            int    gameId    = Convert.ToInt32(labelGameId.Text);
            string dbMessage = ClsExtractData.ExitGame(gameId, labelSessionUser.Text);

            switch (dbMessage)
            {
            case "Successfully quit":
                t.Stop();
                Close();
                break;

            default:
                MessageBox.Show(dbMessage, ClsConstants.DIALOG_INFORMATION,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;
            }
        }
        private void StartGame()
        {
            List <String> dbResult = ClsExtractData.StartGame(labelUsername.Text);

            if (dbResult.Count == 1)
            {
                MessageBox.Show(dbResult[0], ClsConstants.DIALOG_INFORMATION,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                this.Hide();
                int    gameId     = Convert.ToInt32(dbResult[0]);
                string tokenColor = dbResult[1];
                string userTurn   = dbResult[2];
                _GameRoom.ShowDialog(gameId, tokenColor, userTurn, labelUsername.Text);
                this.Show();
            }
        }
        private void CheckAndUpdateGameRoom()
        {
            int    gameId    = Convert.ToInt32(labelGameId.Text);
            string dbMessage = ClsExtractData.GetGameStatus(gameId);

            switch (dbMessage)
            {
            case "continue":
                UpdateGameRoom(gameId);
                UpdateGameBoard(gameId);
                break;

            default:
                t.Stop();
                isTimerStopped = true;
                MessageBox.Show(dbMessage, ClsConstants.DIALOG_INFORMATION,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                Close();
                break;
            }
        }
        private void GetAndIntiateMovement(int gameId, int diceSide, string username)
        {
            DataRowCollection dataRows = ClsExtractData.UpdateUserPosition(gameId, diceSide, username);

            if (dataRows == null || (dataRows.Count == 0))
            {
                MessageBox.Show(ClsConstants.SOMETHING_WRONG_MESSAGE, ClsConstants.DIALOG_INFORMATION,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if (dataRows[0].Table.Columns.Contains("message"))
                {
                    string message = dataRows[0]["message"].ToString();
                    switch (message)
                    {
                    case "WINNER":
                        AnnounceWinnerAndEnd();
                        break;

                    default:
                        MessageBox.Show(message, ClsConstants.DIALOG_INFORMATION, MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                        break;
                    }
                }
                else
                {
                    int    position     = Convert.ToInt32(dataRows[0][1].ToString());
                    string nextUserTurn = dataRows[0][3].ToString();
                    MakeMovement(position);
                    labelUserTurnUpdate.Text = nextUserTurn;
                    buttonRollDice.Enabled   = false;
                    UpdateGameRoom(gameId);
                }
            }
        }
        private void GetAndRegisterUser()
        {
            String dbMessage = ClsExtractData.RegisterNewUser(textBoxUsername.Text,
                                                              textBoxPassword.Text, textBoxEmail.Text);

            switch (dbMessage)
            {
            case "username already taken":
                MessageBox.Show(ClsConstants.USERNAME_EXISTS_ERROR, ClsConstants.DIALOG_ERROR,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case "email should be unique":
                MessageBox.Show(ClsConstants.EMAIL_EXISTS_ERROR, ClsConstants.DIALOG_ERROR,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case "invalid email":
                MessageBox.Show(ClsConstants.INVALID_EMAIL_ERROR, ClsConstants.DIALOG_ERROR,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case "user added succefully":
                if (DialogResult.OK == MessageBox.Show(ClsConstants.RESGISTRATION_SUCCESSFULL, ClsConstants.DIALOG_INFORMATION,
                                                       MessageBoxButtons.OK, MessageBoxIcon.Information))
                {
                    Close();
                }
                break;

            default:
                MessageBox.Show(ClsConstants.DIALOG_ERROR, dbMessage, MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                break;
            }
        }
 private void ButtonLogout_Click(object sender, EventArgs e)
 {
     ClsExtractData.LogOutSession(labelUsername.Text);
     Close();
 }
        private void UpdateGameBoard(int gameId)
        {
            List <ClsGameBoard> boardList = ClsExtractData.GetGameBoardData(gameId);
            int  playerRedPosition        = 0;
            int  playerGreenPosition      = 0;
            int  playerBluePosition       = 0;
            int  playerBlackPosition      = 0;
            bool redPlayer   = false;
            bool greenPlayer = false;
            bool bluePlayer  = false;
            bool blackPlayer = false;

            if (boardList.Any())
            {
                foreach (ClsGameBoard boardEntry in boardList)
                {
                    switch (boardEntry.PlayerColor)
                    {
                    case "red":
                        playerRedPosition = boardEntry.PlayerPosition;
                        redPlayer         = true;
                        break;

                    case "green":
                        playerGreenPosition = boardEntry.PlayerPosition;
                        greenPlayer         = true;
                        break;

                    case "blue":
                        playerBluePosition = boardEntry.PlayerPosition;
                        bluePlayer         = true;
                        break;

                    case "black":
                        playerBlackPosition = boardEntry.PlayerPosition;
                        blackPlayer         = false;
                        break;
                    }
                }
                if (redPlayer)
                {
                    pictureBoxRed.Visible  = true;
                    pictureBoxRed.Location = new Point(ClsPlayerRedPosition.redPosList[playerRedPosition][0],
                                                       ClsPlayerRedPosition.redPosList[playerRedPosition][1]);
                }
                else
                {
                    pictureBoxRed.Visible = false;
                }

                if (greenPlayer)
                {
                    pictureBoxGreen.Visible  = true;
                    pictureBoxGreen.Location = new Point(ClsPlayerGreenPosition.greenPosList[playerGreenPosition][0],
                                                         ClsPlayerGreenPosition.greenPosList[playerGreenPosition][1]);
                }
                else
                {
                    pictureBoxGreen.Visible = false;
                }

                if (bluePlayer)
                {
                    pictureBoxBlue.Visible  = true;
                    pictureBoxBlue.Location = new Point(ClsPlayerBluePosition.bluePosList[playerBluePosition][0],
                                                        ClsPlayerBluePosition.bluePosList[playerBluePosition][1]);
                }
                else
                {
                    pictureBoxBlue.Visible = false;
                }

                if (blackPlayer)
                {
                    pictureBoxBlack.Visible  = true;
                    pictureBoxBlack.Location = new Point(ClsPlayerBlackPosition.blackPosList[playerBlackPosition][0],
                                                         ClsPlayerBlackPosition.blackPosList[playerBlackPosition][1]);
                }
                else
                {
                    pictureBoxBlack.Visible = false;
                }
            }
        }
 private void FrmPlayerDashboard_FormClosing(object sender, FormClosingEventArgs e)
 {
     ClsExtractData.LogOutSession(labelUsername.Text);
 }