Ejemplo n.º 1
0
 public static MovementDirection GetDiagonalDirectionOfXY(MovementDirection x, MovementDirection y)
 {
     if (Enum.GetNames(typeof(MovementDirection)).Contains(x.ToString() + y.ToString()))
     {
         return((MovementDirection)Enum.Parse(typeof(MovementDirection), x.ToString() + y.ToString()));
     }
     else
     {
         return((MovementDirection)Enum.Parse(typeof(MovementDirection), y.ToString() + x.ToString()));
     }
 }
Ejemplo n.º 2
0
	    private void MoveDesk(MovementDirection direction, int movementDuration)
	    {
		    var commandString = direction.ToString();

		    if (movementDuration > 0)
			    commandString += " " + movementDuration;

		    var command = Encoding.UTF8.GetBytes(commandString);

		    _deskSocket.Send(command);
	    }
Ejemplo n.º 3
0
    private void ApplyMoving(MovementDirection direction, float pixels)
    {
        Debug.Log(string.Format("Moving {0} {1} pixels", direction.ToString(), pixels));

        if (this.selectedGamePiece != null)
        {
            Debug.Log("Applying moving");

            this.selectedGamePiece.OnMoving(direction, pixels);
        }
        else
        {
            Debug.Log("Gamepiece is null");
        }
    }
Ejemplo n.º 4
0
 public void UpdateEventTimeData(MovementDirection direction)
 {
     EventData = "Move Direction: " + direction.ToString();
 }
Ejemplo n.º 5
0
 public override string ToString()
 {
     return("Direction change from " + oldDirection.ToString() + " to " + newDirection.ToString());
 }
