Exemplo n.º 1
0
    /*
     *  Funció que avança al seguent jugador.
     */
    private void NextPlayer()
    {
        selectedSlime = null;
        int playerIndex = players.IndexOf(currentPlayer);

        playerIndex++;
        currentPlayer = players[playerIndex % players.Count];
        playerActions = 0;


        if (playerIndex >= players.Count)
        {
            // Tots els jugadors han fet la seva accio, passem al seguent torn.
            NextTurn();
        }
        else
        {
            status = GameControllerStatus.PLAYINGACTION;
            uiController.NextPlayer(GetCurrentPlayer().GetColor(), playerActions, GetCurrentPlayer().actions);
        }
        //camController.InitMaxZoom();

        camController.GlobalCamera();
        //Debug.Log("SLIMES: " + players [currentPlayer].GetSlimes ().Count);
    }
Exemplo n.º 2
0
    private void ConquerTile(Tile tile)
    {
        tile.tileConquerLayer.sprite = conquerSprite;
        tile.tileConquerLayer.transform.localScale    = new Vector3(0.3f, 0.3f, 0f);
        tile.tileConquerLayer.transform.localPosition = new Vector3(-2.4f, 3.5f, 0f);
        //borrem la tile conquerida de qui la tenia abans
        foreach (Player player in players)
        {
            if (player.HasConqueredTile(tile))
            {
                player.RemoveConqueredTile(tile);
            }
        }
        //afegim la tile conquerida
        currentPlayer.AddConqueredTile(tile);
        Color c = selectedSlime.GetPlayer().GetColor();

        //c.a = 0.5f;
        tile.tileConquerLayer.color = c;
        tile.SetOwner(currentPlayer);
        if (!(currentPlayer.statsCoreInfo.name == "Greed"))
        {
            playerActions++;
        }
        selectedSlime.ChangeElement(tile.elementType);
        tile.RemoveElement();
        status = GameControllerStatus.CHECKINGLOGIC;
    }
Exemplo n.º 3
0
    private void RangedAttack(Slime toAttack)
    {
        GameObject projectile = new GameObject("projectile");
        Sprite     sprite     = GetSpriteForElement(selectedSlime.GetElementType(), projectile);

        projectile.AddComponent <ProjectileTrajectory>();
        projectile.AddComponent <SpriteRenderer>().sprite           = sprite;
        projectile.GetComponent <SpriteRenderer>().sortingLayerName = "Slime";
        //projectile.GetComponent<SpriteRenderer> ().color = selectedSlime.GetPlayer ().GetColor ();
        projectile.GetComponent <ProjectileTrajectory>().SetTrajectorySlimes(selectedSlime, toAttack);

        /*
         * Vector3 horizontal = new Vector3 (1f, 0f, 0f);
         * if (MathUtils.Vect3ScalarProduct(horizontal,(toAttack.transform.parent.position - selectedSlime.transform.parent.position)) >= 0) {
         *      Debug.Log ("positive");
         *      projectile.transform.Rotate (new Vector3 (0f, 0f, Vector3.Angle (horizontal, toAttack.transform.parent.position - selectedSlime.transform.parent.position)));
         * } else {
         *      Debug.Log ("negative");
         *      projectile.transform.Rotate (new Vector3 (0f, 0f, -Vector3.Angle (horizontal, toAttack.transform.parent.position - selectedSlime.transform.parent.position)));
         * }
         */
        projectile.transform.Rotate(new Vector3(0f, 0f, Vector3.SignedAngle(new Vector3(1f, 0f, 0f), (toAttack.transform.parent.position - selectedSlime.transform.parent.position), new Vector3(0f, 0f, 1f))));

        status = GameControllerStatus.PLAYINGACTION;
        AudioClip clip = SoundsLoader.GetInstance().GetResource("Sounds/fireball");

        soundController.PlaySingle(clip);
    }
