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++; } }
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()); } }
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(); }
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(); }
private void _view_Touch(object sender, View.TouchEventArgs e) { if (_worldGen != null) { _view.SetLoadedWorld(_worldGen.GetWorld()); _view.Touch -= _view_Touch; return; } if (e.Event.Action == MotionEventActions.Up) { _view.TapTap(e.Event.GetX(), e.Event.GetY(), _rowsSeekBar.Progress, _rankSeekBar.Progress, GetUnitType()); _totalInSquadEditText.Text = (_rankSeekBar.Progress * _rowsSeekBar.Progress).ToString(); _totalUnitsEditText.Text = _view.Army.Size.ToString(); UpdateSelectors(); } }
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; }
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); }