如何在场景之间不断传递数据

时间:2014-03-07 12:05:23

标签: c# playstation

嘿家伙所以我的问题是我有2个场景,一个代表主要游戏场景的战斗场景和代表玩家怪物技能的结果场景,到目前为止我所拥有的是在角色场景中选择的任何怪物都将决定表示怪物技能等的图像和字符串问题是战斗场景和结果场景需要不断切换,直到任何一个玩家获胜。问题是,当我尝试从结果场景回到战斗场景并再次返回时,标签将重叠,例如说第一次技能在我第一次进入结果场景时有一个1但是第二次而不是用2或3替换1,它将2或3置于1的顶部。

我还注意到,当我添加伤害计算(我已暂时移除)时,如果该技能会造成7HP伤害,它将在第一次使用,但第二次或第三次伤害会每次加倍。

继承我的代码;

using System;
using System.Threading;
using System.Diagnostics;
using System.Collections.Generic;

using Sce.PlayStation.Core;
using Sce.PlayStation.Core.Imaging;
using Sce.PlayStation.Core.Environment;
using Sce.PlayStation.Core.Graphics;
using Sce.PlayStation.Core.Input;
using Sce.PlayStation.HighLevel.UI;

namespace MonsterKombat_v3
{
public class dragonClass : characterClass
{
    public dragonClass ()
    {
        base.maxHealth = new Label();
        base.healthBar = new ProgressBar();
        base.monster = new ImageBox();
        base.name = new Label();
        base.sLabel = new Label[6];
        base.mTitle = new Label();
        base.skills = new string[6];
        base.Skills = new int[6];

        base.name.HorizontalAlignment = HorizontalAlignment.Center;
        base.name.VerticalAlignment = VerticalAlignment.Middle;
        base.name.SetPosition(10, 400);
        base.name.SetSize(160, 50);
        base.name.Text = "Name: Dragon";

        base.currentHealth = 85;

        base.maxHealth.HorizontalAlignment = HorizontalAlignment.Center;
        base.maxHealth.VerticalAlignment = VerticalAlignment.Middle;
        base.maxHealth.SetSize(100, 50);
        base.maxHealth.SetPosition(170, 480);
        base.maxHealth.Text = (base.currentHealth + "/85");

        base.healthBar.Progress = 0.85f;
        base.healthBar.SetSize(250, 50);
        base.healthBar.SetPosition(100, 469);

        base.monster.Image = new ImageAsset("/Application/Images/Monsters/MonsterIcon1.png");
        base.monster.Width = 375;
        base.monster.Height = 400;
        base.monster.PivotType = PivotType.MiddleCenter;
        base.monster.SetPosition(175, 200);

        base.mTitle.HorizontalAlignment = HorizontalAlignment.Center;
        base.mTitle.VerticalAlignment = VerticalAlignment.Middle;
        base.mTitle.Font.Style = FontStyle.Bold;
        base.mTitle.Font.Style = FontStyle.Italic;
        base.mTitle.SetPosition(220, 15);
        base.mTitle.Text = "Dragon";

        for(int i = 0; i < 6; i++)
        { 
            //makes a new label based on the value of 'i'
            base.sLabel[i] = new Label();
            base.sLabel[i].SetSize(600, 100);
            base.sLabel[i].HorizontalAlignment = HorizontalAlignment.Center;
            base.sLabel[i].VerticalAlignment = VerticalAlignment.Middle;
            assetClass.panel2.AddChildLast(base.sLabel[i]);
        }

        for(int i = 0; i < 6; i++)
        {
            //converts the int value of each skill to a string  
            base.skills[i] = base.Skills[i].ToString();
        }

        sLabel[0].Text = "1) Claw: 7HP {1}" + "".PadRight(50) + base.skills[0];
        sLabel[0].SetPosition(270, 40);
        sLabel[1].Text = "2) Tail Smash: 9HP {1}" + "".PadRight(42) + base.skills[1];
        sLabel[1].SetPosition(270, 110);
        sLabel[2].Text = "3) Bite: 17HP {2}" + "".PadRight(49) + base.skills[2];
        sLabel[2].SetPosition(270, 170);
        sLabel[3].Text = "4) Roar: 5HP(all, enemy misses turn) {2}" + "".PadRight(18) + base.skills[3];
        sLabel[3].SetPosition(270, 230);
        sLabel[4].Text = "5) Fire Breath: 20HP + 5 for every odd number {3}" + "".PadRight(5) + base.skills[4];
        sLabel[4].SetPosition(270, 300);
        sLabel[5].Text = "6) Nova Flame: 30HP(all) + 10".PadRight(60) + "\n for every even number {5}" + "".PadRight(37) + base.skills[5];
        sLabel[5].SetPosition(270, 370);

        assetClass.panel2.AddChildLast(base.mTitle);
        assetClass.panel.AddChildLast(base.name);
        assetClass.panel.AddChildLast(base.maxHealth);
        assetClass.panel.AddChildLast(base.healthBar);
        assetClass.panel.AddChildLast(base.monster);
    }

