Exemplo n.º 1
0
    public void Select(Card card)
    {
        if (card.region.Remove(card))
        {
            if (selected.cards.Count > 0)
            {
                Card previous = selected.cards[0];
                selected.Remove(previous);
                hand.AddCardLast(previous);
            }
            selected.AddCardLast(card);

            Map.current.ClearHighlight();
            preview.DoPreviewAction();
        }
    }
Exemplo n.º 2
0
    IEnumerator SolveTurn()
    {
        if (!isSolving)
        {
            Resolution0.gameObject.SetActive(true);

            isSolving = true;
            player2.RevealSelected();
            yield return(new WaitForSeconds(0.5f));

            bool ship1hit = false;
            bool ship2hit = false;
            // attack

            int pos1 = player1.ship.position;
            int pos2 = player2.ship.position;
            Resolution1.gameObject.SetActive(true);

            Map.current.ClearHighlight();
            preview1.DoPreviewAction(1, pos1, pos2);
            preview2.DoPreviewAction(1, pos2, pos1);
            yield return(new WaitForSeconds(0.5f));

            //Debug.Log("Solving turn");
            bool ship1moved = false;
            bool ship2moved = false;
            // move
            foreach (Card c1 in player1.selected.cards)
            {
                ship1moved |= c1.DoMove();
            }
            foreach (Card c2 in player2.selected.cards)
            {
                ship2moved |= c2.DoMove();
            }
            if (ship1moved || ship2moved)
            {
                yield return(new WaitForSeconds(0.5f));
            }

            Resolution2.gameObject.SetActive(true);

            Map.current.ClearHighlight();
            preview1.DoPreviewAction(0, pos1, pos2);
            preview2.DoPreviewAction(0, pos2, pos1);

            yield return(new WaitForSeconds(0.5f));

            if (!ship2moved)
            {
                foreach (Card c1 in player1.selected.cards)
                {
                    ship1hit |= c1.DoAttackNotMoved(ship2moved, pos1, pos2);
                }
            }
            if (!ship1moved)
            {
                foreach (Card c2 in player2.selected.cards)
                {
                    ship2hit |= c2.DoAttackNotMoved(ship1moved, pos2, pos1);
                }
            }

            if (ship1hit || ship2hit)
            {
                yield return(new WaitForSeconds(1));
            }


            Resolution3.gameObject.SetActive(true);

            Map.current.ClearHighlight();
            preview1.DoPreviewAction(2, pos1, pos2);
            preview2.DoPreviewAction(2, pos2, pos1);

            yield return(new WaitForSeconds(0.5f));

            bool dynamicHit = false;
            if (!ship1hit)
            {
                foreach (Card c1 in player1.selected.cards)
                {
                    ship1hit |= c1.DoAttackMoved(ship2moved);
                }
                dynamicHit |= ship1hit;

                /*
                 * if (ship1hit)
                 * {
                 *  ParticleSystem.EmitParams parameter = new ParticleSystem.EmitParams();
                 *  parameter.startColor = player2.color;
                 *  map.tiles[player2.ship.position].emission.Emit(parameter, Random.Range(20, 50));
                 *  dynamicHit = true;
                 * }*/
            }
            if (!ship2hit)
            {
                foreach (Card c2 in player2.selected.cards)
                {
                    ship2hit |= c2.DoAttackMoved(ship1moved);
                }
                dynamicHit |= ship2hit;

                /*
                 * if (ship2hit)
                 * {
                 *  ParticleSystem.EmitParams parameter = new ParticleSystem.EmitParams();
                 *  parameter.startColor = player1.color;
                 *  map.tiles[player1.ship.position].emission.Emit(parameter, Random.Range(20, 50));
                 *  dynamicHit = true;
                 * }*/
            }
            if (dynamicHit)
            {
                yield return(new WaitForSeconds(1));
            }

            if (player1.hp <= 0)
            {
                player1.ship.gameObject.SetActive(false);

                yield return(new WaitForSeconds(1f));

                if (!fightOver)
                {
                    game.LoseFight();
                    fightOver = true;
                }
            }
            else if (player2.hp <= 0)
            {
                player2.ship.gameObject.SetActive(false);
                yield return(new WaitForSeconds(1f));

                if (!fightOver)
                {
                    game.WinFight();
                    fightOver = true;
                }
            }
            if (!fightOver)
            {
                Resolution4.gameObject.SetActive(true);

                Map.current.ClearHighlight();
                preview1.DoPreviewAction(3, pos1, pos2);
                preview2.DoPreviewAction(3, pos2, pos1);

                yield return(new WaitForSeconds(1f));

                // repair
                foreach (Card c1 in player1.selected.cards)
                {
                    c1.DoSpecial();
                }
                foreach (Card c2 in player2.selected.cards)
                {
                    c2.DoSpecial();
                }
                yield return(new WaitForSeconds(0.5f));

                if (player1.ship.position > player2.ship.position)
                {
                    if (!fightOver)
                    {
                        game.DrawFight();
                        fightOver = true;
                    }
                }
                player1.DiscardSelected();
                player2.DiscardSelected();
                yield return(new WaitForSeconds(0.5f));

                player1.Draw();
                player2.Draw();
                yield return(new WaitForSeconds(0.5f));

                BeginTurn();
            }
            isSolving = false;
        }
    }