/// <summary> /// Oyun içinde kullanılacak taşları oluşturur. /// </summary> public static void GenerateGameStones() { for (int i = 0; i < 106; i++) { GameStones.Add(new Stone { Number = i % 53 }); } }
/// <summary> /// Gösterge ve Okey belirler. /// </summary> public static void GenerateOkey() { //Gösterge belirleniyor int indicatorNumber = rnd.Next(0, 53); //sahte okey geldiyse kontrolü indicatorNumber = indicatorNumber != 52 ? indicatorNumber : indicatorNumber - 1; GameStones.FindAll(x => x.Number == indicatorNumber).ToList <Stone>().ForEach(item => item.IsIndicator = true); //Göstergelerden biri kullanıldı olarak belirleniyor ki oyunculara 2 kere gösterge dağıtılmasın. GameStones.FirstOrDefault(c => c.IsIndicator).IsDistributed = true; //Okey ayarlanıyor GameStones.FindAll(x => x.Number == (indicatorNumber + 1 % 13 == 0 ? indicatorNumber - 12 : indicatorNumber + 1)). ToList <Stone>().ForEach(item => item.IsOkey = true); }
/// <summary> /// Taşları kullanıcılara dağıtır. /// </summary> public static void DistributeStones() { PlayerList.Add(new Player { Id = 1, UserName = "******" }); PlayerList.Add(new Player { Id = 2, UserName = "******" }); PlayerList.Add(new Player { Id = 3, UserName = "******" }); PlayerList.Add(new Player { Id = 4, UserName = "******" }); //15 Taşlı kullanıcı belirleniyor. int fifteenStonePlayer = rnd.Next(0, 4); for (int i = 0; i < 106; i++) { if (GameStones[i].IsDistributed) { continue; } //ilk önce 15 taş verilmesi gereken kullanıcıya taşlarını veriyoruz. if (PlayerList[fifteenStonePlayer].PlayerStones.Count < 15) { switch (fifteenStonePlayer) { case 0: PlayerList[0].PlayerStones.Add(GameStones[i]); GameStones[i].IsDistributed = true; break; case 1: PlayerList[1].PlayerStones.Add(GameStones[i]); GameStones[i].IsDistributed = true; break; case 2: PlayerList[2].PlayerStones.Add(GameStones[i]); GameStones[i].IsDistributed = true; break; case 3: PlayerList[3].PlayerStones.Add(GameStones[i]); GameStones[i].IsDistributed = true; break; } } else { if (PlayerList.FirstOrDefault(x => x.PlayerStones.Count < 14) != null && PlayerList.FirstOrDefault(x => x.PlayerStones.Count < 14).PlayerStones.Count < 14) { if (PlayerList.FirstOrDefault(x => x.PlayerStones.Count > 0 && x.PlayerStones.Count < 14) != null) { switch (PlayerList.FirstOrDefault(x => x.PlayerStones.Count > 0 && x.PlayerStones.Count < 14).Id) { case 1: PlayerList[0].PlayerStones.Add(GameStones[i]); GameStones[i].IsDistributed = true; break; case 2: PlayerList[1].PlayerStones.Add(GameStones[i]); GameStones[i].IsDistributed = true; break; case 3: PlayerList[2].PlayerStones.Add(GameStones[i]); GameStones[i].IsDistributed = true; break; case 4: PlayerList[3].PlayerStones.Add(GameStones[i]); GameStones[i].IsDistributed = true; break; } } else { switch (PlayerList.FirstOrDefault(x => x.PlayerStones.Count == 0).Id) { case 1: PlayerList[0].PlayerStones.Add(GameStones.FirstOrDefault(x => x.Number == i)); GameStones.FirstOrDefault(x => x.Number == i).IsDistributed = true; break; case 2: PlayerList[1].PlayerStones.Add(GameStones.FirstOrDefault(x => x.Number == i)); GameStones.FirstOrDefault(x => x.Number == i).IsDistributed = true; break; case 3: PlayerList[2].PlayerStones.Add(GameStones.FirstOrDefault(x => x.Number == i)); GameStones.FirstOrDefault(x => x.Number == i).IsDistributed = true; break; case 4: PlayerList[3].PlayerStones.Add(GameStones.FirstOrDefault(x => x.Number == i)); GameStones.FirstOrDefault(x => x.Number == i).IsDistributed = true; break; } } } } } }
/// <summary> /// Taşları karıştırır /// </summary> public static void MixStones() { GameStones = GameStones.OrderBy(item => rnd.Next()).ToList <Stone>(); }
private static int CalculateHandPoint(List <Stone> userStones) { int okey = GameStones.FirstOrDefault(x => x.IsOkey).Number; int point = 0; int jokerCount = userStones.Where(s => s.Number.Equals(okey)).Count(); point += jokerCount * 3; userStones.Where(w => w.Number.Equals(okey)).ToList().ForEach(s => s.Number = 999); userStones.Where(w => w.Number.Equals(52)).ToList().ForEach(s => s.Number = okey); userStones.Sort(new SortStonesByNumber()); var groupsYellow = userStones.Where(x => ((int)(x.Number / 13)) == 0).GroupConsecutive(); var groupsBlue = userStones.Where(x => ((int)(x.Number / 13)) == 1).GroupConsecutive(); var groupsBlack = userStones.Where(x => ((int)(x.Number / 13)) == 2).GroupConsecutive(); var groupsRed = userStones.Where(x => ((int)(x.Number / 13)) == 3).GroupConsecutive(); for (int i = 0; i < groupsYellow.Count(); i++) { int plusPoint = GetPoint(groupsYellow.ToList()[i].Count()); if (groupsYellow.ToList()[i].Count() > 2) { foreach (var item in groupsYellow.ToList()[i]) { userStones.Where(x => x.Number == item).First().Used = true; } } point += plusPoint; } for (int i = 0; i < groupsBlue.Count(); i++) { int plusPoint = GetPoint(groupsBlue.ToList()[i].Count()); if (groupsBlue.ToList()[i].Count() > 2) { foreach (var item in groupsBlue.ToList()[i]) { userStones.Where(x => x.Number == item).First().Used = true; } } point += plusPoint; } for (int i = 0; i < groupsBlack.Count(); i++) { int plusPoint = GetPoint(groupsBlack.ToList()[i].Count()); if (groupsBlack.ToList()[i].Count() > 2) { foreach (var item in groupsBlack.ToList()[i]) { userStones.Where(x => x.Number == item).First().Used = true; } } point += plusPoint; } for (int i = 0; i < groupsRed.Count(); i++) { int plusPoint = GetPoint(groupsRed.ToList()[i].Count()); if (groupsRed.ToList()[i].Count() > 2) { foreach (var item in groupsRed.ToList()[i]) { userStones.Where(x => x.Number == item).First().Used = true; } } point += plusPoint; } for (int i = 0; i < userStones.Count; i++) { if (!userStones[i].Used) { var lst = userStones.Where(x => !x.Used && (x.Number == userStones[i].Number + 13 || x.Number == userStones[i].Number + 26 || x.Number == userStones[i].Number + 39) ); int count = lst.Count() + 1; if (count == 2) { point += 1; } else if (count == 3) { point += 3; } else if (count == 4) { point += 4; } if (count > 2) { foreach (var item in lst) { userStones.Where(x => x.Number == item.Number).First().Used = true; } userStones.Where(x => x.Number == userStones[i].Number).First().Used = true; } } } int twinPoint = 0; for (int i = 0; i < userStones.Count; i++) { if (userStones[i].Number != 999 && userStones.Where(x => x.Number == userStones[i].Number).Count() == 2) { twinPoint += 2; } } twinPoint += (jokerCount * 2); for (int i = 0; i < userStones.Count; i++) { if (userStones[i].Number < 13) { Console.WriteLine(userStones[i].Number % 13 + 1 + "\tSARI"); } else if (userStones[i].Number < 26) { Console.WriteLine(userStones[i].Number % 13 + 1 + "\tMAVİ"); } else if (userStones[i].Number < 39) { Console.WriteLine(userStones[i].Number % 13 + 1 + "\tSİYAH"); } else if (userStones[i].Number < 52) { Console.WriteLine(userStones[i].Number % 13 + 1 + "\tKIRMIZI"); } } Console.WriteLine(jokerCount + "\tAdet Okey"); Console.WriteLine(Math.Max(point, twinPoint) + "\tPuan"); Console.WriteLine("=================================================="); return(Math.Max(point, twinPoint)); }