Пример #1
0
        public bool CanPlaySpellCard(SampleSpellCard card, SamplePlayer player, int x, int y)
        {
            if (x < -1 || x >= PlayfieldWidth)
            {
                return(false);
            }
            if (y < 0 || y >= PlayfieldHeight)
            {
                return(false);
            }

            if (x == -1)
            {
                // Target is hero
                return(true);
            }

            int row = y;

            int numCardsOnPlayfield = GetNumberOfCards(row);

            if (x >= numCardsOnPlayfield)
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
 public int GetRowForPlayer(SamplePlayer pl)
 {
     for (int i = 0; i < playerList.Count; i++)
     {
         if (playerList[i] == pl)
         {
             return(i);
         }
     }
     return(-1);
 }
Пример #3
0
        public bool PlayCard(SampleBaseCard card, SamplePlayer player, int x, int y)
        {
            if (card.CardType == SampleCardType.Minion)
            {
                return(PlayMinionCard(card as SampleMinionCard, player, x, y));
            }
            else if (card.CardType == SampleCardType.Spell)
            {
                return(PlaySpellCard(card as SampleSpellCard, player, x, y));
            }

            return(false);
        }
Пример #4
0
        public bool PlayMinionCard(SampleMinionCard card, SamplePlayer player, int x, int y)
        {
            if (CanPlayCard(card, player, x, y) == false)
            {
                return(false);
            }

            int row = GetRowForPlayer(player);

            if (row == -1)
            {
                return(false);
            }

            InsertCard(card, x, row);

            card.ApplyPlayEffect();

            return(true);
        }
Пример #5
0
        private static void LogHero(SampleMatch match, SamplePlayer player, bool isUpper)
        {
            int    heroStartIndex = (int)((float)match.PlayfieldWidth / 2.0f - 0.5f);
            string emptyLine      = new String(' ', heroStartIndex * match.CardWidth);

            if (isUpper == true)
            {
                Logger.Log(emptyLine + "+=====+");
            }

            string manaSubstring = player.CurrentMana.ToString("D2") + "/" + player.MaxMana.ToString("D2");
            string manaString    = "        Mana: " + manaSubstring;

            Logger.Log(emptyLine + "|     |");
            Logger.Log(ReplaceWithName(emptyLine, player.Name, emptyLine.Length - 1) + "| " + player.CurrentHealth.ToString("D3") + " |" + manaString);
            Logger.Log(emptyLine + "|     |");

            if (isUpper == false)
            {
                Logger.Log(emptyLine + "+=====+");
            }
        }
Пример #6
0
        public bool CanPlayMinionCard(SampleMinionCard card, SamplePlayer player, int x, int y)
        {
            int row = GetRowForPlayer(player);

            if (row == -1)
            {
                return(false);
            }

            int numCardsOnPlayfield = GetNumberOfCards(row);

            if (numCardsOnPlayfield >= PlayfieldWidth)
            {
                return(false);
            }

            if (x > numCardsOnPlayfield)
            {
                return(false);
            }

            return(true);
        }
Пример #7
0
        public bool AttackWithCardUsingIndexes(int attackerRow, int attackerIndex, int victimRow, int victimIndex)
        {
            if (attackerIndex == -1)
            {
                // Hero attack is not supported
                return(false);
            }

            SampleMinionCard minion = Playfield[attackerIndex, attackerRow] as SampleMinionCard;

            if (minion == null)
            {
                return(false);
            }

            if (victimIndex == -1)
            {
                if (minion.ApplyPreActionEffect() == false)
                {
                    Logger.Log("AttackWithCardUsingIndexes of card '" + minion + "' was aborted by PreAction trigger");
                    return(false);
                }

                // Target is hero
                SamplePlayer pl = playerList[victimRow] as SamplePlayer;
                pl.ReceiveHealth(-minion.Attack);

                if (pl.CurrentHealth < 0)
                {
                    DeclareLoser(pl);
                }

                minion.ApplyPostActionEffect();

                return(true);
            }

            SampleMinionCard targetMinion = Playfield[victimIndex, victimRow] as SampleMinionCard;

            if (targetMinion == null)
            {
                return(false);
            }

            if (minion.ApplyPreActionEffect() == false)
            {
                Logger.Log("AttackWithCardUsingIndexes of card '" + minion + "' was aborted by PreAction trigger");
                return(false);
            }

            if (targetMinion.ApplyPreAttackedEffect(minion) == false)
            {
                Logger.Log("AttackWithCardUsingIndexes of card '" + minion + "' was aborted by PreAttack trigger of target card '" + targetMinion + "'");
                return(false);
            }
            if (minion.ApplyPreAttackedEffect(targetMinion) == false)
            {
                Logger.Log("AttackWithCardUsingIndexes of card '" + minion + "' was aborted by PreAttack trigger of source card '" + minion + "'");
                return(false);
            }

            targetMinion.CurrentHealth -= minion.Attack;
            minion.CurrentHealth       -= targetMinion.Attack;

            targetMinion.ApplyPostAttackedEffect(minion);
            minion.ApplyPostAttackedEffect(targetMinion);

            if (minion.CurrentHealth <= 0)
            {
                minion.ApplyDeathEffect();

                RemoveCard(attackerIndex, attackerRow);
            }
            if (targetMinion.CurrentHealth <= 0)
            {
                targetMinion.ApplyDeathEffect();

                RemoveCard(victimIndex, victimRow);
            }

            minion.ApplyPostActionEffect();

            return(true);
        }
Пример #8
0
        public bool PlaySpellCard(SampleSpellCard card, SamplePlayer player, int x, int y)
        {
            if (CanPlaySpellCard(card, player, x, y) == false)
            {
                return(false);
            }

            if (x == -1)
            {
                if (card.ApplyPreActionEffect() == false)
                {
                    Logger.Log("PlaySpellCard of card '" + card + "' was aborted by PreAction trigger");
                    return(false);
                }

                // Target is hero
                SamplePlayer pl = playerList[y] as SamplePlayer;
                pl.ReceiveHealth(card.SpellPower);

                if (pl.CurrentHealth < 0)
                {
                    DeclareLoser(pl);
                }

                card.ApplyPostActionEffect();

                return(true);
            }

            SampleMinionCard targetCard = Playfield[x, y] as SampleMinionCard;

            if (targetCard == null)
            {
                return(false);
            }

            if (card.ApplyPreActionEffect() == false)
            {
                Logger.Log("PlaySpellCard of card '" + card + "' was aborted by PreAction trigger");
                return(false);
            }

            if (targetCard.ApplyPreTargetEffect(card) == false)
            {
                Logger.Log("PlaySpellCard of card '" + card + "' was aborted by PreTarget trigger of target card '" + targetCard + "'");
                return(false);
            }

            targetCard.CurrentHealth += card.SpellPower;

            targetCard.ApplyPostTargetEffect(card);

            if (targetCard.CurrentHealth <= 0)
            {
                targetCard.ApplyDeathEffect();

                RemoveCard(x, y);
            }
            if (targetCard.CurrentHealth > targetCard.MaxHealth)
            {
                targetCard.CurrentHealth = targetCard.MaxHealth;
            }

            card.ApplyPostActionEffect();

            return(true);
        }
Пример #9
0
        public SampleBaseCard[] GetCardsForPlayer(SamplePlayer player)
        {
            int row = GetRowForPlayer(player);

            return(GetCardsForRow(row));
        }
Пример #10
0
        public static void Main(string[] args)
        {
            MainClass cls = new MainClass();

            Logger.LogWriter = cls;

            Console.WriteLine("Hello SampleTCG!");
            Console.WriteLine();
            Console.WriteLine("Choose player setup:");
            Console.WriteLine("1 - Human vs. Human");
            Console.WriteLine("2 - Human vs. CPU");
            Console.WriteLine("3 - CPU vs. CPU");
            Console.WriteLine();
            string mode = Console.ReadLine();

            while (isValidPlayerSetup(mode) == false)
            {
                Console.WriteLine("Please enter either 1, 2 or 3.");
                mode = Console.ReadLine();
            }

            SamplePlayer player1 = null;
            SamplePlayer player2 = null;

            switch (mode)
            {
            case "1":
                player1      = new SampleHumanPlayer();
                player1.Name = "Human1";
                player2      = new SampleHumanPlayer();
                player2.Name = "Human2";
                break;

            case "2":
                player1      = new SampleCPUPlayer();
                player1.Name = "CPU";
                player2      = new SampleHumanPlayer();
                player2.Name = "Human2";
                break;

            case "3":
                player1      = new SampleCPUPlayer();
                player1.Name = "CPU1";
                player2      = new SampleCPUPlayer();
                player2.Name = "CPU2";
                break;
            }

            Random rnd = new Random();

            SampleGame game = new SampleGame();

            game.InitCollection();

            SampleMatch match = new SampleMatch(rnd);

            match.Player1 = player1;
            match.Player2 = player2;

            player1.CreateRandomDeck(game.CardCollection, 20, match.Random);
            player2.CreateRandomDeck(game.CardCollection, 20, match.Random);

            match.PreStart();
            match.Start();

            while (match.IsRunning)
            {
                SampleMatchPrinter.PrintSampleMatch(match);

                if (match.ActivePlayer.IsLocallyControlled)
                {
                    string  line = Console.ReadLine();
                    Command cmd  = ParseCommand(line, match);
                    while (cmd == Command.None)
                    {
                        line = Console.ReadLine();
                        cmd  = ParseCommand(line, match);
                    }

                    if (cmd == Command.PrintHand)
                    {
                        match.ActivePlayer.LogHand();
                    }

                    if (cmd == Command.End)
                    {
                        match.StartNextRound();
                    }
                }
                else
                {
                    SampleCPUPlayer cpu = match.ActiveSamplePlayer as SampleCPUPlayer;
                    if (cpu != null)
                    {
                        cpu.PerformActions();
                    }

                    match.StartNextRound();
                }
            }

            Console.WriteLine("Press return to exit");
            Console.ReadLine();
        }