Beispiel #1
0
        static void Main()
        {
            LinkedList <Bunny> bunnies = new LinkedList <Bunny>();

            Bunny[,] bunniesGrid = new Bunny[GridSize, GridSize];

            // Place a dragon on the grid. (Using the Bunny class). The dragon will be at least 2 spaces from the edges.
            dragonX = new Random().Next(2, GridSize - 2);
            dragonY = dragonX;

            Dragon dragon = new Dragon(RandomString(10));

            dragon.Direction = 0;
            bunnies.AddLast(dragon);
            bunniesGrid[dragonX, dragonY] = dragon;

            // Inializing the list, creating 8 bunnies. One male and one female for each Noble house.
            for (int i = 0; i < 8; i++)
            {
                string sex;
                if (i % 2 == 0)
                {
                    sex = "Male";
                }
                else
                {
                    sex = "Female";
                }

                string color = Enum.GetName(typeof(Color), new Random().Next(6));

                Bunny bunny = null;
                switch (i / 2)
                {
                case 0:
                    bunny = new Stark(sex, color, 0, RandomString(10));
                    break;

                case 1:
                    bunny = new Baratheon(sex, color, 0, RandomString(10));
                    break;

                case 2:
                    bunny = new Lannister(sex, color, 0, RandomString(10));
                    break;

                case 3:
                    bunny = new Targaryen(sex, color, 0, RandomString(10));
                    break;
                }

                bunnies.AddLast(bunny);
                PlaceBunnyOnGrid(bunniesGrid, bunny);
                PrintANewbornBunny(bunny);
            }

            PrintBunniesGrid(bunniesGrid);

            NextTurnController(bunnies, bunniesGrid);
        }
Beispiel #2
0
        // Load a saved game state from a json file.
        public static void LoadSavedGame(LinkedList <Bunny> bunnies, Bunny[, ] bunniesGrid)
        {
            // Clear current game data.
            bunnies.Clear();
            Array.Clear(bunniesGrid, 0, bunniesGrid.Length);

            // Deserialize the data from the json file.
            string json = File.ReadAllText(@"C:\Users\itiel\Desktop\BunnyWorldSavedGame.json");

            Bunny[,] savedBunniesGrid = JsonConvert.DeserializeObject <Bunny[, ]>(json);

            for (int x = 0; x < savedBunniesGrid.GetLength(0); x++)
            {
                for (int y = 0; y < savedBunniesGrid.GetLength(1); y++)
                {
                    if (savedBunniesGrid[x, y] != null)
                    {
                        Bunny bunny = null;
                        switch (savedBunniesGrid[x, y].HouseName)
                        {
                        case "Stark":
                            bunny = new Stark(savedBunniesGrid[x, y].sex, savedBunniesGrid[x, y].color, savedBunniesGrid[x, y].age, savedBunniesGrid[x, y].name);
                            break;

                        case "Baratheon":
                            bunny = new Baratheon(savedBunniesGrid[x, y].sex, savedBunniesGrid[x, y].color, savedBunniesGrid[x, y].age, savedBunniesGrid[x, y].name);
                            break;

                        case "Lannister":
                            bunny = new Lannister(savedBunniesGrid[x, y].sex, savedBunniesGrid[x, y].color, savedBunniesGrid[x, y].age, savedBunniesGrid[x, y].name);
                            break;

                        case "Targaryen":
                            bunny = new Targaryen(savedBunniesGrid[x, y].sex, savedBunniesGrid[x, y].color, savedBunniesGrid[x, y].age, savedBunniesGrid[x, y].name);
                            ((Targaryen)bunny).Invincible = savedBunniesGrid[x, y].Invincible;
                            break;

                        case "White Walker":
                            bunny = new WhiteWalker(savedBunniesGrid[x, y].age, savedBunniesGrid[x, y].name);
                            break;

                        case "Dragon":
                            bunny   = new Dragon(savedBunniesGrid[x, y].name);
                            dragonX = x;
                            dragonY = y;
                            ((Dragon)bunny).Direction = savedBunniesGrid[x, y].Direction;
                            break;
                        }
                        bunnies.AddLast(bunny);
                        bunniesGrid[x, y] = bunny;
                    }
                }
            }

            PrintBunniesGrid(bunniesGrid);

            NextTurnController(bunnies, bunniesGrid);
        }
Beispiel #3
0
        // Create a new baby bunny.
        private static void CreateABabyBunny(int motherX, int motherY, Bunny[,] bunniesGrid, Bunny fatherBunny, LinkedList <Bunny> bunnies)
        {
            Space emptySpace = GetASpaceFromSurrounding(motherX, motherY, bunniesGrid, true);

            if (emptySpace != null)
            {
                string sex;
                if (new Random().NextDouble() < 0.5)
                {
                    sex = "Male";
                }
                else
                {
                    sex = "Female";
                }

                Bunny babyBunny = null;

                string color;
                // 2% chance the bunny will be a white walker.
                if (new Random().NextDouble() < 0.98)
                {
                    color = bunniesGrid[motherX, motherY].color;

                    switch (fatherBunny.HouseName)
                    {
                    case "Stark":
                        babyBunny = new Stark(sex, color, 0, RandomString(10));
                        break;

                    case "Baratheon":
                        babyBunny = new Baratheon(sex, color, 0, RandomString(10));
                        break;

                    case "Lannister":
                        babyBunny = new Lannister(sex, color, 0, RandomString(10));
                        break;

                    case "Targaryen":
                        babyBunny = new Targaryen(sex, color, 0, RandomString(10));
                        break;
                    }
                }
                else
                {
                    babyBunny = new WhiteWalker(0, RandomString(10));
                }

                bunniesGrid[emptySpace.x, emptySpace.y] = babyBunny;
                bunnies.AddLast(babyBunny);
                PrintANewbornBunny(babyBunny);
            }
        }
