Ejemplo n.º 1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text;

            if (username.Length <= MIN_NAME_LENGTH || username.Length > MAX_NAME_LENGTH)
            {
                lblPrompt.Text   = "Your username must be 1-4 characters in length";
                txtUsername.Text = "";
            }
            else
            {
                //Make username all caps
                username.ToUpper();
                //But for now just create a player
                StatsPlayer currentPlayer = new StatsPlayer(username);
                //We want this currentPlayer to be Global and persist across windows
                //Do we need to make a constructor for the frmGame to accept a StatsPlayer
                //as an option?

                // hiding frmStatsPrompt
                Hide();

                //Finally open the game
                frmGame game = new frmGame(username); //create an instance
                game.ShowDialog();                    //show the form

                // close username input form
                Close();
            }
        }
Ejemplo n.º 2
0
        public static StatsPlayer SearchForExistingUser(string username)
        {
            const int NUM_OF_COLUMNS = 4; //we know the length of each line

            string[]    playersRaw  = Properties.Resources.DurakStats.Split('\n');
            int         lineCounter = 0;
            StatsPlayer tempPlayer  = new StatsPlayer();

            while (lineCounter < playersRaw.Length)
            {
                int      columnCounter = 0;
                string[] columns       = playersRaw[lineCounter].Split(',');

                while (columnCounter < NUM_OF_COLUMNS)
                {
                    if (username == columns[columnCounter].ToString()) //if the username is found
                    {
                        tempPlayer.setPlayerName(columnCounter.ToString());
                        tempPlayer.setPlayerWins(int.Parse(columns[columnCounter + 1]));
                        tempPlayer.setPlayerTies(int.Parse(columns[columnCounter + 2]));
                        tempPlayer.setPlayerLosses(int.Parse(columns[columnCounter + 3]));
                        break;
                    }
                }
            }
            if (tempPlayer == new StatsPlayer())
            {
                tempPlayer = new StatsPlayer(username);
            }

            return(tempPlayer);
        }
Ejemplo n.º 3
0
        public static StatsPlayer[] CreatePlayerArray()
        {
            const int NUM_OF_COLUMNS = 4;//we know the number of columns in this case

            //Creates an array of strings that equal an individual line from LogsAndStats.dat
            string[] playersRaw = Properties.Resources.DurakStats.Split('\n');
            // before transferring them to the dictionary
            int arraySize   = playersRaw.Length;
            int lineCounter = 0;

            // StatsPlayer[] allPlayers = new StatsPlayer[arraySize];
            StatsPlayer[] tempPlayer = new StatsPlayer[arraySize];
            while (lineCounter < arraySize)
            {
                int      columnCounter = 0;
                string[] columns       = playersRaw[lineCounter].Split(','); //splits the line variable into an array using
                                                                             // a comma as a delimeter
                                                                             // Dictionary<string, StatsPlayer> tempPlayers = new Dictionary<string, StatsPlayer>(); //Initialize the dictionary
                StatsPlayer player = new StatsPlayer();

                while (columnCounter < NUM_OF_COLUMNS) //this while loop is used for assigning data
                {                                      //to a StatsPlayer that will be added to a
                                                       //dictionary of StatsPlayer's
                    tempPlayer[lineCounter] = player;
                    //allPlayers[lineCounter] = tempPlayer;
                    if (columnCounter == 0) //first piece of data (name)
                    {
                        tempPlayer[lineCounter].setPlayerName(columns[columnCounter]);
                        columnCounter++;
                    }

                    if (columnCounter == 1) //second piece of data (wins)
                    {
                        tempPlayer[lineCounter].setPlayerWins(int.Parse(columns[columnCounter]));
                        columnCounter++;
                    }

                    if (columnCounter == 2) //third piece of data (ties)
                    {
                        tempPlayer[lineCounter].setPlayerTies(int.Parse(columns[columnCounter]));
                        columnCounter++;
                    }

                    if (columnCounter == 3) //fourth piece of data (losses)
                    {
                        tempPlayer[lineCounter].setPlayerLosses(int.Parse(columns[columnCounter]));
                        columnCounter++;
                    }
                }
                //allPlayers[lineCounter] = tempPlayer[lineCounter];
                // allPlayers.
                lineCounter++;
            }
            return(tempPlayer);
        }
Ejemplo n.º 4
0
        //Public Methods
        /// <summary>
        /// This method will return a dictionary of StatsPlayers that can be used later for output
        /// </summary>
        /// <returns>Dictionary<string, StatsPlayer></returns>
        public static Dictionary <string, StatsPlayer> CreatePlayerDictionary()
        // public static List<StatsPlayer> CreatePlayerList()
        {
            string tempString = "";

            const int NUM_OF_COLUMNS = 4;//we know the number of columns in this case

            //Creates an array of strings that equal an individual line from LogsAndStats.dat
            string[] playersRaw = Properties.Resources.DurakStats.Split('\n');
            // before transferring them to the dictionary

            int lineCounter = 0;

            Dictionary <string, StatsPlayer> allPlayers = new Dictionary <string, StatsPlayer>(); //Initialize the dictionary
            //List<StatsPlayer> temp = new List<StatsPlayer>();
            int numberOfLines = playersRaw.Length;

            //while ((line = file.ReadLine()) != null) //assigns the current line to our variable, and does so until it is null
            while (lineCounter < numberOfLines)
            {
                int      columnCounter = 0;
                string[] columns       = playersRaw[lineCounter].Split(','); //splits the line variable into an array using
                                                                             // a comma as a delimeter
                // Dictionary<string, StatsPlayer> tempPlayers = new Dictionary<string, StatsPlayer>(); //Initialize the dictionary

                StatsPlayer tempPlayer = new StatsPlayer();
                while (columnCounter < NUM_OF_COLUMNS) //this while loop is used for assigning data
                {                                      //to a StatsPlayer that will be added to a
                                                       //dictionary of StatsPlayer's
                    if (columnCounter == 0)            //first piece of data (name)
                    {
                        tempPlayer.setPlayerName(columns[columnCounter]);
                        columnCounter++;
                    }

                    if (columnCounter == 1) //second piece of data (wins)
                    {
                        tempPlayer.setPlayerWins(int.Parse(columns[columnCounter]));
                        columnCounter++;
                    }

                    if (columnCounter == 2) //third piece of data (ties)
                    {
                        tempPlayer.setPlayerTies(int.Parse(columns[columnCounter]));
                        columnCounter++;
                    }

                    if (columnCounter == 3) //fourth piece of data (losses)
                    {
                        tempPlayer.setPlayerLosses(int.Parse(columns[columnCounter]));
                        columnCounter++;
                    }
                    //temp.Add(tempPlayer);
                    //tempString += tempPlayer.ToString();
                }
                allPlayers.Add(tempPlayer.getPlayerName(), tempPlayer);
                // allPlayers.Add(temp[lineCounter].getPlayerName(), temp[lineCounter]);

                //tempPlayer = null;
                // Console.WriteLine(allPlayers.ElementAt(lineCounter).ToString());

                //temp.Add(tempPlayer);

                lineCounter++;
            }
            // return temp;
            MessageBox.Show(tempString);
            return(allPlayers); //return the dictionary
        }