public static bool AdjancentToLastPiece(ISquarePiece selectedPiece, ISquarePiece lastPiece)
        {
            if (lastPiece == null)
            {
                return(true);
            }

            var myx = selectedPiece.Position.x;
            var myy = selectedPiece.Position.y;

            var lastx = lastPiece.Position.x;
            var lasty = lastPiece.Position.y;

            // check above and below
            int gap = 1;

            if (CheckAdjancent(myx, myy + gap, lastx, lasty) ||
                CheckAdjancent(myx + gap, myy + gap, lastx, lasty) ||
                CheckAdjancent(myx + gap, myy, lastx, lasty) ||
                CheckAdjancent(myx + gap, myy - gap, lastx, lasty) ||
                CheckAdjancent(myx, myy - gap, lastx, lasty) ||
                CheckAdjancent(myx - gap, myy - gap, lastx, lasty) ||
                CheckAdjancent(myx - gap, myy, lastx, lasty) ||
                CheckAdjancent(myx - gap, myy + gap, lastx, lasty))
            {
                return(true);
            }

            return(false);
        }
        public bool ConnectionValidTo(ISquarePiece nextPiece)
        {
            if (!ConnectionHelper.AdjancentToLastPiece(_squarePiece, nextPiece))
            {
                return(false);
            }

            if (nextPiece != null && nextPiece.PieceConnection is AnyAdjancentConnection)
            {
                return(true);
            }

            if (nextPiece != null && nextPiece.PieceConnection is TwoSpriteConnection)
            {
                var fade = nextPiece.PieceConnection as TwoSpriteConnection;
                if (fade.SecondColour == _squarePiece.PieceColour || fade.SecondColour == SecondColour)
                {
                    return(true);
                }
            }

            if (nextPiece != null && nextPiece.PieceColour != _squarePiece.PieceColour && nextPiece.PieceColour != SecondColour)
            {
                return(false);
            }

            return(true);
        }
        public static bool ValidConnectionBetween(ISquarePiece first, ISquarePiece second)
        {
            // If the first piece is null (eg we haven't selected anything) then it's valid.
            if (first == null)
            {
                return(true);
            }

            if (second == null)
            {
                return(false);
            }

            if (first == second)
            {
                return(false);
            }

            if (first.PieceConnection is NoConnection || second.PieceConnection is NoConnection)
            {
                return(false);
            }

            return(first.PieceConnection.ConnectionValidTo(second) || second.PieceConnection.ConnectionValidTo(first));
        }
