Beispiel #1
0
    public void adicionarMemento(CenaMemento memento)
    {
        estadosCena.AddFirst(memento);

        if (estadosCena.Count > LIMITE_DE_DESFAZER)
        {
            estadosCena.RemoveLast();
        }
    }
Beispiel #2
0
 public CenaMemento getUltimoEstadoSalvo()
 {
     if (contemElementos())
     {
         CenaMemento estadoSalvo = estadosCena.First.Value;
         estadosCena.RemoveFirst();
         return(estadoSalvo);
     }
     return(null);
 }
Beispiel #3
0
    public static void mudaTurno(bool enviaMsg = true)
    {
        turno = turno == 0 ? 1 : 0;
        LinkedList <GameObject> players        = new LinkedList <GameObject>(GameObject.FindGameObjectsWithTag("Player"));
        LinkedList <GameObject> estadoAnterior = new LinkedList <GameObject>();

        LinkedList <GameObject> .Enumerator enu = players.GetEnumerator();
        while (enu.MoveNext())
        {
            enu.Current.GetComponent <Personagem>().mudaTurno();
            estadoAnterior.AddFirst(enu.Current.GetComponent <Personagem>().clone());
        }
        CenaMemento novaCena = new CenaMemento(estadoAnterior);

        cenas.adicionarMemento(novaCena);
    }
Beispiel #4
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("PassaTurno") || cliqueBotaoTurno)
        {
            if (Metodos.checaAcao())
            {
                mudaTurno();
                if (Fluxo.tipoJogo == 2)
                {
                    cliente.EnviaTurnMsg();
                }
            }
        }

        if (Input.GetButtonDown("Volta"))
        {
            if (cenas.contemElementos())
            {
                GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
                for (int i = 0; i < players.Length; i++)
                {
                    Destroy(players[i]);
                }
                CenaMemento             cenaAnterior = cenas.getUltimoEstadoSalvo();
                LinkedList <GameObject> personagens  = cenaAnterior.getCena();
                turno = cenaAnterior.getTurno();
                while (personagens.Count > 0)
                {
                    GameObject original = Instantiate(personagens.First.Value);
                    original.GetComponent <Personagem>().mudaTurno();
                    original.SetActive(true);
                    personagens.RemoveFirst();
                }
                Debug.Log("Desfazer");
            }
        }
    }