Example #1
0
        static void Main(string[] args)
        {
            Player player1 = new Player(1);
            Player player2 = new Player(2);
            Control.SettingUp();
            Control.NewPlayers(player1, player2);
            Control.GivePlayerADeck(player1, player2);

            Console.WriteLine("");
            Console.WriteLine("START GAME");

            int result = 0;
            int turn = 1;
            do
            {
                Console.WriteLine("***Turn " + turn + "***");
                result = Control.CompareCardDeck(player1, player2);
                player1.ShowPlayerProperties();
                player2.ShowPlayerProperties();
                if (player1.PlayingDeck.Cards.Count == 0)
                {
                    Console.WriteLine("---[Both Players Have No Card]---");
                    break;
                }
                Console.WriteLine("");
                ++turn;

            } while (result != -1);
            Control.FinishedPlaying(player1, player2);
            Console.ReadKey();
        }
 public Game()
 {
     deck = new Deck();
     p1 = new Player();
     p2 = new Player();
     Console.WriteLine("Enter to play");
     deck.shuffle();
     deal();
     play();
 }
        static void Main(string[] args)
        {
            Player player1 = new Player(1);
                Player player2 = new Player(2);
                Control.SettingUp();
                Control.NewPlayers(player1, player2);
                Control.GivePlayerADeck(player1, player2);

                // Display all cards in both player decks
                Console.WriteLine("== [" + player1.Name + "] Card deck is containing these cards :");
                player1.PlayDeck.ViewCardsinDeck();
                Console.WriteLine("== [" + player2.Name + "] Card deck is containing these cards :");
                player2.PlayDeck.ViewCardsinDeck();

                Console.WriteLine("");
                Console.WriteLine("> STARTING GAME <");

                int result = 0;
                int turn = 1;
                do
                {
                    Console.WriteLine("___ {Turn " + turn + " } ___ ");
                    //Console.WriteLine("Comparing player 1 and player 2 card deck");
                    result = Control.CompareCardDeck(player1, player2);
                    player1.ShowPlayer();
                    player2.ShowPlayer();
                    if (player1.PlayDeck.Cards.Count == 0)
                    {
                        Console.WriteLine("[Summary] No more card left in the both players card deck");
                        break;
                    }
                    Console.WriteLine("");
                    ++turn;
                    //Console.ReadKey();
                } while (result != -1);
                Control.FinishedPlaying(player1, player2);
                Console.ReadKey();
        }
