Beispiel #1
0
        public void Run()
        {
            _running = true;
            _state   = GameState.Setup;
            while (_running)
            {
                switch (_state)
                {
                case GameState.Setup:
                    if (_initialEvent)
                    {
                        _weather = new Weather(_settings);
                        _animator.SetWeather(_weather);
                        _animator.Render();
                        _initialEvent = false;
                    }
                    _animator.ReadInput();
                    Thread.Sleep(100);
                    break;

                case GameState.Transaction:
                    if (_initialEvent)
                    {
                        _transaction.SetUp(_players[_currentPlayer], _settings, _currentPlayer, _day, _weather,
                                           signCost, GlassCost);
                        _transaction.Render();
                        _initialEvent = false;
                    }
                    _transaction.ReadInput();
                    Thread.Sleep(100);
                    break;

                case GameState.Event:
                    if (_initialEvent)
                    {
                        _result.Setup(_players, _weather);
                        _result.Render();
                        _day++;
                        if (_players.Any(s => s.Budget < GlassCost))
                        {
                            Console.Clear();
                            IEnumerable <PlayerState> lost = _players.Where(s => s.Budget < GlassCost);
                            Console.WriteLine($"The following players are out: {string.Join(", ", lost.Select(s => s.Number.ToString()))}");
                            Thread.Sleep(2000);
                            Console.Clear();
                            _players.RemoveAll(s => lost.Contains(s));
                        }
                        DiffDraw.Draw(_settings.Color, true);
                        _initialEvent = false;
                    }
                    _result.ReadInput();
                    Thread.Sleep(100);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Beispiel #2
0
        private static TimeSpan Perform(bool smooth1, bool smooth2, bool color)
        {
            DiffDraw.Clear(0, 0);
            Renderer.Player.Clear();
            Pixel[,] init = new Pixel[1, 2];
            init.Populate(new Pixel());
            DiffDraw.Clear(init);
            DiffDraw.Draw(false, true);
            Stopwatch t = Stopwatch.StartNew();

            (char[,] level, _) =
                CharArrayLoader.LoadLevel(@"
#####################
#                 ###
#               ### #
#            # ##   #
#             #     #
#            ##     #
#####################", smooth1);
            DiffDraw.Clear(ColorSelector.Get(level));
            Renderer.Player.Add(new Tuple <Point, Point>(new Point(1, 2), new Point(0, 0)));
            Renderer.Player.Add(new Tuple <Point, Point>(new Point(2, 2), new Point(0, 0)));
            Renderer.Player.Add(new Tuple <Point, Point>(new Point(2, 3), new Point(0, 0)));
            Renderer.Player.Add(new Tuple <Point, Point>(new Point(1, 3), new Point(0, 0)));
            Renderer.Player.Add(new Tuple <Point, Point>(new Point(1, 4), new Point(0, 0)));
            Renderer.Player.Add(new Tuple <Point, Point>(new Point(1, 5), new Point(0, 0)));
            Renderer.Player.Add(new Tuple <Point, Point>(new Point(1, 6), new Point(0, 0)));
            Renderer.Player.Add(new Tuple <Point, Point>(new Point(2, 6), new Point(0, 0)));
            Renderer.Player.Add(new Tuple <Point, Point>(new Point(2, 5), new Point(0, 0)));
            Renderer.Player.Add(new Tuple <Point, Point>(new Point(2, 4), new Point(0, 0)));
            Renderer.Player.Add(new Tuple <Point, Point>(new Point(3, 4), new Point(0, 0)));
            Renderer.Player.Add(new Tuple <Point, Point>(new Point(3, 3), new Point(0, 0)));
            Renderer.Player.Add(new Tuple <Point, Point>(new Point(3, 2), new Point(0, 0)));
            Renderer.Player.Add(new Tuple <Point, Point>(new Point(4, 2), new Point(0, 0)));
            Renderer.Enemies.Add(new Point(5, 4));
            Renderer.Enemies.Add(new Point(5, 5));
            Renderer.Enemies.Add(new Point(5, 6));
            Renderer.Enemies.Add(new Point(6, 6));
            Renderer.Enemies.Add(new Point(7, 6));
            Renderer.Enemies.Add(new Point(7, 5));
            Renderer.Enemies.Add(new Point(7, 4));
            Renderer.Enemies.Add(new Point(6, 3));
            Renderer.Enemies.Add(new Point(5, 2));
            Renderer.Render(smooth2);
            DiffDraw.Draw(color);
            foreach (string t1 in Levels.levels)
            {
                (char[,] lvl, _) =
                    CharArrayLoader.LoadLevel(t1, SettingsMan.SmoothTerrain);
                DiffDraw.Clear(ColorSelector.Get(lvl));
                DiffDraw.Draw(true);
            }
            t.Stop();
            return(t.Elapsed);
        }
Beispiel #3
0
        public static void Perform()
        {
            Levels.Load();
            Console.Clear();
            Renderer.Enemies.Clear();
            Renderer.Labels.Clear();
            Renderer.Player.Clear();
            DiffDraw.Clear(21, 1);
            Label status = new Label(new Point(0, 0), "Snakity Bench running");

            Renderer.Labels.Add(status);
            Renderer.Render(false);
            Tuple <bool, bool, bool, TimeSpan>[] result = new[] { false, true }.SelectMany(b1 => new[] { false, true }, (b1, b2) => new { b1, b2 })
            .SelectMany(t => new[] { false, true }, (t, b3) => new { t, b3 })
            .Select(t => new Tuple <bool, bool, bool, TimeSpan>(t.t.b1, t.t.b2, t.b3, Perform(t.t.b1, t.t.b2, t.b3)))
            .OrderBy(s => s.Item4).ToArray();
            Console.Clear();
            Console.WriteLine("╔═Smooth1═╤═Smooth2═╤═Color═╤═Time═╗");
            bool color2 = false;

            foreach ((bool smooth1, bool smooth2, bool color, TimeSpan time) in result)
            {
                color2 = !color2;
                Console.BackgroundColor = color2 ? ConsoleColor.Black : ConsoleColor.White;
                Console.ForegroundColor = color2 ? ConsoleColor.White : ConsoleColor.Black;
                string tmp = time.TotalSeconds.ToString(CultureInfo.InvariantCulture);
                if (tmp.Length > 5)
                {
                    tmp = tmp.Remove(5);
                }
                else if (tmp.Length < 5)
                {
                    tmp += new string(' ', 6 - tmp.Length);
                }
                Console.WriteLine(
                    $"║    {(smooth1 ? "X" : " ")}    │    {(smooth2 ? "X" : " ")}    │   {(color ? "X" : " ")}   │{tmp}s║");
            }
            Console.ResetColor();
            Console.WriteLine("╚═Smooth1═╧═Smooth2═╧═Color═╧═Time═╝");
            Console.WriteLine();
            Console.WriteLine("Impact:");
            Console.WriteLine($"- Smooth1: {GetImpact(result, tuple => tuple.Item1)}s");
            Console.WriteLine($"- Smooth2: {GetImpact(result, tuple => tuple.Item2)}s");
            Console.WriteLine($"- Color:   {GetImpact(result, tuple => tuple.Item3)}s");
            Console.WriteLine();
            Console.WriteLine("Press any key to return");
            Console.ReadKey();
        }
Beispiel #4
0
 public void Render()
 {
     string[] lines = Text.Split('\n').Select(s => s.EndsWith('\r') ? s.Remove(s.Length - 1) : s).ToArray();
     for (int i = 0; i < lines.Length; i++)
     {
         for (int j = 0; j < lines[i].Length; j++)
         {
             int tmpX = Position.X + j;
             int tmpY = Position.Y + i;
             if (tmpX < DiffDraw.Width && tmpY < DiffDraw.Height)
             {
                 DiffDraw.Set(tmpX, tmpY, ColorSelector.Get(lines[i][j]));
             }
         }
     }
 }
Beispiel #5
0
        private static void PlayRound()
        {
            Console.Clear();
            bool playing = true;

            Pixel[,] init = new Pixel[1, 2];
            init.Populate(new Pixel());
            DiffDraw.Clear(init);
            DiffDraw.Draw(false);
            Label scoreLabel = new Label(new Point(0, 0), "");

            Renderer.Labels.Clear();
            Renderer.Labels.Add(scoreLabel);
            Levels.Load();
            (char[,] level, bool[,] spawnable) =
                CharArrayLoader.LoadLevel(Levels.levels[Rnd.Next(Levels.levels.Length)], SettingsMan.SmoothTerrain);
            bool hasIncreased = false;

            Renderer.Player.Clear();
            Renderer.Player.Add(new Tuple <Point, Point>(new Point(1, 1), new Point(0, 1)));
            Renderer.Enemies.Clear();
            DiffDraw.Clear(ColorSelector.Get(level));
            DiffDraw.Draw(SettingsMan.Color);
            Input.Reset();
            while (playing)
            {
                DiffDraw.Clear(ColorSelector.Get(level));
                scoreLabel.Text = $"Score: {_score}";
                Renderer.Render(SettingsMan.SmoothPlayer);
                Input.Get();
                if (Input.Move(hasIncreased) || Input.Esc)
                {
                    Renderer.Player.Clear();
                    Input.Reset();
                    playing   = false;
                    Input.Esc = false;
                    continue;
                }

                if (Input.R)
                {
                    _score = 0;
                    init.Populate(new Pixel());
                    DiffDraw.Clear(init);
                    DiffDraw.Draw(SettingsMan.Color);
                    Console.Clear();
                    (level, spawnable) = CharArrayLoader.LoadLevel(Levels.levels[Rnd.Next(Levels.levels.Length)], SettingsMan.SmoothTerrain);
                    DiffDraw.Clear(ColorSelector.Get(level));
                    Renderer.Player.Clear();
                    Renderer.Player.Add(new Tuple <Point, Point>(new Point(2, 2), new Point(0, 1)));
                    Renderer.Enemies.Clear();
                    Input.Reset();
                    Input.R = false;
                }

                Renderer.Render(SettingsMan.SmoothPlayer);
                hasIncreased = Enemy.Compute(spawnable);
                if (hasIncreased)
                {
                    _score++;
                }
                DiffDraw.Draw(SettingsMan.Color);
            }
            Console.ResetColor();
        }
Beispiel #6
0
        public void Configure()
        {
            CenteredScreen settingsScreen = new CenteredScreen(200, 20, ConsoleColor.Black, Color)
            {
                TabPoint = 0,
                Title    = "Lemonade - Settings"
#if DEBUG
                           + "[R to redraw]"
#endif
            };
            Panel scr = settingsScreen.ContentPanel;

            scr.ForeColor = ConsoleColor.DarkGray;

            Label playerLabel = new Label("Players");

            playerLabel.Point = new Point(scr.Size.Width / 2 - playerLabel.Content.Length / 2, 3);
            scr.Controls.Add(playerLabel);

            Slider playerSlider = new Slider {
                MinValue = 1, Value = 2, Size = new Size(100, 1)
            };

            playerSlider.Point = new Point(scr.Size.Width / 2 - playerSlider.Size.Width / 2, 4);
            scr.Controls.Add(playerSlider);

            Label difficultyLabel = new Label("Difficulty");

            difficultyLabel.Point = new Point(scr.Size.Width / 2 - difficultyLabel.Content.Length / 2, 7);
            scr.Controls.Add(difficultyLabel);

            Slider difficulty = new Slider {
                Value = 5, Size = new Size(100, 1)
            };

            difficulty.Point = new Point(scr.Size.Width / 2 - difficulty.Size.Width / 2, 8);
            scr.Controls.Add(difficulty);

            CheckBox colorBox = new CheckBox("Color")
            {
                Checked = true
            };

            colorBox.Point           = new Point(scr.Size.Width / 2 - (colorBox.Content.Length + 4) / 2, 12);
            colorBox.CheckedChanged += (screen, args) => { settingsScreen.Color = colorBox.Checked; };
#if DEBUG
            settingsScreen.Input += (screen, args) =>
            {
                if (args.Info.Key == ConsoleKey.R)
                {
                    DiffDraw.Draw(Color, true);
                }
            };
#endif
            scr.Controls.Add(colorBox);

            Button okButton = new Button("OK");
            okButton.Point = new Point(scr.Size.Width / 2 - okButton.Content.Length / 2, 16);
            scr.Controls.Add(okButton);

            bool visible = true;
            okButton.Click       += (screen, args) => visible = false;
            settingsScreen.Close += (screen, args) => visible = false;

            if (!File.Exists(Settingsfile))
            {
                GenDef();
            }
            try {
                XElement conf = XElement.Parse(File.ReadAllText(Settingsfile));
                playerSlider.Value   = int.Parse(conf.Element("Players").Value);
                difficulty.Value     = int.Parse(conf.Element("Difficulty").Value);
                colorBox.Checked     = bool.Parse(conf.Element("Color").Value);
                settingsScreen.Color = colorBox.Checked;
            } catch { Debug.Fail("Failed to load settings"); }

            settingsScreen.Render();
            while (visible)
            {
                settingsScreen.ReadInput();
                Thread.Sleep(100);
            }
            PlayerCount      = playerSlider.Value;
            DifficultyFactor = difficulty.Value / 10f;
            Color            = colorBox.Checked;
            try
            {
                Gen(PlayerCount, difficulty.Value, Color);
            }
            catch { Debug.Fail("Failed to save settings"); }
        }
Beispiel #7
0
        public static void Render(bool smooth)
        {
            foreach (Label label in Labels)
            {
                label.Render();
            }
            foreach (Point point in Enemies)
            {
                DiffDraw.Set(point, ColorSelector.Get(SpecialChars.Enemy));
            }
            for (int i = 0; i < Player.Count; i++)
            {
                (Point position, Point direction) = Player[i];
                char selected;
                if (smooth)
                {
                    if (i == 0)
                    {
                        if (Player.Count == 1)
                        {
                            if (direction == new Point(0, 1))
                            {
                                selected = OneLineSimple.Up;
                            }
                            else if (direction == new Point(0, -1))
                            {
                                selected = OneLineSimple.Down;
                            }
                            else if (direction == new Point(1, 0))
                            {
                                selected = OneLineSimple.Left;
                            }
                            else if (direction == new Point(-1, 0))
                            {
                                selected = OneLineSimple.Right;
                            }
                            else
                            {
                                selected = OneLineSimple.Down;
                            }
                        }
                        else
                        {
                            Point prevPosition = Player[i + 1].Item1;
                            Point tmp          = new Point(prevPosition.X - position.X, prevPosition.Y - position.Y);
                            if (tmp == new Point(0, 1))
                            {
                                selected = OneLineSimple.Down;
                            }
                            else if (tmp == new Point(0, -1))
                            {
                                selected = OneLineSimple.Up;
                            }
                            else if (tmp == new Point(1, 0))
                            {
                                selected = OneLineSimple.Right;
                            }
                            else if (tmp == new Point(-1, 0))
                            {
                                selected = OneLineSimple.Left;
                            }
                            else
                            {
                                throw new ArgumentException($"Unexpected: {{X={tmp.X};Y={tmp.Y}}}");
                            }
                        }
                    }
                    else if (i == Player.Count - 1)
                    {
                        Point prevPosition = Player[i - 1].Item1;
                        Point tmp          = new Point(prevPosition.X - position.X, prevPosition.Y - position.Y);
                        if (tmp == new Point(0, 1))
                        {
                            selected = OneLineSimple.Down;
                        }
                        else if (tmp == new Point(0, -1))
                        {
                            selected = OneLineSimple.Up;
                        }
                        else if (tmp == new Point(1, 0))
                        {
                            selected = OneLineSimple.Right;
                        }
                        else if (tmp == new Point(-1, 0))
                        {
                            selected = OneLineSimple.Left;
                        }
                        else
                        {
                            throw new ArgumentException($"Unexpected: {{X={tmp.X};Y={tmp.Y}}}");
                        }
                    }
                    else
                    {
                        Point prevPosition = Player[i - 1].Item1;
                        Point nextPosition = Player[i + 1].Item1;
                        prevPosition = new Point(prevPosition.X - position.X, position.Y - prevPosition.Y);
                        nextPosition = new Point(nextPosition.X - position.X, position.Y - nextPosition.Y);
                        Direction[] directions = new Direction[2];

                        if (prevPosition == new Point(0, 1))
                        {
                            directions[0] = Direction.Up;
                        }
                        else if (prevPosition == new Point(0, -1))
                        {
                            directions[0] = Direction.Down;
                        }
                        else if (prevPosition == new Point(1, 0))
                        {
                            directions[0] = Direction.Right;
                        }
                        else if (prevPosition == new Point(-1, 0))
                        {
                            directions[0] = Direction.Left;
                        }
                        else
                        {
                            throw new ArgumentException("Unexpected previous position delta");
                        }

                        if (nextPosition == new Point(0, 1))
                        {
                            directions[1] = Direction.Up;
                        }
                        else if (nextPosition == new Point(0, -1))
                        {
                            directions[1] = Direction.Down;
                        }
                        else if (nextPosition == new Point(1, 0))
                        {
                            directions[1] = Direction.Right;
                        }
                        else if (nextPosition == new Point(-1, 0))
                        {
                            directions[1] = Direction.Left;
                        }
                        else
                        {
                            throw new ArgumentException("Unexpected next position delta");
                        }

                        directions = directions.OrderBy(s => (int)s).ToArray();

                        switch (directions[0])
                        {
                        case Direction.Up:
                            switch (directions[1])
                            {
                            case Direction.Down:
                                selected = OneLineSimple.UpDown;
                                break;

                            case Direction.Left:
                                selected = OneLineSimple.UpLeft;
                                break;

                            case Direction.Right:
                                selected = OneLineSimple.UpRight;
                                break;

                            default:
                                throw new ArgumentOutOfRangeException();
                            }

                            break;

                        case Direction.Down:
                            switch (directions[1])
                            {
                            case Direction.Left:
                                selected = OneLineSimple.DownLeft;
                                break;

                            case Direction.Right:
                                selected = OneLineSimple.DownRight;
                                break;

                            default:
                                throw new ArgumentOutOfRangeException();
                            }

                            break;

                        case Direction.Left:
                            switch (directions[1])
                            {
                            case Direction.Right:
                                selected = OneLineSimple.LeftRight;
                                break;

                            default:
                                throw new ArgumentOutOfRangeException();
                            }

                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                }
                else
                {
                    selected = 'P';
                }

                DiffDraw.Set(position, ColorSelector.Get(selected));
            }
        }
Beispiel #8
0
 private static bool CheckPoint(Point point) =>
 DiffDraw.Get(point) == CC_Functions.Misc.SpecialChars.Empty || DiffDraw.Get(point) == SpecialChars.Enemy;
Beispiel #9
0
        private static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;
            Console.Clear();
            CenteredScreen cScreen = new CenteredScreen(40, 20, ConsoleColor.Green);
            Panel          screen  = cScreen.ContentPanel;
            Button         btn1    = new Button("Test")
            {
                Point     = new Point(2, 0),
                BackColor = ConsoleColor.DarkGreen
            };

            screen.Controls.Add(btn1);
            btn1.Click += (screen1, eventArgs) => { DiffDraw.Draw(true, true); };
            Label lab1 = new Label("Meem")
            {
                Point     = new Point(2, 1),
                BackColor = ConsoleColor.Green
            };

            screen.Controls.Add(lab1);
            screen.Controls.Add(new Label("Saas\nSoos")
            {
                Point     = new Point(2, 2),
                BackColor = ConsoleColor.Green
            });
            Button btn2 = new Button("X")
            {
                BackColor = ConsoleColor.Red,
                ForeColor = ConsoleColor.White
            };

            screen.Controls.Add(btn2);

            CheckBox box = new CheckBox("Are u gae?")
            {
                Point     = new Point(2, 3),
                BackColor = ConsoleColor.DarkGreen
            };

            screen.Controls.Add(box);
            box.CheckedChanged += (screen1, eventArgs) => { lab1.Content = box.Checked ? "Sas" : "Meem"; };

            TextBox tbox = new TextBox("Hello\nWorld1\n\nHow are u?")
            {
                Size      = new Size(20, 10),
                Point     = new Point(0, 6),
                BackColor = ConsoleColor.DarkYellow
            };

            screen.Controls.Add(tbox);

            Slider slider = new Slider
            {
                Point     = new Point(2, 4),
                Size      = new Size(16, 2),
                MaxValue  = 75,
                StepSize  = 14,
                MinValue  = -3,
                Value     = 7,
                BackColor = ConsoleColor.Magenta
            };

            screen.Controls.Add(slider);

            bool visible = true;

            btn2.Click         += (screen1, eventArgs) => visible = false;
            cScreen.Close      += (screen1, eventArgs) => visible = false;
            cScreen.TabChanged += (screen1, eventArgs) => btn1.Content = $"Test {cScreen.TabPoint}";
            cScreen.Render();
            while (visible)
            {
                Thread.Sleep(50);
                cScreen.ReadInput();
            }
            Console.ResetColor();
            Console.Clear();
            Console.WriteLine("Test2");
            Thread.Sleep(100);
            DiffDraw.Clear(10, 10);
            DiffDraw.Draw(true, false);
            Console.Clear();
            Console.WriteLine("Bye");
        }