コード例 #1
0
        // Use this for initialization
        void Start()
        {
            // Init control
            playerTurn = true;
            playerNum = GameMaster.Instance.Turn;
            die = new Die ();
            die.Reseed (Environment.TickCount);
            damage = 0;

            // Init IDamageable objects
            // Create the enemy
            GameMaster.Instance.CreateEnemy(HostileType.Bandit, "Bandit");

            // Get the enemyID from the list of enemy IDs; since this a 1v1 fight there should only be a single ID
            enemyID = GameMaster.Instance.EnemyIdentifiers[0];

            // Get the enemy entity
            enemyEntity = (Bandit)EntityManager.Instance.GetEntity(enemyID);

            // Set the stats of the enemy
            enemyEntity.AttackPower = die.Roll(1, 9) + 5;
            enemyEntity.DefencePower = die.Roll(1, 9) + 5;

            // Set sprite of enemy
            if(enemyEntity.AttackPower > enemyEntity.DefencePower)
            {
                GameObject.Find ("Battler2Sprite").GetComponent<Image> ().sprite = Resources.Load<Sprite> ("Bandit1");
            } //end if
            else
            {
                GameObject.Find ("Battler2Sprite").GetComponent<Image> ().sprite = Resources.Load<Sprite> ("Bandit2");
            }

            // Set the enemy
            enemy = (IDamageable) enemyEntity;

            // Get the player's merchant
            GameMaster.Instance.LoadPlayers ();
            playerMerchant = (Merchant)GameMaster.Instance.GetPlayerScript(playerNum).Entity;
            playerAttack = playerMerchant.AttackPower;
            playerDefense = playerMerchant.DefencePower;
            GameObject.Find ("Battler1Sprite").GetComponent<Image> ().sprite = playerMerchant.GetSprite (2);

            // Set the player
            player = (IDamageable)playerMerchant;

            // Set background
            if(GameMaster.Instance.BattleMap == BattleMap.area01)
            {
                GameObject.Find("Background").GetComponent<Image>().sprite = Resources.Load<Sprite> ("BattleBackgrounds/Battle_Desert");
            } //end if
            else if(GameMaster.Instance.BattleMap == BattleMap.area02)
            {
                GameObject.Find("Background").GetComponent<Image>().sprite = Resources.Load<Sprite> ("BattleBackgrounds/Battle_Euro");
            } //end else if
            else if(GameMaster.Instance.BattleMap == BattleMap.area03)
            {
                GameObject.Find("Background").GetComponent<Image>().sprite = Resources.Load<Sprite> ("BattleBackgrounds/Battle_Metro");
            } //end if
            else
            {
                GameObject.Find("Background").GetComponent<Image>().sprite = Resources.Load<Sprite> ("BattleBackgrounds/Battle_Snow");
            } //end else

            // Init and set HUD objects
            GameObject.Find("Canvas").transform.Find("PlayerInventory").gameObject.SetActive(false);
            GameObject.Find("Canvas").transform.Find("AllyInventory").gameObject.SetActive(false);
            GameObject.Find("Canvas").transform.Find("Tooltip").gameObject.SetActive(false);
            playerName = GameObject.Find ("Battler1Name").GetComponent<Text> ();
            playerName.text = GameMaster.Instance.GetPlayerName (playerNum);
            enemyName = GameObject.Find ("Battler2Name").GetComponent<Text> ();
            GameObject.Find ("Battler1Attack").GetComponent<Text> ().text = playerMerchant.AttackPower.ToString ();
            GameObject.Find ("Battler2Attack").GetComponent<Text> ().text = enemyEntity.AttackPower.ToString ();
            GameObject.Find ("Battler1Defense").GetComponent<Text> ().text = playerMerchant.DefencePower.ToString ();
            GameObject.Find ("Battler2Defense").GetComponent<Text> ().text = enemyEntity.DefencePower.ToString ();
            playerHealth = GameObject.Find ("Battler1Health").GetComponent<Text> ();
            playerHealth.text = player.Health.ToString ();
            enemyHealth = GameObject.Find ("Battler2Health").GetComponent<Text> ();
            enemyHealth.text = enemy.Health.ToString ();
            playerBar = GameObject.Find ("Battler1HealthLeft").GetComponent<RectTransform> ();
            enemyBar = GameObject.Find ("Battler2HealthLeft").GetComponent<RectTransform> ();
            fightBoxText = GameObject.Find ("FightText").GetComponent<Text> ();

            // Init fight box and flavor
            fightBoxText.text = "The battlers square off!";
            linesOfText = 1;
            verbs = new List<string>();
            verbs.Add ("attacked");
            verbs.Add ("retaliated against");
            verbs.Add ("hammered");
            verbs.Add ("struck");
            verbs.Add ("lashed at");

            // Check if the player is an AI
            if (playerMerchant.GameObj.GetComponent<Player>().IsAI)
            {
                // Disable the fight buttons
                GameObject.Find("AttackButtons/HeadButton").GetComponent<Button>().interactable = false;
                GameObject.Find("AttackButtons/TorsoButton").GetComponent<Button>().interactable = false;
                GameObject.Find("AttackButtons/FeintButton").GetComponent<Button>().interactable = false;
            }
        }
