Exemple #1
0
        public override void Load(Game game)
        {
            var font = new Font("ARIAL.TTF");

            uiBaseShow = new MarqueeAnim();
            uiBaseHide = new MarqueeAnim();

            uiBase = new Frame(game, new Vector2f(Bounds.X / 2 - 250, -400), new Vector2f(500, 300), new Color(177, 219, 222, 200));

            var restartButton = new Button(game, new Vector2f(190, 200), new Vector2f(120, 40), new Color(121, 219, 147), "Restart", font, Color.Black, 24);
            var menuButton    = new Button(game, new Vector2f(190, 250), new Vector2f(120, 40), new Color(121, 219, 147), "Main menu", font, Color.Black, 24);

            restartButton.Clicked += (s, e) => uiBaseHide.Start(uiBase, new Vector2f(Bounds.X / 2 - 250, Bounds.Y + 100), 0.2f);

            uiBase.AddChild(new Label(game, new Vector2f(250, 20), String.Format("{0} has won the game!", winner), font, winner == PieceColor.Red ? Color.Red : Color.Black, 32));

            uiBase.AddChild(restartButton);
            uiBase.AddChild(menuButton);

            uiBaseHide.Stopped += (s, e) =>
            {
                GameState.Ingame.Start();
                game.SetActiveGameState(GameState.Ingame);
            };

            base.Load(game);
        }
Exemple #2
0
        private void UpdateWorlds()
        {
            worldFrame.ClearChildren();

            const int ButtonHeight = 60;
            const int Margin       = 10;

            int i = 0;

            foreach (var world in worlds)
            {
                Button button = new Button(0, i * (ButtonHeight + Margin), 0, ButtonHeight);
                button.Constraints.width = new RelativeConstraint(1, RelativeTo.Parent);
                button.OnLeftClick      += (sender) =>
                {
                    Game game = new Game(world);
                    game.OnExit += () => { SceneManager.LoadScene(new Transition(this, 10)); };
                    SceneManager.LoadScene(new Transition(game, 10));
                };

                TextBlock text = new TextBlock($"{world.Title}: {world.Levels.Count} Level", 3, 10, 10);
                text.Constraints.x = new CenterConstraint();
                text.Constraints.y = new CenterConstraint();
                text.Color         = Color.Black;
                button.AddChild(text);

                worldFrame.AddChild(button);
                i++;
            }
        }
Exemple #3
0
        private void InitUI()
        {
            const int ButtonSize = 28;

            ui       = new UI.UI();
            ui.Input = SceneManager.Input;

            Button exitButton = new Button(20, 20, 40, 40)
            {
                Shortcut = Key.Escape
            };

            exitButton.OnLeftClick += (sender) => SceneManager.LoadScene(new Transition(new MainMenu(), 10));

            UI.Image exitImage = new UI.Image(Textures.Get("Icons"), new RectangleF(0, 10, 10, 10), Color.Black);
            exitImage.SetConstraints(new UIConstraints(10, 10, 20, 20));

            exitButton.AddChild(exitImage);
            ui.Add(exitButton);

            Frame buttonFrame = new Frame
            {
                Color       = Color.Transparent,
                Constraints = new UIConstraints(new CenterConstraint(), new CenterConstraint(), new PixelConstraint(ButtonSize * width), new PixelConstraint(ButtonSize * height))
            };

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Button button = new Button(x * ButtonSize, y * ButtonSize, ButtonSize, ButtonSize)
                    {
                        Style = 1
                    };

                    int copyX = x;
                    int copyY = y;

                    button.OnLeftClick += (sender) =>
                    {
                        if (firstClick)
                        {
                            InitTiles(copyX, copyY);
                            firstClick = false;
                        }

                        RevealTile(copyX, copyY);
                    };
                    button.OnRightClick += (sender) => MarkTile(copyX, copyY);

                    tiles[x, y].Button = button;

                    buttonFrame.AddChild(button);
                }
            }

            ui.Add(buttonFrame);
        }
