Ejemplo n.º 1
0
        static void Start(ref Map map, ref Player player)
        {
            List <string> menuItems = new List <string>();
            int           choice;

            do
            {
                Console.Clear();
                choice = ShowMenu(map, ref menuItems, player);
                Dictionary <string, Objects> list = map.GetLocation().GetItems();
                Objects[] obj = list.Values.ToArray();

                if (choice != menuItems.Count())
                {
                    if (validDirections.Contains(menuItems[choice]))
                    {
                        Console.Clear();
                        Console.WriteLine("Your are now leaving the " + map.GetLocation().GetName());
                        Console.ReadKey();
                        map.GetLocation().firstime = false;
                        map.Move(menuItems[choice]);
                    }
                    switch (menuItems[choice])
                    {
                    case ACTION_SEARCH:
                        if (player.lookItem(map, 0))
                        {
                            player.PickupItem(obj[0]);
                            info.infoText = (obj[0].GetName() + " \t\tHas had to your inventory");
                        }
                        break;

                    case ACTION_SPEAK:
                        map.GetLocation().GetActor().Text(player);
                        break;

                    case ACTION_SPECIFIC:
                        if (player.GetMoney() >= 600)
                        {
                            Console.Clear();
                        }
                        break;
                    }
                }
            }while (choice < menuItems.Count() - 1);
        }
Ejemplo n.º 2
0
        // This Method builds the menu
        static int ShowMenu(Map map, ref List <string> menu, Player player)
        {
            int            selectPosition = 0;
            ConsoleKeyInfo keyinfo;

            menu.Clear();
            ShowDirections(map, ref menu);

            if (map.GetLocation().CheckForItems())
            {
                bool acquirableitems = false;
                Dictionary <string, Objects> list = map.GetLocation().GetItems();
                Objects[] obj = list.Values.ToArray();
                for (int i = 0; i < obj.Count(); i++)
                {
                    if (obj[i].GetAcquirable())
                    {
                        acquirableitems = true;
                    }
                }
                if (acquirableitems)
                {
                    menu.Add(ACTION_SEARCH);
                }
            }
            if (map.GetLocation().HasPeople())
            {
                menu.Add(ACTION_SPEAK);
                //menu.Add( ACTION_SPECIFIC );
            }
            if (map.GetLocation().specificAction)
            {
                menu.Add(ACTION_SPECIFIC);
            }
            menu.Add(ACTION_QUIT);


            do
            {
                Console.Clear();
                if (map.GetLocation().firstime)
                {
                    map.GetLocation().Description();
                }
                else
                {
                    Console.WriteLine("welcom back to {0}", map.GetLocation().GetName());
                }
                for (int i = 0; i < menu.Count(); i++)
                {
                    if (i == selectPosition)
                    {
                        Console.WriteLine("<{0}>", menu[i]);
                    }
                    else
                    {
                        Console.WriteLine(" {0} ", menu[i]);
                    }
                }
                //gMap(map);
                if (info.infoText != "")
                {
                    info.AddInfoMessage();
                    info.infoText = "";
                }
                Console.WriteLine("money : {0}", player.GetMoney());

                keyinfo = Console.ReadKey();
                if (keyinfo.Key == ConsoleKey.DownArrow && selectPosition != menu.Count - 1)
                {
                    selectPosition++;
                }
                else if (keyinfo.Key == ConsoleKey.UpArrow && selectPosition != 0)
                {
                    selectPosition--;
                }
                else if (keyinfo.Key == ConsoleKey.E)
                {
                    if (!player.ShowInventoryMenu())
                    {
                        info.infoText = ("Sorry there are none items in your inventory");
                    }
                }
                //Console.Beep();
            } while (keyinfo.Key != ConsoleKey.Enter);
            return(selectPosition);

            //return choice;
        }