Ejemplo n.º 1
0
        public static void LoadUnitsFromFile(this WorldsGenerator worldGen, string fname, bool android = false)
        {
            if (android)
            {
                var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                fname = Path.Combine(path, fname);
            }

            var lines = File.ReadAllLines(fname, Encoding.Unicode);

            if (lines.Length < 0)
            {
                return;
            }

            var world = worldGen.GetWorld();

            world.Army.Clear();

            int y = 0;

            foreach (var line in lines)
            {
                int x = 0;
                if (y >= world.Length)
                {
                    break;
                }

                foreach (var c in line)
                {
                    if (x >= world.Width)
                    {
                        break;
                    }

                    switch (c)
                    {
                    case 'a': worldGen.CreateUnit(UnitType.Archer, Team.Blue, y, x); break;

                    case 's': worldGen.CreateUnit(UnitType.SwordsMan, Team.Blue, y, x); break;

                    case 'h': worldGen.CreateUnit(UnitType.HorseMan, Team.Blue, y, x); break;

                    case 'A': worldGen.CreateUnit(UnitType.Archer, Team.Red, y, x); break;

                    case 'S': worldGen.CreateUnit(UnitType.SwordsMan, Team.Red, y, x); break;

                    case 'H': worldGen.CreateUnit(UnitType.HorseMan, Team.Red, y, x); break;

                    case ' ': break;

                    default: throw new InvalidOperationException("Unknown unit type " + c);
                    }
                    x++;
                }
                y++;
            }
        }
Ejemplo n.º 2
0
        public void GenerateEnemies(WorldsGenerator generator)
        {
            generator.AddUnitSquare(Team.Blue, 8, 8, 8, 8, UnitType.HorseMan, 64);
            generator.AddUnitSquare(Team.Blue, 8, 48, 8, 8, UnitType.HorseMan, 64);

            generator.AddUnitSquare(Team.Blue, 8, 24, 16, 8, UnitType.Archer, 128);

            generator.AddUnitSquare(Team.Blue, 24, 16, 16, 8, UnitType.SwordsMan, 128);
            generator.AddUnitSquare(Team.Blue, 24, 32, 16, 8, UnitType.SwordsMan, 128);
        }
Ejemplo n.º 3
0
        private void buttonTerrainLoad_Click(object sender, EventArgs e)
        {
            var dialog = new OpenFileDialog();

            dialog.Filter = "*.terr|*.terr|*.*|*.*";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                WorldGen = SaveLoadHelper.LoadTerrainFromFile(dialog.FileName);
                SetWorld(WorldGen.GetWorld());
            }
        }
Ejemplo n.º 4
0
        private void buttonGenerateWorld_Click(object sender, EventArgs e)
        {
            int x = Int32.Parse(textBoxWorldX.Text);
            int y = Int32.Parse(textBoxWorldY.Text);

            WorldGen = WorldsGenerator.GetDefault(y, x);

            var world = WorldGen.GetWorld();

            SetWorld(world);
            _render.UpdateBackgroundImage(world);

            SetPaused(true);
        }
        public MainForm()
        {
            InitializeComponent();

            WorldGen           = WorldsGenerator.GetDefault(64, 64);
            textBoxWorldX.Text = "64";
            textBoxWorldY.Text = "64";

            SetWorld(WorldGen.GetWorld());

            _gfx = Graphics.FromImage(image);

            UpdateDrawMode();
        }
