Exemplo n.º 1
0
        public override string HandleInputs(State controllerState, GameStateData lgsd, int oldPacketNumber, KeyboardUpdate[] keyData)
        {
            foreach (var state in keyData)
            {
                if (state.IsPressed)
                {
                    switch (state.Key)
                    {
                    case Key.Space:
                    case Key.Return:
                    {
                        switch (activeControl)
                        {
                        case 0:
                        {
                            return("start");
                        }
                        break;
                        }
                    }
                    break;
                    }
                }
            }


            if (controllerState.PacketNumber != oldPacketNumber)
            {
                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.A)
                {
                    return("start");
                }
            }
            return("gameover");
        }
Exemplo n.º 2
0
        public SettingsMenu(RenderTarget D2DRT, TextFormat tf, int width, int height, GameStateData gsd, string name) : base(D2DRT, tf, width, height, name)
        {
            lgsd         = gsd;
            menuControls = new List <SDXMenuControl>();
            int controlYSpacing = 60;
            int menuYOffset     = 200;

            tf.TextAlignment = SharpDX.DirectWrite.TextAlignment.Center;
            menuControls.Add(new SDXMenuIntegerBox(D2DRT, tf, "Grid Size", menuWidth / 2 - 125, menuHeight / 2 - menuYOffset + controlYSpacing * menuControls.Count, 250, 50, 60, 50, 4));
            menuControls.Add(new SDXMenuToggle(D2DRT, tf, "Undos", menuWidth / 2 - 80, menuHeight / 2 - menuYOffset + controlYSpacing * menuControls.Count, 160, 50, 90, 50, 1));
            menuControls.Add(new SDXMenuButton(D2DRT, MenuTextFormat, "Exit Settings",
                                               menuWidth / 2 - 200, menuHeight / 2 - menuYOffset + controlYSpacing * menuControls.Count, 400, 50));
            activeControl = 0;
            menuControls[activeControl].isActive = true;
        }
Exemplo n.º 3
0
        public override string HandleInputs(State controllerState, GameStateData lgsd, int oldPacketNumber, KeyboardUpdate[] keyData)
        {
            foreach (var state in keyData)
            {
                if (state.IsPressed)
                {
                    switch (state.Key)
                    {
                    case Key.Space:
                    case Key.Return:
                    {
                        switch (activeControl)
                        {
                        case 0:
                        {
                            FileUtils.WriteToXmlFile <HighScores>(WorkingPath + @"\HighScores.sco", lHighs, false);
                            return("start");
                        }
                        break;
                        }
                    }
                    break;
                    }
                }
            }

            if (controllerState.PacketNumber != oldPacketNumber)
            {
                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.A)
                {
                    FileUtils.WriteToXmlFile <HighScores>(WorkingPath + @"\HighScores.sco", lHighs, false);
                    return("start");
                }
            }
            return("viewhighscores");
        }
Exemplo n.º 4
0
        public override string HandleInputs(State controllerState, GameStateData gsd, int oldPacketNumber, KeyboardUpdate[] keyData)
        {
            lgsd = gsd;
            foreach (var state in keyData)
            {
                if (state.IsPressed)
                {
                    switch (state.Key)
                    {
                    case Key.Up:
                    {
                        if (activeControl > 0)
                        {
                            menuControls[activeControl].isActive = false;
                            activeControl--;
                            menuControls[activeControl].isActive = true;
                        }
                    }
                    break;

                    case Key.Down:
                    {
                        if (activeControl < menuControls.Count - 1)
                        {
                            menuControls[activeControl].isActive = false;
                            activeControl++;
                            menuControls[activeControl].isActive = true;
                        }
                    }
                    break;

                    case Key.Left:
                    {
                        if (activeControl == 0)
                        {
                            menuControls[activeControl].value = 3;
                        }
                    }
                    break;

                    case Key.Right:
                    {
                        if (activeControl == 0)
                        {
                            menuControls[activeControl].value = 4;
                        }
                    }
                    break;

                    case Key.Space:
                    case Key.Return:
                    {
                        switch (activeControl)
                        {
                        case 1:
                        {
                            if (menuControls[1].value == 0)
                            {
                                menuControls[1].value = 1;
                                lgsd.allowUndo        = true;
                            }
                            else
                            {
                                menuControls[1].value = 0;
                                lgsd.allowUndo        = false;
                            }
                        }
                        break;

                        case 2:
                        {
                            lgsd.gridSize = menuControls[0].value;
                            return("start");
                        }
                        break;
                        }
                    }
                    break;
                    }
                }
            }


            if (controllerState.PacketNumber != oldPacketNumber)
            {
                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.Start)
                {
                }

                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.DPadUp)
                {
                    if (activeControl > 0)
                    {
                        menuControls[activeControl].isActive = false;
                        activeControl--;
                        menuControls[activeControl].isActive = true;
                    }
                }
                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.DPadDown)
                {
                    if (activeControl < menuControls.Count - 1)
                    {
                        menuControls[activeControl].isActive = false;
                        activeControl++;
                        menuControls[activeControl].isActive = true;
                    }
                }
                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.DPadLeft)
                {
                    if (activeControl == 0)
                    {
                        menuControls[activeControl].value = 3;
                    }
                }
                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.DPadRight)
                {
                    if (activeControl == 0)
                    {
                        menuControls[activeControl].value = 4;
                    }
                }


                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.A)
                {
                    switch (activeControl)
                    {
                    case 1:
                    {
                        if (menuControls[1].value == 0)
                        {
                            menuControls[1].value = 1;
                            lgsd.allowUndo        = true;
                        }
                        else
                        {
                            menuControls[1].value = 0;
                            lgsd.allowUndo        = false;
                        }
                    }
                    break;

                    case 2:
                    {
                        lgsd.gridSize    = menuControls[0].value;
                        lgsd.bs.gridSize = menuControls[0].value;
                        //lgsd.NewGame();
                        return("start");
                    }
                    break;
                    }
                }
            }
            return("settings");
        }