Example #4
0
        static void Main(string[] args)
        {
            Player player1 = new Player(1);
            Player player2 = new Player(2);
            Control.Setting();
            Control.NewPlayer(player1, player2);
            Control.PlayerAddDeck(player1, player2);
            Console.WriteLine("GAME START!!!");

            int gamestop = 0;
            int turn = 1;
            do
            {
                Console.WriteLine("Turn : " + turn + " ");
                gamestop = Control.comparePlayerCard(player1, player2);
                player1.ShowPlayerCard();
                player2.ShowPlayerCard();
                Console.WriteLine("");
                ++turn;
            } while (gamestop != -1);

            Control.FinishGame(player1, player2);
            Console.ReadKey();
        }
        public static int comparePlayerCard(Player player1, Player player2)
        {
            _tie = false;
            if (player1.DeckPlayer.card.Count == 0)
            {
                Console.WriteLine("No more card left form the both players.");
                return -1;
            }
            int lastCard = player1.DeckPlayer.card.Count - 1;
            int player1_last = player1.DeckPlayer.card[lastCard].Value;
            int player2_last = player2.DeckPlayer.card[lastCard].Value;
            Console.WriteLine("" + player1.Name + "has last card is " + player1.DeckPlayer.card[lastCard]);
            Console.WriteLine("" + player2.Name + "has last card is " + player2.DeckPlayer.card[lastCard]);

            if (player1.DeckPlayer.card.Count == 1 && player1.DeckPlayer.card[lastCard].Value == player2.DeckPlayer.card[lastCard].Value)
            {
                Console.WriteLine("The last card of the both players is same . (Tie)");
                return -1;
            }

            else if (player1_last == player2_last)
            {
                bool continueGame = true;
                for (int i = 0; i <= lastCard; i++)
                {
                    for (int j = 0; j <= lastCard; j++)
                    {
                        if (player1.DeckPlayer.card[i].Value > player2.DeckPlayer.card[j].Value)
                        {
                            continueGame = false;
                        }
                        else
                        {
                            continueGame = true;
                        }
                    }
                }

                if (!continueGame)
                {
                    Console.WriteLine("" + player1.Name + "card is containing pile : ");
                    player1.DeckPlayer.ViewCardinDeck();
                    Console.WriteLine("" + player2.Name + "card is containing pile : ");
                    player2.DeckPlayer.ViewCardinDeck();
                    return -1;
                }

                int numberFromLastCard = player1_last;
                if (numberFromLastCard > lastCard)
                {
                    //PlayerTie(player1, player2);
                    numberFromLastCard = lastCard;
                    // return 0;
                }

                Console.WriteLine("" + player1.Name + " has " + player1.DeckPlayer.card[numberFromLastCard]);
                Console.WriteLine("" + player2.Name + " has " + player2.DeckPlayer.card[numberFromLastCard]);
                int player1_last2 = player1.DeckPlayer.card[numberFromLastCard].Value;
                int player2_last2 = player2.DeckPlayer.card[numberFromLastCard].Value;
                if (player1_last2 < player2_last2)
                {
                    PlayerWin(player1, numberFromLastCard);
                    RemovePlayerCard(player1, player2, numberFromLastCard);
                    return 1;
                }
                else if (player1_last2 > player2_last2)
                {
                    PlayerWin(player2, numberFromLastCard);
                    RemovePlayerCard(player1, player2, numberFromLastCard);
                    return 2;
                }
                else
                {
                    PlayerTie(player1, player2);
                    return 0;
                }
            }
            else if (player1_last < player2_last) // Player 1 WIN
            {
                PlayerWin(player1);
                RemovePlayerCard(player1, player2, 1);
                return 1;
            }

            else if (player1_last > player2_last) // Player2 Win
            {
                PlayerWin(player2);
                RemovePlayerCard(player1, player2, 1);
                return 2;
            }
            return -1;
        }
        public static void FinishGame(Player player1 , Player player2)
        {
            Console.WriteLine("");
            string stringwinner = " The Winner is ";
            if (player1.Count > player2.Count)
            {
                stringwinner += player1.Name;
            }
            else if (player2.Count > player1.Count)
            {
                stringwinner += player2.Name;
            }
            else stringwinner += "no one";

            Console.WriteLine(stringwinner);
        }
        public static void PlayerWin(Player player1 , int numberOfCard = 1)
        {
            player1.Count += (numberOfCard) * 2;
            if (_tie) player1.Count += 2;

            Console.WriteLine("Wninner is " + player1.Name + " get " + (numberOfCard * 2) + " cards into his pile");
        }
 public static void RemovePlayerCard(Player player1 , Player player2 , int range)
 {
     int lastCard = player1.DeckPlayer.card.Count - 1;
     player1.DeckPlayer.card.RemoveRange(lastCard - range + 1, range);
     player2.DeckPlayer.card.RemoveRange(lastCard - range + 1, range);
 }
Example #9
0
 public static void TieTurn(Player pPlayer1, Player pPlayer2)
 {
     Console.WriteLine("[ReShuffle]");
     pPlayer1.PlayingDeck.Shuffle();
     {
         pPlayer2.PlayingDeck.Shuffle();
     }
     tie = true;
 }
 public static void GivePlayerADeck(Player pPlayer1, Player pPlayer2)
 {
     for (int i = 0; i < 26; i++)
     {
         pPlayer1.PlayDeck.Cards.Add(base_deck.Cards[i]);
     }
     for (int i = 0; i < 26; i++)
     {
         pPlayer2.PlayDeck.Cards.Add(base_deck.Cards[i + 26]);
     }
     Console.WriteLine("[Control] Two players card deck are each equal to the number of cards");
 }
Example #11
0
 public static void GivePlayerADeck(Player pPlayer1, Player pPlayer2)
 {
     for (int i = 0; i < 26; i++)
     {
         pPlayer1.PlayingDeck.Cards.Add(base_deck.Cards[i]);
         pPlayer2.PlayingDeck.Cards.Add(base_deck.Cards[i + 26]);
     }
 }
