Ejemplo n.º 1
0
        public void setColony(string name)
        {
            Colony newColony = new Colony(name, this.fertility);

            this.colonies.Add(newColony);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            SoundPlayer sp = new SoundPlayer("soundtrack.wav");

            sp.PlayLooping();
            Game game = new Game();

            game.setTimer();

            game.generateGamePreset();
            string readMeText;

            using (StreamReader readtext = new StreamReader("logo.txt"))
            {
                readMeText = readtext.ReadToEnd();
                Console.Write(readMeText);
                Console.WriteLine("");
            }
            int cnt = 0;

            while (true)
            {
                String cmd;
                cmd = Console.ReadLine();

                if (cmd == "exit")
                {
                    break;
                }
                if (cnt == 2)
                {
                    Console.Clear();
                    Console.Write(readMeText);
                    Console.WriteLine("");
                    cnt = 0;
                }
                cnt++;
                switch (cmd)
                {
                case "back":
                    game.status.goBack();
                    break;

                case "create planet":
                    Console.WriteLine("enter planet name:");
                    string createName = Console.ReadLine();

                    Console.WriteLine("enter planet coordinates 'x y z' - float):");
                    string   coords  = Console.ReadLine();
                    string[] numbers = coords.Split(' ');
                    double   x       = Convert.ToDouble(numbers[0]);
                    double   y       = Convert.ToDouble(numbers[1]);
                    double   z       = Convert.ToDouble(numbers[2]);

                    Console.WriteLine("enter planet fertility 'iron gold spice' - integer):");
                    string   fert      = Console.ReadLine();
                    string[] fertility = fert.Split(' ');
                    int      iron      = Convert.ToInt32(fertility[0]);
                    int      gold      = Convert.ToInt32(fertility[1]);
                    int      spice     = Convert.ToInt32(fertility[2]);

                    game.addPlanet(createName, x, y, z, iron, gold, spice);

                    Console.WriteLine("planet created");
                    break;

                case "add colony":
                    Console.WriteLine("enter colony name:");
                    string newColonyName = Console.ReadLine();

                    game.addColony(newColonyName);

                    break;

                case "move to planet":
                    Console.WriteLine("enter planet name:");
                    string moveName = Console.ReadLine();
                    if (game.status.setDestination(moveName, game.planets))
                    {
                        Console.WriteLine("Set destination to " + moveName);
                    }
                    else
                    {
                        Console.WriteLine("No such planet");
                    }
                    break;

                case "move to colony":
                    Console.WriteLine("enter colony name:");
                    string colonyName = Console.ReadLine();
                    game.status.moveToColony(colonyName);
                    break;

                case "upgrade building":
                    Console.WriteLine("enter building name");
                    if (game.status.currentColony == null)
                    {
                        Console.WriteLine("Enter a colony first");
                    }
                    else
                    {
                        string name = Console.ReadLine();
                        game.status.currentColony.upgradeBuilding(name, game.status);
                    }
                    break;

                case "info":
                    game.status.getCurrentInfo(game.planets, game.mineTypes, new List <StatueType> {
                        game.statue
                    });
                    break;

                case "destroy planet":
                    Console.WriteLine("enter planet name:");
                    string destroyingPlanetName = Console.ReadLine();
                    game.destroyPlanet(destroyingPlanetName);
                    break;

                case "destroy colony":
                    Console.WriteLine("enter colony name:");
                    string destroyingColonyName = Console.ReadLine();
                    game.destroyColony(destroyingColonyName);
                    break;

                case "build mine":
                    Colony colony = game.status.currentColony;
                    if (colony == null)
                    {
                        Console.WriteLine("Not in a colony");
                    }
                    else
                    {
                        if (colony.buildingCount < colony.maxBuildings)
                        {
                            foreach (MineType t in game.mineTypes)
                            {
                                Console.WriteLine(t.Name + " Cost: " + t.cost.ToString());
                            }
                            Console.WriteLine("Enter mine type");
                            string name = Console.ReadLine();
                            foreach (MineType t in game.mineTypes)
                            {
                                if (t.Name == name)
                                {
                                    if (game.status.payResources(t.cost))
                                    {
                                        Console.WriteLine("Enter mine name");
                                        name = Console.ReadLine();
                                        colony.createBuilding(t, name);
                                        Console.WriteLine("Factory built");
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine("Max buildings capacity");
                        }
                    }

                    break;

                case "build statue":
                    Colony cur_colony = game.status.currentColony;
                    if (cur_colony == null)
                    {
                        Console.WriteLine("Not in a colony");
                    }
                    else
                    {
                        Console.WriteLine("enter statue name:");
                        string Name = Console.ReadLine();
                        if (game.status.payResources(game.statue.cost))
                        {
                            cur_colony.createBuilding(game.statue, Name);
                            Console.WriteLine("Statue built");
                        }
                        else
                        {
                            Console.WriteLine("Insufficient resources");
                        }
                    }
                    break;

                default:
                    Console.WriteLine("unknown command");
                    break;
                }
            }
        }