int IComparable.CompareTo(object obj)
        {
            BoardGame input = obj as BoardGame;

            if (obj == null)
            {
                throw new ArgumentException();
            }
            else
            {
                return(this.Name.CompareTo(input.Name));
            }
        }
Пример #2
0
        public bool AddGame(BoardGame newGame)
        {
            foreach (BoardGame thisGame in gameList)
            {
                if (thisGame.gameTitle == newGame.gameTitle)
                {
                    return(false);
                }
            }
            gameList.Add(newGame);

            return(true);
        }
Пример #3
0
        public int CompareTo(object obj)
        {
            BoardGame p = obj as BoardGame;

            if (this.gameValue == p.gameValue)
            {
                return(0);
            }
            else if (this.gameValue < p.gameValue)
            {
                return(1);
            }
            else
            {
                return(-1); // this.Length > p.Length
            }
        }
Пример #4
0
        private void dataGames_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            frmBoardGame dialog = new BoardGameChooser.frmBoardGame();
            BoardGame    temp   = selectedGame;

            dialog.Value = temp;
            settings.BoardGames.Remove(temp);
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                settings.BoardGames.Add(dialog.Value);
                RefreshGames();
            }
            else
            {
                settings.BoardGames.Add(temp);
            }
        }
Пример #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            DataTable gameTable = MakeGameTable();

            Globals.columnList.Clear();

            using (var reader = new StreamReader(@"C:\Users\brian\Documents\GitHub\BoardGameChooser\Geekway2018.csv"))
            {
                // Loop through the rows in the csv table
                int gameCount = 0;
                while (!reader.EndOfStream)
                {
                    // Parse the current row of the csv table
                    var line   = reader.ReadLine();
                    var values = line.Split(',');


                    DataRow newRow = gameTable.NewRow();
                    for (int i = 0; i < values.Length; i++)
                    {
                        if (gameCount == 0)
                        {
                            Globals.columnList.Add(values[i]);
                        }
                        else
                        {
                            if (values[i] != "")
                            {
                                newRow[Globals.columnList[i]] = values[i];
                            }
                        }
                    }

                    if (gameCount != 0)
                    {
                        gameTable.Rows.Add(newRow);

                        // Add this game to the GameList
                        BoardGame newGame = new BoardGame();
                        newGame.gameTitle = newRow["Title"] as string;

                        try
                        {
                            newGame.minPlayers = Int32.Parse(newRow["Min"].ToString());
                        }
                        catch
                        {
                            newGame.minPlayers = 0;
                        }

                        try
                        {
                            newGame.maxPlayers = Int32.Parse(newRow["Max"].ToString());
                        }
                        catch
                        {
                            newGame.maxPlayers = 0;
                        }

                        Globals.globalGameList.AddGame(newGame);
                    }

                    gameCount++;
                }
            }

            dataGridView1.DataSource = gameTable;

            dataGridView1.AutoResizeColumns();

            // Fill player listbox
            foreach (GamePlayer player in Globals.globalPlayerList.playerList)
            {
                PlayersListbox.Items.Add(player.playerName);
            }
        }
