Beispiel #1
0
        public static void Main()
        {
            System.Console.WriteLine("Creating random board.");
            PuzzleBoard           board           = new PuzzleBoard(5, 5);
            PuzzleBoardController boardController = new PuzzleBoardController(board);

            boardController.FillBoardWithNewOrbs();
            System.Console.WriteLine(boardController.GetBoardString());

            System.Console.WriteLine("Checking matches");
            boardController.CheckForMatches();
            boardController.CheckForCombos();
            System.Console.WriteLine(boardController.GetCombosString());

            if (boardController.ComboCount > 0)
            {
                System.Console.WriteLine("Moving matched orbs to the top");
                boardController.MoveMatchedOrbsToTheTop();
                System.Console.WriteLine(boardController.GetBoardString());

                System.Console.WriteLine("Assign new color to matched orbs");
                boardController.AssignNewColorToMatchedOrbs();
                boardController.ClearMatches();
                System.Console.WriteLine(boardController.GetBoardString());
            }
        }
    private PuzzlePiece currentPieceFromBoard; //ссылка на элемент на доске

    // Use this for initialization
    void Start()
    {
        gameBoard = FindObjectOfType <PuzzleBoard>();

        size = (gameBoard.mainImgSquareSize / (gameBoard.boardDimension * gameBoard.boardDimension)) * gameBoard.piecesMargin;

        //пячим фишку в зависимости от количества элементов
        //uiImage.transform.localScale = new Vector3(board.piecesMargin / board.boardDimension, board.piecesMargin / board.boardDimension, board.piecesMargin / board.boardDimension);
        uiImage.rectTransform.sizeDelta = new Vector2(size,
                                                      size);
        uiImage.uvRect = new Rect(xPos * size, yPos * size, 100 / size, 100 / size);

        if (pawnNumber == 0)
        {
            uiImage.enabled = false;
        }

        foreach (PuzzlePiece item in gameBoard.pieces)
        {
            if (item.pawnNumber == this.pawnNumber)
            {
                currentPieceFromBoard = item;
            }
        }
    }
Beispiel #3
0
	// Use this for initialization
	void Start () 
	{
		PuzzleBoard = ComponentContainer.PuzzleBoardController.PuzzleBoard;
		PuzzlePresentation = ComponentContainer.PuzzlePresentation;
		PuzzlePresentation.Instance.GemCellAdded += Grid_GemCellAdded;
		PuzzlePresentation.Instance.GemCellRemoved += Grid_GemCellRemoved;
		selectedGemCell = null;
	}
Beispiel #4
0
 // Use this for initialization
 void Start()
 {
     PuzzleBoard        = ComponentContainer.PuzzleBoardController.PuzzleBoard;
     PuzzlePresentation = ComponentContainer.PuzzlePresentation;
     PuzzlePresentation.Instance.GemCellAdded   += Grid_GemCellAdded;
     PuzzlePresentation.Instance.GemCellRemoved += Grid_GemCellRemoved;
     selectedGemCell = null;
 }
