static void ToOtboi(Otboi otboi, Computer comp, params ICardeble[] unit) { for (int i = 0; i < unit.Count(); i++) { while (unit[i] != null && unit[i].Count() > 0) { otboi.SetCard(unit[i].GetCard()); } while (comp.Count() > 0) { otboi.SetCard(comp.GetCard()); } } }
static void Main(string[] args) { #region init bool splited = false; bool surrended = false; bool blackJack = false; bool doubleSplit = false; string tmp; int tmpI; string divTmp; int div; int num = 0; bool finish = false; bool firstCompCard = false; Deck deck= new Deck(); Player[] players = new Player[6]; players[0] = new Player(100); Computer computer = new Computer(); Otboi otboi = new Otboi(); //deck.TestPrint(); Console.WriteLine("Разделите колоду (от 13 до 18)"); //divTmp = Console.ReadLine(); //div = int.Parse(divTmp); div = 14; deck.Div = div; #endregion do { #region first firstCompCard = false; surrended = false; finish = false; splited = false; Console.WriteLine("Делайте ставку"); //tmp = Console.ReadLine(); //players[0].Bet = int.Parse(tmp); players[0].Bet = 10; players[0].Score -= players[0].Bet; if (!players[0].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[0].SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); if (!computer.SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); computer.SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); if (!players[0].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[0].SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); if (!computer.SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); computer.SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); #endregion #region insurance if (computer.Cards[1].GetScore() == 11 && (players[0].GetScore() != 21)) { Console.WriteLine("Страховка? (1 - да; 2 - нет)"); tmp = Console.ReadLine(); tmpI = int.Parse(tmp); if (tmpI == 1) { Player.score -= (players[0].Bet / 2); players[0].Bet += (players[0].Bet / 2); firstCompCard = true; if (computer.Cards[0].GetScore() == 10) { Print(firstCompCard, computer, players); finish = true; surrended = true; Console.WriteLine("Loose"); Thread.Sleep(1000); } else { players[0].Bet = (players[0].Bet * 2 / 3); Print(firstCompCard, computer, players); } } if (tmpI == 2) { firstCompCard = true; Print(firstCompCard, computer, players); if (computer.Cards[0].GetScore() == 10) { finish = true; surrended = true; Console.WriteLine("Loose"); Thread.Sleep(1000); //players[0] = null; } } } #endregion while (num < players.Count() && !finish && !surrended) { if (players[num] != null) { #region blackJack if (players[num].Count() == 2 && players[num].GetScore() == 21 && !splited) { if (computer.Cards[1].GetScore() == 11) { Console.WriteLine("Равные деньги? (1 - да; 2 - нет)"); tmp = Console.ReadLine(); tmpI = int.Parse(tmp); if (tmpI == 1) { players[0].Score += 2 * players[num].Bet; finish = true; Console.WriteLine("Win"); Thread.Sleep(3000); blackJack = true; break; } if (tmpI == 2) { firstCompCard = true; Print(firstCompCard, computer, players); if (computer.Cards[0].GetScore() == 10) { players[0].Score += players[0].Bet; finish = true; Console.WriteLine("Ничья"); Thread.Sleep(3000); blackJack = true; break; } else { blackJack = true; Console.WriteLine("Win"); Thread.Sleep(3000); Player.score += (players[0].Bet + players[0].Bet * 3 / 2); } } } else { Player.score += (players[0].Bet + players[0].Bet * 3 / 2); finish = true; blackJack = true; Console.WriteLine("Win"); Thread.Sleep(3000); break; } } #endregion #region split if (players[num].Count() == 2 && players[num].Cards[0].GetScore() == players[num].Cards[1].GetScore() && players[num].Cards[0].GetScore() != 11) { Console.WriteLine("Split (1 - yes, 2 - no)?"); tmp = Console.ReadLine(); tmpI = int.Parse(tmp); if (tmpI == 1) { if (players[1] == null) { players[1] = new Player(); players[1].Bet = players[0].Bet; Player.score -= players[0].Bet; players[1].SetCard(players[num].GetCard()); if (!players[1].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[1].SetCard(deck.GetCard()); } if (!players[num].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[num].SetCard(deck.GetCard()); } } else { if (players[2] == null) { players[2] = new Player(); players[2].Bet = players[0].Bet; Player.score -= players[0].Bet; players[2].SetCard(players[num].GetCard()); if (!players[2].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[2].SetCard(deck.GetCard()); } if (!players[num].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[num].SetCard(deck.GetCard()); } } else { players[3] = new Player(); players[3].Bet = players[0].Bet; Player.score -= players[0].Bet; players[3].SetCard(players[num].GetCard()); if (!players[3].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[3].SetCard(deck.GetCard()); } if (!players[num].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[num].SetCard(deck.GetCard()); } } } splited = true; } doubleSplit = true; Print(firstCompCard, computer, players); } else { doubleSplit = false; if (players[num].Count() == 2 && players[num].Cards[0].GetScore() == players[num].Cards[1].GetScore() && players[num].Cards[0].GetScore() == 11 && !splited) { Console.WriteLine("Split (1 - yes, 2 - no)?"); tmp = Console.ReadLine(); tmpI = int.Parse(tmp); if (tmpI == 1) { splited = true; players[num + 1] = new Player(); players[num + 1].Bet = players[num].Bet; players[num].Score -= players[num].Bet; players[num + 1].SetCard(players[num].GetCard()); if (!players[num].SetCard(deck.GetCard())) { ToDeck(deck, otboi); players[num].SetCard(deck.GetCard()); } if (!players[num + 1].SetCard(deck.GetCard())) { ToDeck(deck, otboi); players[num + 1].SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); finish = true; break; } } } #endregion if (!doubleSplit) { #region next Console.WriteLine("Введите 1 - ещё; 2 - дальше; 3 - сбросить; 4 - удвоение"); tmp = Console.ReadLine(); tmpI = int.Parse(tmp); switch (tmpI) { case 1: { do { if (!players[num].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[num].SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); Thread.Sleep(1000); if (players[num].Upped(otboi)) { if (num != 0) { players[num] = null; } tmpI = 2; num++; break; } Print(firstCompCard, computer, players); Console.WriteLine("Введите 1 - ещё; 2 - дальше;"); tmp = Console.ReadLine(); tmpI = int.Parse(tmp); } while (tmpI == 1); //if (tmpI == 2) { num++; } break; } case 2: { num++; break; } case 3: { while (players[num].Count() > 0) { otboi.SetCard(players[num].GetCard()); } Player.score += (players[num].Bet / 2); players[num].Bet = 0; if (num == 0) { finish = true; surrended = true; } num++; Print(firstCompCard, computer, players); break; } case 4: { Player.score -= players[num].Bet; players[num].Bet *= 2; if (!players[num].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[num].SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); Thread.Sleep(1000); if (players[num].Upped(otboi)) { /*if (num == 0) { surrended = true; }*/ num++; break; } Print(firstCompCard, computer, players); num++; break; } default: break; } } #endregion } else { num++; } } firstCompCard = true; Print(firstCompCard, computer, players); if (!surrended) { #region comp if (!blackJack) { firstCompCard = true; while (computer.GetScore() < 17) { if (!computer.SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); computer.SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); } num = 0; for (int i = 0; i < players.Count(); i++) { int compScore = computer.GetScore(); if (players[i] != null) { if (players[i].GetScore() > 21) { Console.WriteLine("Loose"); } if (players[i].GetScore() > compScore && players[i].GetScore() < 22) { Console.WriteLine("Win"); players[0].Score += (players[i].Bet * 2); } if (players[i].GetScore() < compScore) { if (compScore < 22 || players[i].GetScore() == 0) { Console.WriteLine("Loose"); } else { Console.WriteLine("Win"); players[0].Score += (players[i].Bet * 2); } } if (players[i].GetScore() == compScore) { Console.WriteLine("Ничья"); players[0].Score += players[i].Bet; } num++; } else { num++; } if (i != 0) { players[i] = null; } } } Thread.Sleep(2000); finish = true; } #endregion else { Console.WriteLine("Loose"); Thread.Sleep(1000); } if (players[0] == null) { players[0] = new Player(); } num = 0; ToOtboi(otboi, computer, players); for (int i = 1; i < players.Count(); i++) { players[i] = null; } Console.Clear(); Console.SetCursorPosition(0, 0); } while (true); }
static void Main(string[] args) { #region init bool splited = false; bool surrended = false; bool blackJack = false; bool doubleSplit = false; string tmp; int tmpI; string divTmp; int div; int num = 0; bool finish = false; bool firstCompCard = false; Deck deck = new Deck(); Player[] players = new Player[6]; players[0] = new Player(100); Computer computer = new Computer(); Otboi otboi = new Otboi(); //deck.TestPrint(); Console.WriteLine("Разделите колоду (от 13 до 18)"); //divTmp = Console.ReadLine(); //div = int.Parse(divTmp); div = 14; deck.Div = div; #endregion do { #region first firstCompCard = false; surrended = false; finish = false; splited = false; Console.WriteLine("Делайте ставку"); //tmp = Console.ReadLine(); //players[0].Bet = int.Parse(tmp); players[0].Bet = 10; players[0].Score -= players[0].Bet; if (!players[0].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[0].SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); if (!computer.SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); computer.SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); if (!players[0].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[0].SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); if (!computer.SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); computer.SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); #endregion #region insurance if (computer.Cards[1].GetScore() == 11 && (players[0].GetScore() != 21)) { Console.WriteLine("Страховка? (1 - да; 2 - нет)"); tmp = Console.ReadLine(); tmpI = int.Parse(tmp); if (tmpI == 1) { Player.score -= (players[0].Bet / 2); players[0].Bet += (players[0].Bet / 2); firstCompCard = true; if (computer.Cards[0].GetScore() == 10) { Print(firstCompCard, computer, players); finish = true; surrended = true; Console.WriteLine("Loose"); Thread.Sleep(1000); } else { players[0].Bet = (players[0].Bet * 2 / 3); Print(firstCompCard, computer, players); } } if (tmpI == 2) { firstCompCard = true; Print(firstCompCard, computer, players); if (computer.Cards[0].GetScore() == 10) { finish = true; surrended = true; Console.WriteLine("Loose"); Thread.Sleep(1000); //players[0] = null; } } } #endregion while (num < players.Count() && !finish && !surrended) { if (players[num] != null) { #region blackJack if (players[num].Count() == 2 && players[num].GetScore() == 21 && !splited) { if (computer.Cards[1].GetScore() == 11) { Console.WriteLine("Равные деньги? (1 - да; 2 - нет)"); tmp = Console.ReadLine(); tmpI = int.Parse(tmp); if (tmpI == 1) { players[0].Score += 2 * players[num].Bet; finish = true; Console.WriteLine("Win"); Thread.Sleep(3000); blackJack = true; break; } if (tmpI == 2) { firstCompCard = true; Print(firstCompCard, computer, players); if (computer.Cards[0].GetScore() == 10) { players[0].Score += players[0].Bet; finish = true; Console.WriteLine("Ничья"); Thread.Sleep(3000); blackJack = true; break; } else { blackJack = true; Console.WriteLine("Win"); Thread.Sleep(3000); Player.score += (players[0].Bet + players[0].Bet * 3 / 2); } } } else { Player.score += (players[0].Bet + players[0].Bet * 3 / 2); finish = true; blackJack = true; Console.WriteLine("Win"); Thread.Sleep(3000); break; } } #endregion #region split if (players[num].Count() == 2 && players[num].Cards[0].GetScore() == players[num].Cards[1].GetScore() && players[num].Cards[0].GetScore() != 11) { Console.WriteLine("Split (1 - yes, 2 - no)?"); tmp = Console.ReadLine(); tmpI = int.Parse(tmp); if (tmpI == 1) { if (players[1] == null) { players[1] = new Player(); players[1].Bet = players[0].Bet; Player.score -= players[0].Bet; players[1].SetCard(players[num].GetCard()); if (!players[1].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[1].SetCard(deck.GetCard()); } if (!players[num].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[num].SetCard(deck.GetCard()); } } else { if (players[2] == null) { players[2] = new Player(); players[2].Bet = players[0].Bet; Player.score -= players[0].Bet; players[2].SetCard(players[num].GetCard()); if (!players[2].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[2].SetCard(deck.GetCard()); } if (!players[num].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[num].SetCard(deck.GetCard()); } } else { players[3] = new Player(); players[3].Bet = players[0].Bet; Player.score -= players[0].Bet; players[3].SetCard(players[num].GetCard()); if (!players[3].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[3].SetCard(deck.GetCard()); } if (!players[num].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[num].SetCard(deck.GetCard()); } } } splited = true; } doubleSplit = true; Print(firstCompCard, computer, players); } else { doubleSplit = false; if (players[num].Count() == 2 && players[num].Cards[0].GetScore() == players[num].Cards[1].GetScore() && players[num].Cards[0].GetScore() == 11 && !splited) { Console.WriteLine("Split (1 - yes, 2 - no)?"); tmp = Console.ReadLine(); tmpI = int.Parse(tmp); if (tmpI == 1) { splited = true; players[num + 1] = new Player(); players[num + 1].Bet = players[num].Bet; players[num].Score -= players[num].Bet; players[num + 1].SetCard(players[num].GetCard()); if (!players[num].SetCard(deck.GetCard())) { ToDeck(deck, otboi); players[num].SetCard(deck.GetCard()); } if (!players[num + 1].SetCard(deck.GetCard())) { ToDeck(deck, otboi); players[num + 1].SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); finish = true; break; } } } #endregion if (!doubleSplit) { #region next Console.WriteLine("Введите 1 - ещё; 2 - дальше; 3 - сбросить; 4 - удвоение"); tmp = Console.ReadLine(); tmpI = int.Parse(tmp); switch (tmpI) { case 1: { do { if (!players[num].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[num].SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); Thread.Sleep(1000); if (players[num].Upped(otboi)) { if (num != 0) { players[num] = null; } tmpI = 2; num++; break; } Print(firstCompCard, computer, players); Console.WriteLine("Введите 1 - ещё; 2 - дальше;"); tmp = Console.ReadLine(); tmpI = int.Parse(tmp); } while (tmpI == 1); //if (tmpI == 2) { num++; } break; } case 2: { num++; break; } case 3: { while (players[num].Count() > 0) { otboi.SetCard(players[num].GetCard()); } Player.score += (players[num].Bet / 2); players[num].Bet = 0; if (num == 0) { finish = true; surrended = true; } num++; Print(firstCompCard, computer, players); break; } case 4: { Player.score -= players[num].Bet; players[num].Bet *= 2; if (!players[num].SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); players[num].SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); Thread.Sleep(1000); if (players[num].Upped(otboi)) /*if (num == 0) { surrended = true; }*/ num { ++; break; } Print(firstCompCard, computer, players); num++; break; } default: break; } } #endregion } else { num++; } } firstCompCard = true; Print(firstCompCard, computer, players); if (!surrended) { #region comp if (!blackJack) { firstCompCard = true; while (computer.GetScore() < 17) { if (!computer.SetCard(deck.GetCard())) { div = ToDeck(deck, otboi); deck.Shuffle(); computer.SetCard(deck.GetCard()); } Print(firstCompCard, computer, players); } num = 0; for (int i = 0; i < players.Count(); i++) { int compScore = computer.GetScore(); if (players[i] != null) { if (players[i].GetScore() > 21) { Console.WriteLine("Loose"); } if (players[i].GetScore() > compScore && players[i].GetScore() < 22) { Console.WriteLine("Win"); players[0].Score += (players[i].Bet * 2); } if (players[i].GetScore() < compScore) { if (compScore < 22 || players[i].GetScore() == 0) { Console.WriteLine("Loose"); } else { Console.WriteLine("Win"); players[0].Score += (players[i].Bet * 2); } } if (players[i].GetScore() == compScore) { Console.WriteLine("Ничья"); players[0].Score += players[i].Bet; } num++; } else { num++; } if (i != 0) { players[i] = null; } } } Thread.Sleep(2000); finish = true; } #endregion else { Console.WriteLine("Loose"); Thread.Sleep(1000); } if (players[0] == null) { players[0] = new Player(); } num = 0; ToOtboi(otboi, computer, players); for (int i = 1; i < players.Count(); i++) { players[i] = null; } Console.Clear(); Console.SetCursorPosition(0, 0); } while (true); }