示例#1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            //Tools.Print(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width.ToString());
              // TODO: Add your initialization logic here
            mSprite = new Sprite();
            Console.WriteLine("Initializing Game1.Init stuff");
            base.Initialize();

            //window size

            //load user and pet into a session instance
            this.session = new CurrentSession();
            session.createUser();

            //add some food items to its inventory
            session.user.inventory.AddItem(new FoodFruit());
            session.user.inventory.AddItem(new FoodApple());

            //give him a pet
            session.addPet("PerfectPet");

            //TextBasedGame.GameMain(session);
        }
        /// <summary>
        /// Is the main initialization of the game
        /// </summary>
        public static void GameMain(CurrentSession session)
        {
            //debugging stuff

            //end debugging

            //Intro to the app
            Console.Title = Meta.name_ver;

            Console.BackgroundColor = defaultBG;
            Console.ForegroundColor = defaultFG;

            //Print intro line
            string welcomeString = "Welcome to the PET GAME version: {0}\n\n";
            string welcomeArg = Meta.ver;
            Tools.Print(ConsoleColor.Black, ConsoleColor.White, welcomeString, welcomeArg);

            //Creates a session instance with a default user
            //CurrentSession session = new CurrentSession();

            //user.inventory.AddItem(new FoodApple());
            //user.inventory.AddItem(new FoodMeat());

            //Intro message
            Tools.Print(newFG: ConsoleColor.DarkBlue,
                        newBG: ConsoleColor.Cyan,
                        text: "\nThis is the main loop for the game. \n" +
                            "It is here that you'll feed or fight your" +
                            "\npet in order to train the shit out of it" +
                            "\n\n\n\t\tBEGIN!\n");

            //main loop
            while (true)
            {
                //give the user a choice of actions.
                string choices = "\t[f]eed, [b]attle, [t]hrow, [s]tats or [q]uit.";
                KeyValuePair<string, string> action = getUserAction(choices);

                //feed the pet
                if (action.Value == "feed")
                {
                    //this is  a real shitty way of doing this. There
                    // shouldn't be a class all on its own... :(
                    FeedAction feeding = new FeedAction(session.user);

                    session.user.inventory.ShowInventory();

                    string choice = Tools.Prompt("Choose a key from your items to feed");
                    char charChoice = (char)choice[0];

                    feeding.FeedPet(session.pet, session.user.inventory.items[charChoice] as FoodType);
                    //feeding.FeedPet(yourPet, new FoodMeat());
                }
                //check stats of the current pet
                else if (action.Value == "stats")
                {
                    StatAction stats = new StatAction(session.user);
                    stats.CheckPetStats(session.pet);
                }

                else if (action.Value == "throw")
                {
                    Tools.Print(newBG:ConsoleColor.DarkRed, text:"You throw your pet against the wall\n");

                    session.pet.battle.TakeDamage(10);
                }

                else if (action.Value == "battle")
                {
                    Creature enemy = new Creature();

                    BattleAction battle = new BattleAction(session.user);
                    battle.BattlePet(session.pet, enemy);
                }

                //quit the main loop
                else if (action.Value == "quit")
                {
                    break;
                }

                //Tools.Print(newFG: ConsoleColor.Yellow, text:"This was the action chosen: {0}\n", vals:action);

            }

            //Wait for Key on exit
            Tools.Print(ConsoleColor.DarkRed,
                    ConsoleColor.DarkYellow,
                    "Press any key to exit {0}",
                    Meta.name_ver);
            Console.ReadKey();
        }