コード例 #2
0
        public bool CreateEntity(out int entID, EntityType type, GameObject gameObject, int playerNum = 0)
        {
            // The result of creation
            bool result = false;

            // Create the proper type of entity based upon the given type
            switch (type)
            {
                case EntityType.Merchant:
                    {
                        // Create the entity
                        Merchant merchant = new Merchant(nextId, gameObject, GameMaster.Instance.GetPlayerColor(playerNum), GameMaster.Instance.GetPlayerName(playerNum));

                        // Now try to add the entity to the manager
                        if (!EntityManager.Instance.AddEntity(merchant))
                        {
                            // The entity couldn't be added to the manager so return failure
                            result = false;
                        }

                        // Return success
                        result = true;

                        break;
                    } // end case Merchant
                case EntityType.Porter:
                    {
                        // Create the entity
                        Porter porter = new Porter(nextId, gameObject);

                        // Now try to add the entity to the manager
                        if (!EntityManager.Instance.AddEntity(porter))
                        {
                            // The entity coulnd't be added to the manager so return failure
                            result = false;
                        }

                        // Return success
                        result = true;

                        break;
                    } // end case Porter
                case EntityType.Mercenary:
                    {
                        // Create the entity
                        Mercenary mercenary = new Mercenary(nextId, gameObject);

                        // Now try to add the entity to the manager
                        if (!EntityManager.Instance.AddEntity(mercenary))
                        {
                            // The entity coulnd't be added to the manager so return failure
                            result = false;
                        }

                        // Return success
                        result = true;

                        break;
                    } // end Mercenary
                case EntityType.Bandit:
                    {
                        // Create the entity
                        Bandit bandit = new Bandit(nextId, gameObject);

                        // Now try to add the entity to the manager
                        if (!EntityManager.Instance.AddEntity(bandit))
                        {
                            // The entity coulnd't be added to the manager so return failure
                            result = false;
                        }

                        // Return success
                        result = true;

                        break;
                    } // end case Bandit
                case EntityType.Mimic:
                    {
                        // Create the entity
                        Mimic mimic = new Mimic(nextId, gameObject);

                        // Now try to add the entity to the manager
                        if (!EntityManager.Instance.AddEntity(mimic))
                        {
                            // The entity coulnd't be added to the manager so return failure
                            result = false;
                        }

                        // Return success
                        result = true;

                        break;
                    } // end Mimic
            } // end switch type

            // Set the out ID variable
            entID = nextId;

            // Increment to the next ID
            nextId++;

            // Return the result
            return result;
        }