Ejemplo n.º 1
0
        public ViewHighScores(RenderTarget D2DRT, TextFormat tf, int width, int height, HighScores highs, string wp, string name)
            : base(D2DRT, tf, width, height, name)
        {
            lHighs       = highs;
            WorkingPath  = wp;
            menuControls = new List <SDXMenuControl>();
            int controlYSpacing = 45;

            //int menuYOffset = 200;
            MenuTextFormat   = tf;
            tf.TextAlignment = SharpDX.DirectWrite.TextAlignment.Center;
            menuControls.Add(new SDXMenuButton(D2DRT, tf, "OK", screenWidth / 2 - 40, screenHeight - 100, 80, 50));
            menuControls.Add(new SDXMenuLabel(D2DRT, tf, "High Scores", screenWidth / 2 - 200, 20, 400, 100));
            TextFormat temptf = new TextFormat(new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated), "Gill Sans", FontWeight.UltraBold, FontStyle.Normal, 30);

            temptf.WordWrapping  = SharpDX.DirectWrite.WordWrapping.NoWrap;
            temptf.TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading;
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "1)  ", 350, controlYSpacing * 1 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "2)  ", 350, controlYSpacing * 2 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "3)  ", 350, controlYSpacing * 3 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "4)  ", 350, controlYSpacing * 4 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "5)  ", 350, controlYSpacing * 5 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "6)  ", 350, controlYSpacing * 6 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "7)  ", 350, controlYSpacing * 7 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "8)  ", 350, controlYSpacing * 8 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "9)  ", 350, controlYSpacing * 9 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "10) ", 350, controlYSpacing * 10 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 450, controlYSpacing * 1 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 450, controlYSpacing * 2 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 450, controlYSpacing * 3 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 450, controlYSpacing * 4 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 450, controlYSpacing * 5 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 450, controlYSpacing * 6 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 450, controlYSpacing * 7 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 450, controlYSpacing * 8 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 450, controlYSpacing * 9 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 450, controlYSpacing * 10 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 800, controlYSpacing * 1 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 800, controlYSpacing * 2 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 800, controlYSpacing * 3 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 800, controlYSpacing * 4 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 800, controlYSpacing * 5 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 800, controlYSpacing * 6 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 800, controlYSpacing * 7 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 800, controlYSpacing * 8 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 800, controlYSpacing * 9 + 75, 50, 100));
            menuControls.Add(new SDXMenuLabel(D2DRT, temptf, "", 800, controlYSpacing * 10 + 75, 50, 100));
            activeControl = 0;
            menuControls[activeControl].isActive = true;
            isVisible = false;
        }
Ejemplo n.º 2
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);
        }