    public static void Skills(int number1, int number2, int number3)
    {
        Label[] sLabel = new Label[6];
        Label mTitle = new Label();
        string[] skills = new string[6];
        int[] Skills = new int[6];

        switch(number1)
        {
            case 1:
                Skills[0]++;
                break;
            case 2:
                Skills[1]++;
                break;
            case 3:
                Skills[2]++;
                break;
            case 4:
                Skills[3]++;
                break;
            case 5:
                Skills[4]++;
                break;
            case 6:
                Skills[5]++;
                break;
        }

        switch(number2)
        {
            case 1:
                Skills[0]++;
                break;
            case 2:
                Skills[1]++;
                break;
            case 3:
                Skills[2]++;
                break;
            case 4:
                Skills[3]++;
                break;
            case 5:
                Skills[4]++;
                break;
            case 6:
                Skills[5]++;
                break;
        }

        switch(number3)
        {
            case 1:
                Skills[0]++;
                break;
            case 2:
                Skills[1]++;
                break;
            case 3:
                Skills[2]++;
                break;
            case 4:
                Skills[3]++;
                break;
            case 5:
                Skills[4]++;
                break;
            case 6:
                Skills[5]++;
                break;
        }

        mTitle.HorizontalAlignment = HorizontalAlignment.Center;
        mTitle.VerticalAlignment = VerticalAlignment.Middle;
        mTitle.Font.Style = FontStyle.Bold;
        mTitle.Font.Style = FontStyle.Italic;
        mTitle.SetPosition(220, 15);
        mTitle.Text = "Dragon";

        for(int i = 0; i < 6; i++)
        {
            //converts the int value of each skill to a string  
            skills[i] = Skills[i].ToString();
        }

        for(int i = 0; i < 6; i++)
        { 
            //makes a new label based on the value of 'i'
            sLabel[i] = new Label();
            sLabel[i].SetSize(600, 100);
            sLabel[i].HorizontalAlignment = HorizontalAlignment.Center;
            sLabel[i].VerticalAlignment = VerticalAlignment.Middle;
            assetClass.panel2.AddChildLast(sLabel[i]);
        }

        sLabel[0].Text = "1) Claw: 7HP {1}" + "".PadRight(50) + skills[0];
        sLabel[0].SetPosition(270, 40);
        sLabel[1].Text = "2) Tail Smash: 9HP {1}" + "".PadRight(42) + skills[1];
        sLabel[1].SetPosition(270, 110);
        sLabel[2].Text = "3) Bite: 17HP {2}" + "".PadRight(49) + skills[2];
        sLabel[2].SetPosition(270, 170);
        sLabel[3].Text = "4) Roar: 5HP(all, enemy misses turn) {2}" + "".PadRight(18) + skills[3];
        sLabel[3].SetPosition(270, 230);
        sLabel[4].Text = "5) Fire Breath: 20HP + 5 for every odd number {3}" + "".PadRight(5) + skills[4];
        sLabel[4].SetPosition(270, 300);
        sLabel[5].Text = "6) Nova Flame: 30HP(all) + 10".PadRight(60) + "\n for every even number {5}" + "".PadRight(37) + skills[5];
        sLabel[5].SetPosition(270, 370);

        assetClass.panel2.AddChildLast(mTitle);
    }
}
}