Exemplo n.º 4
0
    private void MoveSlime(Tile tile)
    {
        TileData tileTo = tile.GetTileData();

        /*if(tileTo.GetSlimeOnTop() != null) {
         *  Debug.Log("WARNING: trying to move to tile with a slime");
         *  Debug.Log("ID:" + tileTo.GetSlimeOnTop().GetId());
         * }
         * if(tileTo.getTileType() == TileType.Null) Debug.Log("WARNING: trying to move to BLOCK");
         * if(Matrix.GetDistance(selectedSlime.GetActualTile().getPosition(), tileTo.getPosition()) > selectedSlime.GetMovementRange())
         *  Debug.Log("WARNING: trying to move to tile too far");*/

        Dictionary <TileData, List <TileData> > moves = matrix.possibleCoordinatesAndPath(
            (int)selectedSlime.actualTile.getPosition().x, (int)selectedSlime.actualTile.getPosition().y, selectedSlime.GetMovementRange());

        //if(moves[tileTo] == null) Debug.Log("WARNING!!!\n" + moves.Keys);
        List <TileData> path = moves[tileTo];

        path [path.Count - 1].SetSlimeOnTop(selectedSlime);
        selectedSlime.SetActualTile(tile);
        selectedSlime.gameObject.GetComponent <SlimeMovement>().SetBufferAndPlay(path);

        status = GameControllerStatus.PLAYINGACTION;
        playerActions++;
    }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (status == GameControllerStatus.CHECKINGLOGIC)
        {
            checkLogic();
        }

        //S'ha de posar despres de la comprovacio de ended
        // Si estamos en modo "espera accion" y el jugador es una IA, calculamos la accion.

        if (status == GameControllerStatus.WAITINGFORACTION && currentPlayer.isPlayerAI())
        {
            status = GameControllerStatus.AILOGIC;
            GetCurrentPlayer().ThinkAction();
        }
        else if (status == GameControllerStatus.AILOGIC && !GetCurrentPlayer().IsThinking() && currentPlayer.isPlayerAI())
        {
            status = GameControllerStatus.PLAYINGACTION;
            AISlimeAction action = currentPlayer.GetThoughtAction();
            if (action != null)
            {
                SetSelectedSlime(action.GetMainSlime());       // Simulamos la seleccion de la slime que hace la accion.
                DoAction((SlimeAction)action);                 // Hacemos la accion.
            }
            else
            {
                Debug.Log("IA returned NULL action");
                NextPlayer();                 // No pot fer cap accio
            }
        }
    }
Exemplo n.º 6
0
 /*
  *  Funció que avança al seguent torn.
  */
 public void NextTurn()
 {
     currentPlayer = players[0];
     playerActions = 0;
     currentTurn++;
     status = GameControllerStatus.PLAYINGACTION;
     uiController.NextRound(currentTurn + 1, GetCurrentPlayer().GetColor(), playerActions, GetCurrentPlayer().actions);
 }
Exemplo n.º 7
0
    private void FusionSlime(Slime fusionTarget)
    {
        RemoveSlime(selectedSlime);
        //players[currentPlayer].updateActions();
        selectedSlime.GetActualTile().SetSlimeOnTop(null);
        fusionTarget.SetMass((int)(selectedSlime.GetMass() + fusionTarget.GetMass()), true);

        Destroy(selectedSlime.gameObject);
        playerActions++;
        status = GameControllerStatus.CHECKINGLOGIC;
    }
Exemplo n.º 8
0
 private void SplitSlime(Tile targetTile)
 {
     if (selectedSlime.canSplit)
     {
         Slime newSlime = SlimeFactory.instantiateSlime(selectedSlime.GetPlayer(), new Vector2(targetTile.GetTileData().getPosition().x, targetTile.GetTileData().getPosition().y));
         newSlime.InitMass();             //posem vida a 0, i a la seguent linia li posem la vida real, d'aquesta manera es veu el popup amb '+'
         newSlime.SetMass((int)(selectedSlime.GetMass() / 2.0f), true);
         selectedSlime.SetMass((int)(selectedSlime.GetMass() / 2.0f), true);
         newSlime.ChangeElement(selectedSlime.GetElementType());
         playerActions++;
         status = GameControllerStatus.CHECKINGLOGIC;
     }
 }
