public static Resources ParseResources(string text) { Resources res = new Resources(); /* Resources ? Brimstone: 8793 Crystal: 8101 Essence: 1410 Granite: 16767 Power: 5381 */ List<string> lines = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (lines.Where(s => s.Trim().StartsWith("Brimstone:")).Any()) res.Brimstone = Convert.ToInt32(lines.Where(s => s.Trim().StartsWith("Brimstone: ")).First().Replace("Brimstone: ", "")); if (lines.Where(s => s.Trim().StartsWith("Crystal:")).Any()) res.Crystal = Convert.ToInt32(lines.Where(s => s.Trim().StartsWith("Crystal: ")).First().Replace("Crystal: ", "")); if (lines.Where(s => s.Trim().StartsWith("Essence:")).Any()) res.Essence = Convert.ToInt32(lines.Where(s => s.Trim().StartsWith("Essence: ")).First().Replace("Essence: ", "")); if (lines.Where(s => s.Trim().StartsWith("Granite:")).Any()) res.Granite = Convert.ToInt32(lines.Where(s => s.Trim().StartsWith("Granite: ")).First().Replace("Granite: ", "")); if (lines.Where(s => s.Trim().StartsWith("Power:")).Any()) res.Power = Convert.ToInt32(lines.Where(s => s.Trim().StartsWith("Power: ")).First().Replace("Power: ", "")); return res; }
public Resources(Resources resourcesToCopy) { Brimstone = resourcesToCopy.Brimstone; Crystal = resourcesToCopy.Crystal; Essence = resourcesToCopy.Essence; Granite = resourcesToCopy.Granite; Power = resourcesToCopy.Power; }
public static Resources operator -(Resources left, Resources right) { Resources result = new Resources(left); result.Brimstone -= right.Brimstone; result.Crystal -= right.Crystal; result.Essence -= right.Essence; result.Granite -= right.Granite; result.Power -= right.Power; return result; }
private void txtCurrentResources_TextChanged(object sender, EventArgs e) { string input = txtCurrentResources.Text; string formattedInput = ResourceParser.CleanInput(input); if (input != formattedInput) { txtCurrentResources.Text = formattedInput; return; } try { _currentRes = ResourceParser.ParseResources(txtCurrentResources.Text); dtpCurrentTime.Value = DateTime.Now; } catch { // Ignore parsing errors } CalculateResourcesGained(); }
private void txtStartingResources_TextChanged(object sender, EventArgs e) { string input = txtStartingResources.Text; string formattedInput = ResourceParser.CleanInput(input); if (input != formattedInput) { txtStartingResources.Text = formattedInput; return; } try { _startingRes = ResourceParser.ParseResources(txtStartingResources.Text); dtpStartTime.Value = DateTime.Now; txtStartingResources.ReadOnly = true; } catch { // Ignore parsing errors } }