Exemplo n.º 1
0
        public Board(int sizeX, int sizeY, bool twoSided)
        {
            this.twoSided = twoSided;
            this.width    = sizeX;
            this.height   = sizeY;

            camera =
                new Camera((float)Math.Max(sizeX, sizeY) * 400.0f / 5.0f);

            nextPictureSet = PictureDatabase.GetNextPictureSet(twoSided ? 2 : 1);

            this.layout = new Chip[Width, Height];
            this.boardPositionMatrices = new Matrix[Width, Height];

            // Create all the chips
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    Chip chip = new Chip();
                    chips.Add(chip);

                    chip.XPosition = x;
                    chip.YPosition = y;
                    layout[x, y]   = chip;

                    Vector2 chipTexCoordFactor =
                        new Vector2(1.0f / Width, 1.0f / Height);

                    chip.TexCoordScale            = chipTexCoordFactor;
                    chip.TexCoordTranslationFront =
                        new Vector2((x * chipTexCoordFactor.X),
                                    ((Height - 1) - y) * chipTexCoordFactor.Y);
                    chip.TexCoordTranslationBack =
                        new Vector2(((Width - 1) - x) * chipTexCoordFactor.X,
                                    ((Height - 1) - y) * chipTexCoordFactor.Y);
                }
            }

            // Remove one random chip
            emptyX = RandomHelper.Random.Next(0, Width);
            emptyY = RandomHelper.Random.Next(0, Height);
            Chip removed = layout[emptyX, emptyY];

            chips.Remove(removed);
            layout[emptyX, emptyY] = null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Construct a new instance of Pickture. This method will enforce that it is
        /// only ever called once because the game class itself is a singleton.
        /// </summary>
        public Pickture()
        {
            // Enforce singleton
            if (instance != null)
            {
                throw new InvalidOperationException(
                          "Only one instance of Pickture may be created.");
            }
            instance = this;

            // Initalize graphics
            graphics = new GraphicsDeviceManager(this);
            graphics.MinimumVertexShaderProfile = ShaderProfile.VS_2_0;
            graphics.MinimumPixelShaderProfile  = ShaderProfile.PS_2_0;

#if XBOX360
            // On Xbox360, always use the user's preferred resolution and multisampling
            // The other approach is to always use the same resolution (typically
            // 1920x1080). The hardware will automatically down scale and letterbox as
            // needed. However, Pickture is already resolution independant for Windows
            graphics.PreferredBackBufferWidth  = Window.ClientBounds.Width;
            graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
            graphics.PreferMultiSampling       = true;
            graphics.PreparingDeviceSettings  +=
                new EventHandler <PreparingDeviceSettingsEventArgs>(
                    graphics_PreparingDeviceSettings);
#else
            // On Windows, just use a small and simple starting size, but allow
            // the user to resize the Window however they like
            graphics.PreferredBackBufferWidth  = 800;
            graphics.PreferredBackBufferHeight = 600;
            Window.AllowUserResizing           = true;
            graphics.IsFullScreen = false;
#endif


            // Initalzie content
            Content.RootDirectory = "Content";

            // Initalize screen management
            ScreenManager screenManager = new ScreenManager(this);
            Components.Add(screenManager);

            // Initalize picture database
            PictureDatabase.Initialize();

            // If enough pictures are available,
            if (PictureDatabase.Count >= 2)
            {
                // start up the game
                screenManager.AddScreen(new MainMenuScreen());
            }
            else
            {
                // Otherwise, show error and quit
                MessageBoxScreen messageBox = new MessageBoxScreen(
                    "Unable to find enough pictures to play.", false);
                messageBox.Accepted += new EventHandler <EventArgs>(messageBox_Accepted);
                screenManager.AddScreen(messageBox);
            }
        }