Пример #1
0
 public void AddPuzzleBrick(PuzzleBrick puzzleBrick)
 {
     _puzzleBricks.Add(puzzleBrick);
 }
Пример #2
0
 private void RandomizeBrickPosition(PuzzleBrick brick, Random random)
 {
     brick.Position = new Vector2(random.Next(50 + brick.Width/2, -50 + ScreenWidth - brick.Width/2),
                                  random.Next(50 + brick.Height/2, -50 + ScreenHeight - brick.Height/2));
 }
Пример #3
0
        private void UpdatePuzzleBrickTargetLocation(PuzzleBrick brick)
        {
            var v = brick.OriginalTargetLocation;

            v += new Vector2(ScreenWidth - PuzzleBackground.Width, ScreenHeight - PuzzleBackground.Height) / 2;
            v += PuzzleBackground.Position - Center;

            brick.TargetLocation = v;
        }
Пример #4
0
        public override void Update(GameTime gameTime, Game game)
        {
            if (Mouse.GetState().LeftButton == ButtonState.Released)
            {
                _lastButtonState = ButtonState.Released;
                if (_carriedBrick != null)
                {
                    //relase puzzlebrick;

                    var v = _carriedBrick.Position - _carriedBrick.TargetLocation;

                    if (v.Length() < PuzzleDropTolerance)
                    {
                        //brick is relased in correct spot

                        _dropSound.Play();

                        _carriedBrick.MoveTo(_carriedBrick.TargetLocation, 5f);
                        _carriedBrick.BrickIsInPlace();

                        MissingBricks--;

                        if (MissingBricks == 0)
                        {
                            //all bricks correctly placed

                            _applause.Play();

                        }

                    }
                    else
                    {
                        Console.WriteLine(String.Format("name={2}, x={0}, y={1}",_carriedBrick.Position.X.ToString(), _carriedBrick.Position.Y.ToString(), _carriedBrick.Texture.Name));
                        //brick is not relased in correct spot

                        PuzzleBricks.ForEach(brick => brick.FadeIn());

                        //_returnBrick.Play();
                        //_carriedBrick.MoveTo(_carriedBrick.PanelPosition, 40.0f);
                    }
                }

                _carriedBrick = null;
            }
            if (Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                var gesturePos = GetMouseCoordinates();

                if (_carriedBrick == null && _lastButtonState == ButtonState.Released)
                {

                    PuzzleBricks.ForEach(brick =>
                    {
                        if (brick.TryPickup(gesturePos))
                            _carriedBrick = brick;

                    });

                    if (_carriedBrick!=null)
                    PuzzleBricks.Where(brick => brick.Id!=_carriedBrick.Id)
                        .ToList().ForEach(b => b.FadeOut());

                }
                else
                    if (_carriedBrick != null)
                    {
                        _carriedBrick.Position = gesturePos;

                    }
                _lastButtonState = ButtonState.Pressed;

            }

            PuzzleBricks.ForEach(brick => brick.Move());
            PuzzleBricks.ForEach(brick => brick.Fade());
        }