Beispiel #5
0
        public void Experience(FieldOfVisionTypes fieldOfVisionType, PuzzleBoard partialBoard)
        {
            Point centerPos = new Point();

            switch (fieldOfVisionType)
            {
            case FieldOfVisionTypes.Single:
                centerPos = new Point(0, 0);
                break;

            case FieldOfVisionTypes.ThreeByThree:
                centerPos = new Point(1, 1);
                break;

            case FieldOfVisionTypes.FiveByFive:
                centerPos = new Point(2, 2);
                break;
            }

            List <ISensoryPattern> sensoryPatterns = new List <ISensoryPattern>();

            for (int y = 0; y < partialBoard.Rows; y++)
            {
                for (int x = 0; x < partialBoard.Columns; x++)
                {
                    Point                pos           = new Point(x, y);
                    DirectionTypes       directionType = PuzzleReferee.ConvertToDirectionType(new Point(pos.X - centerPos.X, pos.Y - centerPos.Y));
                    PuzzleCellStateTypes state         = partialBoard.GetState(pos);
                    int    value       = partialBoard.GetValue(pos);
                    string valueString = value >= 0 ? value.ToString() : " ";

                    if (state != PuzzleCellStateTypes.Undefined)
                    {
                        ISensoryUnit sensoryUnitState = GetOrCreateSensoryUnit(SensoryTypes.FieldState, state.ToString());
                        ISensoryUnit sensoryUnitValue = GetOrCreateSensoryUnit(SensoryTypes.FieldValue, valueString);

                        List <ISensoryUnit> sensoryUnits = new List <ISensoryUnit>();
                        sensoryUnits.Add(sensoryUnitState);
                        sensoryUnits.Add(sensoryUnitValue);

                        ISensoryPattern sensoryPattern = new SensoryPattern(directionType, sensoryUnits);

                        if (_kownSensoryPatterns.Contains(sensoryPattern))
                        {
                            sensoryPattern = _kownSensoryPatterns[_kownSensoryPatterns.IndexOf(sensoryPattern)];
                        }
                        else
                        {
                            _kownSensoryPatterns.Add(sensoryPattern);
                            _kownSensoryPatterns.Sort();
                        }

                        sensoryPatterns.Add(sensoryPattern);
                    }
                }
            }
            _lastSensationSnapshot = new SensationSnapshot(DirectionTypes.Center, fieldOfVisionType, sensoryPatterns, IS_SAVEABLE_SNAPSHOT);
        }
        private void RobotBrain_ExperienceWanted(object sender, EventArgs e)
        {
            PuzzleBoard partialBoard = CreatePartialBoard(_fieldOfVisionType, _robotBrain.Position);

            if (partialBoard == null)
            {
                return;
            }
            _robotBrain.Experience(_fieldOfVisionType, partialBoard);
        }
Beispiel #7
0
        public void Draw(Graphics graphics, Point mouse, Field selectedColour)
        {
            // Draw it to a bitmap
            adjustToNumberSizes();
            int squareSize = this.CalculateSquareSize();

            Point  hover = PuzzleBoard.Mouse2Point(mouse, squareSize, this);
            Bitmap bmp   = this.drawToBitmap(squareSize, hover, selectedColour, true, Settings.Get.DarkerBackground);

            // Draw that bitmap to form
            graphics.DrawImage(bmp, this.Offset);
        }
Beispiel #8
0
        private void newPuzzleClick(object o, EventArgs e)
        {
            this.clearMessage();

            SizeDialog dialog = new SizeDialog("Create a new picross puzzle.");

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.puzzleBoard = new PuzzleBoard(dialog.ChosenSize.X, dialog.ChosenSize.Y, Settings.Get.EditorMode);
                this.OnResize();
            }
        }
Beispiel #9
0
        public PuzzleBoard CreateCopy()
        {
            PuzzleBoard newBoard = new PuzzleBoard(Rows, Columns);

            for (int y = 0; y < Rows; y++)
            {
                for (int x = 0; x < Columns; x++)
                {
                    newBoard[y, x] = new PuzzleOrb(x, y, _boardArray[y, x].orbColor);
                }
            }
            return(newBoard);
        }
        private void SetValueAndState(Point position, Point distancePoint, PuzzleBoard patialBoard)
        {
            int   width                = patialBoard.Columns;
            int   height               = patialBoard.Rows;
            Point centerPos            = new Point((width - 1) / 2, (height - 1) / 2);
            Point nextPosition         = new Point(position.X + distancePoint.X, position.Y + distancePoint.Y);
            Point partialPos           = new Point(centerPos.X + distancePoint.X, centerPos.Y + distancePoint.Y);
            int   number               = _puzzleBoard.GetValue(nextPosition);
            PuzzleCellStateTypes state = _puzzleBoard.GetState(nextPosition);

            patialBoard.SetValue(partialPos, number);
            patialBoard.SetState(partialPos, state);
        }
    public void Initialize(StageDefinition stageDefinition, PoemInstance poemInstance)
    {
        this.StageDefinition = stageDefinition;
        this.poemInstance    = poemInstance;

        this.puzzleBoard = new PuzzleBoard(this, stageDefinition, poemInstance);


        // Render the board
        foreach (PuzzleCharacter character in puzzleBoard.PuzzleCharacters)
        {
            RenderPuzzleNode(character);
        }
    }
Beispiel #12
0
        public static ProblemState <T> ToProblemState <T>(this PuzzleBoard <T> perceptedObj)
        {
            var perceptedState = new ProblemState <T>(
                perceptedObj.Pieces.GetLength(0), perceptedObj.Pieces.GetLength(1));

            for (int i = 0; i < perceptedState.GetLength(0); i++)
            {
                for (int j = 0; j < perceptedState.GetLength(1); j++)
                {
                    perceptedState[i, j] = perceptedObj.Pieces[i, j].Value;
                }
            }

            return(perceptedState);
        }