Exemple #4
0
        public override void Load(Game game)
        {
            var font = new Font("ARIAL.TTF");

            uiBaseShow = new MarqueeAnim();
            uiBaseHide = new MarqueeAnim();

            uiBase = new Frame(game, new Vector2f(Bounds.X / 2 - 250, -400), new Vector2f(500, 300), new Color(177, 219, 222, 200));

            var startButton = new Button(game, new Vector2f(190, 250), new Vector2f(120, 40), new Color(121, 219, 147), "Start!", font, Color.Black, 24);

            startButton.Clicked += (s, e) => uiBaseHide.Start(uiBase, new Vector2f(Bounds.X / 2 - 250, Bounds.Y + 100), 0.2f);

            var ply1Check = new Checkbox(game, new Vector2f(10, 80), "Player 1 AI", Color.Black, font);
            var ply2Check = new Checkbox(game, new Vector2f(10, 130), "Player 2 AI", Color.Black, font);

            var ply1ai = false;
            var ply2ai = false;

            ply1Check.CheckChanged += (s, e) => ply1ai = e.Checked;
            ply2Check.CheckChanged += (s, e) => ply2ai = e.Checked;

            uiBase.AddChild(new Label(game, new Vector2f(250, 20), "AI Checkers", font, Color.Black, 32));
            uiBase.AddChild(startButton);
            uiBase.AddChild(ply1Check);
            uiBase.AddChild(ply2Check);

            uiBaseHide.Stopped += (s, e) =>
            {
                GameState.Ingame.SetPlayerAI(ply1ai, ply2ai);
                GameState.Ingame.Start();
                game.SetActiveGameState(GameState.Ingame);
            };

            GameState.Ingame.Load(game);

            base.Load(game);
        }
        private void InitUI()
        {
            ui       = new UI.UI();
            ui.Input = SceneManager.Input;

            TextBlock title = new TextBlock("Einstellungen", 4);

            title.Color = Color.White;
            title.SetConstraints(new CenterConstraint(), new PixelConstraint(50), new PixelConstraint((int)title.TextWidth), new PixelConstraint((int)title.TextHeight));
            ui.Add(title);

            {
                Button button = new Button(40, 40, 40, 40);
                button.Shortcut     = OpenTK.Input.Key.Escape;
                button.OnLeftClick += (sender) =>
                {
                    SceneManager.LoadScene(new Transition(new MainMenu(), 10));
                };
                UI.Image exitImage = new UI.Image(Textures.Get("Icons"), new RectangleF(0, 10, 10, 10), Color.Black);
                exitImage.SetConstraints(new UIConstraints(10, 10, 20, 20));

                button.AddChild(exitImage);
                ui.Add(button);
            }

            void AddCheckBox(string s, int y, bool state, CheckEvent clickEvent)
            {
                Frame frame = new Frame();

                frame.Color = Color.Transparent;

                CheckBox box = new CheckBox(0, 0, 36, 36);

                box.Checked    = state;
                box.OnChecked += clickEvent;
                frame.AddChild(box);

                TextBlock text = new TextBlock(s, 3, 45, 0);

                text.Constraints.y = new CenterConstraint();
                text.Color         = Color.White;
                frame.AddChild(text);

                frame.SetConstraints(new CenterConstraint(), new PixelConstraint(y), new PixelConstraint(45 + (int)text.TextWidth), new PixelConstraint(36));
                ui.Add(frame);
            }

            void AddText(string s, int y)
            {
                TextBlock text = new TextBlock(s, 3);

                text.Color = Color.White;
                text.SetConstraints(new CenterConstraint(), new PixelConstraint(y), new PixelConstraint((int)text.TextWidth), new PixelConstraint((int)text.TextHeight));
                ui.Add(text);
            }

            AddCheckBox("Vollbild", 100, Settings.Current.Fullscreen, (b) =>
            {
                Settings.Current.Fullscreen     = b;
                SceneManager.Window.WindowState = b ? WindowState.Fullscreen : WindowState.Normal;
            });
            AddCheckBox("Züge anzeigen", 150, Settings.Current.ShowMoves, (b) =>
            {
                Settings.Current.ShowMoves = b;
            });
            AddCheckBox("FPS/UPS anzeigen", 200, Settings.Current.ShowFps, (b) =>
            {
                Settings.Current.ShowFps = b;
            });
            AddCheckBox("Animationen anzeigen", 250, Settings.Current.ShowAnimations, (b) =>
            {
                Settings.Current.ShowAnimations = b;
            });

            TextBox textBox = new TextBox
            {
                Constraints = new UIConstraints(new CenterConstraint(), new PixelConstraint(310), new PixelConstraint(180), new PixelConstraint(34)),
                Enabled     = !Settings.Current.LoggedIn,
                TextColor   = Color.Black,
                MaxTextSize = 15,
                Text        = Settings.Current.UserName ?? ""
            };

            ui.Add(textBox);

            Button sendButton = new Button();

            sendButton.SetConstraints(new CenterConstraint(), new PixelConstraint(350), new PixelConstraint(120), new PixelConstraint(34));
            sendButton.Enabled      = !Settings.Current.LoggedIn;
            sendButton.OnLeftClick += (sender) => SignUp(textBox);

            TextBlock sendText = new TextBlock("Anmelden", 2, 10, 10);

            sendButton.AddChild(sendText);
            ui.Add(sendButton);

            AddText($"ID: {Settings.Current.UserID.ToID()}", 400);
            AddText($"LoginInfo: {Settings.Current.LoginInfo.ToID()}", 440);
        }