Ejemplo n.º 6
0
        private async Task <MotionDetectionResult> DetectMotionAsync(Bitmap previousFrame, Bitmap currentFrame)
        {
            var stopwatch = new System.Diagnostics.Stopwatch();

            stopwatch.Start();
            var result = _motionDetector.ProcessFrame(currentFrame);

            stopwatch.Stop();

            MovementDirection xDirection = MovementDirection.None;
            MovementDirection yDirection = MovementDirection.None;

            if (result > DetectorConfiguration.Sensitivity)
            {
                var motionZonesList = new List <System.Drawing.Rectangle>();
                for (int x = 0, i = 0; x < _processor.MotionGrid.GetLength(0); x++)
                {
                    for (int y = 0; y < _processor.MotionGrid.GetLength(1); y++, i++)
                    {
                        if (_processor.MotionGrid[x, y] <= _processor.MotionAmountToHighlight)
                        {
                            continue;
                        }
                        motionZonesList.Add(new System.Drawing.Rectangle(new System.Drawing.Point(x, y), new System.Drawing.Size(new System.Drawing.Point(0))));
                    }
                }
                _motionDetector.MotionZones = motionZonesList.ToArray();
                if (_motionDetector.MotionZones != null && _motionDetector.MotionZones.Length > 0)
                {
                    var currentAverage = new System.Drawing.Point((int)_motionDetector.MotionZones.Average(x => x.Y), (int)_motionDetector.MotionZones.Average(x => x.X));
                    {
                        if (currentAverage.X < _lastDetectionAveragePosition.X)
                        {
                            xDirection = MovementDirection.Left;
                        }
                        else
                        {
                            xDirection = MovementDirection.Right;
                        }
                    }
                    if (currentAverage.Y < _lastDetectionAveragePosition.Y)
                    {
                        yDirection = MovementDirection.Up;
                    }
                    else
                    {
                        yDirection = MovementDirection.Down;
                    }

                    if (directionStopwatch.Elapsed.TotalMilliseconds > _directionDetectionTime)
                    {
                        _line.X1 = _lastDetectionAveragePosition.X * DetectionGrid.ActualWidth / DetectorConfiguration.Size;
                        _line.Y1 = _lastDetectionAveragePosition.Y * DetectionGrid.ActualHeight / DetectorConfiguration.Size;
                        directionStopwatch.Restart();
                        ResetDetector();
                    }

                    _lastDetectionAveragePosition = currentAverage;
                    _lastDirection = xDirection;

                    _line.X2 = _lastDetectionAveragePosition.X * DetectionGrid.ActualWidth / DetectorConfiguration.Size;
                    _line.Y2 = _lastDetectionAveragePosition.Y * DetectionGrid.ActualHeight / DetectorConfiguration.Size;
                    ;
                    XDirectionTextBlock.Text = xDirection.ToString();
                    YDirectionTextBlock.Text = yDirection.ToString();
                }
                ResetDetector();
            }
            return(new MotionDetectionResult()
            {
                Direction = (xDirection, yDirection),
                DetectionTimeMilliseconds = stopwatch.Elapsed.TotalMilliseconds
            });
Ejemplo n.º 7
0
 private void LoadScene()
 {
     SceneManager.LoadScene(directionToTeleport.ToString());
     Score.diffinc += 0.5f;
 }
Ejemplo n.º 8
0
    private void ApplyMove(MovementDirection direction)
    {
        Debug.Log(string.Format("Applying move {0}", direction.ToString()));

        if (this.selectedGamePiece != null && this.selectedGamePiece.GameBlock is IGameBlockParent)
        {
            Debug.Log("Applying move");

            BlockMovement move;
            bool          moveApplied = this.selectedGamePiece.ApplyMove(null, direction, out move);

            if (moveApplied)
            {
                Debug.Log("Move applied");

                this.movesHistory.Push(move);

                if (this.firstMove)
                {
                    this.firstMove = false;

                    this.startLevelTime = Time.time;

                    // Update the number of times played
                    string key = this.specialStageMode
                                                                         ? string.Format(
                        "{0}_{1}_{2}", SharedResources.TimesLevelPlayedPrefix, this.SpecialStage.StageId, this.Level)
                                                                         : string.Format("{0}_{1}", SharedResources.TimesLevelPlayedPrefix, this.Level);

                    int timesPlayed = PlayerPrefsFast.GetInt(key, 0);
                    timesPlayed++;
                    PlayerPrefsFast.SetInt(key, timesPlayed);
                    PlayerPrefsFast.Flush();
                }

                this.goToNextLevel = this.GameBoard.IsSolved();

                if (this.goToNextLevel)
                {
                    this.endLevelTime = Time.time;

                    bool fastComplete = this.endLevelTime - this.startLevelTime <= this.FastCompleteTime;

                    // Set the number of times it took to complete this level.  Only set this once.
                    string key = this.specialStageMode
                                                                         ? string.Format(
                        "{0}_{1}_{2}", SharedResources.TimesLevelPlayedToCompletePrefix, this.SpecialStage.StageId, this.Level)
                                                                         : string.Format("{0}_{1}", SharedResources.TimesLevelPlayedToCompletePrefix, this.Level);

                    int timesToComplete = PlayerPrefsFast.GetInt(key, 0);

                    if (timesToComplete == 0)
                    {
                        string timesPlayedKey = this.specialStageMode
                                                                                ? string.Format(
                            "{0}_{1}_{2}", SharedResources.TimesLevelPlayedPrefix, this.SpecialStage.StageId, this.Level)
                                                                                : string.Format("{0}_{1}", SharedResources.TimesLevelPlayedPrefix, this.Level);

                        timesToComplete = PlayerPrefsFast.GetInt(timesPlayedKey, 1);
                        PlayerPrefsFast.SetInt(key, timesToComplete);

                        bool beatOnFirstTry     = timesToComplete == 1;
                        bool beatOnTooManyTries = timesToComplete >= this.PlayedTooManyTimes;

                        // Give a free token if passed on the first try
                        if (beatOnFirstTry && fastComplete && !this.usedUndo)
                        {
                            ShopManager.Instance.GiveTokens(this.FastCompleteReward);
                            this.ResultsScreenFreeToken.GetComponent <UILabel>().text = string.Format(
                                "You earned {0} free tokens!", this.FastCompleteReward);
                        }
                        else if (beatOnFirstTry && !this.usedUndo)
                        {
                            ShopManager.Instance.GiveTokens(1);
                            this.ResultsScreenFreeToken.GetComponent <UILabel>().text = "You earned a free token!";
                        }
                        else if (beatOnTooManyTries)
                        {
                            this.PlayedTooManyTimesSounds.SetActive(true);
                        }

                        this.ResultsScreenFreeToken.SetActive(beatOnFirstTry && !usedUndo);
                    }
                    else
                    {
                        // This level has been beaten before, so no free token
                        this.ResultsScreenFreeToken.SetActive(false);

                        this.PlayedTooManyTimesSounds.SetActive(false);
                    }

                    if (!this.specialStageMode)
                    {
                        // Unlock the next level if needed
                        int levelUnlocked = PlayerPrefsFast.GetInt(SharedResources.LevelUnlockedKey, this.Level);

                        if (levelUnlocked <= this.Level)
                        {
                            levelUnlocked++;
                            PlayerPrefsFast.SetInt(SharedResources.LevelUnlockedKey, levelUnlocked);
                        }
                    }

                    // Log how many tries it took to complete the level
                    string levelPlayed = this.specialStageMode
                                                                                         ? string.Format("{0}_{1}", this.SpecialStage.StageId, this.Level)
                                                                                         : this.Level.ToString();
                    GoogleAnalyticsV3.instance.LogEvent("Levels", "Completed Level", levelPlayed, timesToComplete);

                    PlayerPrefsFast.Flush();
                }
            }
        }
        else
        {
            Debug.Log("Gamepiece is null");
        }
    }