Beispiel #13
0
        public PuzzlePainter(PuzzleBoard board)
        {
            this.numberFont = new Font("Arial", 12);
            this.board      = board;

            this.Offset         = new Point(10, 10);
            this.minInnerOffset = new Point(120, 100);
            this.Size           = new Point(20 * this.puzzle.Width, 20 * this.puzzle.Height); // Dummy size

            Settings s = Settings.Get;

            this.colors = new Color[5] {
                s.GetColor(Field.Decoration), s.GetColor(Field.Empty), s.GetColor(Field.Unknown), s.GetColor(Field.Black), s.GetColor(Field.Red)
            };
        }
	public void PopulateGrid(PuzzleBoard board)
	{
		PuzzleBoard = board;
		for (int y = 0; y < BoardConfig.Instance.Height; y++)
		{
			for (int x = 0; x < BoardConfig.Instance.Width; x++)
			{
				var thisOne = PuzzleBoard.GetGemAtPos(x, y);
				var newGem = GemCellPool.Instance.GetOneGemCell(thisOne);
				newGem.transform.parent = this.gameObject.transform;

				PuzzlePresentation.Instance.InitGemCell(x, y, newGem);
				//OnGemAdded(newGem);
			}
		}
	}
Beispiel #15
0
        public static PuzzleBoard <T> ToPuzzleBoard <T>(this ProblemState <T> problemState)
        {
            var state = new PuzzleBoard <T>(new PuzzlePiece <T> [problemState.GetLength(0), problemState.GetLength(1)]);

            for (int i = 0; i < problemState.GetLength(0); i++)
            {
                for (int j = 0; j < problemState.GetLength(0); j++)
                {
                    state.Pieces[i, j] = new PuzzlePiece <T> {
                        Value = problemState[i, j]
                    };
                }
            }

            return(state);
        }
Beispiel #16
0
    public void PopulateGrid(PuzzleBoard board)
    {
        PuzzleBoard = board;
        for (int y = 0; y < BoardConfig.Instance.Height; y++)
        {
            for (int x = 0; x < BoardConfig.Instance.Width; x++)
            {
                var thisOne = PuzzleBoard.GetGemAtPos(x, y);
                var newGem  = GemCellPool.Instance.GetOneGemCell(thisOne);
                newGem.transform.parent = this.gameObject.transform;

                PuzzlePresentation.Instance.InitGemCell(x, y, newGem);
                //OnGemAdded(newGem);
            }
        }
    }
 private void OnTriggerStay2D(Collider2D collision)
 {
     if (collision.gameObject.tag == "Board" && !isMouseDown && !clear)
     {
         PuzzleBoard board = collision.GetComponent <PuzzleBoard>();
         if (board.puzzleNum == puzzleNum)
         {
             clear = true;
             transform.position = collision.transform.position;
         }
     }
     if (collision.gameObject.tag == "Respawn")
     {
         remove             = false;
         transform.position = startPos;
     }
 }
        private void BtnLoadPuzzle_Click(object sender, EventArgs e)
        {
            DialogLoadPuzzle loadDialog = new DialogLoadPuzzle();

            // ToDo: Replace static hard coded folder reference with relative path
            loadDialog.InitialDirectory = @"..\..\FillAPixRobot\Puzzles";
            if (loadDialog.ShowDialog() == DialogResult.OK)
            {
                _puzzleBoard = new PuzzleBoard(loadDialog.FileName);
                _robotBrain.Activate(new Point(0, 0), new Rectangle(new Point(0, 0), _puzzleBoard.Size));
                _puzzleReferee = new PuzzleReferee(_puzzleBoard);
            }
            _gbxRobot.Enabled           = _puzzleBoard != null;
            _btnRunInBackground.Enabled = _puzzleBoard != null;
            RefreshRobotSettings();
            RefreshPlayGround();
            RecreateCells();
        }