Exemplo n.º 5
0
        public override string HandleInputs(State controllerState, GameStateData lgsd, int oldPacketNumber, KeyboardUpdate[] keyData)
        {
            foreach (var state in keyData)
            {
                if (state.IsPressed)
                {
                    switch (state.Key)
                    {
                    case Key.Up:
                    {
                        if (activeControl > 0)
                        {
                            menuControls[activeControl].isActive = false;
                            activeControl--;
                            menuControls[activeControl].isActive = true;
                        }
                    }
                    break;

                    case Key.Down:
                    {
                        if (activeControl < menuControls.Count - 1)
                        {
                            menuControls[activeControl].isActive = false;
                            activeControl++;
                            menuControls[activeControl].isActive = true;
                        }
                    }
                    break;

                    case Key.Space:
                    case Key.Return:
                    {
                        switch (activeControl)
                        {
                        case 0:
                        {
                            return("start");
                        }
                        break;

                        case 1:
                        {
                            //Returning empty string sends the control to the game
                            return("");
                        }
                        break;
                        }
                    }
                    break;
                    }
                }
            }

            if (controllerState.PacketNumber != oldPacketNumber)
            {
                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.Start)
                {
                }

                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.DPadUp)
                {
                    if (activeControl > 0)
                    {
                        menuControls[activeControl].isActive = false;
                        activeControl--;
                        menuControls[activeControl].isActive = true;
                    }
                }
                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.DPadDown)
                {
                    if (activeControl < menuControls.Count - 1)
                    {
                        if (menuControls[activeControl + 1].isSelectable)
                        {
                            menuControls[activeControl].isActive = false;
                            activeControl++;
                            menuControls[activeControl].isActive = true;
                        }
                    }
                }

                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.A)
                {
                    switch (activeControl)
                    {
                    case 0:
                    {
                        return("start");
                    }
                    break;

                    case 1:
                    {
                        //Returning empty string sends the control to the game
                        return("");
                    }
                    break;
                    }
                }
            }
            return("areyousure");
        }
Exemplo n.º 6
0
        public override string HandleInputs(State controllerState, GameStateData lgsd, int oldPacketNumber, KeyboardUpdate[] keyData)
        {
            foreach (var state in keyData)
            {
                if (state.IsPressed)
                {
                    switch (state.Key)
                    {
                    case Key.Up:
                    {
                        if (activeControl > 0)
                        {
                            menuControls[activeControl].isActive = false;
                            activeControl--;
                            menuControls[activeControl].isActive = true;
                        }
                    }
                    break;

                    case Key.Down:
                    {
                        if (activeControl < menuControls.Count - 1)
                        {
                            menuControls[activeControl].isActive = false;
                            activeControl++;
                            menuControls[activeControl].isActive = true;
                        }
                    }
                    break;

                    case Key.Space:
                    case Key.Return:
                    {
                        switch (activeControl)
                        {
                        case 0:
                        {
                            lgsd.NewGame();
                            return("");
                        }
                        break;

                        case 1:
                        {
                            return("viewhighscores");
                        }
                        break;

                        case 2:
                        {
                            return("settings");
                        }
                        break;

                        case 3:
                        {
                            Application.Exit();
                        }
                        break;
                        }
                    }
                    break;
                    }
                }
            }


            if (controllerState.PacketNumber != oldPacketNumber)
            {
                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.Start)
                {
                }

                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.DPadUp)
                {
                    if (activeControl > 0)
                    {
                        menuControls[activeControl].isActive = false;
                        activeControl--;
                        menuControls[activeControl].isActive = true;
                    }
                }
                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.DPadDown)
                {
                    if (activeControl < menuControls.Count - 1)
                    {
                        menuControls[activeControl].isActive = false;
                        activeControl++;
                        menuControls[activeControl].isActive = true;
                    }
                }

                if (controllerState.Gamepad.Buttons == GamepadButtonFlags.A)
                {
                    switch (activeControl)
                    {
                    case 0:
                    {
                        lgsd.NewGame();
                        return("");
                    }
                    break;

                    case 1:
                    {
                        return("viewhighscores");
                    }
                    break;

                    case 2:
                    {
                        return("settings");
                    }
                    break;

                    case 3:
                    {
                        Application.Exit();
                    }
                    break;
                    }
                }
            }
            return("start");
        }