Exemple #6
0
        private void InitUI()
        {
            ui = new UI.UI
            {
                Input = SceneManager.Input
            };

            TextBlock title = new TextBlock("KREATIVER NAME", 5, 0, 50);

            title.Constraints.x = new CenterConstraint();
            title.Color         = Color.White;
            ui.Add(title);

            TextBlock splash = new TextBlock(File.ReadAllLines(@"Resources\Splash.txt").Random(), 2, 0, 90);

            splash.Constraints.x = new CenterConstraint();
            splash.Color         = Color.White;
            ui.Add(splash);

            TextBlock version = new TextBlock($"Version {MainWindow.version}", 2, 5, 0);

            version.Constraints.y = new PixelConstraint(5, RelativeTo.Window, Direction.Bottom);
            version.Color         = Color.White;
            ui.Add(version);

            Frame mainFrame = new Frame
            {
                Constraints = new UIConstraints(new CenterConstraint(), new CenterConstraint(-50), new PixelConstraint(300), new PixelConstraint(200)),
                Color       = Color.Transparent
            };

            // Add start button
            Button startButton = new Button
            {
                Color       = Color.FromArgb(100, 255, 100),
                Shortcut    = OpenTK.Input.Key.S,
                Constraints = new UIConstraints(new CenterConstraint(), new PixelConstraint(0), new PixelConstraint(300), new PixelConstraint(60))
            };

            startButton.OnLeftClick += (sender) => { SceneManager.LoadScene(new Transition(new WorldMenu(), 10)); };

            TextBlock startText = new TextBlock("Spiel starten", 3);

            startText.SetConstraints(new CenterConstraint(), new CenterConstraint(), new PixelConstraint((int)startText.TextWidth), new PixelConstraint((int)startText.TextHeight));
            startButton.AddChild(startText);

            mainFrame.AddChild(startButton);

            // Add middle frame
            Frame frame = new Frame
            {
                Color       = Color.Transparent,
                Constraints = new UIConstraints(new CenterConstraint(), new PixelConstraint(100), new PixelConstraint(300), new PixelConstraint(60))
            };

            void AddButton(int x, int icon, ClickEvent click)
            {
                Button button = new Button(x, 0, 60, 60);

                button.OnLeftClick += click;

                UI.Image image = new UI.Image(Textures.Get("Icons"), new RectangleF(icon * 10, 10, 10, 10))
                {
                    Color       = Color.Black,
                    Constraints = new UIConstraints(10, 10, 40, 40)
                };

                button.AddChild(image);
                frame.AddChild(button);
            }

            AddButton(0, 1, (sender) => { SceneManager.LoadScene(new Transition(new StatisticsScene(), 10)); });
            AddButton(80, 2, (sender) => { SceneManager.LoadScene(new Transition(new SettingsScene(), 10)); });
            AddButton(160, 3, NewEditor);
            AddButton(240, 4, (sender) => { SceneManager.LoadScene(new Transition(new OnlineScene(), 10)); });

            mainFrame.AddChild(frame);

            // Add exit button
            Button exitButton = new Button
            {
                Color       = Color.FromArgb(255, 100, 100),
                Constraints = new UIConstraints(new CenterConstraint(), new PixelConstraint(200), new PixelConstraint(300), new PixelConstraint(60))
            };

            exitButton.OnLeftClick += (sender) => { SceneManager.CloseWindow(); };

            TextBlock exitText = new TextBlock("Schliessen", 3);

            exitText.Constraints = new UIConstraints(new CenterConstraint(), new CenterConstraint(), new PixelConstraint((int)exitText.TextWidth), new PixelConstraint((int)exitText.TextHeight));
            exitButton.AddChild(exitText);

            mainFrame.AddChild(exitButton);

            ui.Add(mainFrame);
        }