Beispiel #19
0
        // -- Public methods --
        public bool LoadPuzzleFromFile(string filename)
        {
            // Create the streamReader
            try {
                using (StreamReader reader = new StreamReader(filename)) {
                    // Load the puzzle
                    this.puzzleBoard            = PuzzleBoard.FromString(reader.ReadToEnd());
                    this.puzzleBoard.EditorMode = Settings.Get.EditorMode;
                    this.OnResize();

                    this.updateTitleBar(filename);
                    return(true);
                }
            }
            catch {
                this.showMessage("There was an error loading the puzzle.", "Loading", StatusIcon.Error);
                return(false);
            }
        }
        private void FillPartialBoard(PuzzleBoard patialBoard, FieldOfVisionTypes fieldOfVisionType, Point position)
        {
            switch (fieldOfVisionType)
            {
            case FieldOfVisionTypes.Single:
                SetValueAndState(position, new Point(0, 0), patialBoard);
                break;

            case FieldOfVisionTypes.ThreeByThree:
                FillPartialBoard(patialBoard, FieldOfVisionTypes.Single, position);
                SetValueAndState(position, new Point(-1, 0), patialBoard);
                SetValueAndState(position, new Point(1, 0), patialBoard);
                SetValueAndState(position, new Point(0, -1), patialBoard);
                SetValueAndState(position, new Point(0, 1), patialBoard);
                SetValueAndState(position, new Point(-1, -1), patialBoard);
                SetValueAndState(position, new Point(-1, 1), patialBoard);
                SetValueAndState(position, new Point(1, 1), patialBoard);
                SetValueAndState(position, new Point(1, -1), patialBoard);
                break;

            case FieldOfVisionTypes.FiveByFive:
                FillPartialBoard(patialBoard, FieldOfVisionTypes.ThreeByThree, position);
                SetValueAndState(position, new Point(-2, 0), patialBoard);
                SetValueAndState(position, new Point(2, 0), patialBoard);
                SetValueAndState(position, new Point(0, 2), patialBoard);
                SetValueAndState(position, new Point(0, -2), patialBoard);
                SetValueAndState(position, new Point(-2, -1), patialBoard);
                SetValueAndState(position, new Point(-2, 1), patialBoard);
                SetValueAndState(position, new Point(2, -1), patialBoard);
                SetValueAndState(position, new Point(2, 1), patialBoard);

                SetValueAndState(position, new Point(-1, 2), patialBoard);
                SetValueAndState(position, new Point(1, 2), patialBoard);
                SetValueAndState(position, new Point(-1, -2), patialBoard);
                SetValueAndState(position, new Point(1, -2), patialBoard);
                SetValueAndState(position, new Point(-2, -2), patialBoard);
                SetValueAndState(position, new Point(-2, 2), patialBoard);
                SetValueAndState(position, new Point(2, -2), patialBoard);
                SetValueAndState(position, new Point(2, 2), patialBoard);
                break;
            }
        }
Beispiel #21
0
        public MainControl(StatusBarElements statusBarElements)
        {
            // Set some members
            this.puzzleBoard = new PuzzleBoard(20, 15, Settings.Get.EditorMode);
            this.mouse       = new Point(-1, -1);
            this.fileName    = "";

            // Manage threadhelper
            this.threadHelper              = new ThreadHelper();
            this.threadHelper.OnBeforeRun += updateButtonsForThreadHelper;
            this.threadHelper.OnAfterRun  += updateButtonsForThreadHelper;

            // Manage events
            this.manageEvents();

            // Add the controls
            this.statusBar = statusBarElements;
            this.addControls();
            this.clearMessage();
        }
        private PuzzleBoard CreatePartialBoard(FieldOfVisionTypes fieldOfVisionType, Point position)
        {
            PuzzleBoard partialBoard;

            switch (fieldOfVisionType)
            {
            case FieldOfVisionTypes.Single:
                partialBoard = new PuzzleBoard(1, 1);
                break;

            case FieldOfVisionTypes.ThreeByThree:
                partialBoard = new PuzzleBoard(3, 3);
                break;

            case FieldOfVisionTypes.FiveByFive:
                partialBoard = new PuzzleBoard(5, 5);
                break;

            default:
                return(null);
            }
            FillPartialBoard(partialBoard, fieldOfVisionType, position);
            return(partialBoard);
        }
