Beispiel #1
0
 public void FocusNext()
 {
     Focused.RemoveFocus();
     Index = Index == Items.Count - 1 ? 0 : ++Index;
     Focused.Focus();
     Render.Update();
 }
Beispiel #2
0
        public void BuyFocused()
        {
            var focusedElement = Focus.Focused;

            if (focusedElement is Item)
            {
                var item = (Item)focusedElement;
                if (item.Price <= Score.Value)
                {
                    Score.Value -= item.Price;
                    item.Income += item.BaseIncome * item.IncomeMultiplier;
                    item.Amount++;
                    item.Price   = (decimal)Math.Pow(item.PriceIncrease, (int)item.Amount) * item.BasePrice;
                    TotalIncome += item.BaseIncome * item.IncomeMultiplier;
                    Render.Update();
                }
            }
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            var render     = new ConsoleRender();
            var score      = new Score();
            var click_data = new ClickData();

            var items = new List <Item> {
                new Item(10, 0.1m, "First Item"),
                new Item(50, 1.1m, "Second Item")
            };
            var   focus = new Focus(render);
            State state = new State(render)
            {
                ClickData = click_data,
                Score     = score,
                Items     = items,
                Focus     = focus
            };

            click_data.OnClick = (state) =>
            {
                state.Score.Value += click_data.ClickValue;
                click_data.TotalClicks++;
                render.Update();
            };
            render.Add(score);
            render.Add(state);
            render.Add(click_data);
            items.ForEach(item =>
            {
                render.Add(item);
                focus.Add(item);
            });
            render.Add(new Hints());
            new TimerBasedAction(1000, () =>
            {
                score.Value += state.TotalIncome;
                render.Update();
            }).Start();
            new Thread(
                new ThreadStart(() =>
            {
                Take_User_Input:
                var input = Console.ReadKey(true).Key;
                if (UserInputs.InputMap.TryGetValue(input, out Action <State> action))
                {
                    action.Invoke(state);
                    render.Update();
                }
                goto Take_User_Input;
            })
                ).Start();

            var _quitEvent = new ManualResetEvent(false);

            Console.CancelKeyPress += (sender, eArgs) => {
                _quitEvent.Set();
                eArgs.Cancel = true;
            };
            // kick off asynchronous stuff
            Console.BackgroundColor = ConsoleColor.DarkBlue;
            render.Update();
            _quitEvent.WaitOne();
        }