Exemplo n.º 1
0
        public GameSession()
        {
            // Create message log
            messageLog = new MessageLog();

            // Populate player object
            CurrentPlayer = new Player("Dom", 500, 500, 0, 1, 0);

            // Create new GUI dimensions
            gui = new GUI(100, 30);

            // Create new WorldFactory
            WorldFactory worldFactory = new WorldFactory();

            // Put it into CurrentWorld property
            CurrentWorld    = worldFactory.CreateWorld();
            CurrentLocation = CurrentWorld.GetLocation(0, 0);

            // Create new ActionFactory
            ActionFactory actionFactory = new ActionFactory();

            action       = actionFactory.CreateAction();
            battleAction = actionFactory.CreateBattleAction();


            CurrentPlayer.AddItemToInventory(ItemFactory.CreateItem(2001));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateItem(2002));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateItem(2003));
            CurrentPlayer.AddItemToInventory(ItemFactory.CreateItem(1001));

            CurrentPlayer.CurrentWeapon = CurrentPlayer.Inventory.Where(i => i.Type == Item.ItemType.Weapon).FirstOrDefault();
        }
Exemplo n.º 2
0
        public void Update(ConsoleKeyInfo input)
        {
            // Open Inventory
            if (input.KeyChar == action.GetKeybind("inventory") && CAN_OPEN_INVENTORY)
            {
                gui.OpenInventoryWindow();
            }
            // Trade
            if (input.KeyChar == action.GetKeybind("trade") && CAN_TRADE)
            {
                gui.OpenTradeWindow();
            }
            // Trade window logic
            if (gui.GetTradeWindowState())
            {
                // Switch between player and trader window
                if (input.KeyChar == action.GetKeybind("trader_side") || input.Key == ConsoleKey.RightArrow)
                {
                    gui.ChooseTraderTradeSide();
                    itemChoice = 0;
                }
                if (input.KeyChar == action.GetKeybind("player_side") || input.Key == ConsoleKey.LeftArrow)
                {
                    gui.ChoosePlayerTradeSide();
                    itemChoice = 0;
                }
                // Move up and down on the list
                if (input.Key == ConsoleKey.UpArrow && itemChoice > 0)
                {
                    itemChoice--;
                }
                if (input.Key == ConsoleKey.DownArrow)
                {
                    if (gui.GetTraderTradeSide() && itemChoice < CurrentTrader.Inventory.Count - 1)
                    {
                        itemChoice++;
                    }
                    else if (gui.GetPlayerTradeSide() && itemChoice < CurrentPlayer.Inventory.Count - 1)
                    {
                        itemChoice++;
                    }
                }
                // Select item from player and trader window
                if (gui.GetPlayerTradeSide())
                {
                    SelectedItemAction(CurrentPlayer, input);
                }
                if (gui.GetTraderTradeSide())
                {
                    SelectedItemAction(CurrentLocation.TraderHere, input);
                }
                // Selected item actions
                if (gui.GetItemSelectedState())
                {
                    // Visible on both windows
                    if (input.KeyChar == action.GetKeybind("cancel"))
                    {
                        gui.CloseItemSelected();
                    }
                    // Visible on player window
                    if (input.KeyChar == action.GetKeybind("sell") && gui.GetPlayerTradeSide())
                    {
                        SellSelectedItem();
                    }
                    // Visible on trader window
                    if (input.KeyChar == action.GetKeybind("buy") && gui.GetTraderTradeSide())
                    {
                        BuySelectedItem();
                    }
                }

                // Exit
                if (input.KeyChar == action.GetKeybind("exit") && !gui.GetItemSelectedState())
                {
                    gui.CloseTradeWindow();
                }
            }
            // Inventory window logic
            if (gui.GetInventoryWindowState())
            {
                if (!gui.GetItemSelectedState())
                {
                    // Open Misc Tab
                    if (input.KeyChar == action.GetKeybind("misc_tab"))
                    {
                        gui.MiscVisibility(true);
                    }
                    // Open Weapons Tab
                    if (input.KeyChar == action.GetKeybind("weapons_tab"))
                    {
                        gui.WeaponsVisibility(true);
                    }
                    // Close Inventory
                    if (input.KeyChar == action.GetKeybind("exit"))
                    {
                        gui.CloseInventoryWindow();
                    }
                }
                else
                {
                    // Equip selected weapon
                    if (input.KeyChar == action.GetKeybind("equip"))
                    {
                        EquipWeapon();
                        gui.CloseItemSelected();
                    }
                    // Remove item from inventory
                    if (input.KeyChar == action.GetKeybind("drop"))
                    {
                        DropItem();
                    }
                    // Close specific item option menu
                    if (input.KeyChar == action.GetKeybind("cancel"))
                    {
                        gui.CloseItemSelected();
                    }
                }
                SelectedItemAction(CurrentPlayer, input);
            }

            if (CAN_TRAVEL)
            {
                // Open Travel Menu
                if (input.KeyChar == action.GetKeybind("travel"))
                {
                    gui.OpenTravelWindow();
                }
                // Close Travel Menu
                if (input.KeyChar == action.GetKeybind("exit"))
                {
                    gui.CloseTravelWindow();
                }
                // Commence X Travel
                if (char.IsDigit(input.KeyChar) && gui.GetTravelWindowState()) // GetTravelWindow state shouldn't be here
                {
                    if (char.IsDigit(input.KeyChar))
                    {
                        int choice = 0;
                        choice = int.Parse(input.KeyChar.ToString()) - 1;
                        for (int i = 0; i < CurrentWorld.locations.Count; i++)
                        {
                            if (choice == CurrentWorld.locations[i].X && CurrentWorld.locations[i].Y == 0)
                            {
                                CurrentLocation = CurrentWorld.GetLocation(choice, 0);
                                messageLog.Add($"Travelling to {CurrentWorld.GetLocation(choice, 0).Name}...");
                                gui.CloseTravelWindow();
                            }
                        }
                    }
                }
            }


            // Location specific
            if (CAN_TRAVEL)
            {
                if (CurrentLocation.X == 1)
                {
                    if (input.KeyChar == action.GetKeybind("blacksmith") && action.GetActionState("blacksmith"))
                    {
                        CurrentLocation = CurrentWorld.GetLocation(1, 1);
                    }
                    if (input.KeyChar == action.GetKeybind("market") && action.GetActionState("market"))
                    {
                        CurrentLocation = CurrentWorld.GetLocation(1, 2);
                    }
                }

                if (CurrentLocation.X == 2)
                {
                    if (input.KeyChar == action.GetKeybind("hunt") && action.GetActionState("hunt") && InCombat != true)
                    {
                        GetEnemyAtLocation();
                        gui.OpenBattleWindow();
                        InCombat = true;
                    }
                }
            }


            // Battle system
            if (InCombat)
            {
                if (input.KeyChar == battleAction.GetKeybind("attack") && battleAction.GetActionState("attack") && CurrentEnemy.Health > 0)
                {
                    CurrentPlayer.UseCurrentWeaponOn(CurrentEnemy);
                    CurrentEnemy.UseCurrentWeaponOn(CurrentPlayer);
                    KillReward();
                }
                if (input.KeyChar == action.GetKeybind("exit") && CurrentEnemy.Health <= 0)
                {
                    if (CurrentEnemy.Health <= 0)
                    {
                        InCombat = false;
                        gui.CloseBattleWindow();
                    }
                }
            }

            // Redraw
            gui.Render(this);
        }