Ejemplo n.º 6
0
        public MainForm()
        {
            InitializeComponent();

            WorldGen           = WorldsGenerator.GetDefault(64, 64);
            textBoxWorldX.Text = "64";
            textBoxWorldY.Text = "64";

            SetWorld(WorldGen.GetWorld());


            _render.UpdateBackgroundImage(World);
            UpdateDrawMode();
            pictureBox1.Image = _render.GetImage();
        }
 protected override void OnCreate(Bundle savedInstanceState)
 {
     base.OnCreate(savedInstanceState);
     SetContentView(Resource.Layout.PrepareView);
     _somethingButton      = FindViewById <Button>(Resource.Id.doSomethingButton);
     _rowsSeekBar          = FindViewById <SeekBar>(Resource.Id.rowsSeekBar);
     _rankSeekBar          = FindViewById <SeekBar>(Resource.Id.rankSeekBar);
     _totalUnitsEditText   = FindViewById <TextView>(Resource.Id.totalUnits);
     _totalInSquadEditText = FindViewById <TextView>(Resource.Id.totalInSquad);
     _rowText     = FindViewById <TextView>(Resource.Id.rowText);
     _rankText    = FindViewById <TextView>(Resource.Id.rankText);
     _topLayout   = FindViewById <LinearLayout>(Resource.Id.topLayout);
     _cocosLayout = FindViewById <LinearLayout>(Resource.Id.cocosLayout);
     _spinner     = FindViewById <Spinner>(Resource.Id.squadTypeSpinner);
     _view        = new MyView(_cocosLayout.Context);
     _cocosLayout.AddView(_view);
     _rowsSeekBar.Max              = 15;
     _rankSeekBar.Max              = 15;
     _rowsSeekBar.ProgressChanged += _rankSeekBar_ProgressChanged;
     _rankSeekBar.ProgressChanged += _rankSeekBar_ProgressChanged;
     _somethingButton.Click       += _somethingButton_Click;
     _totalInSquadEditText.Text    = (_rankSeekBar.Progress * _rowsSeekBar.Progress).ToString();
     _totalUnitsEditText.Text      = _view.Army.Size.ToString();
     Forms.Init(this, savedInstanceState);
     if (Intent.GetBooleanExtra("ISLOAD", false))
     {
         WorldGen = WorldsGenerator.GetDefault(MyView.SIZE * 3 / 2, MyView.SIZE);
         if (WorldGen.GetWorld().Width != MyView.SIZE)
         {
             WorldGen = null;
         }
         else
         {
             try
             {
                 WorldGen.LoadUnitsFromFile("units.units", true);
             }
             catch
             {
                 WorldGen = null;
             }
         }
     }
     _view.Touch += _view_Touch;
 }
        public static WorldsGenerator LoadTerrainFromFile(string fname, bool android = false)
        {
            if (android)
            {
                var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                fname = Path.Combine(path, fname);
            }

            var lines = System.IO.File.ReadAllLines(fname, Encoding.Unicode);

            var width  = lines[0].Length;
            var height = lines.Length;

            var WorldGen = WorldsGenerator.GetDefault(height, width);
            var World    = WorldGen.GetWorld();

            int x = 0;

            foreach (var line in lines)
            {
                int y = 0;
                if (x >= World.Width)
                {
                    break;
                }

                foreach (var c in line)
                {
                    if (y >= World.Length)
                    {
                        break;
                    }

                    if (c == 'm')
                    {
                        World.Terrain[x, y] = 1;
                    }
                    y++;
                }
                x++;
            }

            return(WorldGen);
        }
Ejemplo n.º 9
0
        public IWorld GenerateWorld()
        {
            var generator = WorldsGenerator.GetDefault(MyView.SIZE * 3 / 2, MyView.SIZE);

            foreach (var s in _squads)
            {
                for (var x = s.MinX; x < s.MaxX; x++)
                {
                    for (var y = s.MinY; y < s.MaxY; y++)
                    {
                        generator.CreateUnit(s.Type, s.Team, y + MyView.SIZE / 2, x);
                    }
                }
            }

            GenerateEnemies(generator);

            return(generator.GetWorld());
        }
        private void buttonGenerateWorld_Click(object sender, EventArgs e)
        {
            int x = Int32.Parse(textBoxWorldX.Text);
            int y = Int32.Parse(textBoxWorldY.Text);

            if (comboBoxPreset.SelectedIndex == -1)
            {
                WorldGen = WorldsGenerator.GetDefault(y, x);
            }
            else
            {
                WorldGen = WorldsGenerator.CreatePreset(y, x);
            }

            var world = WorldGen.GetWorld();

            SetWorld(world);
            SetPaused(true);
        }