Example #12
0
 public static void PlayerWinTurn(Player pPlayer, int NumberofCards = 1)
 {
     pPlayer.Count += (NumberofCards) * 2;
     if (tie) pPlayer.Count += 2;
     Console.WriteLine("[Winner = " + pPlayer.Name + "] Gots " + (NumberofCards * 2) + " Cards");
 }
 public static void NewPlayers(Player pPlayer1, Player pPlayer2, string pPlayerName1 = "Anonymous", string pPlayerName2 = "Anonymous")
 {
     Console.WriteLine("Creating new two players...");
     Console.WriteLine(" ");
     Console.Write("[" + pPlayer1.Name + "] Enter name of player 1 : ");
     pPlayerName1 = Console.ReadLine();
     Console.Write("[" + pPlayer2.Name + "] Enter name of player 2 : ");
     pPlayerName2 = Console.ReadLine();
     pPlayer1.Name = pPlayerName1;
     pPlayer2.Name = pPlayerName2;
     Console.WriteLine("[" + pPlayer1.Name + "] is " + pPlayer1.Name);
     Console.WriteLine("[" + pPlayer2.Name + "] is " + pPlayer2.Name);
 }
 public static void PlayerWinTurn(Player pPlayer, int NumberofCards = 1)
 {
     pPlayer.Count += (NumberofCards) * 2;
     //Console.WriteLine("[WIN][Player " + pPlayer.Order + "] get 2 card into his/her pile");
     Console.WriteLine("[WIN][" + pPlayer.Name + "] get 2 card into his/her pile");
 }
 public static int CompareCardDeck(Player pPlayer1, Player pPlayer2)
 {
     if (pPlayer1.PlayDeck.Cards.Count == 0) // No longer be playing
     {
         Console.WriteLine("[Summary] No more card left in the both players card deck");
         return -1;
     }
     int LastCard = pPlayer1.PlayDeck.Cards.Count - 1;
     int pPlayer1_last = pPlayer1.PlayDeck.Cards[LastCard].Value;
     int pPlayer2_last = pPlayer2.PlayDeck.Cards[LastCard].Value;
     Console.WriteLine("[" + pPlayer1.Name + "] \thas " + pPlayer1.PlayDeck.Cards[LastCard]);
     Console.WriteLine("[" + pPlayer2.Name + "] \thas " + pPlayer2.PlayDeck.Cards[LastCard]);
     if (pPlayer1.PlayDeck.Cards.Count == 1 && pPlayer1.PlayDeck.Cards[LastCard].Value == pPlayer2.PlayDeck.Cards[LastCard].Value) // No longer be playing
     {
         Console.WriteLine("[Tie] The last card of both players is the same.");
         return -1;
     }
     if (pPlayer1_last == pPlayer2_last)
     {
         bool Continue_Game = true;
         for (int i = 0; i <= LastCard; i++)
         {
             for (int j = 0; j <= LastCard; j++)
             {
                 if (pPlayer1.PlayDeck.Cards[i].Value > pPlayer2.PlayDeck.Cards[j].Value)
                 {
                     Continue_Game = false;
                 }
                 else
                 {
                     Continue_Game = true;
                 }
             }
         }
         if (!Continue_Game)
         {
             Console.WriteLine("== [" + pPlayer1.Name + "] Card deck is containing these cards :");
             pPlayer1.PlayDeck.ViewCardsinDeck();
             Console.WriteLine("== [" + pPlayer2.Name + "] Card deck is containing these cards :");
             pPlayer2.PlayDeck.ViewCardsinDeck();
             return -1;
         }
         int NumberFromLastCard = pPlayer1_last;
         if (NumberFromLastCard > LastCard) // More value of the card than number of left cards
         {
             TieTurn(pPlayer1, pPlayer2);
             //Console.WriteLine("== [" + pPlayer1.Name + "] Card deck is containing these cards :");
             //pPlayer1.PlayDeck.ViewCardsinDeck();
             //Console.WriteLine("== [" + pPlayer2.Name + "] Card deck is containing these cards :");
             //pPlayer2.PlayDeck.ViewCardsinDeck();
             //Console.ReadKey();
             return 0;
         }
         Console.WriteLine("[" + pPlayer1.Name + "] has " + pPlayer1.PlayDeck.Cards[NumberFromLastCard]);
         Console.WriteLine("[" + pPlayer2.Name + "] has " + pPlayer2.PlayDeck.Cards[NumberFromLastCard]);
         int pPlayer1_fromlast = pPlayer1.PlayDeck.Cards[NumberFromLastCard].Value;
         int pPlayer2_fromlast = pPlayer2.PlayDeck.Cards[NumberFromLastCard].Value;
         if (pPlayer1_fromlast < pPlayer2_fromlast) // Player 1 WIN
         {
             PlayerWinTurn(pPlayer1, NumberFromLastCard);
             RemovePlayerCards(pPlayer1, pPlayer2, NumberFromLastCard);
             return 1;
         }
         else if (pPlayer1_fromlast > pPlayer2_fromlast) // Player 2 WIN
         {
             PlayerWinTurn(pPlayer2, NumberFromLastCard);
             RemovePlayerCards(pPlayer1, pPlayer2, NumberFromLastCard);
             return 2;
         }
         else // Tie
         {
             TieTurn(pPlayer1, pPlayer2);
             return 0;
         }
     }
     // Player 1 WIN
     else if (pPlayer1_last < pPlayer2_last)
     {
         PlayerWinTurn(pPlayer1);
         RemovePlayerCards(pPlayer1, pPlayer2, 1);
         return 1;
     }
     // Player 2 WIN
     else if (pPlayer1_last > pPlayer2_last)
     {
         PlayerWinTurn(pPlayer2);
         RemovePlayerCards(pPlayer1, pPlayer2, 1);
         return 2;
     }
     return -1;
 }
 public static void TieTurn(Player pPlayer1, Player pPlayer2)
 {
     Console.WriteLine("[Tie] Reshuffle the both players card deck");
     pPlayer1.PlayDeck.Shuffle();
     //if (pPlayer1.PlayDeck.Cards.Count != 2)
     {
         pPlayer2.PlayDeck.Shuffle();
     }
 }
 public static void RemovePlayerCards(Player pPlayer1, Player pPlayer2, int range)
 {
     int LastCard = pPlayer1.PlayDeck.Cards.Count - 1;
     pPlayer1.PlayDeck.Cards.RemoveRange(LastCard - range + 1, range);
     pPlayer2.PlayDeck.Cards.RemoveRange(LastCard - range + 1, range);
     //Console.WriteLine("[Remove] " + range + " card(s) of both players card deck");
 }
