public Elf(string name) : base(name) { Health = 4; Attacks.Add("Elven special", 2.5); Defends.Add("Potion", 2.5); Defends.Add("Confusion", 3); }
public IEnumerator evolve() { timer.pause(); yield return(new WaitForSeconds(1.0f)); Defends[] allDefs = new Defends[fileCount]; for (int i = 0; i < fileCount; i++) { StreamReader file = new StreamReader("Assets/kNNData/Defends/" + i + ".json"); allDefs[i] = JsonUtility.FromJson <Defends>(file.ReadToEnd()); file.Close(); } allDefs = sortDefends(allDefs); for (int i = survivors; i < survivors * 1.5f; i++) { allDefs[i] = combine(allDefs[i - survivors], allDefs[i - (survivors / 2)]); } for (int i = 0; i < fileCount; i++) { StreamWriter file = new StreamWriter("Assets/kNNData/Defends/" + i + ".json"); file.Write(JsonUtility.ToJson(allDefs[i])); file.Close(); } //yield return new WaitForSeconds(1.0f); foreach (ResetGame r in resets) { r.resume(); } timer.resume(); yield return(null); }
public override double Defend() { var x = Defends.ToList()[_random.Next(Attacks.Count - 1)]; Console.WriteLine(Name + " counters with " + x.Key + " for : " + x.Value); return(x.Value); }
/// <summary> /// packs the defend data into the json file /// </summary> /// <param name="def">the data to save</param> /// <param name="fileName">the file to save to</param> public void packIntoFile(Defends def, short fileName) { StreamWriter file = new StreamWriter("Assets/kNNData/Defends/" + fileName + ".json", false); file.Write(JsonUtility.ToJson(def)); file.Close(); }
public Wizard(string name) : base(name) { Health = 3; Attacks.Add("Wizard special", 2.5); Defends.Add("Summon", 2); Defends.Add("wand wave", 1.5); }
public void reload() { System.IO.StreamReader file = new System.IO.StreamReader("Assets/kNNData/Defends/" + defend_file + ".json"); defends = JsonUtility.FromJson <Defends>(file.ReadToEnd()); file.Close(); file = new System.IO.StreamReader("Assets/kNNData/Attacks/" + attack_file + ".json"); attacks = JsonUtility.FromJson <Attacks>(file.ReadToEnd()); file.Close(); }
/// <summary> /// Gets the data for the game from a json file /// </summary> void getFileData() { StreamReader file = new StreamReader("Assets/kNNData/Attacks/" + pathIn + ".json"); attacks = JsonUtility.FromJson <Attacks>(file.ReadToEnd()); file.Close(); file = new StreamReader("Assets/kNNData/Defends/" + pathIn + ".json"); defends = JsonUtility.FromJson <Defends>(file.ReadToEnd()); file.Close(); }
Defends[] sortDefends(Defends[] defends) { bool canExit = true; do { canExit = true; for (int i = 0; i < defends.Length - 1; i++) { if (defends[i].score < defends[i + 1].score) { Defends temp = defends[i]; defends[i] = defends[i + 1]; defends[i + 1] = temp; canExit = false; } } } while (!canExit); return(defends); }
Defends combine(Defends a, Defends b) { int expectedCount = (a.defends.Count + b.defends.Count) / 2; Defends combined = new Defends() { defends = new List <IODSetup>() }; foreach (IODSetup d in a.defends) { combined.defends.Add(d); } foreach (IODSetup d in b.defends) { combined.defends.Add(d); } while (combined.defends.Count > expectedCount) { combined.defends.RemoveAt(Random.Range(0, combined.defends.Count)); } return(combined); }
private void Awake() { string fileOut = ""; foreach (char c in gameObject.name) { if (char.IsDigit(c)) { fileOut += c; } } pathOut = short.Parse(fileOut); if (manyGames) { m_camera.rect = new Rect(0.1f * (pathOut / 10), 0.1f * (pathOut % 10), 0.1f, 0.1f); transform.position = new Vector3(40 * pathOut, 0, 0); } m.gsr = this; if (clear_files) { clearFiles(); } if (pathIn != -1) { getFileData(); } else { attacks = new Attacks() { attacks = new List <IOASetup>() }; defends = new Defends() { defends = new List <IODSetup>() }; } }