Ejemplo n.º 1
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");
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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();
            }
        }