Example #1
0
    public List <UbimonIcon> Fit(List <Ubimon> list, Ubimon toAdd = null)
    {
        List <UbimonIcon> result = SortedIcons(list, toAdd);

        var heap = new Heap();

        heap.Push(view);
        for (int i = 0; i < result.Count; ++i)
        {
            UbimonIconCanvas canvas = result[i].canvas;

            // Gets the largest available region...
            UbimonIconCanvas r = heap.Pop();
            if (!r.Fits(canvas.width, canvas.height))
            {
                return(null);
            }

            // Uses this region's position...
            canvas.x = r.x;
            canvas.y = r.y;

            // Splits the largest region in remaining spaces...
            heap.Push(new UbimonIconCanvas(r.x + canvas.width, r.y, r.width - canvas.width, r.height));
            heap.Push(new UbimonIconCanvas(r.x, r.y + canvas.height, canvas.width, r.height - canvas.height));
        }

        return(result);
    }
Example #2
0
 private void StartBattle()
 {
     mode = Mode.Battle;
     WorldMapController.main.HideMap();
     enemy = RandomEnemy();
     PrepareBattleBG();
     turn           = TURN_PICK;
     nextTurn       = 0;
     battleMessage  = null;
     ubimonNickname = "";
 }
Example #3
0
    private void StationCommand(string command)
    {
        peekedUbimon   = null;
        newUbimonIcons = null;
        Call call = new Call("app", command, "ubimon");

        call.AddParameter("playerId", playerId);
        gateway.CallService(stationDevice, call);

        if (command.Contains("cursor"))
        {
            StationPeek();
        }
    }
Example #4
0
    private UbimonIcon CreateIcon(Ubimon ubimon)
    {
        UbimonIcon ui = new UbimonIcon();

        ui.ubimon     = ubimon;
        ui.image      = ubimon.prototype.texture;
        ui.screenSize = prop * ubimon.prototype.textureSize;
        ui.insets     = new Insets(3, 3, 3, 3);
        ui.canvas     = new UbimonIconCanvas(
            0, 0,
            Mathf.CeilToInt(ui.screenSize.x + ui.insets.left + ui.insets.right),
            Mathf.CeilToInt(ui.screenSize.y + ui.insets.top + ui.insets.bottom));

        return(ui);
    }
Example #5
0
    private List <UbimonIcon> SortedIcons(List <Ubimon> list, Ubimon toAdd)
    {
        List <UbimonIcon> result = new List <UbimonIcon>(list.Count + 1);

        foreach (var u in list)
        {
            result.Add(CreateIcon(u));
        }
        if (toAdd != null)
        {
            result.Add(CreateIcon(toAdd));
        }

        result.Sort((a, b) => b.canvas.area.CompareTo(a.canvas.area));
        return(result);
    }
Example #6
0
    public static Ubimon FromJSON(IDictionary <string, object> json, UbimonDatabase db)
    {
        var ubimon = new Ubimon();

        ubimon.prototype = db.GetUbimonData(json["prototype"] as string);
        ubimon.id        = json["id"] as string;
        ubimon.trainer   = json["trainer"] as string;
        ubimon.name      = json["name"] as string;
        ubimon.level     = int.Parse(json["level"].ToString());
        ubimon.moves     = new List <Move>();
        foreach (var move in (json["moves"] as IList <object>))
        {
            ubimon.moves.Add(db.GetMove(move as string));
        }
        ubimon.life    = int.Parse(json["life"].ToString());
        ubimon.maxLife = int.Parse(json["maxLife"].ToString());

        return(ubimon);
    }
Example #7
0
    private Ubimon RandomEnemy()
    {
        UbimonData data = ubimonDB.ubimons[Random.Range(0, ubimonDB.ubimons.Length)];
        Ubimon     e    = new Ubimon();

        e.prototype = data;
        e.id        = System.Guid.NewGuid().ToString();
        e.trainer   = playerId;
        e.name      = char.ToUpper(data.name[0]) + data.name.ToLower().Substring(1);
        e.level     = 1;
        Move m = new Move();

        m.minLevel = 1;
        m.name     = "Tackle";
        e.moves    = new List <Move>()
        {
            m
        };
        e.maxLife = 10;
        e.life    = 10;

        return(e);
    }
Example #8
0
    private void StationPeek()
    {
        peekedUbimon   = null;
        newUbimonIcons = null;
        Call call = new Call("app", "peek", "ubimon");

        call.AddParameter("playerId", playerId);
        Response r      = gateway.CallService(stationDevice, call);
        string   ubimon = r.GetResponseString("ubimon");

        if (ubimon != null)
        {
            try
            {
                peekedUbimon   = Ubimon.FromJSON(ubimon, ubimonDB);
                newUbimonIcons = ubimonContainer.Fit(ubimons, peekedUbimon);
            }
            catch (System.Exception e)
            {
                StationCommand("leave");
                stationError = e.ToString();
            }
        }
    }
