Exemple #1
0
        /// <summary>
        /// 抽奖API
        /// </summary>
        /// <returns></returns>
        public IHttpActionResult Draw()
        {
            var roulette   = RouletteHelper.BuildRoulette();
            var prizeIndex = RouletteHelper.rand.Next(roulette.Count);

            return(Ok(roulette[prizeIndex]));
        }
Exemple #2
0
        public async Task <Roulette> ConfigureRoulette(BetModel model, User user)
        {
            Roulette roulette = await _rouletteRepository.GetRouletteById(model.RouletteId);

            RouletteHelper.CheckBetRoulette(roulette, model.RouletteId);
            BetRoulette bet = new BetRoulette(model, user);

            roulette.AddBet(bet);
            return(roulette);
        }
Exemple #3
0
        public async Task <BetMessageModel> CloseRoulette(string id)
        {
            var roulette = await _rouletteRepository.GetRouletteById(id);

            RouletteHelper.CheckBetRoulette(roulette, id);
            roulette.Status = "Close";
            await _rouletteRepository.UpdateRoulette(roulette);

            var message = RouletteHelper.ChooseWinningBet(roulette);

            return(new BetMessageModel(
                       message,
                       roulette.Bets
                       ));
        }
Exemple #4
0
        /// <summary>
        /// 抽奖
        /// </summary>
        /// <param name="member"></param>
        /// <returns></returns>
        public JsonResult Draw(Member member)
        {
            member.IP = Request.UserHostAddress;

            if (CheckMember(member))
            {
                return(Json(new { result = false, msg = "您已经参加抽奖,请不要重复抽奖。" }, JsonRequestBehavior.AllowGet));
            }

#if DEBUG
            return(Json(new { result = true, prize = new Prize()
                              {
                                  Id = 1, Name = "特等奖", Angle = 117
                              }, ticket = "000" }, JsonRequestBehavior.AllowGet));
#else
            var roulette   = RouletteHelper.BuildRoulette();
            var prizeIndex = RouletteHelper.rand.Next(roulette.Count);
            var prize      = roulette[prizeIndex];

            var ticket = LogPrize(member, prize);

            return(Json(new { result = true, prize = roulette[prizeIndex], ticket = ticket }, JsonRequestBehavior.AllowGet));
#endif
        }
        /// <summary>
        /// Update Method
        /// </summary>
        /// <param name="gameTime">Current Game Time</param>
        protected override void Update(TimeSpan gameTime)
        {
            WaveServices.Layout.PerformLayout();

            switch (_scene.GameState)
            {
            case GameStateEnum.Automatic:
                if (_timer == null)
                {
                    _soundManager.PlaySound(SimpleSoundService.SoundType.Timer, 1f, true);

                    _timer = WaveServices.TimerFactory.CreateTimer("TimeToWait", TimeSpan.FromSeconds(1f), () =>
                    {
                        _time--;
                        _scene.TimerLeftTextBlock.Text = _time + " s";
                    });
                }
                else if (_time <= 0)
                {
                    WaveServices.TimerFactory.RemoveTimer("TimeToWait");
                    _scene.TimerLeftTextBlock.Text = "- s";

                    if (_timer2 == null)
                    {
                        _soundManager.StopAllSounds();

                        _revoluteJoint.EnableMotor = true;

                        _timer2 = WaveServices.TimerFactory.CreateTimer("TimeToAceletare", TimeSpan.FromSeconds(1f), () =>
                        {
                            _aceleratingTime--;
                        });
                    }

                    if (_aceleratingTime <= 0)
                    {
                        WaveServices.TimerFactory.RemoveTimer("TimeToAceletare");

                        _revoluteJoint.EnableMotor = false;
                    }
                }

                break;

            case GameStateEnum.Manual:
                WaveServices.TimerFactory.RemoveAllTimers();
                _timer  = null;
                _timer2 = null;
                _scene.TimerLeftTextBlock.Text = "- s";
                _revoluteJoint.EnableMotor     = false;

                _touchState = WaveServices.Input.TouchPanelState;
                if (_touchState.IsConnected)
                {
                    // Checks Mouse Left Button Click and anyone entity linked
                    if (_touchState.Count > 0 && _mouseJoint == null)
                    {
                        foreach (var touch in _touchState)
                        {
                            // Updates Mouse Position
                            _touchPosition = touch.Position;

                            // Adjust the position to the Viewport.
                            _scene.VirtualScreenManager.ToVirtualPosition(ref _touchPosition);

                            // Collider Test
                            var collider = _needleImage.FindComponent <CircleCollider2D>();
                            if (collider != null && collider.Contain(_touchPosition))
                            {
                                var rigidBody = _needleImage.FindComponent <RigidBody2D>();
                                if (rigidBody != null)
                                {
                                    _touchingId = touch.Id;

                                    // Create Mouse Joint
                                    _mouseJoint = new MouseJoint2D()
                                    {
                                        Target = _touchPosition
                                    };
                                    _needleImage.AddComponent(_mouseJoint);

                                    // We break after collide because no more than one touch can be Joint to entity.
                                    break;
                                }
                            }
                        }
                    }

                    // If joint exists then update joint anchor position.
                    // If touchReleased Then touchFound = false; so Remove the Joint to conserve physics.
                    if (_mouseJoint != null)
                    {
                        TouchLocation touchLocation;

                        if (_touchState.TryGetTouch(_touchingId, out touchLocation))
                        {
                            _touchPosition = touchLocation.Position;
                            _scene.VirtualScreenManager.ToVirtualPosition(ref _touchPosition);

                            _mouseJoint.Target = _touchPosition;
                        }
                        else
                        {
                            if (!_needleImage.IsDisposed)
                            {
                                _needleImage.RemoveComponent <MouseJoint2D>();
                            }

                            _mouseJoint = null;
                        }
                    }
                }

                break;
            }

            // Collision with pieces when the needle stops.
            var angularVelocity = _needleImageRigidBody2D.AngularVelocity;

            if (!_stopRepeat && angularVelocity > -0.005f && angularVelocity < 0.005f)
            {
                _soundManager.StopAllSounds();

                Movement movement = RouletteHelper.GetMovementFromRotation(_needleImage.FindComponent <Transform2D>().Rotation);

                movement.Number          = _movementsCount++;
                movement.NumberOfPlayers = _numberOfPlayers;

                Movement repeatedFingerMovement = null;
                switch (_numberOfPlayers)
                {
                case NumberPlayerEnum.OnePlayer:
                    repeatedFingerMovement = _movementsList.Find(x => x.Finger == movement.Finger);
                    if (repeatedFingerMovement != null)
                    {
                        if (repeatedFingerMovement.Color != movement.Color)
                        {
                            _movementToRemove = repeatedFingerMovement;
                            _movementsList.Add(movement);
                        }
                    }
                    else
                    {
                        _movementsList.Add(movement);
                    }
                    break;

                case NumberPlayerEnum.TwoPlayers:
                    repeatedFingerMovement = _movementsList.Find(x => x.PlayerNumber != _playerPlaying && x.Finger == movement.Finger);
                    if (repeatedFingerMovement != null)
                    {
                        if (repeatedFingerMovement.Color != movement.Color)
                        {
                            _movementToRemove = repeatedFingerMovement;
                            _movementsList.Add(movement);
                        }
                    }
                    else
                    {
                        _movementsList.Add(movement);
                    }
                    break;
                }

                _noMovementsTextBlock.IsVisible = false;
                _movementsTextBlockText.Text   += "\n" + movement.ToString();

                if (_numberOfPlayers == NumberPlayerEnum.TwoPlayers)
                {
                    if (_playerPlaying == 1)
                    {
                        _playerPlaying++;
                    }
                    else
                    {
                        _playerPlaying--;
                    }
                }

                if (_scene.GameState == GameStateEnum.Automatic)
                {
                    ResetAutomaticTimers();
                }

                _soundManager.PlaySound(SimpleSoundService.SoundType.Pick);

                _stopRepeat = true;
            }

            // When needle start to ride, it's time to another movement
            if (angularVelocity > 0.01f || angularVelocity < -0.01f)
            {
                _stopRepeat = false;

                if (_movementsList.Any(x => x.CirclePressed == null))
                {
                    GameOver();
                }
            }

            if (angularVelocity > 2f || angularVelocity < -2f)
            {
                if (_sound == null || _sound.State == SoundState.Stopped)
                {
                    _sound = _soundManager.PlaySound(SimpleSoundService.SoundType.Rotating);
                }
            }

            List <Entity> circlesPressed = new List <Entity>();

            // We check the Circles to assign the collider with touch.
            _touchState = WaveServices.Input.TouchPanelState;
            if (_touchState.IsConnected)
            {
                foreach (Entity entity in _scene.EntityManager.FindAllByTag("MatCircles"))
                {
                    var opacity = 1f;

                    foreach (var touch in _touchState)
                    {
                        // Updates Mouse Position
                        _touchPosition = touch.Position;

                        _scene.VirtualScreenManager.ToVirtualPosition(ref _touchPosition);

                        var collider = entity.FindComponent <CircleCollider2D>();
                        if (collider != null && collider.Contain(_touchPosition))
                        {
                            circlesPressed.Add(entity);
                            opacity = 0.5f;

                            break;
                        }
                    }

                    entity.FindComponent <Transform2D>().Opacity = opacity;
                }
            }

            // Check if user adds a new circle touch.
            foreach (var circle in circlesPressed)
            {
                if (!_movementsList.Any(x => x.CirclePressed == circle))
                {
                    var emptyMovement = _movementsList.Find(x => x.CirclePressed == null);
                    if (emptyMovement != null && emptyMovement.Color == circle.FindComponent <Sprite>().TintColor)
                    {
                        emptyMovement.CirclePressed = circle;
                        _movementsList.Remove(_movementToRemove);
                        _movementToRemove = null;
                    }
                    else
                    {
                        GameOver();
                    }
                }
            }

            // Check if user removes a circle touch.
            if (circlesPressed.Count < _lastCirclesPressed.Count)
            {
                Entity circleRemoved = null;

                foreach (var lastCircle in _lastCirclesPressed)
                {
                    if (!circlesPressed.Contains(lastCircle))
                    {
                        circleRemoved = lastCircle;
                        break;
                    }
                }

                if (circleRemoved != null)
                {
                    var movement = _movementsList.Find(x => x.CirclePressed == circleRemoved);

                    if (movement != null && movement != _movementToRemove)
                    {
                        GameOver();
                    }
                }
            }

            _lastCirclesPressed = circlesPressed.ToList();
        }