Beispiel #23
0
 public GameState_SHOW_REWARD_AD(Patterns.FiniteStateMachine fsm, int id, PuzzleBoard puzzle) : base(fsm, id, puzzle)
 {
 }
        private void DrawFieldOfVision(FieldOfVisionTypes fieldOfVisionType, Point position)
        {
            PuzzleBoard partialBoard = CreatePartialBoard(fieldOfVisionType, position);

            if (partialBoard == null)
            {
                return;
            }

            int width             = partialBoard.Columns;
            int height            = partialBoard.Rows;
            int drawCellSize      = Math.Min(_pbxLookResult.Width, _pbxLookResult.Height);
            int maxFieldDimension = Math.Max(width, height);

            drawCellSize = drawCellSize / maxFieldDimension;

            int    drawWidth            = width * drawCellSize;
            int    drawHeight           = height * drawCellSize;
            Bitmap playGround           = new Bitmap(drawWidth + 1, drawHeight + 1);
            Bitmap playGroundBackground = new Bitmap(drawWidth + 1, drawHeight + 1);
            Font   font = new Font(Font.FontFamily, (int)Math.Round(drawCellSize * 0.55));

            using (Graphics graphics = Graphics.FromImage(playGround))
            {
                using (Graphics graphicsBackground = Graphics.FromImage(playGroundBackground))
                {
                    graphics.Clear(Color.Transparent);
                    graphicsBackground.Clear(Color.White);

                    for (int y = 0; y <= partialBoard.Rows; y++)
                    {
                        graphics.DrawLine(new Pen(Color.Gray), 0, y * drawCellSize, drawWidth, y * drawCellSize);
                    }
                    for (int x = 0; x <= partialBoard.Columns; x++)
                    {
                        graphics.DrawLine(new Pen(Color.Gray), x * drawCellSize, 0, x * drawCellSize, drawHeight);
                    }
                    for (int y = 0; y < partialBoard.Rows; y++)
                    {
                        for (int x = 0; x < partialBoard.Columns; x++)
                        {
                            Point cellPos = new Point(x, y);
                            int   drawX   = x * drawCellSize;
                            int   drawY   = y * drawCellSize;
                            int   number  = partialBoard.GetValue(cellPos);
                            if (number >= 0 && number <= 9)
                            {
                                Brush fontBrush = partialBoard.GetState(cellPos) == PuzzleCellStateTypes.Filled ? Brushes.White : Brushes.Black;
                                graphics.DrawString(number.ToString(), font, fontBrush, new Rectangle(drawX + (30 / maxFieldDimension), drawY + (10 / maxFieldDimension), drawCellSize, drawCellSize));
                            }
                            switch (partialBoard.GetState(cellPos))
                            {
                            case PuzzleCellStateTypes.Undefined:
                                graphicsBackground.FillRectangle(Brushes.Yellow, drawX, drawY, drawCellSize, drawCellSize);
                                break;

                            case PuzzleCellStateTypes.Filled:
                                graphicsBackground.FillRectangle(Brushes.Black, drawX, drawY, drawCellSize, drawCellSize);
                                break;

                            case PuzzleCellStateTypes.Empty:
                                graphicsBackground.FillRectangle(Brushes.Gainsboro, drawX, drawY, drawCellSize, drawCellSize);
                                graphicsBackground.DrawLine(new Pen(Color.Gray), drawX, drawY, drawX + drawCellSize, drawY + drawCellSize);
                                graphicsBackground.DrawLine(new Pen(Color.Gray), drawX, drawY + drawCellSize, drawX + drawCellSize, drawY);
                                break;

                            case PuzzleCellStateTypes.Outside:
                                graphicsBackground.FillRectangle(Brushes.DarkBlue, drawX, drawY, drawCellSize, drawCellSize);
                                graphicsBackground.DrawLine(new Pen(Color.White), drawX, drawY, drawX + drawCellSize, drawY + drawCellSize);
                                graphicsBackground.DrawLine(new Pen(Color.White), drawX, drawY + drawCellSize, drawX + drawCellSize, drawY);
                                break;
                            }
                        }
                    }
                }
            }
            _pbxLookResult.Image           = playGround;
            _pbxLookResult.BackgroundImage = playGroundBackground;
        }
Beispiel #25
0
	public void UseBoard(PuzzleBoard board)
	{
		PuzzleBoard = board;
	}
	// Use this for initialization
	void Start () 
	{
		PuzzleBoard = new PuzzleBoard(BoardConfig);
	}
Beispiel #27
0
 // Use this for initialization
 void Start()
 {
     PuzzleBoard = new PuzzleBoard(BoardConfig);
 }
Beispiel #28
0
 public void UseBoard(PuzzleBoard board)
 {
     PuzzleBoard = board;
 }
Beispiel #29
0
 public PuzzleReferee(PuzzleBoard board)
 {
     _board = board;
 }