Exemple #7
0
        private void InitWorlds()
        {
            const int ButtonSize    = 60;
            const int StarsPerWorld = 2;
            const int WorldsPerRow  = 5;

            List <World> worlds     = new List <World>();
            int          worldcount = 0;

            while (File.Exists($"{World.BasePath}{worldcount:000}.wld"))
            {
                World item = World.LoadFromFile($"{worldcount:000}");
                worlds.Add(item);
                worldcount++;
            }

            // Get stars
            bool[,] stars = new bool[worldcount, StarsPerWorld];
            int totalStars = 0;

            bool[] showWorld = new bool[worldcount];

            for (int i = 0; i < worldcount; i++)
            {
                stars[i, 0] = worlds[i].AllCompleted;
                totalStars += worlds[i].AllCompleted ? 1 : 0;
                stars[i, 1] = worlds[i].AllPerfect;
                totalStars += worlds[i].AllPerfect ? 1 : 0;
            }

            // Decide if world is shown
            for (int i = 0; i < worldcount; i++)
            {
                if (i > 1)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        for (int k = 0; k < StarsPerWorld; k++)
                        {
                            if (stars[i - j, k])
                            {
                                showWorld[i] = true;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    showWorld[i] = true;
                }
            }

            Frame worldFrame = new Frame
            {
                Color       = Color.Transparent,
                Constraints = new UIConstraints(
                    new CenterConstraint(),
                    new PixelConstraint(180),
                    new PixelConstraint((showWorld.Count(x => x) / WorldsPerRow < 1 ? showWorld.Count(x => x) % WorldsPerRow : WorldsPerRow) * (ButtonSize + 20) + 20),
                    new PixelConstraint((ButtonSize + 20) * (showWorld.Count(x => x) / WorldsPerRow + 1) + 20))
            };

            // Make buttons
            int count = 0;

            for (int i = 0; i < worldcount; i++)
            {
                if (showWorld[i])
                {
                    Button button = new Button((ButtonSize + 20) * (count % WorldsPerRow) + 20, (ButtonSize + 20) * (count / WorldsPerRow) + 20, ButtonSize, ButtonSize);

                    for (int j = 0; j < StarsPerWorld; j++)
                    {
                        UI.Image image = new UI.Image(Textures.Get("Icons"), new RectangleF(stars[i, j] ? 10 : 0, 0, 10, 10));
                        image.SetConstraints(new UIConstraints(
                                                 ButtonSize * (j + 1) / (StarsPerWorld + 1) - 10,
                                                 ButtonSize - 15, 20, 20));

                        button.AddChild(image);
                    }

                    if (i < 10)
                    {
                        button.Shortcut = (Key)(110 + i);
                    }

                    if (i > 0)
                    {
                        button.Enabled = worlds[i - 1].AllCompleted || worlds[i - 1].AllPerfect;
                    }

                    int world = i;
                    button.OnLeftClick += (sender) => { NewGame(world); };

                    TextBlock text = new TextBlock((i + 1).ToRoman().ToLower(), 3);
                    text.Constraints = new UIConstraints(new CenterConstraint(), new CenterConstraint(), new PixelConstraint((int)text.TextWidth), new PixelConstraint((int)text.TextHeight));
                    button.AddChild(text);
                    worldFrame.AddChild(button);

                    count++;
                }
            }

            ui.Add(worldFrame);
        }
Exemple #8
0
        private void InitLevels()
        {
            const int ButtonSize    = 60;
            const int StarsPerLevel = 2;

            int lvlCount = world.Levels.Count;

            // Read stars
            bool[,] stars = new bool[lvlCount, StarsPerLevel];
            int totalStars = 0;

            for (int i = 0; i < lvlCount; i++)
            {
                stars[i, 0] = world.Levels[i].Completed;
                totalStars += world.Levels[i].Completed ? 1 : 0;
                stars[i, 1] = world.Levels[i].Perfect;
                totalStars += world.Levels[i].Perfect ? 1 : 0;
            }

            Frame levelFrame = new Frame()
            {
                Color       = Color.Transparent,
                Constraints = new UIConstraints(
                    new CenterConstraint(),
                    new PixelConstraint(180),
                    new PixelConstraint(lvlCount * (ButtonSize + 20) + 20),
                    new PixelConstraint(ButtonSize + 40))
            };

            List <Tuple <int, int> > connections = new List <Tuple <int, int> >();

            for (int i = 0; i < lvlCount; i++)
            {
                for (int j = 0; j < world.LevelConnections[i].Count; j++)
                {
                    connections.Add(new Tuple <int, int>(i, world.LevelConnections[i][j]));
                }
            }

            Vector2[] positions = new Vector2[lvlCount];

            void CalcPosition(int level, int index, int prev = 0, int count = 0)
            {
                int next = world.LevelConnections[level][index];

                if (world.LevelConnections[next].Count > 0)
                {
                    for (int i = 0; i < world.LevelConnections[next].Count; i++)
                    {
                        CalcPosition(next, i, level, count + 1);
                    }
                }
                else
                {
                    positions[next] = new Vector2(count + 1, index);
                }

                positions[level] = new Vector2(count, index);
            }

            CalcPosition(0, 0);

            // Create buttons
            int count = 0;

            for (int i = 0; i < lvlCount; i++)
            {
                Button button = new Button((ButtonSize + 20) * (int)positions[i].X + 20, (ButtonSize + 20) * (int)positions[i].Y + 20, ButtonSize, ButtonSize);

                // Create stars
                for (int j = 0; j < StarsPerLevel; j++)
                {
                    UI.Image image = new UI.Image(Textures.Get("Icons"), new RectangleF(stars[i, j] ? 10 : 0, 0, 10, 10));
                    image.SetConstraints(new UIConstraints(
                                             ButtonSize * (j + 1) / (StarsPerLevel + 1) - 10,
                                             ButtonSize - 15, 20, 20));

                    button.AddChild(image);
                }

                if (i < 10)
                {
                    button.Shortcut = (Key)(110 + i);
                }

                if (i > 0)
                {
                    button.Enabled = false;
                    for (int j = 0; j < world.LevelConnections.Length; j++)
                    {
                        if (world.Levels[j].Completed && world.LevelConnections[j].Contains(i))
                        {
                            button.Enabled = true;
                            break;
                        }
                    }
                }

                int level = i;
                button.OnLeftClick += (sender) => NewGame(level);

                TextBlock text = new TextBlock((i + 1).ToString(), 3);
                text.SetConstraints(new CenterConstraint(), new CenterConstraint(), new PixelConstraint((int)text.TextWidth), new PixelConstraint((int)text.TextHeight));
                button.AddChild(text);
                levelFrame.AddChild(button);

                count++;
            }

            ui.Add(levelFrame);
        }