public void ExpectFalseEqualsMethodWhithNullObjeckTest()
 {
     var numberTileFirst = new NumberTile(1);
     NumberTile numberTileSecond = null;
     bool result = numberTileFirst.Equals(numberTileSecond);
     Assert.IsFalse(result);
 }
 public void ExpectTrueEqualsMethodWhithTwoITileObjeckTest()
 {
     var numberTileFirst = new NumberTile(1);
     var numberTileSecond = new NumberTile(1);
     bool result = numberTileFirst.Equals(numberTileSecond);
     Assert.IsTrue(result);
 }
示例#3
0
    IEnumerator FallTile(NumberTile tile)
    {
        if (tile.IsOnFloor())
        {
            yield break;
        }

        List <NumberTile> aboveTiles = NumberTile.FindActiveTilesInDirection(tile, Direction.up);

        do
        {
            yield return(fallWait);

            tile.MoveTile(Direction.down);
            foreach (NumberTile aboveTile in aboveTiles)
            {
                aboveTile.MoveTile(Direction.down);
            }
        } while (!tile.IsOnFloor());

        // Add tiles to the queue to process later
        fallingTiles.Enqueue(tile);
        foreach (NumberTile aboveTile in aboveTiles)
        {
            fallingTiles.Enqueue(aboveTile);
        }
    }
示例#4
0
    void Awake()
    {
        _tile       = GetComponent <NumberTile>();
        _linkedPath = GetComponent <LinkedPath>();

        _spriteImage = GetComponent <Image>();
    }
示例#5
0
        public void InitDummy()//13*4*2 + 2
        {
            Dummy.Clear();

            Tile      tile;
            TileColor color = TileColor.RED;
            var       type  = Enum.GetValues(color.GetType());

            for (int j = 0; j < 2; j++)
            {
                foreach (TileColor v in type)
                {
                    for (int k = 1; k <= 13; k++)
                    {
                        tile = new NumberTile(v, k);
                        Dummy.Add(tile);
                    }
                }
            }

            Dummy.Add(new JokerTile(TileColor.RED));
            Dummy.Add(new JokerTile(TileColor.BLACK));

            return;
        }
示例#6
0
    bool MergeNeighbourTiles(NumberTile tile, ref List <NumberTile> mergedTiles)
    {
        int mergeCount = 0;

        foreach (Direction direction in mergeDirections)
        {
            NumberTile neighbour = tile.FindNeighbourTile(direction);
            if (NumberTile.IsActiveTile(neighbour) && tile.IsEqualNumber(neighbour))
            {
                neighbour.DeActivate();
                mergedTiles.Add(neighbour);
                mergeCount++;
            }
        }

        int multiplier = (int)Mathf.Pow(2, mergeCount);

        if (multiplier > 1)
        {
            tile.Multiply(multiplier);
            if (handler != null)
            {
                handler.OnTileMerged(tile);
            }

            return(true);
        }

        return(false);
    }
    // Use this for initialization
    void Awake()
    {
        Application.targetFrameRate = -1;
        m_timerDirector             = m_timerText.gameObject.GetComponent <PlayableDirector>();
        m_streakText.color          = new Color(Color.black.r, Color.black.g, Color.black.b, 0);
        m_streakDirector            = m_streakText.gameObject.GetComponent <PlayableDirector>();
        m_boardDirector             = GetComponent <PlayableDirector>();
        m_timer = m_turnTime;
        m_timerImage.fillAmount = m_timer / m_turnTime;
        //m_timerText.text = Mathf.CeilToInt(m_timer).ToString();

        m_boardGrid = new NumberTile[m_boardWidth, m_boardHeight];
        int boardTotal = 0;

        for (int y = 0; y < BoardGrid.GetLength(1); y++)
        {
            for (int x = 0; x < BoardGrid.GetLength(0); x++)
            {
                GameObject tileObject = Instantiate(m_tilePrefab);
                tileObject.transform.SetParent(transform, false);
                NumberTile tile = tileObject.GetComponent <NumberTile>();
                BoardGrid[x, y] = tile;
                PositionTile(tileObject, x, y);
                tile.Init(new Vector2(x, y));
                boardTotal += tile.MyNumber;
            }
        }

        m_swipeAmount         = 0;
        m_currentSwipeTotal   = 0;
        m_currentTargetNumber = UnityEngine.Random.Range(boardTotal / 4, boardTotal - 1);

        m_swipeTotal.text   = m_currentSwipeTotal.ToString();
        m_targetNumber.text = m_currentTargetNumber.ToString();
    }