Example #18
0
 public static void FinishedPlaying(Player pPlayer1, Player pPlayer2)
 {
     Console.WriteLine("");
     string WinningMSG = "=== [Winner Is : ";
     if (pPlayer1.Count > pPlayer2.Count) WinningMSG += pPlayer1.Name;
     else if (pPlayer2.Count > pPlayer1.Count) WinningMSG += pPlayer2.Name;
     else WinningMSG += "NO ONE";
     WinningMSG += "] ===";
     Console.WriteLine(WinningMSG);
 }
 public static void NewPlayer(Player player1 , Player player2,string playername1 = "xxxxxx1",string playername2 = "xxxxxx2")
 {
     Console.Write("Player1 Name : ");
     playername1 = Console.ReadLine();
     Console.Write("Player2 Name : ");
     playername2 = Console.ReadLine();
     player1.Name = playername1;
     player2.Name = playername2;
 }
Example #20
0
 public static void NewPlayers(Player pPlayer1, Player pPlayer2, string pPlayerName1 = "Anonymous", string pPlayerName2 = "Anonymous")
 {
     Console.Write("1st Player's Name : ");
     pPlayerName1 = Console.ReadLine();
     Console.Write("2nd Player's Name : ");
     pPlayerName2 = Console.ReadLine();
     pPlayer1.Name = pPlayerName1;
     pPlayer2.Name = pPlayerName2;
 }
 public static void PlayerAddDeck(Player player1 , Player player2)
 {
     for(int i = 0; i < 26; i++)
     {
         player1.DeckPlayer.card.Add(_baseDeck.card[i]);
         player2.DeckPlayer.card.Add(_baseDeck.card[i + 26]);
     }
 }
Example #22
0
 public static void RemovePlayerCards(Player pPlayer1, Player pPlayer2, int range)
 {
     int LastCard = pPlayer1.PlayingDeck.Cards.Count - 1;
     pPlayer1.PlayingDeck.Cards.RemoveRange(LastCard - range + 1, range);
     pPlayer2.PlayingDeck.Cards.RemoveRange(LastCard - range + 1, range);
 }
 public static void PlayerTie(Player player1 , Player player2)
 {
     Console.WriteLine("This turn is Tie. System will reshuffle deck of the both players. ");
     player1.DeckPlayer.Shuffle();
     player2.DeckPlayer.Shuffle();
     _tie = true;
 }