Exemplo n.º 7
0
        public GameOverScreen(RenderTarget D2DRT, TextFormat tf, int width, int height, GameStateData lgsd, string name) : base(D2DRT, tf, width, height, name)
        {
            menuControls = new List <SDXMenuControl>();
            int controlYSpacing = 60;
            int menuYOffset     = 200;

            menuControls.Add(new SDXMenuButton(D2DRT, tf, "OK", screenWidth / 2 - 100, screenHeight / 2 + 50, 200, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, tf, "Game Over", screenWidth / 2 - 250, screenHeight / 2 - 200, 500, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, tf, "Your Score: " + finalScore, screenWidth / 2 - 350, screenHeight / 2 - 110, 700, 100));
            activeControl = 0;
            menuControls[activeControl].isActive = true;
            isVisible = false;
        }
Exemplo n.º 8
0
        public RForm(string text) : base(text)
        {
            this.ClientSize = new System.Drawing.Size(screenWidth, screenHeight);
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RForm));
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

            //SharpDX variable initialization
            desc = new SwapChainDescription()
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(this.ClientSize.Width, this.ClientSize.Height, new Rational(144, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = this.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };
            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, new SharpDX.Direct3D.FeatureLevel[] { SharpDX.Direct3D.FeatureLevel.Level_10_0 }, desc, out device, out swapChain);
            d2dFactory = new SharpDX.Direct2D1.Factory();
            factory    = swapChain.GetParent <Factory>();
            factory.MakeWindowAssociation(this.Handle, WindowAssociationFlags.IgnoreAll);
            backBuffer      = Texture2D.FromSwapChain <Texture2D>(swapChain, 0);
            renderView      = new RenderTargetView(device, backBuffer);
            surface         = backBuffer.QueryInterface <Surface>();
            d2dRenderTarget = new RenderTarget(d2dFactory, surface, new RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
            solidColorBrush = new SolidColorBrush(d2dRenderTarget, Color.White);
            directInput     = new DirectInput();
            keyboard        = new Keyboard(directInput);
            keyboard.Properties.BufferSize = 128;
            keyboard.Acquire();
            keys = new KeyboardState();
            userInputProcessor = new UserInputProcessor();
            gameInputTimer     = new Stopwatch();
            gameInputTimer.Start();

            //Colors
            boardColor        = new SolidColorBrush(d2dRenderTarget, new RawColor4(0.9215686f, 0.4235294f, 0.07058824f, 1.0f));
            boardSpotColor    = new SolidColorBrush(d2dRenderTarget, new RawColor4(0.1882353f, 0.2431373f, 0.2862745f, 1.0f));
            boardValueColor   = new SolidColorBrush(d2dRenderTarget, Color.Black);
            activePieceColors = new List <SolidColorBrush>();
            activePieceColors.Add(new SolidColorBrush(d2dRenderTarget, new RawColor4(0.3960784f, 0.3960784f, 0.372549f, 1.0f)));
            activePieceColors.Add(new SolidColorBrush(d2dRenderTarget, new RawColor4(0.7411765f, 0.5843138f, 0.4f, 1.0f)));
            activePieceColors.Add(new SolidColorBrush(d2dRenderTarget, new RawColor4(0.9176471f, 0.6784314f, 0.3921569f, 1.0f)));
            activePieceColors.Add(new SolidColorBrush(d2dRenderTarget, new RawColor4(0.972549f, 0.627451f, 0.1137255f, 1.0f)));
            activePieceColors.Add(new SolidColorBrush(d2dRenderTarget, new RawColor4(0.9137255f, 0.7411765f, 0.2235294f, 1.0f)));
            activePieceColors.Add(new SolidColorBrush(d2dRenderTarget, new RawColor4(0.427451f, 0.7843137f, 0.654902f, 1.0f)));
            activePieceColors.Add(new SolidColorBrush(d2dRenderTarget, new RawColor4(0.6627451f, 0.7686275f, 0.3411765f, 1.0f)));

            //Gameboard drawing initialization
            topLeftX        = screenWidth / 2 - boardWidth / 2;
            topLeftY        = screenHeight / 2 - boardHeight / 2;
            boardRect       = new RawRectangleF(topLeftX, topLeftY, topLeftX + boardWidth, topLeftY + boardHeight);
            pieceTextFormat = new SharpDX.DirectWrite.TextFormat(new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated), "Gill Sans", FontWeight.UltraBold, FontStyle.Normal, 36);
            pieceTextFormat.TextAlignment             = SharpDX.DirectWrite.TextAlignment.Center;
            pieceTextFormat.ParagraphAlignment        = ParagraphAlignment.Center;
            pieceTextFormat4Digits                    = new SharpDX.DirectWrite.TextFormat(new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated), "Gill Sans", FontWeight.UltraBold, FontStyle.Normal, 24);
            pieceTextFormat4Digits.TextAlignment      = SharpDX.DirectWrite.TextAlignment.Center;
            pieceTextFormat4Digits.ParagraphAlignment = ParagraphAlignment.Center;
            scoreColor      = new SolidColorBrush(d2dRenderTarget, new RawColor4(1f, 1f, 1f, 1f));
            scoreTextFormat = new TextFormat(new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated), "Gill Sans", FontWeight.UltraBold, FontStyle.Normal, 36);


            //Game variable initialization
            gsd             = new GameStateData();
            gridSize        = 4;
            gsd.gridSize    = gridSize;
            gsd.bs.gridSize = gridSize;
            gsd.bs.GenerateANewPiece(gsd.boardValues);
            if (gsd.bs.Value == 4)
            {
                gsd.score += 4;
            }
            moveSuccess = false;


            //Menu Initialization and font setup
            TextFormat startMenuText = new TextFormat(new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated), "Gill Sans", FontWeight.UltraBold, FontStyle.Normal, 36);

            startMenu = new StartMenu(d2dRenderTarget, startMenuText, screenWidth, screenHeight, "start");
            TextFormat gameOverMenuText = new TextFormat(new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated), "Gill Sans", FontWeight.UltraBold, FontStyle.Normal, 72);

            gameOverScreen = new GameOverScreen(d2dRenderTarget, gameOverMenuText, screenWidth, screenHeight, gsd, "gameover");
            TextFormat settingsMenuText = new TextFormat(new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated), "Gill Sans", FontWeight.UltraBold, FontStyle.Normal, 36);

            settingsMenu = new SettingsMenu(d2dRenderTarget, settingsMenuText, screenWidth, screenHeight, gsd, "settings");
            TextFormat sureMenuText = new TextFormat(new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated), "Gill Sans", FontWeight.UltraBold, FontStyle.Normal, 36);

            areYouSureBox = new AreYouSureBox(d2dRenderTarget, sureMenuText, screenWidth, screenHeight, "areyousure");

            //Load high scores and initialize the high score related menus
            WorkingPath = Directory.GetCurrentDirectory();
            if (File.Exists(WorkingPath + @"\HighScores.sco"))
            {
                highs = FileUtils.ReadFromXmlFile <HighScores>(WorkingPath + @"\HighScores.sco");
            }
            else
            {
                highs = new HighScores();
            }
            viewHighScoresTF = new TextFormat(new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated), "Gill Sans", FontWeight.UltraBold, FontStyle.Normal, 30);
            viewHighScoresTF.WordWrapping  = SharpDX.DirectWrite.WordWrapping.NoWrap;
            viewHighScoresTF.TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading;
            viewHighScores    = new ViewHighScores(d2dRenderTarget, viewHighScoresTF, screenWidth, screenHeight, highs, WorkingPath, "viewhighscores");
            madeHighScoreMenu = new MadeHighScoreMenu(d2dRenderTarget, settingsMenuText, screenWidth, screenHeight, gsd, "madehighscore", highs);

            //Link all the menus together
            sceneFlow = new SDXSceneFlow();
            sceneFlow.menuList.Add(startMenu);
            sceneFlow.menuList.Add(gameOverScreen);
            sceneFlow.menuList.Add(settingsMenu);
            sceneFlow.menuList.Add(areYouSureBox);
            sceneFlow.menuList.Add(viewHighScores);
            sceneFlow.menuList.Add(madeHighScoreMenu);
            currentMenu          = "start";
            sceneFlow.activeMenu = sceneFlow.NextMenu(currentMenu);
        }