战斗场景课;

using System;
using System.Threading;
using System.Diagnostics;
using System.Collections.Generic;

using Sce.PlayStation.Core;
using Sce.PlayStation.Core.Imaging;
using Sce.PlayStation.Core.Environment;
using Sce.PlayStation.Core.Graphics;
using Sce.PlayStation.Core.Input;
using Sce.PlayStation.HighLevel.GameEngine2D;
using Sce.PlayStation.HighLevel.GameEngine2D.Base;
using Sce.PlayStation.HighLevel.UI;

namespace MonsterKombat_v3
{
public class battleScene : Sce.PlayStation.HighLevel.GameEngine2D.Scene
{
    public static int[] bsNumber = new int[3];

    public battleScene()
    {           
        //defines a variable to store random numbers for each die
        //3 ints used to calculate a random number between 1-6 for each die
        var bsDice = new Random();
        bsNumber[0] = (bsDice.Next() % 6) + 1;
        bsNumber[1] = (bsDice.Next() % 6) + 1;
        bsNumber[2] = (bsDice.Next() % 6) + 1;

        for(int i = 0; i < 2; i++)
        { 
            //makes a new label based on the value of 'i'
            assetClass.bsLabel[i] = new Sce.PlayStation.HighLevel.UI.Label();
            assetClass.bsLabel[i].HorizontalAlignment = HorizontalAlignment.Center;
            assetClass.bsLabel[i].VerticalAlignment = VerticalAlignment.Middle;
            assetClass.bsLabel[i].SetSize(80, 50);
            assetClass.bsLabel[i].Text = "Health:";
            assetClass.bsLabel[i].PivotType = PivotType.MiddleCenter;
            assetClass.panel.AddChildLast(assetClass.bsLabel[i]);
        }

        assetClass.bsLabel[0].SetPosition(50, 470);
        assetClass.bsLabel[1].SetPosition(610, 470);

        //defines the properties for the player monster
        /*assetClass.playerMonster.Width = 375;
        assetClass.playerMonster.Height = 400;
        assetClass.playerMonster.PivotType = PivotType.MiddleCenter;
        assetClass.playerMonster.SetPosition(175, 200);*/

        //defines the properties for the enemy monster
        /*assetClass.enemyMonster.Width = 375;
        assetClass.enemyMonster.Height = 400;
        assetClass.enemyMonster.PivotType = PivotType.MiddleCenter;
        assetClass.enemyMonster.SetPosition(775, 200);*/

        //defines the properties for the player health bar
        //assetClass.playerBar.SetSize(250, 50);
        //assetClass.playerBar.SetPosition(100, 469);

        //defines the properties for the enemy health bar
        /*assetClass.enemyBar.SetSize(250, 50);
        assetClass.enemyBar.SetPosition(670, 469);*/

        for(int i = 0; i < 3; i++)
        { 
            //makes a new die based on the value of 'i'
            assetClass.dice[i] = new ImageBox();
            assetClass.dice[i].Width = 250;
            assetClass.dice[i].Height = 120;
            assetClass.dice[i].PivotType = PivotType.MiddleCenter;
            assetClass.panel.AddChildLast(assetClass.dice[i]);
        }

        //assigns the position for each die
        assetClass.dice[0].SetPosition(475, 65);
        assetClass.dice[1].SetPosition(475, 200);
        assetClass.dice[2].SetPosition(475, 332);

        //defines the properties for the roll button
        assetClass.button.Width = 300;
        assetClass.button.Height = 100;
        assetClass.button.PivotType = PivotType.MiddleCenter;
        assetClass.button.SetPosition(475, 469);
        assetClass.button.IconImage = new ImageAsset("/Application/Images/Buttons/RollButton.png");
        assetClass.button.Style = ButtonStyle.Custom;
        assetClass.button.TouchEventReceived += (sender, e) => {
            //changes the scene to the result scene
            sceneClass.sceneSelect("result");
            //hides the panel
            //assetClass.panel.Visible = false;
            assetClass.panel.RemoveChild(assetClass.title);
            //calls the set die function from the diceclass
            diceClass.setDie(bsNumber[0], bsNumber[1], bsNumber[2]);
            /*switch(characterScene.selectedMonster)
            {
                case 1:
                    dragonClass.Skills(bsNumber[0], bsNumber[1], bsNumber[2]);
                    break;

            }*/
            //skillClass.applyPoints(bsNumber[0], bsNumber[1], bsNumber[2]);
            //playerClass.playerSkill(characterScene.player);
        };

        //DamageCalculationClass.Damage();
        //EnemyClass.EnemyHealth();

        //assigns the assets to the panel
        assetClass.panel.AddChildLast(assetClass.button);

        //assigns the panel to the UI scene
        sceneClass.battleScene.RootWidget.AddChildLast(assetClass.panel);
        Director.Instance.GL.Context.SetClearColor(0, 0, 0, 0);
    }
}
}