Example #24
0
        public static int CompareCardDeck(Player pPlayer1, Player pPlayer2)
        {
            tie = false;
            if (pPlayer1.PlayingDeck.Cards.Count == 0)
            {
                Console.WriteLine("---[Both Players Have No Card]---");
                return -1;
            }
            int LastCard = pPlayer1.PlayingDeck.Cards.Count - 1;
            int pPlayer1_last = pPlayer1.PlayingDeck.Cards[LastCard].Value;
            int pPlayer2_last = pPlayer2.PlayingDeck.Cards[LastCard].Value;
            Console.WriteLine("[" + pPlayer1.Name + "] Has " + pPlayer1.PlayingDeck.Cards[LastCard], -30);
            Console.WriteLine("[" + pPlayer2.Name + "] Has " + pPlayer2.PlayingDeck.Cards[LastCard]);
            if (pPlayer1.PlayingDeck.Cards.Count == 1 && pPlayer1.PlayingDeck.Cards[LastCard].Value == pPlayer2.PlayingDeck.Cards[LastCard].Value) // No longer be playing
            {
                Console.WriteLine("[Both Players Cards Are Same]");
                return -1;
            }
            if (pPlayer1_last == pPlayer2_last)
            {
                bool Continue_Game = true;
                for (int i = 0; i <= LastCard; i++)
                {
                    for (int j = 0; j <= LastCard; j++)
                    {
                        if (pPlayer1.PlayingDeck.Cards[i].Value > pPlayer2.PlayingDeck.Cards[j].Value)
                        {
                            Continue_Game = false;
                        }
                        else
                        {
                            Continue_Game = true;
                        }
                    }
                }
                if (!Continue_Game)
                {
                    Console.WriteLine("= [" + pPlayer1.Name + "] Card Deck Is Containing : ");
                    pPlayer1.PlayingDeck.ViewCardsinDeck();
                    Console.WriteLine("= [" + pPlayer2.Name + "] Card Deck Is Containing : ");
                    pPlayer2.PlayingDeck.ViewCardsinDeck();
                    return -1;
                }
                int NumberFromLastCard = pPlayer1_last;
                if (NumberFromLastCard > LastCard)
                {

                    NumberFromLastCard = LastCard;

                }
                Console.WriteLine("[" + pPlayer1.Name + "] Has " + pPlayer1.PlayingDeck.Cards[NumberFromLastCard]);
                Console.WriteLine("[" + pPlayer2.Name + "] Has " + pPlayer2.PlayingDeck.Cards[NumberFromLastCard]);
                int pPlayer1_fromlast = pPlayer1.PlayingDeck.Cards[NumberFromLastCard].Value;
                int pPlayer2_fromlast = pPlayer2.PlayingDeck.Cards[NumberFromLastCard].Value;
                if (pPlayer1_fromlast < pPlayer2_fromlast)
                {
                    PlayerWinTurn(pPlayer1, NumberFromLastCard);
                    RemovePlayerCards(pPlayer1, pPlayer2, NumberFromLastCard);
                    return 1;
                }
                else if (pPlayer1_fromlast > pPlayer2_fromlast)
                {
                    PlayerWinTurn(pPlayer2, NumberFromLastCard);
                    RemovePlayerCards(pPlayer1, pPlayer2, NumberFromLastCard);
                    return 2;
                }
                else
                {
                    TieTurn(pPlayer1, pPlayer2);
                    return 0;
                }
            }
            // Player 1 WIN
            else if (pPlayer1_last < pPlayer2_last)
            {
                PlayerWinTurn(pPlayer1);
                RemovePlayerCards(pPlayer1, pPlayer2, 1);
                return 1;
            }
            // Player 2 WIN
            else if (pPlayer1_last > pPlayer2_last)
            {
                PlayerWinTurn(pPlayer2);
                RemovePlayerCards(pPlayer1, pPlayer2, 1);
                return 2;
            }
            return -1;
        }
 public static void FinishedPlaying(Player pPlayer1, Player pPlayer2)
 {
     Console.WriteLine("");
     Console.WriteLine("=== [ " + (pPlayer1.Count > pPlayer2.Count ? pPlayer1.Name : pPlayer2.Name) + " Win ] ===");
 }