Exemplo n.º 9
0
    public void checkLogic()
    {
        for (int i = players.Count - 1; i >= 0; i--)
        {
            if (players[i].GetNumSlimes() == 0)
            {
                //This player loses
                GameOverInfo.SetLoser(players[i]);
                //si li tocava al que ha mort i aquest era l'ultim de la llista, el torn es el del primer de la llista
                players.RemoveAt(i); //definitivament el borrem de la llista
                break;
            }
        }

        Player winner = IsGameEndedAndWinner();

        if (winner != null)
        {
            GameOverInfo.SetWinner(winner);
            foreach (Player p in players)
            {
                if (p != winner)
                {
                    GameOverInfo.SetLoser(p);
                }
            }
            GameSelection.playerColors.Clear();
            GameSelection.playerCores.Clear();
            GameSelection.playerIAs.Clear();
            //players.Clear ();
            SceneManager.LoadScene("GameOver");
        }

        if (playerActions >= currentPlayer.actions)
        {
            NextPlayer();
        }
        else
        {
            status = GameControllerStatus.WAITINGFORACTION;
        }
    }
Exemplo n.º 10
0
 public void OnProjectileAnimationEnded()
 {
     status = GameControllerStatus.CHECKINGLOGIC;
 }
Exemplo n.º 11
0
 private void GrowSlime(Slime slime)
 {
     selectedSlime.GrowSlime();
     playerActions++;
     status = GameControllerStatus.CHECKINGLOGIC;
 }