Exemple #6
0
        /// <summary>
        /// Update Method
        /// </summary>
        /// <param name="gameTime">Current Game Time</param>
        protected override void Update(TimeSpan gameTime)
        {
            WaveServices.Layout.PerformLayout();

            switch (_scene.GameState)
            {
            case GameStateEnum.Automatic:
                if (_timer == null)
                {
                    _soundManager.PlaySound(SimpleSoundService.SoundType.Timer, 1f, true);

                    _timer = WaveServices.TimerFactory.CreateTimer("TimeToWait", TimeSpan.FromSeconds(1f), () =>
                    {
                        _time--;
                        _scene.TimerLeftTextBlock.Text = _time + " s";
                    });
                }
                else if (_time <= 0)
                {
                    WaveServices.TimerFactory.RemoveTimer("TimeToWait");
                    _scene.TimerLeftTextBlock.Text = "- s";

                    if (_timer2 == null)
                    {
                        _soundManager.StopAllSounds();

                        _revoluteJoint.EnableMotor = true;

                        _timer2 = WaveServices.TimerFactory.CreateTimer("TimeToAceletare", TimeSpan.FromSeconds(1f), () => { _aceleratingTime--; });
                    }

                    if (_aceleratingTime <= 0)
                    {
                        WaveServices.TimerFactory.RemoveTimer("TimeToAceletare");

                        _revoluteJoint.EnableMotor = false;
                    }
                }

                break;

            case GameStateEnum.Manual:
                WaveServices.TimerFactory.RemoveAllTimers();
                _timer  = null;
                _timer2 = null;
                _scene.TimerLeftTextBlock.Text = "- s";
                _revoluteJoint.EnableMotor     = false;

                _touchState = WaveServices.Input.TouchPanelState;
                if (_touchState.IsConnected)
                {
                    // Checks Mouse Left Button Click and anyone entity linked
                    if (_touchState.Count > 0 && _mouseJoint == null)
                    {
                        foreach (var touch in _touchState)
                        {
                            // Updates Mouse Position
                            _touchPosition = touch.Position;

                            // Adjust the position to the Viewport.
                            _scene.VirtualScreenManager.ToVirtualPosition(ref _touchPosition);

                            // Collider Test
                            var collider = _needleImage.FindComponent <CircleCollider2D>();
                            if (collider != null && collider.Contain(_touchPosition))
                            {
                                var rigidBody = _needleImage.FindComponent <RigidBody2D>();
                                if (rigidBody != null)
                                {
                                    _touchingId = touch.Id;

                                    // Create Mouse Joint
                                    _mouseJoint = new MouseJoint2D()
                                    {
                                        Target = _touchPosition
                                    };
                                    _needleImage.AddComponent(_mouseJoint);

                                    // We break after collide because no more than one touch can be Joint to entity.
                                    break;
                                }
                            }
                        }
                    }

                    // If joint exists then update joint anchor position.
                    // If touchReleased Then touchFound = false; so Remove the Joint to conserve physics.
                    if (_mouseJoint != null)
                    {
                        TouchLocation touchLocation;

                        if (_touchState.TryGetTouch(_touchingId, out touchLocation))
                        {
                            _touchPosition = touchLocation.Position;
                            _scene.VirtualScreenManager.ToVirtualPosition(ref _touchPosition);

                            _mouseJoint.Target = _touchPosition;
                        }
                        else
                        {
                            if (!_needleImage.IsDisposed)
                            {
                                _needleImage.RemoveComponent <MouseJoint2D>();
                            }

                            _mouseJoint = null;
                        }
                    }
                }

                break;
            }

            // Collision with pieces when the needle stops.
            float angularVelocity = _needleImageRigidBody2D.AngularVelocity;

            if (!_stopRepeat && angularVelocity > -0.005f && angularVelocity < 0.005f)
            {
                _soundManager.StopAllSounds();

                Movement movement = RouletteHelper.GetMovementFromRotation(_needleImage.FindComponent <Transform2D>().Rotation);

                movement.Number          = _movementsCount++;
                movement.NumberOfPlayers = _scene.NumberOfPlayers;

                _noMovementsTextBlock.IsVisible = false;
                _movementsTextBlockText.Text   += "\n" + movement.ToString();

                if (_scene.GameState == GameStateEnum.Automatic)
                {
                    ResetAutomaticTimers();
                }

                _soundManager.PlaySound(SimpleSoundService.SoundType.Pick);

                _stopRepeat = true;
            }

            // When needle start to ride, it's time to another movement
            if (angularVelocity > 0.01f || angularVelocity < -0.01f)
            {
                _stopRepeat = false;
            }

            if (angularVelocity > 2f || angularVelocity < -2f)
            {
                if (_sound == null || _sound.State == SoundState.Stopped)
                {
                    _sound = _soundManager.PlaySound(SimpleSoundService.SoundType.Rotating);
                }
            }
        }