コード例 #1
0
ファイル: GameData.cs プロジェクト: TimoTheeus/NvHbugfixing
    static public void ClientInitialize(List <Forest> trees, Player plyr)
    {
        Tile tile = new Tile();

        GameData.Player    = plyr;
        GameData.LevelGrid = new HexaGrid(30, 40, tile.Width, tile.Height, true, "levelGrid");
        for (int i = 0; i < LevelGrid.Columns; i++)
        {
            for (int j = 0; j < LevelGrid.Rows; j++)
            {
                if (i > (int)(LevelGrid.Columns * .25) && i < (int)(LevelGrid.Columns * .75))
                {
                    bool   ftile = false;
                    string id    = "";
                    foreach (Forest f in trees)
                    {
                        if (f.forestPoint.X == i && f.forestPoint.Y == j)
                        {
                            id    = f.ID;
                            ftile = true;
                            break;
                        }
                    }
                    if (ftile)
                    {
                        Forest f = new Forest(new Point(i, j));
                        f.gridPosition = new Point(i, j);
                        f.ID           = id;
                        GameData.LevelGrid.Add(f, i, j);
                        GameData.Buildings.Add(f);
                        forests.Add(f);
                    }
                    else
                    {
                        int  type = 1 + (int)(GameWorld.Random.NextDouble() * 7);
                        Tile t    = new Tile("environment" + type);
                        t.gridPosition = new Point(i, j);
                        GameData.LevelGrid.Add(t, i, j);
                    }
                }

                else
                {
                    int  type = 1 + (int)(GameWorld.Random.NextDouble() * 7);
                    Tile t    = new Tile("environment" + type);
                    t.gridPosition = new Point(i, j);
                    GameData.LevelGrid.Add(t, i, j);
                }
            }
        }
        Mine mine = new Mine();

        mine.gridPosition = new Point(4, 8);
        GameData.LevelGrid.replaceTile((Tile)GameData.LevelGrid.Objects[4, 8], mine, false);
        HumanityBase hBase = new HumanityBase();

        hBase.gridPosition = new Point(2, 11);
        hBase.Position     = GameData.LevelGrid.Objects[2, 11].Position;
        GameData.LevelGrid.Objects[2, 11] = hBase;
        GameData.Buildings.Add(hBase);
        GameData.Buildings.Add(mine);
        mine.HasBeenBuiltAction();

        SunlightTree sunlightTree = new SunlightTree();
        NatureBase   nBase        = new NatureBase();

        nBase.gridPosition        = new Point(GameData.LevelGrid.Columns - 2, GameData.LevelGrid.Rows - 11);
        sunlightTree.gridPosition = new Point(GameData.LevelGrid.Columns - 4, GameData.LevelGrid.Rows - 8);
        GameData.LevelGrid.replaceTile((Tile)GameData.LevelGrid.Objects[GameData.LevelGrid.Columns - 4, GameData.LevelGrid.Rows - 8], sunlightTree, false);
        nBase.Position = GameData.LevelGrid.Objects[GameData.LevelGrid.Columns - 2, GameData.LevelGrid.Rows - 11].Position;
        GameData.LevelGrid.Objects[GameData.LevelGrid.Columns - 2, GameData.LevelGrid.Rows - 11] = nBase;
        GameData.Buildings.Add(nBase);
        GameData.Buildings.Add(sunlightTree);
        sunlightTree.HasBeenBuiltAction();

        GameData.LevelObjects.Add(GameData.LevelGrid);

        if (GameData.Cursor != null)
        {
            GameData.LevelObjects.Remove(GameData.Cursor);
        }
        if (GameData.player.GetFaction == Player.Faction.humanity)
        {
            GameData.Cursor = new Cursor("humanityCursor");
            GameWorld.AssetLoader.PlayMusic("hMusic");
        }
        else
        {
            GameData.Cursor = new Cursor("natureCursor");
            GameWorld.AssetLoader.PlayMusic("nMusic");
        }
        GameData.LevelObjects.Add(GameData.Cursor);

        GameWorld.Camera.Bounds = new Rectangle(0 - (int)tile.Sprite.Center.X - (int)(0.5 * GameWorld.Screen.X), -(int)tile.Sprite.Center.Y -
                                                (int)(0.5 * GameWorld.Screen.Y), GameData.LevelGrid.GetWidth(), GameData.LevelGrid.GetHeight());
        GameWorld.Camera.Bounds = new Rectangle(0 - (int)tile.Sprite.Center.X, -(int)tile.Sprite.Center.Y,
                                                GameData.LevelGrid.GetWidth(), (GameData.LevelGrid.GetHeight()));
        if (plyr.GetFaction == Player.Faction.humanity)
        {
            //GameWorld.Camera.Pos = new Vector2(0, 0);
            GameWorld.Camera.Pos = new Vector2(-(int)tile.Sprite.Center.X, -(int)tile.Sprite.Center.Y);
        }
        else
        {
            GameWorld.Camera.Pos = new Vector2(-(int)tile.Sprite.Center.X, -(int)tile.Sprite.Center.Y);
            int y = GameData.LevelGrid.GetHeight();
            int x = GameData.LevelGrid.GetWidth();
            GameWorld.Camera.Pos = new Vector2(3380, 85);
        }

        selectedTile          = new SpriteGameObject("selectedTile", 0, "selectedTile", 1);
        selectedTile.Origin   = selectedTile.Sprite.Center;
        selectedTile.Position = new Vector2(-3000, -3000);
        GameData.LevelObjects.Add(selectedTile);



        //naturePlayer = new Player(Player.Faction.nature);
        //GameData.LevelObjects.Add(naturePlayer);
        GameData.LevelObjects.Add(player);
        //ResourceController = new ResourceController(1, 10, 10);
        //GameData.LevelObjects.Add(ResourceController);

        foreach (Unit u in GameData.Units.Objects)
        {
            if (u.Faction == Player.Faction.humanity)
            {
                u.Sprite.Color = Color.Red;
            }
            else
            {
                u.Sprite.Color = Color.Green;
            }
        }
    }
