public void Nearest_Enemy() { Arena arena = new Arena(); Team red = arena.CreateTeam("Red"); Team blue = arena.CreateTeam("Blue"); Team green = arena.CreateTeam("Green"); red.AddArcher(1); blue.AddGoblin(2); green.AddPaladin(1); Unit[] t_red = red.Find(); Unit[] t_blue = blue.Find(); Unit[] t_green = green.Find(); t_red[0] = arena.SpawnUnit(t_red[0], 0, 1); t_blue[0] = arena.SpawnUnit(t_blue[0], 5, 5); t_blue[1] = arena.SpawnUnit(t_blue[1], 7, 7); t_green[0] = arena.SpawnUnit(t_green[0], 11, 11); t_red[0].SearchTarget(); t_blue[0].SearchTarget(); t_blue[1].SearchTarget(); t_green[0].SearchTarget(); Assert.That(t_red[0].Target, Is.EqualTo(t_blue[0])); Assert.That(t_blue[0].Target, Is.EqualTo(t_red[0])); Assert.That(t_blue[1].Target, Is.EqualTo(t_green[0])); Assert.That(t_green[0].Target, Is.EqualTo(t_blue[1])); }
public void archer_count_is_exact() { Arena a4 = new Arena(); Team t4 = a4.CreateTeam("RED"); t4.AddArcher(10); Assert.That(t4.UnitCount, Is.EqualTo(10)); }
public void gold_calculation() { Arena ag = new Arena(); Team tb = ag.CreateTeam("Blue"); Team tr = ag.CreateTeam("RED"); tb.AddArcher(5); tr.AddArcher(5); //50.0 tr.AddGoblin(10); //30.0 tr.AddPaladin(6); //75.0 }
public void unit_count_is_exact() { Arena a4 = new Arena(); Team t4 = a4.CreateTeam("RED"); t4.AddArcher(10); t4.AddPaladin(5); t4.AddGoblin(3); Assert.That(t4.UnitCount, Is.EqualTo(18)); }
public void team_limit_is_effective() { Arena a = new Arena(); Team t = a.CreateTeam("RED"); Team t1 = a.CreateTeam("Green"); t1.AddGoblin(125); Assert.Throws <ArgumentException>(() => t.AddArcher(126)); Assert.Throws <ArgumentException>(() => t1.AddGoblin(1)); Assert.Throws <ArgumentException>(() => t.AddPaladin(260)); }
public void add_an_archer() { Arena arena = new Arena(); Team t1 = arena.CreateTeam("RED"); t1.AddArcher(1); Unit[] tab = t1.Find(); Unit u = t1.FindUnitByName(tab[0].Name); Assert.That(u, Is.SameAs(tab[0])); }
/// <summary> /// Writte the different levels in a JSON /// </summary> internal void LevelWritte() { Dictionary <int, Arena> arenas = new Dictionary <int, Arena>(); string path = "../../../../res/HistoryMode.JSON"; Arena a = new Arena(); Team t = a.CreateTeam("red"); t.AddArcher(10); t.Acount = 10; arenas.Add(0, a); Arena a1 = new Arena(); Team t1 = a1.CreateTeam("red"); t1.AddGoblin(10); t.Gcount = 10; arenas.Add(1, a1); Arena a2 = new Arena(); Team t2 = a2.CreateTeam("red"); t2.AddDrake(10); t2.Dcount = 10; arenas.Add(2, a2); Arena a3 = new Arena(); Team t3 = a3.CreateTeam("red"); t3.AddPaladin(10); t3.Pcount = 10; arenas.Add(3, a3); Arena a4 = new Arena(); Team t4 = a4.CreateTeam("red"); t4.AddCatapult(10); t4.Ccount = 10; arenas.Add(4, a4); { JToken jToken = Serialize(arenas); using (FileStream fs = File.OpenWrite(path)) using (StreamWriter sw = new StreamWriter(fs)) using (JsonTextWriter jw = new JsonTextWriter(sw)) { jToken.WriteTo(jw); } } Console.WriteLine("serilization ended"); }
public void remove_unit_from_team() { Arena ab = new Arena(); Team t = ab.CreateTeam("Yellow"); t.AddArcher(2); Unit[] tab = t.Find(); Unit u = t.FindUnitByName(tab[0].Name); Assert.That(u, Is.SameAs(tab[0])); t.RemoveUnit(u); Assert.That(t.UnitCount, Is.EqualTo(1)); Assert.That(t.Acount, Is.EqualTo(1)); }
public void specific_spawn_location() { Arena arena = new Arena(); Team firstTeam = arena.CreateTeam("firstTeam"); firstTeam.AddArcher(2); Unit[] tab = firstTeam.Find(); Unit u = firstTeam.FindUnitByName(tab[0].Name); Unit u2 = firstTeam.FindUnitByName(tab[1].Name); Assert.Throws <ArgumentException>(() => u = arena.SpawnUnit(u, 0, 0)); Assert.Throws <ArgumentException>(() => u = arena.SpawnUnit(u, 2000, 0)); Assert.Throws <ArgumentException>(() => u = arena.SpawnUnit(u, 0, 20000)); u2 = arena.SpawnUnit(u2, 1, 1); Assert.Throws <ArgumentException>(() => u = arena.SpawnUnit(u, 1, 1)); }
public void team_is_wiped_when_there_is_no_unit_left() { Arena a = new Arena(); Team t = a.CreateTeam("RED"); Team t2 = a.CreateTeam("BLUE"); t.AddArcher(0); t.AddGoblin(1); t2.AddArcher(1); Unit[] tab = t.Find(); Unit u = t.FindUnitByName(tab[0].Name); t.RemoveUnit(u); Assert.That(t.UnitCount, Is.EqualTo(0)); Assert.That(t.IsWiped, Is.True); Assert.That(t2.UnitCount, Is.EqualTo(t2.Acount)); Assert.That(t2.UnitCount, Is.EqualTo(1)); Assert.That(t2.IsWiped, Is.False); }
public void serialization_of_arena() { Arena sut = new Arena(); Team team = sut.CreateTeam("red"); team.AddArcher(2); team.AddPaladin(2); JToken jToken = sut.Serialize(); Arena result = new Arena(jToken); IEnumerable <Team> teams = result.GetTeams(); Assert.That(teams.Count(), Is.EqualTo(1)); Assert.That(sut.TeamCount == 1); Assert.That(sut.Teams.ContainsKey("red")); Assert.That(sut.Teams.Count == result.Teams.Count); Assert.That(teams.All(t => t.Context == result)); }
public void serialize_a_team() { Arena arena = new Arena(); Team sut = arena.CreateTeam("blue"); sut.AddArcher(2); sut.AddBalista(2); sut.AddCatapult(2); sut.AddDrake(2); sut.AddGoblin(2); sut.AddPaladin(2); JToken jToken = sut.Serialize(); Team result = new Team(arena, jToken); IEnumerable <Unit> units = result.GetUnits(); Assert.That(units.Count(), Is.EqualTo(12)); Assert.That(units.Any(u => u.Life == 12.0 && u.Speed == 1.8)); Assert.That(units.All(u => u.Team == result)); }
public void PreGame() { Team blue = Arena.CreateTeam("blue"); Team red = Arena.CreateTeam("red"); Team green = null; Team yellow = null; string[] status = new string[8]; status[0] = "selected"; status[1] = "active"; status[2] = "inactive"; status[3] = "inactive"; status[4] = "none"; status[5] = "add"; status[6] = "1"; status[7] = "yes"; int[,] teamComposition = { { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 } }; double previous = GetCurrentTime(); while (Window.IsOpen && Status == "preGame") { double current = GetCurrentTime(); if (current - previous >= 0.0000025) { previous = current; Shape[] buttons = InitPreGame(status, teamComposition); Window.DispatchEvents(); status = _iHandler.HandlerPreGame(buttons, status); if (status[7] == "no") { for (int i = 0; i < status.Length; i++) { if (status[i] == "selected") { teamComposition = FillRandom(i, teamComposition); status[7] = "yes"; } } } if (status[2] == "inactiveTemp") { status[3] = "inactive"; status[2] = "active"; for (int i = 0; i < 6; i++) { teamComposition[2, i] = teamComposition[3, i]; } } if (status[2] == "inactive") { for (int i = 0; i < 6; i++) { teamComposition[2, i] = 0; } } if (status[3] == "inactive") { for (int i = 0; i < 6; i++) { teamComposition[3, i] = 0; } } if (status[2] == "active" && Arena.FindTeam("green") == false) { green = Arena.CreateTeam("green"); } else if (status[3] == "active" && Arena.FindTeam("yellow") == false) { yellow = Arena.CreateTeam("yellow"); } switch (status[4]) { case "archer": for (int i = 0; i < 4; i++) { if (status[i] == "selected" && IsValidToAddUnit(teamComposition, i, status) == true && status[5] == "add") { teamComposition[i, 0] += Int32.Parse(status[6]); } else if (status[i] == "selected" && status[5] != "add") { teamComposition[i, 0] -= Int32.Parse(status[6]); if (teamComposition[i, 0] < 0) { teamComposition[i, 0] = 0; } } } break; case "drake": for (int i = 0; i < 4; i++) { if (status[i] == "selected" && IsValidToAddUnit(teamComposition, i, status) == true && status[5] == "add") { teamComposition[i, 1] += Int32.Parse(status[6]); } else if (status[i] == "selected" && status[5] != "add") { teamComposition[i, 1] -= Int32.Parse(status[6]); if (teamComposition[i, 1] < 0) { teamComposition[i, 1] = 0; } } } break; case "gobelin": for (int i = 0; i < 4; i++) { if (status[i] == "selected" && IsValidToAddUnit(teamComposition, i, status) == true && status[5] == "add") { teamComposition[i, 2] += Int32.Parse(status[6]); } else if (status[i] == "selected" && status[5] != "add") { teamComposition[i, 2] -= Int32.Parse(status[6]); if (teamComposition[i, 2] < 0) { teamComposition[i, 2] = 0; } } } break; case "paladin": for (int i = 0; i < 4; i++) { if (status[i] == "selected" && IsValidToAddUnit(teamComposition, i, status) == true && status[5] == "add") { teamComposition[i, 3] += Int32.Parse(status[6]); } else if (status[i] == "selected" && status[5] != "add") { teamComposition[i, 3] -= Int32.Parse(status[6]); if (teamComposition[i, 3] < 0) { teamComposition[i, 3] = 0; } } } break; case "balista": for (int i = 0; i < 4; i++) { if (status[i] == "selected" && IsValidToAddUnit(teamComposition, i, status) == true && status[5] == "add") { teamComposition[i, 4] += Int32.Parse(status[6]); } else if (status[i] == "selected" && status[5] != "add") { teamComposition[i, 4] -= Int32.Parse(status[6]); if (teamComposition[i, 4] < 0) { teamComposition[i, 4] = 0; } } } break; case "catapult": for (int i = 0; i < 4; i++) { if (status[i] == "selected" && IsValidToAddUnit(teamComposition, i, status) == true && status[5] == "add") { teamComposition[i, 5] += Int32.Parse(status[6]); } else if (status[i] == "selected" && status[5] != "add") { teamComposition[i, 5] -= Int32.Parse(status[6]); if (teamComposition[i, 5] < 0) { teamComposition[i, 5] = 0; } } } break; default: break; } status[4] = "none"; } } if (Status != "preGame") { for (int i = 0; i < teamComposition.GetLength(1); i++) { switch (i) { case 0: red.AddArcher(teamComposition[0, i]); break; case 1: red.AddDrake(teamComposition[0, i]); break; case 2: red.AddGoblin(teamComposition[0, i]); break; case 3: red.AddPaladin(teamComposition[0, i]); break; case 4: red.AddBalista(teamComposition[0, i]); break; case 5: red.AddCatapult(teamComposition[0, i]); break; default: break; } } for (int i = 0; i < teamComposition.GetLength(1); i++) { switch (i) { case 0: blue.AddArcher(teamComposition[1, i]); break; case 1: blue.AddDrake(teamComposition[1, i]); break; case 2: blue.AddGoblin(teamComposition[1, i]); break; case 3: blue.AddPaladin(teamComposition[1, i]); break; case 4: blue.AddBalista(teamComposition[1, i]); break; case 5: blue.AddCatapult(teamComposition[1, i]); break; default: break; } } if (Arena.FindTeam("green") == true) { for (int i = 0; i < teamComposition.GetLength(1); i++) { switch (i) { case 0: green.AddArcher(teamComposition[2, i]); break; case 1: green.AddDrake(teamComposition[2, i]); break; case 2: green.AddGoblin(teamComposition[2, i]); break; case 3: green.AddPaladin(teamComposition[2, i]); break; case 4: green.AddBalista(teamComposition[2, i]); break; case 5: green.AddCatapult(teamComposition[2, i]); break; default: break; } } } if (Arena.FindTeam("yellow") == true) { for (int i = 0; i < teamComposition.GetLength(1); i++) { switch (i) { case 0: yellow.AddArcher(teamComposition[3, i]); break; case 1: yellow.AddDrake(teamComposition[3, i]); break; case 2: yellow.AddGoblin(teamComposition[3, i]); break; case 3: yellow.AddPaladin(teamComposition[3, i]); break; case 4: yellow.AddBalista(teamComposition[3, i]); break; case 5: yellow.AddCatapult(teamComposition[3, i]); break; default: break; } } } TeamCompo = teamComposition; //Arena.SpawnUnit(); } }