示例#8
0
        public void ToString_should_return_Value_message()
        {
            var tile = new NumberTile {
                Location = new Location(0, 0), Value = 2
            };

            tile.ToString().Should().Be("Tile [0, 0]: Value 2");
        }
        public void TestLabelOfNumberTile()
        {
            var numberTile = new NumberTile(2);
            const string ExpectLabel = "2";
            string actualLabel = numberTile.Label;

            Assert.AreEqual(ExpectLabel, actualLabel);
        }
示例#10
0
    public static NumberTile FindFloorTile(NumberTile tile)
    {
        NumberTile nextTile = tile.FindNeighbourTile(Direction.down);

        while (IsInactiveTile(nextTile))
        {
            tile     = nextTile;
            nextTile = tile.FindNeighbourTile(Direction.down);
        }

        return(tile);
    }
示例#11
0
 public bool MoveToTile(NumberTile tile)
 {
     if (IsInactiveTile(tile))
     {
         this.DeActivate();
         this.CopyTileProperties(tile);
         this.Activate();
         this.hasMoved = true;
         return(true);
     }
     return(false);
 }
示例#12
0
    IEnumerator FallAndMergeTile(NumberTile tile)
    {
        yield return(FallTile(tile));

        if (activeTile != null && tile == activeTile)
        {
            DisableControl();
        }

        if (fallingTiles.Count != 0)
        {
            yield return(new WaitForSeconds(0.2f));
        }

        List <NumberTile> mergedTiles = new List <NumberTile>();

        while (fallingTiles.Count != 0)
        {
            NumberTile fallingTile = fallingTiles.Dequeue();
            if (MergeNeighbourTiles(fallingTile, ref mergedTiles))
            {
                yield return(null);

                // Play and wait for animation to finish
                fallingTile.View.PlayUpdateAnimation();
                yield return(new WaitForSeconds(1));

                // Add the Tile again to see if it can merge with anything else
                if (fallingTile.IsOnFloor())
                {
                    fallingTiles.Enqueue(fallingTile);
                }
            }
        }

        Queue <Coroutine> fallingTilesQueue = new Queue <Coroutine>();

        foreach (NumberTile mergedTile in mergedTiles)
        {
            NumberTile neighbour = NumberTile.TryFindActiveTopTile(mergedTile);
            if (NumberTile.IsActiveTile(neighbour))
            {
                Coroutine c = StartCoroutine(FallAndMergeTile(neighbour));
                fallingTilesQueue.Enqueue(c);
            }
        }

        while (fallingTilesQueue.Count != 0)
        {
            yield return(fallingTilesQueue.Dequeue());
        }
    }
示例#13
0
        public int Group()
        {
            List <TileColor> tilesColor = new List <TileColor>();
            int tileNumber1             = 0;
            int count_numberTile        = 0;

            if (Tiles.Count < 3 || Tiles.Count > 4)
            {
                return(0);
            }
            //타일의 개수 3개 미만 4개 초과일 경우 바로 false 반환

            for (int i = 0; i < Tiles.Count; i++)
            {
                Tile tile = Tiles[i];
                if (tile is NumberTile)
                { //조커 타일일 경우 고려x
                    NumberTile numberTile = (NumberTile)tile;
                    count_numberTile++;

                    if (tilesColor.Count == 0)
                    {
                        tilesColor.Add(numberTile.Color);
                        tileNumber1 = numberTile.Number;
                        //처음 타일은 바로 넣기
                    }
                    else
                    {
                        if (tileNumber1 != numberTile.Number)
                        {
                            return(0);
                        }
                        //맨 처음 숫자와 다를 경우 false 반환

                        for (int j = 0; j < count_numberTile - 1; j++)
                        {
                            //그 전까지의 타일 색상 비교
                            if (tilesColor[j] == numberTile.Color)
                            {
                                return(0);
                            }
                            else
                            {
                                tilesColor.Add(numberTile.Color);
                            }
                        }
                    }
                }
            }
            return(tileNumber1 * Tiles.Count);
        }
示例#14
0
    public static List <NumberTile> FindActiveTilesInDirection(NumberTile tile, Direction dir)
    {
        List <NumberTile> tiles = new List <NumberTile>();

        NumberTile nextTile = tile.FindNeighbourTile(dir);

        while (IsActiveTile(nextTile))
        {
            tiles.Add(nextTile);
            nextTile = nextTile.FindNeighbourTile(dir);
        }

        return(tiles);
    }
示例#15
0
    public static NumberTile TryFindActiveTopTile(NumberTile tile)
    {
        NumberTile nextTile = tile.FindNeighbourTile(Direction.up);

        while (IsInactiveTile(nextTile))
        {
            tile     = nextTile;
            nextTile = tile.FindNeighbourTile(Direction.up);
        }

        if (IsActiveTile(nextTile))
        {
            return(nextTile);
        }


        return(null);
    }