Example #9
0
    private void BattleGUI(Vector2 center, float btnWidth, float btnHeight)
    {
        Rect      r;
        Transform enemySprite = transform.FindChild("enemy");

        GUI.skin = battleSkin;
        Rect labelRect = new Rect(20, 20, Screen.width - enemySprite.localPosition.x - 20, 0.2f * Screen.height);
        Rect msgRect   = new Rect(20, 0.7f * Screen.height, Screen.width - 40, 0.3f * Screen.height - 20);

        // Draws battle statuses...
        if (turn >= 0)
        {
            GUI.Label(labelRect, enemy.name + "\n" + "Lvl. " + enemy.level + "\n" + enemy.life + "/" + enemy.maxLife);

            GUIStyle style = new GUIStyle(battleSkin.label);
            style.alignment = TextAnchor.LowerRight;
            r = new Rect(enemySprite.localPosition.x - 20, 0.5f * Screen.height, labelRect.width, labelRect.height);
            GUI.Label(r,
                      battlingUbimon.name + "\n" +
                      "Lvl. " + battlingUbimon.level + "\n" +
                      battlingUbimon.life + "/" + battlingUbimon.maxLife, style);
        }


        // Is there a pending message?
        if (battleMessage != null)
        {
            if (GUI.Button(msgRect, battleMessage))
            {
                if ((turn != TURN_PICK) || battleMessage.Contains("selected"))
                {
                    turn = nextTurn;
                }
                battleMessage = null;

                if (turn >= 0)
                {
                    nextTurn = 1 - turn;
                    if (turn == TURN_ENEMY)
                    {
                        EnemyAI();
                    }
                }
                // Go back to world mode!
                else if (turn == TURN_EXIT)
                {
                    ReleaseBattleBG();
                    WorldMapController.main.ShowMap();
                    mode = Mode.World;

                    foreach (var u in ubimons)
                    {
                        u.life = u.maxLife;
                    }
                    ubimonContainer.icons = ubimonContainer.Fit(ubimons);
                }
            }
        }
        else
        {
            switch (turn)
            {
            // Did I get a ubimon?
            case TURN_CAPTURED:
                GUI.Label(labelRect, "Do you want to give a nickname to your new ubimon?");

                float w = 0.3f * Screen.width;
                float h = 30;
                r = new Rect(center.x - w / 2, center.y - h / 2, w, h);
                ubimonNickname = (GUI.TextField(r, ubimonNickname) ?? "").Trim();

                GUI.enabled = !string.IsNullOrEmpty(ubimonNickname);
                r           = new Rect(center.x - btnWidth - 10, center.y + 2 * btnHeight, btnWidth, btnHeight);
                if (GUI.Button(r, "OK"))
                {
                    enemy.name = ubimonNickname;
                    EnemyCaptured();
                }
                GUI.enabled = true;

                r = new Rect(center.x + 10, center.y + 2 * btnHeight, btnWidth, btnHeight);
                if (GUI.Button(r, "NO"))
                {
                    EnemyCaptured();
                }
                break;


            // Is it in picking mode?
            case TURN_PICK:
                GUI.Label(labelRect, "A wild " + enemy.prototype.name + " appeared... You must pick a ubimon to use!");

                ubimonContainer.OnGUI();

                r           = new Rect(20, center.y + 6.5f * btnHeight, btnWidth, btnHeight);
                GUI.enabled = (ubimonContainer.selected != null);
                if (GUI.Button(r, "USE"))
                {
                    battlingUbimon = ubimonContainer.selected;
                    battleMessage  = "You selected " + battlingUbimon.name + "!";
                }
                GUI.enabled = true;
                break;


            // Is it my turn?
            case TURN_MINE:
                r = new Rect(20, 0.7f * Screen.height, 0.5f * Screen.width - 30, 0.15f * Screen.height - 15);
                if (GUI.Button(r, "ATTACK"))
                {
                    BattleAttack();
                }

                r = new Rect(center.x + 5, 0.7f * Screen.height, 0.5f * Screen.width - 30, 0.15f * Screen.height - 15);
                if (GUI.Button(r, "AURABALL"))
                {
                    BattleAuraBall();
                }

                r = new Rect(20, 0.85f * Screen.height + 5, 0.5f * Screen.width - 30, 0.15f * Screen.height - 15);
                if (GUI.Button(r, "SWITCH"))
                {
                    turn = TURN_PICK;
                }

                r = new Rect(center.x + 5, 0.85f * Screen.height + 5, 0.5f * Screen.width - 30, 0.15f * Screen.height - 15);
                if (GUI.Button(r, "RUN"))
                {
                    BattleRun();
                }
                break;

            default:
                break;
            }
        }
    }