예제 #1
0
        public List <Team> TeamProvide()
        {
            string playerRaw = System.IO.File.ReadAllText(filePlayerName);

            string[]      playerLines = playerRaw.Split('\n');
            List <Player> players     = new List <Player>();

            for (int i = 0; i < playerLines.Length; i++)
            {
                string[] tokens = playerLines[i].Split(';');
                players.Add(new Player()
                {
                    Name   = tokens[0],
                    Nation = tokens[1],
                    Score  = 0
                });
            }

            string data = System.IO.File.ReadAllText(fileCountriesName);

            string[]    lines    = data.Split('\n');
            List <Team> teamList = new List <Team>();

            for (int i = 0; i < lines.Length; i++)
            {
                string[]      tokens     = lines[i].Split(';');
                List <Player> listPlayer = players.Where(player => player.Nation.Trim().ToLower() == tokens[1].Trim().ToLower()).ToList();
                while (listPlayer.Count < MaximumPlayer)
                {
                    listPlayer.Add(new Player()
                    {
                        Name   = "PPlayer#" + (1000 + rand.Next(0, 9999)),
                        Nation = tokens[1],
                        Role   = tokens[2],
                        Score  = 0
                    });
                }
                while (listPlayer.Count > MaximumPlayer)
                {
                    listPlayer.RemoveAt(rand.Next(0, listPlayer.Count));
                }
                Team team = new Team()
                {
                    Code       = tokens[0],
                    Name       = tokens[1],
                    Area       = AreaUtil.GetAreaFromString(tokens[2].Trim()),
                    TotalScore = 0,
                    PlayerList = listPlayer
                };
                teamList.Add(team);
            }
            return(teamList);
        }
예제 #2
0
        public List <Team> TeamProvide()
        {
            List <Team>   result  = new List <Team>();
            List <Player> players = new List <Player>();

            command    = new SQLiteCommand("SELECT * FROM Players", connection);
            dataReader = command.ExecuteReader();
            while (dataReader.Read())
            {
                players.Add(new Player()
                {
                    Name   = dataReader.GetValue(0).ToString(),
                    Nation = dataReader.GetValue(1).ToString(),
                    Role   = dataReader.GetValue(2).ToString(),
                });
            }

            command    = new SQLiteCommand("SELECT * FROM Countries", connection);
            dataReader = command.ExecuteReader();
            while (dataReader.Read())
            {
                string[]      tokens     = new string[] { dataReader.GetValue(0).ToString(), dataReader.GetValue(1).ToString(), dataReader.GetValue(2).ToString() };
                List <Player> listPlayer = players.Where(player => player.Nation.Trim().ToLower() == tokens[1].Trim().ToLower()).ToList();
                while (listPlayer.Count < MaximumPlayer)
                {
                    listPlayer.Add(new Player()
                    {
                        Name   = "PPlayer#" + (1000 + rand.Next(0, 9999)),
                        Nation = tokens[1],
                        Score  = 0,
                        Role   = tokens[2]
                    });
                }
                while (listPlayer.Count > MaximumPlayer)
                {
                    listPlayer.RemoveAt(rand.Next(0, listPlayer.Count));
                }
                Team team = new Team()
                {
                    Code       = tokens[0],
                    Name       = tokens[1],
                    Area       = AreaUtil.GetAreaFromString(tokens[2].Trim()),
                    TotalScore = 0,
                    PlayerList = listPlayer
                };
                result.Add(team);
            }

            connection.Close();

            return(result);
        }
예제 #3
0
 public void GetAreaFromString()
 {
     Assert.AreEqual(AreaUtil.GetAreaFromString("Asia"), Area.Asia);
 }