Beispiel #4
0
        // Attack bunnies.
        private static void AttackBunnies(Bunny attackerBunny, int attackerX, int attackerY, Bunny[,] bunniesGrid, LinkedList <Bunny> bunnies)
        {
            // Get a space of a surrounding bunny to attack.
            Space victimBunnySpace = GetASpaceFromSurrounding(attackerX, attackerY, bunniesGrid, false);

            if (victimBunnySpace != null)
            {
                Bunny victimBunny = bunniesGrid[victimBunnySpace.x, victimBunnySpace.y];
                // Do something only if they're not from the same house. (Skip if victim is a dragon).
                if (victimBunny.HouseName != attackerBunny.HouseName && !(victimBunny is Dragon))
                {
                    // A Targaryen affected by the dragon wins every attack, as attacker or defender.
                    if (attackerBunny is Targaryen && ((Targaryen)attackerBunny).Invincible)
                    {
                        KillBunnyAtIndex(victimBunnySpace.x, victimBunnySpace.y, bunniesGrid, bunnies);
                    }
                    else if (victimBunny is Targaryen && ((Targaryen)victimBunny).Invincible)
                    {
                        KillBunnyAtIndex(attackerX, attackerY, bunniesGrid, bunnies);
                    }
                    else if (victimBunny is WhiteWalker)
                    {
                        // Turn the attacker bunny into a White Walker.
                        bunniesGrid[attackerX, attackerY] = null;
                        bunnies.Remove(attackerBunny);
                        Bunny whiteWalker = new WhiteWalker(attackerBunny.age, attackerBunny.name);
                        bunniesGrid[attackerX, attackerY] = whiteWalker;
                        bunnies.AddLast(whiteWalker);
                        if (!AutoTurns)
                        {
                            if (attackerBunny.sex == "Male")
                            {
                                Console.WriteLine("Lord {0} of bunny house {1} turned to a White! Kill him and burn his body!", attackerBunny.name, attackerBunny.HouseName);
                            }
                            else
                            {
                                Console.WriteLine("Lady {0} of bunny house {1} turned to a White! Kill her and burn her body!", attackerBunny.name, attackerBunny.HouseName);
                            }
                        }
                    }
                    else if (victimBunny.age < 2)
                    {
                        bunniesGrid[victimBunnySpace.x, victimBunnySpace.y] = null;
                        bunnies.Remove(victimBunny);
                        PrintADeadBunny(victimBunny);
                    }
                    // Attack on an adult female from another house.
                    else if (victimBunny.sex == "Female")
                    {
                        // Kill the mother.
                        bunniesGrid[victimBunnySpace.x, victimBunnySpace.y] = null;
                        bunnies.Remove(victimBunny);
                        PrintADeadBunny(victimBunny);

                        // Create a new bastard baby bunny in the mother space.
                        string sex;
                        if (new Random().NextDouble() < 0.5)
                        {
                            sex = "Male";
                        }
                        else
                        {
                            sex = "Female";
                        }

                        Bunny babyBunny = null;

                        string color;
                        // 2% chance the bunny will be a white walker.
                        if (new Random().NextDouble() < 0.98)
                        {
                            color = victimBunny.color;

                            switch (attackerBunny.HouseName)
                            {
                            case "Stark":
                                babyBunny = new Stark(sex, color, 0, RandomString(10));
                                break;

                            case "Baratheon":
                                babyBunny = new Baratheon(sex, color, 0, RandomString(10));
                                break;

                            case "Lannister":
                                babyBunny = new Lannister(sex, color, 0, RandomString(10));
                                break;

                            case "Targaryen":
                                babyBunny = new Targaryen(sex, color, 0, RandomString(10));
                                break;
                            }
                        }
                        else
                        {
                            babyBunny = new WhiteWalker(0, RandomString(10));
                        }

                        // Insert the newborn bastard instead of the mother.
                        bunniesGrid[victimBunnySpace.x, victimBunnySpace.y] = babyBunny;
                        bunnies.AddLast(babyBunny);
                        PrintANewbornBunny(babyBunny);
                    }
                    else
                    {
                        switch (attackerBunny.HouseName)
                        {
                        case "Stark":
                            if (victimBunny is Baratheon || victimBunny is Lannister)
                            {
                                KillBunnyAtIndex(attackerX, attackerY, bunniesGrid, bunnies);
                            }
                            else
                            {
                                KillBunnyAtIndex(victimBunnySpace.x, victimBunnySpace.y, bunniesGrid, bunnies);
                            }
                            break;

                        case "Baratheon":
                            if (victimBunny is Stark || victimBunny is Targaryen)
                            {
                                KillBunnyAtIndex(victimBunnySpace.x, victimBunnySpace.y, bunniesGrid, bunnies);
                            }
                            else
                            {
                                KillBunnyAtIndex(attackerX, attackerY, bunniesGrid, bunnies);
                            }
                            break;

                        case "Lannister":
                            if (victimBunny is Stark || victimBunny is Baratheon)
                            {
                                KillBunnyAtIndex(victimBunnySpace.x, victimBunnySpace.y, bunniesGrid, bunnies);
                            }
                            else
                            {
                                KillBunnyAtIndex(attackerX, attackerY, bunniesGrid, bunnies);
                            }
                            break;

                        case "Targaryen":
                            if (victimBunny is Stark || victimBunny is Baratheon)
                            {
                                KillBunnyAtIndex(attackerX, attackerY, bunniesGrid, bunnies);
                            }
                            else
                            {
                                KillBunnyAtIndex(victimBunnySpace.x, victimBunnySpace.y, bunniesGrid, bunnies);
                            }
                            break;
                        }
                    }
                }
            }
        }