Exemplo n.º 12
0
    // Use this for initialization
    void Start()
    {
        /*
         * TipDialog a = new TipDialog ();
         * a.SetButtonImage(SpritesLoader.GetInstance ().GetResource ("Buttons/button_template"));
         * a.SetBackgroundImage(SpritesLoader.GetInstance ().GetResource ("Panels/emergent"));
         * a.SetInfoTextText ("Has aceptado");
         * a.Hide ();
         * TwoOptionsDialog t = new TwoOptionsDialog();
         * t.SetButtonsImage(SpritesLoader.GetInstance ().GetResource ("Buttons/button_template"));
         * t.SetBackgroundImage(SpritesLoader.GetInstance ().GetResource ("Panels/emergent"));
         * t.SetAceptButtonColor (new Color(0f,0f,1f));
         * t.SetDeclineButtonColor (new Color(1f,0f,0f));
         * t.SetOnClickAceptFunction(()=>{
         *      a.Show();
         * });
         */

        /*
         *      Time.timeScale = 1;
         *      ChainTextDialog ctd = new ChainTextDialog ();
         *      ctd.SetButtonImage(SpritesLoader.GetInstance ().GetResource ("Buttons/button_template"));
         *      ctd.SetBackgroundImage(SpritesLoader.GetInstance ().GetResource ("Panels/emergent"));
         */

        TileFactory.tileMaterial = tileMaterial;
        //InGameMarker igm = new InGameMarker ();
        //igm.SetSprite (SpritesLoader.GetInstance().GetResource("Test/testTileSlim"));
        FloatingTextController.Initialize();
        uiController    = Camera.main.GetComponent <UIController>();
        soundController = gameObject.GetComponent <SoundController>();
        camController   = Camera.main.GetComponent <CameraController>();
        conquerSprite   = SpritesLoader.GetInstance().GetResource("Tiles/conquest_flag");
        //panelTip = GameObject.Find("PanelTip"); //ja tenim el panell, per si el necessitem activar, i desactivar amb : panelTip.GetComponent<DialogInfo> ().Active (boolean);
        //textTip = GameObject.Find("TextTip"); //ja tenim el textBox, per canviar el text : textTip.GetComponent<Text> ().text = "Text nou";
        //panelTip.GetComponent<DialogInfo>().Active(false);
        //textTip.GetComponent<Text>().text = "Aquí es mostraran els diferents trucs que pot fer el jugador";
        players        = new List <Player>();
        Time.timeScale = 1f;
        if (ModosVictoria.IsDefined(typeof(ModosVictoria), GameSelection.modoVictoria))
        {
            condicionVictoria = (ModosVictoria)GameSelection.modoVictoria;
        }
        else
        {
            condicionVictoria = ModosVictoria.ASESINATO; //por defecto
        }

        MAX_TURNS = GameSelection.MAX_TURNS;

        int maxPlayers = GameSelection.playerColors.Count;

        if (maxPlayers == 0)
        {
            GameSelection.playerColors.Add(new Color(0, 0, 1));
            GameSelection.playerColors.Add(new Color(1, 0, 0));
            GameSelection.playerCores.Add(SlimeCoreTypes.SLOTH);
            GameSelection.playerCores.Add(SlimeCoreTypes.WRATH);
            GameSelection.playerIAs.Add(false);
            GameSelection.playerIAs.Add(true);
            maxPlayers = 2;
        }
        for (int i = 0; i < maxPlayers; i++)
        {
            if (GameSelection.playerIAs [i])
            {
                //players.Add(new Player("Jugador "+(i+1),StatsFactory.GetStat(GameSelection.playerCores[i])));
                Debug.Log("Ia true");
                players.Add(new Player("Jugador " + (i + 1), StatsFactory.GetStat(GameSelection.playerCores[i]), AIManager.GetAIByVictoryCondition(this, condicionVictoria)));
            }
            else
            {
                players.Add(new Player("Jugador " + (i + 1), StatsFactory.GetStat(GameSelection.playerCores[i])));
            }
            players[i].SetColor(GameSelection.playerColors[i]);
        }
        matrix = GameSelection.map;//new Matrix(11, 0.3f, 1234567);
        if (matrix == null)
        {
            matrix = new Matrix(5 * players.Count, 0.3f, Random.Range(0, 10000));
        }
        MapDrawer.instantiateMap(matrix.getIterable());
        int numSlimesPerPlayer           = 2;
        List <List <Vector2> > positions = matrix.GetPositions(players.Count, numSlimesPerPlayer);
        int j = 0;

        foreach (Player player in players)
        {
            List <Vector2> positionsSlimes = positions[j];
            foreach (Vector2 positionSlime in positionsSlimes)
            {
                SlimeFactory.instantiateSlime(player, positionSlime);
            }
            j++;
        }
        if (players.Count == 0)
        {
            players.Add(new Player("Jugador 1", StatsFactory.GetStat(SlimeCoreTypes.WRATH), AIManager.GetAIByVictoryCondition(this, condicionVictoria)));            // Test with 2 players
            players.Add(new Player("Jugador 2", StatsFactory.GetStat(SlimeCoreTypes.GLUTTONY)));
            players[0].SetColor(Color.blue);
            players[1].SetColor(Color.red);
            positions = matrix.GetPositions(players.Count, 1);
            SlimeFactory.instantiateSlime(players[0], positions[0][0]);
            SlimeFactory.instantiateSlime(players[1], positions[1][0]);
        }
        //matrix = new Matrix(MapParser.ReadMap(MapTypes.Medium));

        currentTurn   = 0;
        currentPlayer = players[0];
        playerActions = 0;

        uiController.UpdateRound(currentTurn + 1);
        uiController.UpdatePlayer(GetCurrentPlayer().GetColor());

        uiController.UpdateActions(playerActions, GetCurrentPlayer().actions);
        uiController.ShowBothPanels();
        //iniciem la informacio de game over
        totalTiles = matrix.TotalNumTiles();
        //Debug.Log("TILES TOTALS: "+ totalTiles);

        // La condicio de victoria s'assigna mes amunt, aqui nomes s'actualitzen els requisits.
        switch (condicionVictoria)
        {
        case ModosVictoria.CONQUISTA:
            //define percentage tiles to win
            if (MAX_TURNS == 0)
            {
                percentageTilesToWin = 0.25f;
            }
            else
            {
                percentageTilesToWin = 0.75f;
            }

            //Debug.Log("Porcentaje de conquista para ganar: "+percentageTilesToWin);
            break;

        case ModosVictoria.MASA:
            //define mass to win
            massToWin = 0;
            foreach (Player player in players)
            {
                if (player.GetTotalMass() > massToWin)
                {
                    massToWin = player.GetTotalMass();
                }
            }
            massToWin *= 2;
            //Debug.Log("Masa total del jugador para ganar: "+massToWin);
            break;
        }

        GameOverInfo.Init();
        AudioClip clip = SoundsLoader.GetInstance().GetResource("Sounds/MainGameTheme");

        soundController.PlayLoop(clip);
        camController.InitMaxZoom();


        status = GameControllerStatus.CHECKINGLOGIC;
    }
Exemplo n.º 13
0
 public void updateStatus(GameControllerStatus s)
 {
     status = s;
 }