Exemple #4
0
        public static string Serialize(ISquarePiece piece)
        {
            var sb = new StringBuilder();

            sb.Append(string.Format("{0}|{1}|{2}|", piece.Position.X, piece.Position.Y, piece.Type));
            switch (piece.Type)
            {
            case SquareTypes.Goal:
                sb.Append(((GoalPiece)piece).Goal.GoalIndex());
                break;

            case SquareTypes.Player:
                sb.Append(((PlayerPiece)piece).PlayerNumber);
                break;

            case SquareTypes.SolidWall:
                break;

            case SquareTypes.Wall:
                sb.Append(((WallPiece)piece).Direction);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(sb.ToString());
        }
        private void ExplorePiece(ISquarePiece piece, List <ISquarePiece> currentPath, List <ISquarePiece> visited)
        {
            if (TimeExpired)
            {
                return;
            }

            var neighbours = AIHelpers.GetNeighbours(restriction, piece);

            bool executed = false;

            while (neighbours.Count > 0 && currentPath.Count < MaxAllowed)
            {
                var nextPiece = neighbours.Pop();
                if (currentPath.Contains(nextPiece))
                {
                    continue;
                }
                else
                {
                    executed = true;
                    visited.Add(nextPiece);
                    currentPath.Add(nextPiece);
                }
                ExplorePiece(nextPiece, currentPath, visited);
            }

            if (!executed)
            {
                bestMove.Add(currentPath.Select(x => x).ToList());
            }
            currentPath.Remove(piece);
        }
        public override bool ValidForSelection(ISquarePiece piece)
        {
            if (piece == null || !piece.IsActive)
            {
                return(false);
            }

            if (piece.gameObject.GetComponent <ILerp>() != null && piece.gameObject.GetComponent <ILerp>().LerpInProgress)
            {
                return(false);
            }

            if (piece.DestroyPieceHandler is LockedSwap)
            {
                return(false);
            }

            if (piece.Type == PieceBuilderDirector.PieceTypes.Chest)
            {
                return(false);
            }

            if (piece.DestroyPieceHandler is DestroyTriggerFall)
            {
                if ((piece.DestroyPieceHandler as DestroyTriggerFall).ToBeDestroyed)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #7
0
        public void Piece_MouseDown(ISquarePiece piece, bool checkForAdditional)
        {
            if (GameManager.Instance.GamePaused || MenuProvider.Instance.OnDisplay)
            {
                return;
            }

            if (PieceSelectionManager.Instance.AlreadySelected(piece))
            {
                return;
            }

            if (piece.DestroyPieceHandler.ToBeDestroyed)
            {
                return;
            }

            if (ConnectionHelper.ValidConnectionBetween(PieceSelectionManager.Instance.LastPiece, piece))
            {
                PieceSelectionManager.Instance.Add(piece, checkForAdditional);
                piece.Selected();
            }
            else
            {
                TryToMapPath(piece, checkForAdditional);
            }
        }
Exemple #8
0
        public static Stack <ISquarePiece> GetNeighbours(IRestriction restriction, ISquarePiece piece)
        {
            var neighbours = new Stack <ISquarePiece>();

            var x = piece.Position.x;
            var y = piece.Position.y;

            bool DiagonalAllowed = !(restriction is DiagonalRestriction);
            bool StraightAllowed = !(restriction is DiagonalOnlyRestriction);

            if (StraightAllowed)
            {
                AddIfNeighbour(restriction, ref neighbours, piece, x + 1, y);
                AddIfNeighbour(restriction, ref neighbours, piece, x - 1, y);
                AddIfNeighbour(restriction, ref neighbours, piece, x, y + 1);
                AddIfNeighbour(restriction, ref neighbours, piece, x, y - 1);
            }

            if (DiagonalAllowed)
            {
                AddIfNeighbour(restriction, ref neighbours, piece, x + 1, y + 1);
                AddIfNeighbour(restriction, ref neighbours, piece, x - 1, y + 1);
                AddIfNeighbour(restriction, ref neighbours, piece, x + 1, y - 1);
                AddIfNeighbour(restriction, ref neighbours, piece, x - 1, y - 1);
            }

            return(neighbours);
        }
        public void Piece_MouseDown(ISquarePiece piece, bool checkForAdditional)
        {
            if (piece.Type == PieceBuilderDirector.PieceTypes.Rainbow)
            {
                return;
            }

            ChosenSprite = piece.Sprite;
        }
Exemple #10
0
        protected override void InvokeRageActionOnPiece(ISquarePiece piece)
        {
            (Sprite Sprite, Colour colour)newSprite;
            do
            {
                newSprite = PieceCreationHelpers.GetRandomSprite();
            }while (newSprite.Sprite == piece.Sprite);

            piece.gameObject.GetComponent <PieceSwapSprite>().SwapSprite(newSprite.Sprite, newSprite.colour);
        }
Exemple #11
0
        public static bool CheckSpot(ISquarePiece piece, int x, int y)
        {
            var nextPiece = PieceManager.Instance.GetPiece(x, y);

            if (nextPiece == null)
            {
                return(false);
            }

            return(ConnectionHelper.ValidConnectionBetween(piece, nextPiece));
        }
Exemple #12
0
 public void Piece_MouseEnter(ISquarePiece piece)
 {
     if (PieceSelectionManager.Instance.PieceCanBeRemoved(piece))
     {
         PieceSelectionManager.Instance.RemovePiece(piece);
     }
     else
     {
         piece.Pressed(true);
     }
 }
Exemple #13
0
        public void RemovePiece(ISquarePiece piece)
        {
            var lastPiece = CurrentPieces.Last.Value;

            while (lastPiece != piece)
            {
                RemoveLastPiece(lastPiece);
                lastPiece = CurrentPieces.Last.Value;
            }

            SelectedPiecesChanged?.Invoke(CurrentPieces);
        }
        public void AddNewPiece(ISquarePiece newPiece)
        {
            var piecesAtPosition = Pieces.Where(x => x.Position.x == newPiece.Position.x && x.Position.y == newPiece.Position.y);

            if (piecesAtPosition.Any())
            {
                Debug.LogWarning($"Tried to insert a piece into position {newPiece.Position.x}:{newPiece.Position.y} but there is already a piece there");
                return;
            }

            Pieces.Add(newPiece);
            AvaiableSlots.Add(newPiece.Position);
        }
Exemple #15
0
        public bool ConnectionValidTo(ISquarePiece nextPiece)
        {
            if (!ConnectionHelper.AdjancentToLastPiece(_squarePiece, nextPiece))
            {
                return(false);
            }

            if (nextPiece.PieceConnection is NoConnection)
            {
                return(false);
            }

            return(true);
        }
Exemple #16
0
        public void Add(ISquarePiece squarePiece, bool checkForAdditional)
        {
            if (CurrentPieces.Contains(squarePiece))
            {
                return;
            }

            CurrentPieces.AddLast(squarePiece);

            if (CurrentPieces.Count == 1 & checkForAdditional)
            {
                CheckForAdditionalPieces();
            }

            SelectedPiecesChanged?.Invoke(CurrentPieces);
        }
        public static ISquarePiece ChangePiece(ISquarePiece piece, PieceTypes newPieceType)
        {
            GameResources.PlayEffect("Piece Change", piece.transform.position);

            var newPiece = Instance.CreateSquarePiece(newPieceType, false);

            newPiece.transform.position = piece.transform.position;
            newPiece.transform.parent   = piece.transform.parent;
            newPiece.GetComponent <SquarePiece>().Position = piece.Position;

            PieceManager.Instance.Pieces.Remove(piece);
            PieceManager.Instance.Pieces.Add(newPiece.GetComponent <SquarePiece>());

            piece.gameObject.SetActive(false);

            return(newPiece.GetComponent <SquarePiece>());
        }
Exemple #18
0
        public bool AlreadySelected(ISquarePiece piece)
        {
            if (CurrentPieces.Contains(piece))
            {
                return(true);
            }

            foreach (var move in StoredMoves)
            {
                if (move.Contains(piece))
                {
                    return(true);
                }
            }

            return(false);
        }
        public static void ChangePieceColour(ISquarePiece piece, Colour newColour, Colour oldColour)
        {
            GameResources.PlayEffect("Piece Change", piece.transform.position);

            if (newColour == Colour.None)
            {
                newColour = LevelManager.Instance.SelectedLevel.Colours.RandomElement();
            }

            if (piece.PieceConnection is TwoSpriteConnection connection && connection.SecondColour == oldColour)
            {
                connection.SecondColour = newColour;
                foreach (var layer in connection.Layers)
                {
                    layer.GetComponent <SpriteRenderer>().sprite = GameResources.Sprites["Fade" + ((int)newColour).ToString()];
                }
            }
Exemple #20
0
        public bool ConnectionValidTo(ISquarePiece nextPiece)
        {
            if (!ConnectionHelper.AdjancentToLastPiece(_squarePiece, nextPiece))
            {
                return(false);
            }

            if (nextPiece != null && nextPiece.PieceConnection is AnyAdjancentConnection)
            {
                return(true);
            }

            if (nextPiece != null && nextPiece.PieceColour != _squarePiece.PieceColour)
            {
                return(false);
            }

            return(true);
        }
        public void Piece_MouseEnter(ISquarePiece piece)
        {
            if (ChosenSprite == null)
            {
                Piece_MouseDown(piece, false);
                return;
            }

            if (piece.Type == PieceBuilderDirector.PieceTypes.Rainbow)
            {
                return;
            }

            var colour = ChosenSprite.texture.GetTextureColour();

            GameResources.PlayEffect("Piece Destroy", piece.transform.position, colour);

            piece.Sprite = ChosenSprite;
        }
Exemple #22
0
        private bool PieceCanBeDestroyed(ISquarePiece pieceBelow)
        {
            if (pieceBelow.DestroyPieceHandler is HeavyDestroyTriggerFall)
            {
                return(false);
            }

            if (pieceBelow.DestroyPieceHandler is LockedSwap)
            {
                return(false);
            }

            if (pieceBelow.DestroyPieceHandler is DestroyTriggerFall && (pieceBelow.DestroyPieceHandler as DestroyTriggerFall).ToBeDestroyed)
            {
                return(false);
            }

            return(true);
        }
        private PieceBuilder GetPieceBuilder(PieceTypes type, ISquarePiece squarePiece)
        {
            switch (type)
            {
            case PieceTypes.Change:
                return(new Change());

            case PieceTypes.Chest:
                return(new Chest());

            case PieceTypes.DoublePoints:
            case PieceTypes.TriplePoints:
                return(new MultipliedPoints());

            case PieceTypes.Heart:
                return(new ExtraLife());

            case PieceTypes.Heavy:
                return(new Heavy());

            case PieceTypes.Locked:
                return(new Locked());

            case PieceTypes.Rainbow:
                return(new Rainbow());

            case PieceTypes.Swapping:
                return(new Swapping());

            case PieceTypes.FadePiece:
                return(new FadePiece());

            case PieceTypes.Bomb:
                return(new Bomb());

            case PieceTypes.Normal:
            case PieceTypes.Empty:
            default:
                return(new Normal());
            }
        }
        public void Update(ISquarePiece piece, float deltaTime)
        {
            if (PieceSelectionManager.Instance.AlreadySelected(piece))
            {
                return;
            }

            timer += deltaTime;

            if (timer > Constants.GameSettings.SwapPieceChangeFrequency)
            {
                timer = 0;
                var randomPiece = PieceCreationHelpers.GetRandomSprite();
                while (randomPiece.sprite == piece.Sprite)
                {
                    randomPiece = PieceCreationHelpers.GetRandomSprite();
                }

                piece.Sprite      = randomPiece.sprite;
                piece.PieceColour = randomPiece.colour;
            }
        }
Exemple #25
0
        private static void TryToMapPath(ISquarePiece piece, bool checkForAdditional)
        {
            var path = pathFinder.FindPath(PieceSelectionManager.Instance.LastPiece.Position, piece.Position, GameManager.Instance.Restriction);

            if (path.Count == 0)
            {
                return;
            }

            var pieces = path.Select(point => PieceManager.Instance.GetPiece(point.x, point.y));

            // If any of these pieces are currently selected then abort. Things can get a little weird otherwise.
            var alreadySelected = false;

            foreach (var p in pieces)
            {
                if (p == PieceSelectionManager.Instance.LastPiece)
                {
                    continue;
                }
                if (PieceSelectionManager.Instance.CurrentPieces.Contains(p))
                {
                    alreadySelected = true;
                    break;
                }
            }

            if (alreadySelected)
            {
                return;
            }

            // All good so select all of these pieces.
            foreach (var p in pieces)
            {
                PieceSelectionManager.Instance.Add(p, checkForAdditional);
                p.Selected();
            }
        }
        private bool passPress(TouchType eventtype, TouchRect touchbox, int x, int y, bool collide)
        {
            if (State.Congrats)
            {
                return(false);
            }
            if (GameService.ClassicGameState.Board.MoveToPosition != null)
            {
                return(false);
            }
            if (eventtype == TouchType.TouchDown)
            {
                Client.PlaySoundEffect(Assets.Sounds.Click);
                for (int i = State.Moves.Count - 1; i >= 0; i--)
                {
                    PlayerPosition undo = State.Moves[i];
                    undo.Character.Position.X = undo.X;
                    undo.Character.Position.Y = undo.Y;
                    undo.Character.Direction  = undo.Direction;
                }
                State.Moves.Clear();


                GameService.ClassicGameState.ChosenNumbers.Remove(State.CurrentChosenNumber);
                if (GameService.ClassicGameState.ChosenNumbers.Count == 0)
                {
                    ISquarePiece goal = GameService.ClassicGameState.Board.SquarePieces.First(a => a is GoalPiece && ((GoalPiece)a).Goal == GameService.ClassicGameState.CurrentGoal);

                    GameService.ClassicGameState.Board.SquarePieces.Remove(goal);

                    GameService.ClassicGameState.CharacterLost();
                    ScreenTransitioner.ChangeToBoardCardSelectionScreen();
                    return(false);
                }
                startTurn(GameService.ClassicGameState.ChosenNumbers[GameService.ClassicGameState.ChosenNumbers.Count - 1]);
            }
            return(false);
        }
Exemple #27
0
 public override bool ValidForSelection(ISquarePiece piece)
 {
     if (piece.PieceConnection is TwoSpriteConnection connection && connection.SecondColour == specificColour)
     {
         return(true);
     }
Exemple #28
0
 public Explosion(ISquarePiece sqaurePiece)
 {
     this.squarePiece = sqaurePiece;
 }
Exemple #29
0
 public void Piece_MouseDown(ISquarePiece piece, bool checkForAdditional)
 {
 }
Exemple #30
0
 public void Piece_MouseUp(ISquarePiece piece)
 {
     piece.DestroyPiece();
 }