public Cards GetCard() { Cards c= new Cards(); int temp; if(_card.Count!=0) { temp = rand.Next(_card.Count); c = _card[temp]; _card.RemoveAt(temp); _ncard--; } return c; }
public Deck() { for (int i = 1; i <= 13; i++) { Cards d=new Cards("Spades",i); _card.Add(d); } for (int i = 1; i <= 13; i++) { Cards d = new Cards("Hearts", i); _card.Add(d); } for (int i = 1; i <= 13; i++) { Cards d = new Cards("Diamonds", i); _card.Add(d); } for (int i = 1; i <= 13; i++) { Cards d = new Cards("Clubs", i); _card.Add(d); } }
public void AddCard(Cards c) { _card.Add(c); _ncard++; }
public void ComparedCard(Cards c1, Cards c2) { Cards c11, c22; Console.WriteLine("Player1 card: " + c1); Console.WriteLine("Player2 card: " + c2); int count = 1; while (c1.Rank == c2.Rank) { Console.WriteLine("Cards have same rank : " + c1.Rank); if (c1.Rank >= (_game.GetNcard() / 2)) { count += (_game.GetNcard() / 2); _end = true; } else { count += c1.Rank; _end = false; } if (_game.GetNcard() >= 2) { c11 = _game.GetCard(); c22 = _game.GetCard(); Console.Write("press to continue: "); Console.ReadKey(); Console.Write("\n"); Console.WriteLine("Player1 card: " + c11.Rank); Console.WriteLine("Player2 card: " + c22.Rank); if (c11.Rank == c22.Rank) { Console.WriteLine("Cards have same rank : " + c11.Rank); Console.WriteLine("Add cards back and shuffle...."); _game.AddCard(c11); _game.AddCard(c22); _game.AddCard(c1); _game.AddCard(c2); Console.WriteLine("Each player has card " + (_game.GetNcard()/2) + " in your deck."); _end = false; c1 = _game.GetCard(); c2 = _game.GetCard(); if (_game.GetNcard() == 0) { _end = true; break; } Console.WriteLine("Player1 card: " + c1.Rank); Console.WriteLine("Player2 card: " + c2.Rank); count = 1; } else { c1 = c11; c2 = c22; break; } } else { _end = true; break; } } if (c1.Rank < c2.Rank) { Console.WriteLine("" + _player1.Name + " win " + _player2.Name + " in this round"); _player1.Score += count * 2; } else { Console.WriteLine("" + _player2.Name + " win " + _player1.Name + " in this round"); _player2.Score += count * 2; } Console.WriteLine("Player1 Score: " + _player1.Score); Console.WriteLine("Player2 Score: " + _player2.Score); for (int k = 1; k < count - 1; k++) { c1 = _game.GetCard(); c2 = _game.GetCard(); } Console.WriteLine("Each player has card " + (_game.GetNcard()/2) + " in your deck."); }