Esempio n. 1
0
        public void RevertLastChange()
        {
            if (playerChanges.Count == 0)
            {
                return;
            }

            Change  change            = playerChanges.Pop();
            IntPair startPos          = change.pos;
            IntPair direction         = change.dir;
            IntPair newPos            = startPos + direction;
            IntPair oppositeDirection = direction * -1;

            SetBlock(newPos, false);
            SetBlock(startPos, true);
            OnBlockMoved?.Invoke(newPos, oppositeDirection, 1f / 10f);
        }
Esempio n. 2
0
        public bool PushBlock(IntPair blockPosition, IntPair direction)
        {
            if (!BlockExists(blockPosition))
            {
                return(false);
            }
            IntPair pushPosition = blockPosition + direction;

            if (GetIndexFromPosition(pushPosition) == -1 ||
                BlockExists(pushPosition))
            {
                return(false);
            }
            SetBlock(blockPosition, false);
            SetBlock(pushPosition, true);
            playerChanges.Push(new Change(blockPosition, direction));
            OnBlockMoved?.Invoke(blockPosition, direction, 0.5f);
            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="user">User</param>
        /// <param name="gameOptions">Game options</param>
        internal GameManager(User user, GameOptions gameOptions)
        {
            this.user         = user;
            GameOptions       = gameOptions;
            Level             = gameOptions.StartingLevel;
            lastBlockStepTime = DateTime.Now;
            gameManagerThread = new Thread((that) =>
            {
                if (that is GameManager)
                {
                    GameManager game_manager = (GameManager)that;
                    while (game_manager.keepRunning)
                    {
                        EBlock block;
                        EBlockStepState step_state = BlockStep(out block);
                        switch (step_state)
                        {
                        case EBlockStepState.Nothing:
                            break;

                        case EBlockStepState.Move:
                            OnBlockMoved?.Invoke(block);
                            break;

                        case EBlockStepState.Land:
                            OnBlockLanded?.Invoke(block);
                            break;

                        case EBlockStepState.SelectNew:
                            OnNewBlockSelected?.Invoke(block);
                            break;

                        case EBlockStepState.Loose:
                            OnGameLost?.Invoke(block);
                            break;
                        }
                        Thread.Sleep(2);
                    }
                }
            });
            gameManagerThread.Start(this);
        }