结果场景类;

using System;
using System.Threading;
using System.Diagnostics;
using System.Collections.Generic;

using Sce.PlayStation.Core;
using Sce.PlayStation.Core.Imaging;
using Sce.PlayStation.Core.Environment;
using Sce.PlayStation.Core.Graphics;
using Sce.PlayStation.Core.Input;
using Sce.PlayStation.HighLevel.GameEngine2D;
using Sce.PlayStation.HighLevel.GameEngine2D.Base;
using Sce.PlayStation.HighLevel.UI;

namespace MonsterKombat_v3
{
public class resultScene : Sce.PlayStation.HighLevel.GameEngine2D.Scene
{
    public resultScene()
    {
        //defines 3 variables that define random numbers for each die
        //3 ints used to calculate a random number between 1-6 for each die
        var rsDice = new Random();
        int[] rsNumber = new int[3];
        rsNumber[0] = (rsDice.Next() % 6) + 1;
        rsNumber[1] = (rsDice.Next() % 6) + 1;
        rsNumber[2] = (rsDice.Next() % 6) + 1;

        assetClass.panel2.Width = Director.Instance.GL.Context.GetViewport().Width;
        assetClass.panel2.Height = Director.Instance.GL.Context.GetViewport().Height;           

        for(int i = 0; i < 6; i++)
        { 
            //makes a new button based on the value of 'i'
            assetClass.sButton[i] = new Button();
            assetClass.sButton[i].Width = 300;
            assetClass.sButton[i].Height = 100;
            assetClass.sButton[i].PivotType = PivotType.MiddleCenter;
            assetClass.sButton[i].IconImage = new ImageAsset("/Application/Images/Buttons/SkillButton.png");
            assetClass.sButton[i].Style = ButtonStyle.Custom;
            assetClass.sButton[i].TouchEventReceived += (sender, e) => 
                sceneClass.sceneSelect("battle");
            assetClass.panel2.AddChildLast(assetClass.sButton[i]);
        }

        //assigns the position of each button
        assetClass.sButton[0].SetPosition(920, 90);
        assetClass.sButton[1].SetPosition(920, 155);
        assetClass.sButton[2].SetPosition(920, 220);
        assetClass.sButton[3].SetPosition(920, 285);
        assetClass.sButton[4].SetPosition(920, 350);
        assetClass.sButton[5].SetPosition(920, 415);

        for(int i = 0; i < 3; i++)
        { 
            //makes a new die based on the value of 'i'
            assetClass.dice[i] = new ImageBox();
            assetClass.dice[i].Width = 250;
            assetClass.dice[i].Height = 120;
            assetClass.dice[i].PivotType = PivotType.MiddleCenter;
            assetClass.panel2.AddChildLast(assetClass.dice[i]);
        }

        assetClass.dice[0].SetPosition(125, 65);
        assetClass.dice[1].SetPosition(125, 200);
        assetClass.dice[2].SetPosition(125, 332);

        //SkillClass.ApplySkill();

        //assigns the panel to the UI scene
        sceneClass.resultScene.RootWidget.AddChildLast(assetClass.panel2);
        //clears the screen to a specific colour
        Director.Instance.GL.Context.SetClearColor(255, 0, 0, 0);
    }
}
}
抱歉这一团糟,但我是新来的。顺便说一句,我正在PSM工作室制作游戏,因此存在一些语法差异的原因。

0 个答案:

没有答案