コード例 #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
        public static void Attack(HS_Game g, HS_PlayerInstance player, string[] args)
        {
            sbyte playerIndex = Convert.ToSByte(args[1]);
            sbyte fromIndex   = Convert.ToSByte(args[2]);
            sbyte toIndex     = Convert.ToSByte(args[3]);

            g.Battlefield.Attack(g.CurrentPlayer, fromIndex, g.CurrentPlayers[playerIndex], toIndex);
        }
コード例 #3
0
ファイル: PlayerInstance.cs プロジェクト: mtear/hearthclone
        public void Play(HS_Game game, int index)
        {
            HS_CardInstance card = game.CurrentPlayer.Hand.Cards[index];

            SpendMana((byte)card.Stats.Cost);
            game.Battlefield.AddCreature(this, (HS_CreatureInstance)card);
            //game.CurrentBattlefield.Add((HS_CreatureInstance)card);
            Hand.Cards.RemoveAt(index);
            //TODO redo this
        }
コード例 #4
0
 public static void PrintHands(HS_Game game)
 {
     foreach (HS_PlayerInstance player in game.CurrentPlayers)
     {
         Console.WriteLine(player.Name + " " + (int)player.Life + "HP " + player.Mana + "/" +
                           player.Crystals + " (" + player.Hand.Count + "):");
         PrintHand(player.Hand);
         Console.WriteLine("");
     }
 }
コード例 #5
0
        public void StartGame()
        {
            game = new HS_Game(new HS_Battlefield(), players);
            game.StartGame();
            Broadcast(game.CurrentPlayer.Name.ToUpper() + "'S TURN");

            ropetimer = MAX_ROPE;
            System.Timers.Timer aTimer = new System.Timers.Timer();
            aTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
            aTimer.Interval = 1000;
            aTimer.Enabled  = true;
        }
コード例 #6
0
 public static void PrintFields(HS_Game game)
 {
     foreach (HS_PlayerInstance player in game.CurrentPlayers)
     {
         Console.WriteLine(player.Name + " " + (int)player.Life + "HP (" + game.Battlefield.GetField(player).Count + "):");
         foreach (HS_CreatureInstance bi in game.Battlefield.GetField(player))
         {
             Console.WriteLine(bi.Name + " " + bi.CreatureStats.Power + "/[" + bi.CreatureStats.Health + "/" + bi.BaseCreatureStats.Health + "]");
         }
         Console.WriteLine("");
     }
 }
コード例 #7
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Hello!");
            System.Console.WriteLine("Loading decks...");
            HS_PlayerInstance p1 = new HS_PlayerInstance("nic", new HS_Avatar(), new HS_TestDeck());
            HS_PlayerInstance p2 = new HS_PlayerInstance("mike", new HS_Avatar(), new HS_TestDeck());
            HS_Game           g  = new HS_Game(new HS_Battlefield(), new List <HS_PlayerInstance>(new HS_PlayerInstance[] { p1, p2 }));

            g.StartGame();

            System.Console.WriteLine("Game started");
            string query = "";

            while (query != "exit")
            {
                System.Console.WriteLine(g.CurrentPlayer.Name + "'s turn");
                System.Console.Write("Command: ");
                query = System.Console.ReadLine().Trim();
                int      spaceindex = query.IndexOf(' ');
                string   q          = (spaceindex > 0) ? query.Substring(0, spaceindex) : query;
                string[] cs         = query.Split(' ');
                switch (q)
                {
                case "hands": ConsoleUtil.PrintHands(g); break;

                case "fields": ConsoleUtil.PrintFields(g); break;

                //explain card
                case "play": ConsoleUtil.Play(g, g.CurrentPlayer, cs); break;

                case "attack": ConsoleUtil.Attack(g, g.CurrentPlayer, cs); break;

                case "help": break;

                case "clear": System.Console.Clear(); break;

                case "end": g.EndTurn(); break;

                default: System.Console.WriteLine("Unknown command. Use \"help\" to see available commands."); break;
                }
            }
        }
コード例 #8
0
 bool CanPlayCard(HS_Game g, HS_PlayerInstance player, int index)
 {
     try
     {
         HS_CardInstance card = player.Hand.Cards[index];
         //Check have enough mana
         if (player.Mana >= card.Stats.Cost)
         {
             //TODO check full battlefield
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         return(false);
     }
 }