コード例 #2
0
    private void parseAction(string s)
    {
        string[] pairs = s.Split('$');
        if (pairs.Length > 1)
        {
            string sig = pairs[1].Substring(0, 4);
            if (sig.Equals("unit"))
            {
                string id = pairs[1].Substring(5, pairs[1].Length - 5);
                for (int i = 2; i < pairs.Length; i++)
                {
                    switch (pairs[i].Substring(0, 4))
                    {
                    case "move":
                        try
                        {
                            string[] coords = pairs[i].Substring(5, pairs[i].Length - 5).Split(',');
                            Unit     u      = ((Unit)(GameData.LevelObjects.Find(id)));
                            u.TargetPosition = new Vector2(float.Parse(coords[0]), float.Parse(coords[1]));
                            u.TargetUnit     = null;
                        }
                        catch (NullReferenceException e)
                        {
                            string[] coords = pairs[i].Substring(5, pairs[i].Length - 5).Split(',');
                            Unit     u      = ((Unit)(GameData.LevelObjects.Find(id)));
                            if (u != null)
                            {
                                u.TargetPosition = new Vector2(float.Parse(coords[0]), float.Parse(coords[1]));
                                //u.TargetUnit = null;
                            }
                            Console.WriteLine("null");
                        }
                        break;

                    case "targ":
                        try
                        {
                            string targID  = pairs[i].Substring(5, pairs[i].Length - 5);
                            Unit   theUnit = ((Unit)(GameData.LevelObjects.Find(id)));
                            Unit   targetU = (Unit)GameData.LevelObjects.Find(targID);
                            theUnit.SetTargetUnit(targID);
                        }
                        catch (NullReferenceException e) { }
                        break;

                    case "tgbd":
                        string bdtgID = pairs[i].Substring(5, pairs[i].Length - 5);
                        ((Unit)(GameData.LevelObjects.Find(id))).targetBuilding = (Building)GameData.Buildings.Find(bdtgID);
                        break;

                    case "buil":
                        //build
                        break;

                    case "damg":
                        try
                        {
                            string[] parameters = pairs[i].Substring(5, pairs[i].Length - 5).Split(',');
                            string   attackerID = parameters[1];
                            Unit     attacker   = (Unit)(GameData.LevelObjects.Find(attackerID));
                            ((Unit)(GameData.LevelObjects.Find(id))).DealDamage(int.Parse(parameters[0]), attacker);
                        }
                        catch (NullReferenceException e)
                        {
                            Console.WriteLine(e.ToString());
                        }
                        break;

                    case "dead":
                        try
                        {
                            GameData.Units.Remove(((Unit)(GameData.LevelObjects.Find(id))));
                        }
                        catch (NullReferenceException e) {
                            Console.WriteLine(e.ToString());
                        }
                        break;
                    }
                }
            }
            else if (sig.Equals("bdng"))
            {
                Building b        = null;
                bool     polytile = false;
                string   id       = pairs[1].Substring(5, pairs[1].Length - 5);
                for (int i = 2; i < pairs.Length; i++)
                {
                    switch (pairs[i].Substring(0, 4))
                    {
                    case "type":
                        string type = pairs[i].Substring(5, pairs[i].Length - 5);
                        switch (type)
                        {
                        case "NatureBarracks":
                            b = new NatureBarracks();
                            break;

                        case "HumanityBarrack":
                            b        = new HumanityBarrack();
                            polytile = true;
                            break;

                        case "SunlightTree":
                            b = new SunlightTree();
                            break;

                        case "NatureBase":
                            b        = new NatureBase();
                            polytile = true;
                            break;

                        case "HumanityBase":
                            b        = new HumanityBase();
                            polytile = true;
                            break;

                        case "Mine":
                            b = new Mine();
                            break;

                        case "WaterTree":
                            b = new WaterTree();
                            break;
                        }
                        break;

                    case "posi":
                        string[] coords = pairs[i].Substring(5, pairs[i].Length - 5).Split(',');
                        b.gridPosition = new Point(int.Parse(coords[0]), int.Parse(coords[1]));
                        break;

                    case "fnsh":

                        GameData.LevelGrid.replaceTile((Tile)GameData.LevelGrid.Objects[b.gridPosition.X, b.gridPosition.Y], b, false);
                        if (polytile)
                        {
                            ((PolyTileBuilding)b).AddQuadCoTiles();
                        }
                        GameData.Buildings.Add(b);
                        break;

                    case "damg":
                        try
                        {
                            string[] parameters = pairs[i].Substring(5, pairs[i].Length - 5).Split(',');
                            string   attackerID = parameters[1];
                            Unit     attacker   = (Unit)(GameData.LevelObjects.Find(attackerID));
                            ((Building)(GameData.Buildings.Find(id))).DealDamage(int.Parse(parameters[0]), attacker);
                        }
                        catch (NullReferenceException e)
                        {
                            Console.WriteLine(e.ToString());
                        }
                        break;

                    case "dead":
                        try
                        {
                            GameData.Buildings.Remove(((Building)(GameData.LevelObjects.Find(id))));
                        }
                        catch (NullReferenceException e) {
                            Console.WriteLine(e.ToString());
                        }
                        break;
                    }
                }
            }
            else if (sig.Equals("spel"))
            {
                Spell  spell = null;
                string id    = pairs[1].Substring(5, pairs[1].Length - 5);
                for (int i = 2; i < pairs.Length; i++)
                {
                    switch (pairs[i].Substring(0, 4))
                    {
                    case "type":
                        switch (pairs[i].Substring(5, pairs[i].Length - 5))
                        {
                        case "MeteorStorm":
                            spell = new MeteorStorm();
                            break;

                        case "SnowStorm":
                            spell = new SnowStorm();
                            break;

                        case "Spell":
                            spell = new Spell();
                            break;
                        }
                        break;

                    case "posi":
                        string[] coords = pairs[i].Substring(5, pairs[i].Length - 5).Split(',');
                        spell.Position = new Vector2(float.Parse(coords[0]), float.Parse(coords[1]));
                        break;
                    }
                }
                spell.ID = id;
                GameData.LevelObjects.Add(spell);
            }
            else if (sig.Equals("addu"))
            {
                Unit u;//$addu:10$type:HumanityWorker$posi:1080,420
                u = null;
                string id = pairs[1].Substring(5, pairs[1].Length - 5);

                for (int i = 2; i < pairs.Length; i++)
                {
                    switch (pairs[i].Substring(0, 4))
                    {
                    case "type":

                        switch (pairs[i].Substring(5, pairs[i].Length - 5))
                        {
                        case "HumanityWorker":
                            u = new HumanityWorker();
                            break;

                        case "NatureWorker":
                            u = new NatureWorker();
                            break;

                        case "Melee1":
                            string asset = "";
                            asset = "natureWolf";
                            if (GameData.player.OppositeFaction == Player.Faction.humanity)
                            {
                                asset = "chainsaw";
                            }
                            u = new Melee1(GameData.player.OppositeFaction, asset, id);
                            break;

                        case "Ranged":
                            asset = "natureWolf";
                            if (GameData.player.OppositeFaction == Player.Faction.humanity)
                            {
                                asset = "flamethrower";
                            }
                            u = new Ranged(GameData.player.OppositeFaction, asset, id);
                            break;

                        case "Melee2":
                            asset = "treeUnit";
                            if (GameData.player.OppositeFaction == Player.Faction.humanity)
                            {
                                asset = "flamethrower";
                            }
                            u = new Melee2(GameData.player.OppositeFaction, asset, id);
                            break;

                        case "FlameThrower":
                            u = new FlameThrower();
                            break;

                        case "Unicorn":
                            asset = "unicorn";
                            if (GameData.player.OppositeFaction == Player.Faction.humanity)
                            {
                                asset = "quad";
                            }
                            u = new Unicorn(GameData.player.OppositeFaction, asset, id);
                            break;

                        case "WoodCutter":
                            u = new WoodCutter();
                            break;

                        case "Unit":
                            u = new Unit();
                            break;
                        }
                        break;

                    case "posi":
                        string[] coords = pairs[i].Substring(5, pairs[i].Length - 5).Split(',');
                        u.Position = new Vector2(int.Parse(coords[0]), int.Parse(coords[1]));
                        break;
                    }
                }
                u.ID = id;
                GameData.Units.Add(u);
                GameData.unitIdIndex++;
            }
        }
    }