Beispiel #30
0
 public GameState_WAIT(Patterns.FiniteStateMachine fsm, int id, PuzzleBoard puzzle) : base(fsm, id, puzzle)
 {
 }
Beispiel #31
0
 public GameState_ASTAR_SOLUTION(Patterns.FiniteStateMachine fsm, int id, PuzzleBoard puzzle) : base(fsm, id, puzzle)
 {
 }
Beispiel #32
0
 public GameState_NEXT_PUZZLE_IMAGE(Patterns.FiniteStateMachine fsm, int id, PuzzleBoard puzzle) : base(fsm, id, puzzle)
 {
 }
Beispiel #33
0
 public GameState(Patterns.FiniteStateMachine fsm, int id, PuzzleBoard puzzle) : base()
 {
     m_fsm   = fsm;
     ID      = id;
     _puzzle = puzzle;
 }
Beispiel #34
0
            /// <summary>
            /// The default constructor.
            /// </summary>
            public MyWindow()
            {
                int screenWidth;
                int screenHeight;
                int bitsPerPixel;
                int orientation;

                HardwareProvider.HwProvider.GetLCDMetrics(out screenWidth,
                                                          out screenHeight, out bitsPerPixel, out orientation);

                // Create the puzzle board.  Default to square, because all of
                // the images fit in a square.
                puzzleBoard = new PuzzleBoard(240, 240);

#if !MF_FRAMEWORK_VERSION_V3_0
                puzzleBoard.TouchGestureChanged +=
                    new TouchGestureEventHandler(puzzleBoard_Gesture);
#endif

                // Create the Reset button.
                button = new Button("Reset",
                                    Resources.GetFont(Resources.FontResources.small));
                button.HorizontalAlignment = HorizontalAlignment.Right;
                button.VerticalAlignment   = VerticalAlignment.Top;
                button.Click += new EventHandler(button_Click);

                // Create the Solve button.
                button2 = new Button("Solve",
                                     Resources.GetFont(Resources.FontResources.small));
                button2.HorizontalAlignment = HorizontalAlignment.Right;
                button2.VerticalAlignment   = VerticalAlignment.Center;
                button2.Click += new EventHandler(button2_Click);

                if (screenWidth < screenHeight)
                {
                    button.HorizontalAlignment = HorizontalAlignment.Left;
                    button.VerticalAlignment   = VerticalAlignment.Bottom;

                    button2.HorizontalAlignment = HorizontalAlignment.Center;
                    button2.VerticalAlignment   = VerticalAlignment.Bottom;
                }

                // Create a text element to display the action the user just
                // performed.
                text                     = new Text();
                text.Font                = Resources.GetFont(Resources.FontResources.small);
                text.TextContent         = " ";
                text.HorizontalAlignment =
                    Microsoft.SPOT.Presentation.HorizontalAlignment.Right;
                text.VerticalAlignment =
                    Microsoft.SPOT.Presentation.VerticalAlignment.Bottom;

                // Add a panel to hold the other controls.
                this.Child = panel;

                // Add the puzzle, buttons and text controls to the panel.
                panel.Children.Add(puzzleBoard);
                panel.Children.Add(button);
                panel.Children.Add(button2);
                panel.Children.Add(text);

                // Set the drawing attributes to a default set.
                DrawingAttributes da = new DrawingAttributes();
                puzzleBoard.DefaultDrawingAttributes = da;
            }
