public static Item GetHighestLevelItem(this PlayerForAnotherGame player) { List <Item> playersItems = player.Items; int maxval = int.MinValue; int theIndex = 0; for (int i = 0; i < playersItems.Count; i++) { if (maxval < playersItems[i].Level) { maxval = playersItems[i].Level; theIndex = i; } } return(player.Items[theIndex]); }
static void CreatePlayersForAnotherGame(List <PlayerForAnotherGame> players, List <Guid> Ids) { for (int i = 0; i < 10; i++) { PlayerForAnotherGame player = new PlayerForAnotherGame(); //player.Id = Guid.Parse("11223344-5566-7788-99AA-BBCCDDEEFF00"); player.Id = Guid.NewGuid(); players.Add(player); Ids.Add(player.Id); Console.WriteLine(player.Id); } //Check for duplicates if (Ids.Count != Ids.Distinct().Count()) { throw new Exception(); } }
static void CreatePlayers(List <IPlayer> players, List <Guid> Ids, bool playerType) { Random random = new Random(); if (playerType) { for (int i = 0; i < 10; i++) { Player player = new Player(); //player.Id = Guid.Parse("11223344-5566-7788-99AA-BBCCDDEEFF00"); player.Id = Guid.NewGuid(); players.Add(player); Ids.Add(player.Id); player.Score = random.Next(1, 10000); Console.WriteLine(player.Id); } } else { for (int i = 0; i < 10; i++) { PlayerForAnotherGame player = new PlayerForAnotherGame(); //player.Id = Guid.Parse("11223344-5566-7788-99AA-BBCCDDEEFF00"); player.Id = Guid.NewGuid(); players.Add(player); Ids.Add(player.Id); player.Score = random.Next(1, 10000); Console.WriteLine(player.Id); } } //Check for duplicates if (Ids.Count != Ids.Distinct().Count()) { throw new Exception(); } }
static void Main(string[] args) { int player_num = 100; Dictionary <Guid, Player> players = new Dictionary <Guid, Player>(); var rand = new Random(); for (int i = 0; i < player_num; i++) { Guid guid = Guid.NewGuid(); if (!players.ContainsKey(guid)) { Player player = new Player(); player.Id = guid; player.Items = new List <Item>(); for (int j = 0; j < 10; j++) { Item item = new Item(); item.Id = Guid.NewGuid(); //Console.WriteLine(item.Id); item.Level = rand.Next(21); player.Items.Add(item); } players.Add(guid, player); //TEST - Teht2 //Item found_item = player.GetHighestLevelItem(); //TEST - Teht3 /* * Item[] lista = GetItemsWithLinq(player); * for (int a = 0; a < lista.Length; a++) * { * Console.WriteLine(lista[a].Id); * } */ //Test - Teht4 //Console.WriteLine(FirstItem(player).Level); //Console.WriteLine(FirstItemWithLinq(player).Level); //Test - Teht5 //ProcessEachItem(player, PrintItem); //Test - Teht6 /* * ProcessEachItem(player, * item => * { * Console.WriteLine(item.Id); * Console.WriteLine(item.Level); * }); */ } else { i--; } } //Teht 7 player_num = 100; List <IPlayer> list_players = new List <IPlayer>(); for (int i = 0; i < player_num; i++) { IPlayer player = new Player(); player.Score = rand.Next(1000); list_players.Add(player); } var list_seleceted_players = new IPlayer[10]; Console.WriteLine("GAME 1"); List <IPlayer> list_PlayerForAnotherGame = new List <IPlayer>(); for (int i = 0; i < player_num; i++) { IPlayer player = new PlayerForAnotherGame(); player.Score = rand.Next(1000) + 2000; list_PlayerForAnotherGame.Add(player); } Game <IPlayer> next_game_1 = new Game <IPlayer>(list_players); list_seleceted_players = next_game_1.GetTop10Players(); for (int i = 0; i < list_seleceted_players.Count(); i++) { Console.WriteLine(list_seleceted_players[i].Score); } Console.WriteLine("\nGAME 2"); Game <IPlayer> next_game_2 = new Game <IPlayer>(list_PlayerForAnotherGame); list_seleceted_players = next_game_2.GetTop10Players(); for (int i = 0; i < list_seleceted_players.Count(); i++) { Console.WriteLine(list_seleceted_players[i].Score); } }
static void Main(string[] args) { Player[] players = new Player[1000000]; PlayerForAnotherGame[] playersFromAnotherGame = new PlayerForAnotherGame[1000000]; InstantiateId(ref players); for (int i = 0; i < playersFromAnotherGame.Length; i++) { playersFromAnotherGame[i] = new PlayerForAnotherGame(); Random rnd = new Random(); playersFromAnotherGame[i].Score = rnd.Next(1, 1000000); } //Tests for for tehtava2 onward players[0].Items = new List <Item>(); players[0].Items.Add(new Item() { Id = Guid.NewGuid(), Level = 1 }); players[0].Items.Add(new Item() { Id = Guid.NewGuid(), Level = 2 }); players[0].Items.Add(new Item() { Id = Guid.NewGuid(), Level = 3 }); players[0].Items.Add(new Item() { Id = Guid.NewGuid(), Level = 4 }); players[0].Items.Add(new Item() { Id = Guid.NewGuid(), Level = 5 }); players[0].Items.Add(new Item() { Id = Guid.NewGuid(), Level = 6 }); players[0].Items.Add(new Item() { Id = Guid.NewGuid(), Level = 7 }); players[0].Items.Add(new Item() { Id = Guid.NewGuid(), Level = 8 }); players[0].Items.Add(new Item() { Id = Guid.NewGuid(), Level = 9 }); //Tehtava 5 Process test = PrintItem; ProcessEachItem(players[0], test); //Tehtava 6 ProcessEachItem(players[0], Item => Console.WriteLine("Id: " + Item.Id + " Level: " + Item.Level)); //Func<List<Item>, Player> testShit = (List<Item> temp) => {return null;}; //Tests for tehtava 3 and 4 /*Console.WriteLine(players[0].GetHighestLevelItem().Level); * Item[] loopList = GetItemsVariations.GetItems(players[0]); * Item[] linqList = GetItemsVariations.GetItemsWithLinq(players[0]); * foreach (Item item in loopList) * { * Console.WriteLine("Loop: " + item.Level); * } * foreach (Item item in linqList) * { * Console.WriteLine("Linq: " + item.Level); * } * Console.WriteLine("\nSharp: " + players[0].getFirstItem().Level); * Console.WriteLine("\nLinq: " + players[0].getFirstItemWithLinq().Level);*/ //Tehtava 7 Game <Player> game1 = new Game <Player>(players.ToList()); Player[] topPlayers = game1.GetTop10Players(); foreach (Player p in topPlayers) { Console.WriteLine(p.Score); } Console.WriteLine("\nAnother Game:"); Game <PlayerForAnotherGame> game2 = new Game <PlayerForAnotherGame>(playersFromAnotherGame.ToList()); PlayerForAnotherGame[] topPlayersFromAnotherGame = game2.GetTop10Players(); foreach (PlayerForAnotherGame p in topPlayersFromAnotherGame) { Console.WriteLine(p.Score); } }
public void guidfunction() { Console.WriteLine("MAIN MENU: 1(Duplicates) or 2(Highest lvl item) or 3(Get Items array) or 4(First item) or 5(Delegate) or 6(Lambda) or 7(TOP10)"); string value = Console.ReadLine(); var rand = new Random(); int x = 0; string[] lista; lista = new string[1000001]; Player[] players = new Player[1000000]; List <Player> world = new List <Player>(); while (x < 1000000) { players[x] = new Player(); players[x].Id = Guid.NewGuid(); lista[x] = players[x].Id.ToString(); players[x].Items = new List <Item>(); players[x].Score = rand.Next(1000000); world.Add(players[x]); x++; } var firstPlayer = players[0]; for (int i = 0; i < 10; i++) { var item = new Item(); item.Id = Guid.NewGuid(); item.Level = rand.Next(100); firstPlayer.Items.Add(item); } if (value == "1") { if (lista.Length != lista.Distinct().Count()) { Console.WriteLine("Duplicate found!"); } else { Console.WriteLine("No duplicates found!"); } } if (value == "2") { Console.WriteLine("Item with the highest level: {0}", firstPlayer.GetHighestValueItem().Level); } if (value == "3") { var tulos = GetItems(firstPlayer); var tulos2 = GetItemsWithLinq(firstPlayer); Console.WriteLine("Do you want to print items? 1(yes) tai 2(no): "); string vastaus = Console.ReadLine(); int c = 0; if (vastaus == "1") { foreach (var a in tulos) { c++; Console.WriteLine("Item number(no linq) " + c + " = " + a.Level); } Console.WriteLine(""); c = 0; foreach (var b in tulos2) { c++; Console.WriteLine("Item number(linq) " + c + ": Level = " + b.Level); } c = 0; } else { Console.WriteLine("No prints...."); } } if (value == "4") { int values = 0; while (values == 0) { try { Console.WriteLine("First item: {0}", FirstItem(firstPlayer)); } catch (System.NullReferenceException) { Console.WriteLine("Player has no items, he's completely useless now!!!!"); } try { Console.WriteLine("First item with linq: {0}", FirstItemWithLinq(firstPlayer)); } catch (System.NullReferenceException) { Console.WriteLine("Player has no items, he's completely useless now!!!!"); } values++; } string FirstItemWithLinq(Player player) { var satan = player.Items.First().Id.ToString(); return(satan); } string FirstItem(Player player) { return(player.Items[0].Id.ToString()); } } if (value == "5") { ProcessEachItem(firstPlayer, PrintItem); } if (value == "6") { ProcessEachItem(firstPlayer, item => Console.WriteLine("Item ID: " + item.Id + " || Item level: " + item.Level)); } if (value == "7") { var Game = new Game <Player>(world); Console.WriteLine("Game: " + string.Join(",", Game.GetTop10Players().Select(y => y.Score))); var anotherGame = new Game <PlayerForAnotherGame>(new PlayerForAnotherGame[10].Select(y => { y = new PlayerForAnotherGame(); y.Score = rand.Next(1000000); return(y); }).ToList()); Console.WriteLine("Another game: [{0}]", string.Join(",", anotherGame.GetTop10Players().Select(y => y.Score))); } }