source: 2015/26/MikkoL/JRPG/JRPG/JRPG/Overworld/MapData.cs @ 6281

Revision 6281, 2.0 KB checked in by mijoliim, 5 years ago (diff)

Wooo versionhallinta

Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Jypeli;
6
7public class MapData
8{
9    public static List<EnemyGroup> Enemies = new List<EnemyGroup>();
10    public static List<Image> _BackgroundImages = new List<Image>();
11
12    public static int StepsToAnEncounter { get; set; }
13    public static int EncounterProbability { get; set; }
14
15    public List<EnemyGroup> EnemiesList()
16    {
17        return Enemies;
18    }
19    public List<Image> BackgroundImages()
20    {
21        return _BackgroundImages;
22    }
23
24    public EnemyGroup PickRandomWeightedGroup(List<EnemyGroup> Probabilities, Random r)
25    {
26        int totalWeight = Probabilities.Sum(G => G.EncounterProbability);
27        int weightedPick = r.Next(totalWeight);
28        foreach (var item in Probabilities)
29        {
30            if (weightedPick < item.EncounterProbability)
31            {
32                return item;
33            }
34            weightedPick -= item.EncounterProbability;
35        }
36        throw new InvalidOperationException("List must have changed or list count is zero");
37    }
38
39
40    public void LoadMapDataFromString(string MapIndex)
41    {
42        if (MapIndex == "Test")
43        {
44            StepsToAnEncounter = 5;
45            EncounterProbability = 25;
46
47            EnemyBase TestMan = EnemyList.Testman();
48            EnemyBase TestMan2 = EnemyList.Testman();
49            TestMan2.Name = "test 2";
50            EnemyBase TestMan3 = EnemyList.Testman();
51            TestMan3.Name = "test 3";
52            EnemyBase TestMan4 = EnemyList.Testman();
53            TestMan4.Name = "test 4";
54            EnemyGroup Group = new EnemyGroup(100);
55
56            Group.AddEnemyToGroup(TestMan);
57            Group.AddEnemyToGroup(TestMan2);
58            Group.AddEnemyToGroup(TestMan3);
59            Group.AddEnemyToGroup(TestMan4);
60            Enemies.Add(Group);
61
62            _BackgroundImages.Add(Images.Backgrounds.Test);
63        }
64    }
65}
Note: See TracBrowser for help on using the repository browser.