Пример #6
0
        private void chooseGame_Click(object sender, EventArgs e)
        {
            // Clear the gameValues for all the games
            foreach (BoardGame currentGame in Globals.globalGameList.gameList)
            {
                currentGame.gameValue = 0.0;
            }

            // Create a list of the active players
            List <string> activePlayerList = new List <string>();

            foreach (var playerEntry in PlayersListbox.SelectedItems)
            {
                activePlayerList.Add(playerEntry.ToString());
            }


            // Get the score for each game based on user ratings
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                string    currentTitle = row.Cells["Title"].Value as string;
                BoardGame currentGame  = Globals.globalGameList.GetGame(currentTitle);
                if (currentGame == null)
                {
                    continue;
                }

                // Only look at games that support this number of players
                if (activePlayerList.Count > currentGame.maxPlayers || activePlayerList.Count < currentGame.minPlayers)
                {
                    continue;
                }


                foreach (string currentPlayerName in activePlayerList)
                {
                    string playerRating = row.Cells[currentPlayerName].Value as string;

                    if (playerRating == "Woo")
                    {
                        currentGame.gameValue += 1.25;
                    }
                    else if (playerRating == "Yes")
                    {
                        currentGame.gameValue += 1.0;
                    }
                    else if (playerRating == "Eh")
                    {
                        currentGame.gameValue += 0.5;
                    }
                }

                //foreach (DataGridViewCell cell in row.Cells)
                //{
                //    //do operations with cell
                //}
            }

            Globals.globalGameList.gameList.Sort();

            BestListbox.Items.Clear();
            foreach (BoardGame currentGame in Globals.globalGameList.gameList)
            {
                if (currentGame.gameValue > 0.0)
                {
                    string displayText = currentGame.gameTitle + ": " + currentGame.gameValue;
                    BestListbox.Items.Add(displayText);
                }
            }
        }
Пример #7
0
 public int CompareTo(BoardGame other)
 {
     return(gameValue.CompareTo(other.gameValue));
 }
Пример #8
0
        public static BoardGame GetGameInfo(string id)
        {
            string xmlResponse = "";

            while (xmlResponse.Length == 0)
            {
                try
                {
                    System.Threading.Thread.Sleep(timeout);
                    byte[] response = client.GetByteArrayAsync("thing?id=" + id).Result;
                    xmlResponse = Encoding.UTF8.GetString(response);
                }
                catch (Exception exc)
                {
                    if (!exc.ToString().Contains("429"))
                    {
                        throw exc;
                    }
                    else
                    {
                        timeout += 100;
                    }
                }
            }
            XDocument doc = XDocument.Parse(xmlResponse);

            string name = doc.Element("items")
                          .Element("item")
                          .Descendants("name")
                          .Where(node => node.Attribute("type").Value == "primary")
                          .First()
                          .Attribute("value").Value;
            int minPlayers = int.Parse(doc.Element("items")
                                       .Element("item")
                                       .Descendants("minplayers")
                                       .First()
                                       .Attribute("value").Value);
            int maxPlayers = int.Parse(doc.Element("items")
                                       .Element("item")
                                       .Descendants("maxplayers")
                                       .First()
                                       .Attribute("value").Value);
            int minPlayTime = int.Parse(doc.Element("items")
                                        .Element("item")
                                        .Descendants("minplaytime")
                                        .First()
                                        .Attribute("value").Value);
            int maxPlayTime = int.Parse(doc.Element("items")
                                        .Element("item")
                                        .Descendants("maxplaytime")
                                        .First()
                                        .Attribute("value").Value);
            int minAge = int.Parse(doc.Element("items")
                                   .Element("item")
                                   .Descendants("minage")
                                   .First()
                                   .Attribute("value").Value);
            List <string> categories = doc.Element("items")
                                       .Element("item")
                                       .Descendants("link")
                                       .Where(node => node.Attribute("type").Value == "boardgamecategory")
                                       .Select(node => node.Attribute("value").Value)
                                       .ToList();
            List <string> mechanics = doc.Element("items")
                                      .Element("item")
                                      .Descendants("link")
                                      .Where(node => node.Attribute("type").Value == "boardgamemechanic")
                                      .Select(node => node.Attribute("value").Value)
                                      .ToList();

            BoardGame retval = new BoardGame(name, minPlayers, maxPlayers, minPlayTime, maxPlayTime, minAge, new List <string>(), categories, mechanics);

            return(retval);

            /*
             * foreach (dynamic gametype in stuff.item.links.boardgamesubdomain)
             * {
             *  retval.Types.Add(Enum.Parse(typeof(BoardGame.GameType), CleanString(gametype.name.ToString().Replace("Games", "").Replace("games", ""))));
             * }
             */
        }