コード例 #1
0
 public static void Play(HS_Game g, HS_PlayerInstance player, string[] args)
 {
     if (args.Length == 1)
     {
         Console.WriteLine("No card in hand index specified. Supply an index for which card in hand to play. Example: play 1 will play the card in hand at index 1.");
     }
     else
     {
         try
         {
             int index = Convert.ToInt32(args[1]);
             if (index >= player.Hand.Count)
             {
                 Console.WriteLine("The index you supplied is outside the range of the cards in your hand.");
             }
             else
             { // Play the card if able
                 if (CanPlayCard(g, player, index))
                 {
                     Console.WriteLine("Playing card " + player.Hand.Cards[index].Name);
                     player.Play(g, index);
                 }
                 else
                 {
                     Console.WriteLine("Can't play " + player.Hand.Cards[index].Name);
                 }
             }
         }
         catch (Exception e)
         { //Parsing errors
             Console.WriteLine("There was an error parsing your play command.\n" + e);
         }
     }
 }
コード例 #2
0
        string Play(HS_PlayerInstance player, string[] args)
        {
            string response = "";

            if (player != game.CurrentPlayer)
            {
                response = "It's not your turn!\n";
            }
            else if (args.Length == 1)
            {
                response = "No card in hand index specified. Supply an index for which card in hand to play. Example: play 1 will play the card in hand at index 1.\n";
            }
            else
            {
                try
                {
                    int index = Convert.ToInt32(args[1]);
                    if (index >= player.Hand.Count)
                    {
                        response = "The index you supplied is outside the range of the cards in your hand.\n";
                    }
                    else
                    { // Play the card if able
                        if (CanPlayCard(game, player, index))
                        {
                            response = "Playing card " + player.Hand.Cards[index].Name + "\n";
                            Broadcast(player.Name + " played " + player.Hand.Cards[index].Name);
                            player.Play(game, index);
                        }
                        else
                        {
                            response = "Can't play " + player.Hand.Cards[index].Name + "\n";
                        }
                    }
                }
                catch (Exception e)
                { //Parsing errors
                    Console.WriteLine("There was an error parsing your play command.\n" + e);
                }
            }
            return(response);
        }