static void Main(string[] args) { Console.Write("Name A : "); Player player1 = new Player(Console.ReadLine()); Console.Write("Name B : "); Player player2 = new Player(Console.ReadLine()); List<Cards> allCard = new List<Cards>(); for(int i=1; i<=13; i++) { for(int j=1; j<=4;j++) { allCard.Add(new Cards(i, j)); } } allCard = ShuffleList(allCard); for(int i=0;i<52;i+=2) { player1.addCard(allCard[i]); player2.addCard(allCard[i + 1]); } do { if(player1.getNumdeck()==26) { Console.Write("\nStart Game, Each player has " + player1.getNumdeck() + " Cards.\n"); } else if(player1.getNumdeck()==1) { Console.Write("\nNext Round, Each player has " + player1.getNumdeck() + " Card.\n"); } else Console.Write("\nNext Round, Each player has " + player1.getNumdeck() + " Cards.\n"); Cards c1 = player1.Draw(); Console.Write(player1.getName() + " Draw : " + c1.nameRank() + c1.nameSuit()+"\n"); Cards c2 = player2.Draw(); Console.Write(player2.getName() + " Draw : " + c2.nameRank() + c2.nameSuit()+"\n"); if (c1.getRank()<c2.getRank()) { Console.WriteLine(player1.getName() + " Win! and get 2 cards." ); player1.addPile(c1); player1.addPile(c2); } else if (c1.getRank() > c2.getRank()) { Console.WriteLine(player2.getName() + " Win! and get 2 cards." ); player2.addPile(c1); player2.addPile(c2); } else { int i,round; List<Cards> tempc1 = new List<Cards>(); List<Cards> tempc2 = new List<Cards>(); tempc1.Add(c1); tempc2.Add(c2); if (player1.getNumdeck() < c1.getRank()) { round = player1.getNumdeck(); } else round = c1.getRank(); Console.WriteLine("Card is equal at rank " + Convert.ToString(c1.getRank()) + "\nEach player draw " + Convert.ToString(round) + " Cards"); for (i=0;i<round;i++) { tempc1.Add(player1.Draw()); tempc2.Add(player2.Draw()); } Console.WriteLine(player1.getName() + " draw last card is " + tempc1[i - 1].nameRank() + tempc1[i - 1].nameSuit()); Console.WriteLine(player2.getName() + " draw last card is " + tempc2[i - 1].nameRank() + tempc2[i - 1].nameSuit()); if (tempc1[i - 1].getRank() < tempc2[i - 1].getRank()) { Console.WriteLine(player1.getName() + " Win! and get " + Convert.ToString(round*2) + "+2 Cards"); for (i = 0; i < round + 1; i++) { player1.addPile(tempc1[i]); player1.addPile(tempc2[i]); } } else if (tempc1[i - 1].getRank() > tempc2[i - 1].getRank()) { Console.WriteLine(player2.getName() + " Win! and get " + Convert.ToString(round*2) + "+2 Cards"); for (i = 0; i < round + 1; i++) { player2.addPile(tempc1[i]); player2.addPile(tempc2[i]); } } else { Console.WriteLine("Equal again! Return all cards to your deck, then shuffle it."); for(i=0;i<round+1;i++) { player1.addCard(tempc1[i]); player2.addCard(tempc2[i]); } player1.deckShuff(); player2.deckShuff(); } } Console.WriteLine(player1.getName() + " has " + player1.getNumPile() + " Cards in Pile"); Console.WriteLine(player2.getName() + " has " + player2.getNumPile() + " Cards in Pile"); Console.ReadKey(); } while (player1.getNumdeck() > 0); if(player1.getNumPile() > player2.getNumPile()) { Console.WriteLine("\nThe Winner is " +player1.getName()); } else if (player1.getNumPile() < player2.getNumPile()) { Console.WriteLine("\nThe Winner is " + player2.getName()); } else { Console.WriteLine("\nPlease New Game Again."); } Console.ReadKey(); }
public void play() { CardDeck cd = new CardDeck(); string n1, n2; Console.Write("What's player1 name ? : "); n1 = Console.ReadLine(); Console.Write("What's player2 name ? : "); n2 = Console.ReadLine(); cd.shuffle(); p1 = new Player(n1); p2 = new Player(n2); while (cd.getSize() >= 2) { p1.collectCard(cd.deal()); p2.collectCard(cd.deal()); } p1.useWonPile(); p2.useWonPile(); Pile down = new Pile(); int t = 0; while (p1.numCards()>0) { if (!enoughCards(1)) break; Card c1 = p1.playCard(); Card c2 = p2.playCard(); Console.WriteLine("\nTurn " + t + ": "); t++; Console.Write(p1.getName() + ": " + c1 + " "); Console.Write(p2.getName() + ": " + c2 + " "); if (c1.compareTo(c2) > 0) { p1.KeepCard(); } else if (c1.compareTo(c2) < 0) { p2.KeepCard(); } else { temp1 = new Card[14]; temp2 = new Card[14]; temp1[0] = c1; temp2[0] = c2; down.clear(); down.addCard(c1); down.addCard(c2); bool done = false; do { int num = c1.getRank(); if (!enoughCards(num)) break; Console.Write("\nWar! Players put down "); Console.WriteLine(num + " card(s)."); for (int m = 1; m <= num; m++) { c1 = p1.playCard(); c2 = p2.playCard(); temp1[m] = c1; temp2[m] = c2; down.addCard(c1); down.addCard(c2); } Console.Write(p1.getName() + ": " + c1 + " "); Console.Write(p2.getName() + ": " + c2 + " "); if (c1.compareTo(c2) == 0) { for (int m = num; m >= 0 ; m--) { p1.collectCard(temp1[m]); p2.collectCard(temp2[m]); } done = true; } else if (c1.compareTo(c2) > 0) { for (int m = 1; m <= num+1; m++) { p1.KeepCard(); } done = true; } else if (c1.compareTo(c2) < 0) { for (int m = 1; m <= num+1; m++) { p2.KeepCard(); } done = true; } } while (!done); } Console.WriteLine("Card "+ p1.getName()+ " : "+p1.numCards() + " And Card " + p2.getName() + " : " + p2.numCards()); Console.WriteLine(p1.getName()+" Score : "+p1.getscore() + " And "+p2.getName() + " Score : "+ p2.getscore()); } }