コード例 #3
0
ファイル: GameData.cs プロジェクト: TimoTheeus/NvHbugfixing
    public static void HostInitialize()
    {
        Tile tile = new Tile();
        //GameData.player.GetFaction = Player.Faction.nature;

        int idIndex = 0;

        GameData.LevelGrid = new HexaGrid(30, 40, tile.Width, tile.Height, true, "levelGrid");
        for (int i = 0; i < LevelGrid.Columns; i++)
        {
            for (int j = 0; j < LevelGrid.Rows; j++)
            {
                if (i > (int)(LevelGrid.Columns * .25) && i < (int)(LevelGrid.Columns * .75))
                {
                    switch (GameWorld.Random.Next(12))
                    {
                    case 0:
                        Forest f = new Forest(new Point(i, j));
                        f.gridPosition = new Point(i, j);
                        f.ID           = f.ID + idIndex.ToString();
                        idIndex++;
                        GameData.LevelGrid.Add(f, i, j);
                        forests.Add(f);
                        GameData.Buildings.Add(f);
                        break;

                    default:
                        int  type = 1 + (int)(GameWorld.Random.NextDouble() * 7);
                        Tile t    = new Tile("environment" + type);
                        t.gridPosition = new Point(i, j);
                        GameData.LevelGrid.Add(t, i, j);
                        break;
                    }
                }
                else
                {
                    int  type = 1 + (int)(GameWorld.Random.NextDouble() * 7);
                    Tile t    = new Tile("environment" + type);
                    t.gridPosition = new Point(i, j);
                    GameData.LevelGrid.Add(t, i, j);
                }
            }
        }
        Mine mine = new Mine();

        mine.gridPosition = new Point(4, 8);
        GameData.LevelGrid.replaceTile((Tile)GameData.LevelGrid.Objects[4, 8], mine, false);
        HumanityBase hBase = new HumanityBase();

        hBase.gridPosition = new Point(2, 11);
        hBase.Position     = GameData.LevelGrid.Objects[2, 11].Position;
        GameData.LevelGrid.Objects[2, 11] = hBase;
        hBase.AddQuadCoTiles();
        GameData.Buildings.Add(hBase);
        GameData.Buildings.Add(mine);
        mine.HasBeenBuiltAction();
        SunlightTree sunlightTree = new SunlightTree();
        NatureBase   nBase        = new NatureBase();

        nBase.gridPosition        = new Point(GameData.LevelGrid.Columns - 2, GameData.LevelGrid.Rows - 11);
        sunlightTree.gridPosition = new Point(GameData.LevelGrid.Columns - 4, GameData.LevelGrid.Rows - 8);
        GameData.LevelGrid.replaceTile((Tile)GameData.LevelGrid.Objects[GameData.LevelGrid.Columns - 4, GameData.LevelGrid.Rows - 8], sunlightTree, false);
        nBase.Position = GameData.LevelGrid.Objects[GameData.LevelGrid.Columns - 2, GameData.LevelGrid.Rows - 11].Position;
        GameData.LevelGrid.Objects[GameData.LevelGrid.Columns - 2, GameData.LevelGrid.Rows - 11] = nBase;
        nBase.AddQuadCoTiles();
        GameData.Buildings.Add(nBase);
        GameData.Buildings.Add(sunlightTree);
        sunlightTree.HasBeenBuiltAction();
        GameData.LevelObjects.Add(GameData.LevelGrid);

        GameWorld.Camera.Bounds = new Rectangle(0 - (int)tile.Sprite.Center.X, -(int)tile.Sprite.Center.Y,
                                                GameData.LevelGrid.GetWidth(), GameData.LevelGrid.GetHeight());
        GameWorld.Camera.Pos = new Vector2(-(int)tile.Sprite.Center.X, -(int)tile.Sprite.Center.Y);
        if (player.GetFaction == Player.Faction.humanity)
        {
            GameWorld.Camera.Pos = new Vector2(0, 0);
        }
        else
        {
            //GameWorld.Camera.Pos = new Vector2(-(int)tile.Sprite.Center.X, -(int)tile.Sprite.Center.Y);
            int y = GameData.LevelGrid.GetHeight();
            int x = GameData.LevelGrid.GetWidth();
            GameWorld.Camera.Pos = new Vector2(3380, 85);
        }

        selectedTile          = new SpriteGameObject("selectedTile", 0, "selectedTile", 1);
        selectedTile.Origin   = selectedTile.Sprite.Center;
        selectedTile.Position = new Vector2(-3000, -3000);
        GameData.LevelObjects.Add(selectedTile);

        if (GameData.Cursor != null)
        {
            GameData.LevelObjects.Remove(GameData.Cursor);
        }
        if (GameData.player.GetFaction == Player.Faction.humanity)
        {
            GameData.Cursor = new Cursor("humanityCursor");
            GameWorld.AssetLoader.PlayMusic("hMusic");
        }
        else
        {
            GameData.Cursor = new Cursor("natureCursor");
            GameWorld.AssetLoader.PlayMusic("nMusic");
        }



        GameData.LevelObjects.Add(GameData.Cursor);



        //naturePlayer = new Player(Player.Faction.nature);
        //GameData.LevelObjects.Add(naturePlayer);
        GameData.LevelObjects.Add(player);
        //ResourceController = new ResourceController(1, 10, 10) ;
        //GameData.LevelObjects.Add(ResourceController)
    }