示例#16
0
    public void HandlePlayerInput(Direction direction)
    {
        if (!inputEnabled || NumberTile.IsInactiveTile(activeTile))
        {
            return;
        }

        switch (direction)
        {
        case Direction.left:
        case Direction.right:
            activeTile.MoveTile(direction);
            break;

        case Direction.down:
            activeTile.DropToFloor();
            DisableControl();
            break;
        }
    }
示例#17
0
    public bool MoveTile(Direction direction)
    {
        NumberTile neighbour = FindNeighbourTile(direction);

        return(MoveToTile(neighbour));
    }
示例#18
0
 public static bool IsActiveTile(NumberTile tile)
 {
     return(tile != null && tile.Active);
 }
示例#19
0
 public void OnTileMerged(NumberTile tile)
 {
     this.score.IncreaseScore(tile.Number);
 }
示例#20
0
 public bool IsSameCell(NumberTile tile)
 {
     return(this.cell == tile.cell);
 }
示例#21
0
 public bool IsEqualNumber(NumberTile tile)
 {
     return(this.Number == tile.Number);
 }
 public void TestToStringMethodInTile()
 {
     var numberTile = new NumberTile(1);
     numberTile.ToString();
 }
示例#23
0
        public int Run()
        {
            TileColor beginningColor = TileColor.BLACK;
            TileColor currentColor   = TileColor.BLACK;
            int       jokerNumber1   = 0;
            int       jokerNumber2   = 0;

            if (Tiles.Count < 3)
            {
                return(0);
            }
            for (int i = 0; i < Tiles.Count; i++)
            {
                Tile tile = Tiles[i];
                if (tile is NumberTile)
                {
                    NumberTile numberTile = (NumberTile)tile;
                    if (i != 0)
                    {
                        if (Tiles[i - 1] is JokerTile)//전타일이 조커일때
                        {
                            jokerNumber1 = numberTile.Number - 1;
                            if (i >= 2)
                            {
                                if (Tiles[i - 2] is JokerTile)  //조커 조커 일 경우
                                {
                                    jokerNumber2 = jokerNumber1 + 1;
                                }
                                else
                                {
                                    Tile       tile2         = Tiles[i - 2];
                                    NumberTile twotilebefore = (NumberTile)tile2;
                                    if ((twotilebefore.Number + 1) != jokerNumber1)
                                    {
                                        return(0);
                                    }
                                }
                            }
                            beginningColor = numberTile.Color;
                        }
                        else
                        {
                            Tile       tile2       = Tiles[i - 1];
                            NumberTile numberTile2 = (NumberTile)tile2;
                            if (numberTile.Number != numberTile2.Number + 1)
                            {
                                return(0);//전타일 +1 이 아니면 RUN아님
                            }
                        }
                    }
                    if (i == 0)
                    {
                        beginningColor = numberTile.Color;
                    }
                    currentColor = numberTile.Color;
                }
                else if (tile is JokerTile)
                {
                    if (i != 0)
                    {//처음이 조커이면 무시
                        //지금 읽은 타일이 조커라면
                        Tile tile2 = Tiles[i - 1];
                        if (tile2 is JokerTile)
                        {
                            jokerNumber2 = jokerNumber1 + 1;
                        }
                        else
                        {
                            NumberTile numberTile2 = (NumberTile)tile2;
                            jokerNumber2 = numberTile2.Number + 1;
                        }
                    }
                }
                if (!Equals(beginningColor, currentColor))
                {
                    return(0);
                }
            }
            return(jokerNumber1 + jokerNumber2 + Tiles.Sum(tile => {
                return tile is NumberTile ? (tile as NumberTile).Number : 0;
            }));
        }
示例#24
0
 void GetNewActiveTile()
 {
     activeTile = new NumberTile(gameGrid, activeTileSpawnPosition);
     activeTile.Activate();
     activeTile.Number = randomTileSelector.GetRandomTileNumber();
 }
示例#25
0
    public bool DropToFloor()
    {
        NumberTile floorTile = FindFloorTile(this);

        return(MoveToTile(floorTile));
    }
示例#26
0
    public bool IsOnFloor()
    {
        NumberTile neighbour = FindNeighbourTile(Direction.down);

        return(neighbour == null || IsActiveTile(neighbour));
    }
示例#27
0
 void CopyTileProperties(NumberTile tile)
 {
     this.cell = tile.cell;
     tile.numberTileView.Number = this.numberTileView.Number;
     this.numberTileView        = tile.numberTileView;
 }
 public void TestGetHashCodeMethodInTile()
 {
     var numberTile = new NumberTile(1);
     numberTile.GetHashCode();
 }
示例#29
0
 public void ResetFallingTile()
 {
     activeTile = null;
 }