Beispiel #35
0
            /// <summary>
            /// The default constructor.
            /// </summary>
            public MyWindow()
            {
                int screenWidth;
                int screenHeight;
                int bitsPerPixel;
                int orientation;

                HardwareProvider.HwProvider.GetLCDMetrics(out screenWidth, 
                    out screenHeight, out bitsPerPixel, out orientation);

                // Create the puzzle board.  Default to square, because all of 
                // the images fit in a square.
                puzzleBoard = new PuzzleBoard(240, 240);

#if !MF_FRAMEWORK_VERSION_V3_0
                puzzleBoard.TouchGestureChanged += 
                    new TouchGestureEventHandler(puzzleBoard_Gesture);
#endif

                // Create the Reset button.
                button = new Button("Reset", 
                    Resources.GetFont(Resources.FontResources.small));
                button.HorizontalAlignment = HorizontalAlignment.Right;
                button.VerticalAlignment = VerticalAlignment.Top;
                button.Click += new EventHandler(button_Click);

                // Create the Solve button.
                button2 = new Button("Solve", 
                    Resources.GetFont(Resources.FontResources.small));
                button2.HorizontalAlignment = HorizontalAlignment.Right;
                button2.VerticalAlignment = VerticalAlignment.Center;
                button2.Click += new EventHandler(button2_Click);

                if (screenWidth < screenHeight)
                {
                    button.HorizontalAlignment = HorizontalAlignment.Left;
                    button.VerticalAlignment = VerticalAlignment.Bottom;

                    button2.HorizontalAlignment = HorizontalAlignment.Center;
                    button2.VerticalAlignment = VerticalAlignment.Bottom;
                }

                // Create a text element to display the action the user just 
                // performed.
                text = new Text();
                text.Font = Resources.GetFont(Resources.FontResources.small);
                text.TextContent = " ";
                text.HorizontalAlignment = 
                    Microsoft.SPOT.Presentation.HorizontalAlignment.Right;
                text.VerticalAlignment = 
                    Microsoft.SPOT.Presentation.VerticalAlignment.Bottom;

                // Add a panel to hold the other controls.
                this.Child = panel;

                // Add the puzzle, buttons and text controls to the panel.
                panel.Children.Add(puzzleBoard);
                panel.Children.Add(button);
                panel.Children.Add(button2);
                panel.Children.Add(text);

                // Set the drawing attributes to a default set.
                DrawingAttributes da = new DrawingAttributes();
                puzzleBoard.DefaultDrawingAttributes = da;
            }
Beispiel #36
0
        /// <summary>
        ///     Load graphics content for the game.
        /// </summary>
        public override void Activate(bool instancePreserved)
        {
            if (instancePreserved)
            {
                return;
            }
            if (_content == null)
            {
                _content = new ContentManager(ScreenManager.Game.Services, "Content");
            }
            _sceneRenderer = new SimpleSceneRenderer(ScreenManager.GraphicsDevice, _content)
                                 {
                                     RenderShadows = false
                                 };

            var pp = ScreenManager.GraphicsDevice.PresentationParameters;
            var aspectRatio = pp.BackBufferWidth/(float) pp.BackBufferHeight;
            _camera = new FreeCamera(SCENE_CENTER, MathHelper.ToRadians(45), aspectRatio, 0.1f,
                                     1000.0f);

            _cameraManager = new CameraManager(_camera);

            _scene = new Scene {CameraManager = _cameraManager, Ambient = new Color(0.7f, 0.7f, 0.7f)};

            var dirLight = new Light(LightType.Directional, Color.Red)
                               {
                                   Direction =
                                       new Vector3(0.45f, -0.15f, 0.875f),
                                   Position = new Vector3(5.6f, 7.6f, 12.0f)
                               };
            _scene.ShadowCastingLights.Add(dirLight);
            InitializeScene();

            // add the debug puzzleboard control
            int boardMargin = 15;
            int boardWidth = (pp.BackBufferWidth - 3*boardMargin)/3;
            int boardHeight = 5*boardWidth/7;

            var finder = new BoardLayoutFinder();
            ProcessLayouts(finder);

            var board1 = new PuzzleBoard(6, 5) {Player = _player1};
            board1.Randomize();
            _puzzleBoard1 = new PuzzleBoardWidget(this, _content, new Point(boardMargin, boardMargin),
                                                  new Point(boardWidth, boardHeight));
            _puzzleBoard1.LayoutFinder = finder;
            _puzzleBoard1.Board = board1;
            _puzzleBoard1.LayoutAccepted += LayoutAccepted;

            var board2 = new PuzzleBoard(6, 5);
            board2.Player = _player2;
            board2.Randomize();
            _puzzleBoard2 = new PuzzleBoardWidget(this, _content,
                                                  new Point(pp.BackBufferWidth - boardWidth - 2*boardMargin,
                                                            boardMargin), new Point(boardWidth, boardHeight));
            _puzzleBoard2.LayoutFinder = finder;
            _puzzleBoard2.Board = board2;

            _puzzleBoard2.LayoutAccepted += LayoutAccepted;

            //_particleManager = new ParticleManager((Game)ScreenManager.Game);
            //_particleManager.AddSystem<DustParticleSystem>(DUST_PARTICLE_SYSTEM, 10, player1.InitialPosition.Z + 0.1f);

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();
        }