Exemple #1
0
    private void ShuffleBoard()
    {
        int rows            = gemsBoard.GetLength(0);
        int columns         = gemsBoard.GetLength(1);
        var randomizedBoard = new Gem[rows, columns];

        int[] shuffledRowIndexes    = Enumerable.Range(0, rows).ToArray();
        int[] shuffledColumnIndexes = Enumerable.Range(0, columns).ToArray();

        System.Random rnd = new System.Random();
        shuffledRowIndexes = shuffledRowIndexes.OrderBy(x => rnd.Next()).ToArray();

        var center = GetBoardCenterPosition();
        var posX   = center.x - gemSize.x * (boardWidth / 2);

        for (int i = 0; i < rows; i++)
        {
            shuffledColumnIndexes = shuffledColumnIndexes.OrderBy(x => rnd.Next()).ToArray();
            var posY = center.y - gemSize.y * (boardHeight / 2);

            for (int j = 0; j < columns; j++)
            {
                randomizedBoard[i, j] = gemsBoard[shuffledRowIndexes.ElementAt(i), shuffledColumnIndexes.ElementAt(j)];

                randomizedBoard[i, j].TargetPosition = new Vector2(posX, posY);
                randomizedBoard[i, j].Column         = i;
                randomizedBoard[i, j].Row            = j;
                posY += gemSize.y;
            }

            posX += gemSize.x;
        }

        gemsBoard = randomizedBoard;
    }
Exemple #2
0
    public void CreateBoard(int seed)
    {
        if (boardGameObject != null)
        {
            Debug.LogWarning("Trying to create a new board, but this manager already has one. Ignoring...");
            return;
        }

        // Create the root node (aka board node)
        boardGameObject = new GameObject("Board");

        gemsTable = new Gem[boardNumCells.x, boardNumCells.y];
        System.Random rnd = new System.Random(seed);
        for (int x = 0, y = 0; x < boardNumCells.x; x++, y = 0)
        {
            for (; y < boardNumCells.y; y++)
            {
                GameObject obj = Instantiate(gemPrefab, GemPositionForIndex(x, y), Quaternion.identity, boardGameObject.transform) as GameObject;
                Gem        gem = obj.GetComponent <Gem>();

                gem.SetType(gemsInfo.Info[rnd.Next(gemsInfo.Info.Length)]);

                gem.SetIndex(new Vector2Int(x, y));
                gemsTable[x, y] = gem;

                SpriteRenderer spriteRenderer = obj.GetComponent <SpriteRenderer>();
                float          scaleRatioX    = boardCellSize.x / spriteRenderer.size.x;
                float          scaleRatioY    = boardCellSize.y / spriteRenderer.size.y;
                obj.transform.localScale = new Vector3(scaleRatioX, scaleRatioY, obj.transform.localScale.z);
            }
        }

        FixInitialBoard();
    }
Exemple #3
0
        /// <summary>
        /// Прикрепление спрайтов к камешкам в массиве
        /// </summary>
        /// <param name="gems">Двумерный массив камешков.</param>
        public void AttachSpritesTo(Gem[,] gems)
        {
            // маркер появления на игровом поле разрушителя, для проигрывания
            // звука появления разрушителя
            bool hasDestroyers = false;
            bool hasBomb       = false;

            foreach (Gem gem in gems)
            {
                AttachSpriteTo(gem);

                hasDestroyers |= gem.IsALineDestroyer;
                hasBomb       |= gem.IsABomb;
            }

            // проигрывам звук появления разрушителя
            if (hasBomb)
            {
                RunAction(newBombSound);
            }
            else if (hasDestroyers)
            {
                RunAction(newDestroyerSound);
            }
        }
Exemple #4
0
    List <Gem> matchesThree(Gem[,] gemmall, int row, int col)//
    {
        List <Gem> match = new List <Gem>();

        if (col <= 2 && gemmall[row, col].match3(gemmall[row, col + 1]))//
        {
            //if (row >=2 && col<GetArrayMatch.SizeX - 2 && gemmall[row, col].match3(gemmall[row - 1, col + 2]) ||
            //row >= GetArrayMatch.SizeY - 2 && gemmall[row, col].match3(gemmall[row + 1, col + 2]))
            //{
            if (row > 0 && col >= 2 && gemmall[row, col].match3(gemmall[row - 1, col + 2]))
            {
                match.Add(gemmall[row, col]);
                match.Add(gemmall[row, col + 1]);
                Scale2Match(gemmall[row - 1, col + 2].hitGem);
                Scale2Match(gemmall[row, col + 2].hitGem);
                //match.Add(match1);
                Debug.Log("match:" + row + "," + col + ";" + (row) + "," + (col + 1) + ";" + (row - 1) + "," + (col + 2));
                vslist.Add("match:" + row + "," + col + ";" + (row) + "," + (col + 1) + ";" + (row - 1) + "," + (col + 2));
                List <Vector2> vsadd = new List <Vector2>();
                vsadd.Add(new Vector2(-2.37f, -4.27f) + (new Vector2(col * 0.6f, row * 0.6f)));
                vsadd.Add(new Vector2(-2.37f, -4.27f) + (new Vector2((col + 1) * 0.6f, row * 0.6f)));
                vsadd.Add(new Vector2(-2.37f, -4.27f) + (new Vector2((col + 2) * 0.6f, (row - 1) * 0.6f)));
                xlist1.Add(vsadd);
            }
        }
        return(match);//
    }
Exemple #5
0
    public void BoardTest()
    {
        Board board = AssetDatabase.LoadAssetAtPath <Board>("Assets/Prefabs/Board.prefab");

        board = GameObject.Instantiate(board);

        typeof(Board).GetMethod("Start", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(board, null);

        Gem gem = board.GetComponentInChildren <Gem>();

        Assert.IsNotNull(gem);

        FieldInfo  gemsInfo  = typeof(Board).GetField("gems", BindingFlags.NonPublic | BindingFlags.Instance);
        FieldInfo  colorInfo = typeof(Gem).GetField("color", BindingFlags.NonPublic | BindingFlags.Instance);
        MethodInfo checkIsMatchPossibleInfo = typeof(Board).GetMethod("CheckIsMatchPossible", BindingFlags.NonPublic | BindingFlags.Instance);

        Gem[,] gems = (Gem[, ])gemsInfo.GetValue(board);

        int i = 0;

        foreach (int[,] gemColors in gemsToCheck)
        {
            for (int y = 0; y < board.Size.y; y++)
            {
                for (int x = 0; x < board.Size.x; x++)
                {
                    colorInfo.SetValue(gems[x, y], (Gem.Colors)gemColors[x, y]);
                }
            }
            gemsInfo.SetValue(board, gems);
            Debug.Log("Testing.. " + i);
            Assert.AreEqual(results[i], (bool)checkIsMatchPossibleInfo.Invoke(board, null));
            i++;
        }
    }
Exemple #6
0
 private void Awake()
 {
     GemsOnBoard = new Gem[Columns, Rows];
     PoolsManager.RegisterPool(_gemPool);
     _gemPool.Prefab = _gemPrefab.gameObject;
     _gemPool.Initialize();
 }
Exemple #7
0
        public GemSystem(Engine e) : base(e)
        {
            gemNodes       = new List <Node>();
            coordGrid      = new List <Vector2f>();
            idGrid         = new List <int>();
            gemGrid        = new Gem[Settings.GameSize, Settings.GameSize];
            prevClicked    = new List <Pair>();
            needDelete     = new HashSet <int>();
            fieldGrid      = new List <FloatRect>();
            destroyerGrid  = new Dictionary <Name, DestroyerInfo>();
            lastMoved      = -1;
            initCoords     = true;
            gemsDestroying = false;

            for (var i = 0; i < Settings.GameSize; i++)
            {
                for (var j = 0; j < Settings.GameSize; j++)
                {
                    coordGrid.Add(new Vector2f(
                                      Layout.SessionBackgroundX + Layout.GemMargin + Layout.GemDistance * j,
                                      Layout.SessionBackgroundY + Layout.GemMargin + Layout.GemDistance * i
                                      ));
                    idGrid.Add(Settings.GameSize * i + j);
                    gemGrid[i, j] = Gem.Romb;
                    fieldGrid.Add(new FloatRect(
                                      Layout.SessionBackgroundX + Layout.SessionBackgroundWidth / Settings.GameSize * j,
                                      Layout.SessionBackgroundY + Layout.SessionBackgroundHeight / Settings.GameSize * i,
                                      Layout.SessionBackgroundWidth / Settings.GameSize,
                                      Layout.SessionBackgroundHeight / Settings.GameSize
                                      ));
                }
            }
        }
Exemple #8
0
    void Start()
    {
        m_boardGems  = new Gem[width, height];
        m_boardTiles = new Tile[width, height];

        SetupTiles();
        SetupCamera();
        FillBoard(10, 0.5f);
    }
Exemple #9
0
 public void Randomize()
 {
     Gems = new Gem[5, 5] {
         { RandomGem(), RandomGem(), RandomGem(), RandomGem(), RandomGem() },
         { RandomGem(), RandomGem(), RandomGem(), RandomGem(), RandomGem() },
         { RandomGem(), RandomGem(), RandomGem(), RandomGem(), RandomGem() },
         { RandomGem(), RandomGem(), RandomGem(), RandomGem(), RandomGem() },
         { RandomGem(), RandomGem(), RandomGem(), RandomGem(), RandomGem() }
     };
 }
Exemple #10
0
    // Important thing to take note is that the gem's index on the grid are the same as their position in world space.
    // This detail is important in multiple places in the code and how the scene is being setup in the game.
    void SetupGrid()
    {
        Enums.GemId   gem, doubleX, doubleY;
        Enums.GemId[] lineup = _spawner.Lineup;
        _grid = new Gem[_gridSize.x, _gridSize.y];

        for (int x = 0; x < _gridSize.x; x++)
        {
            for (int y = 0; y < _gridSize.y; y++)
            {
                if (x - 2 >= 0)
                {
                    if (_grid[x - 1, y].Id == _grid[x - 2, y].Id)
                    {
                        doubleX = _grid[x - 1, y].Id;
                    }
                    else
                    {
                        doubleX = Enums.GemId.NULL;
                    }
                }
                else
                {
                    doubleX = Enums.GemId.NULL;
                }
                if (y - 2 >= 0)
                {
                    if (_grid[x, y - 1].Id == _grid[x, y - 2].Id)
                    {
                        doubleY = _grid[x, y - 1].Id;
                    }
                    else
                    {
                        doubleY = Enums.GemId.NULL;
                    }
                }
                else
                {
                    doubleY = Enums.GemId.NULL;
                }

                gem = lineup[UnityEngine.Random.Range(0, lineup.Length)];
                if (gem == doubleX || gem == doubleY)
                {
                    Enums.GemId[] tmp = Array.FindAll(lineup, v => (v != doubleX) && (v != doubleY));
                    if (tmp.Length != 0)
                    {
                        gem = tmp[UnityEngine.Random.Range(0, tmp.Length)];
                    }
                }

                _grid[x, y] = _spawner.Spawn(gem, new Vector2(x, y));
            }
        }
    }
Exemple #11
0
    public void DeleteBoard()
    {
        if (boardGameObject == null)
        {
            Debug.LogWarning("Trying to delete the board, but there is no board. Ignoring...");
            return;
        }

        DestroyImmediate(boardGameObject);
        gemsTable = null;
    }
Exemple #12
0
 void InitBoard()
 {
     board     = new Gem[Size, Size];
     boardData = new int[Size, Size];
     columns   = new List <Gem> [Size];
     for (int i = 0; i < Size; i++)
     {
         columns [i] = new List <Gem> ();
     }
     InitialBoardFill();
 }
Exemple #13
0
 void AddGemRandomlyInCells()
 {
     Gems = new Gem[Def.Width, Def.Depth + 2];
     Gems.Fill(CreateGem);
     Gems.ForEach(item => {
         if (!item)
         {
             return;
         }
         DestroyBlock(item.Cell, false);
     });
 }
Exemple #14
0
        /// <summary>
        /// Gem request on the right
        /// </summary>
        /// <param name="gems">Gem grid on the board</param>
        /// <param name="gem">Which gem to watch</param>
        /// <param name="number">How many elements</param>
        /// <returns>Could he find the gem and the gem itself</returns>
        public static (bool, Gem) Right(this Gem[,] gems, Gem gem, int number)
        {
            var columns = gems.GetLength(0);

            if (gem.XPosition + number >= columns || gem.XPosition + number < 0)
            {
                return(false, null);
            }
            var nextGem = gems[gem.XPosition + number, gem.YPosition];

            return(gem.Equals(nextGem), nextGem);
        }
Exemple #15
0
        /// <summary>
        /// Gem request on the bottom
        /// </summary>
        /// <param name="gems">Gem grid on the board</param>
        /// <param name="gem">Which gem to watch</param>
        /// <param name="number">How many elements</param>
        /// <returns>Could he find the gem and the gem itself</returns>
        public static (bool, Gem) Bottom(this Gem[,] gems, Gem gem, int number)
        {
            var lines = gems.GetLength(1);

            if (gem.YPosition + number >= lines || gem.YPosition + number < 0)
            {
                return(false, null);
            }
            var nextGem = gems[gem.XPosition, gem.YPosition + number];

            return(gem.Equals(nextGem), nextGem);
        }
 private void Awake()
 {
     THIS = this;
     gems = new Gem[SizeY, SizeX];
     for (int row = 0; row < SizeY; row++)
     {
         for (int c = 0; c < SizeX; c++)
         {
             gems[row, c] = new Gem(row, c);
         }
     }
 }
Exemple #17
0
		void expand(){
			cells = new Cell[width,height];
			gems = new Gem[width,height];
			foreach(TwoTuple t in sCells.Keys){
				cells[t.x, t.y] = sCells[t];
			}

			foreach(TwoTuple t in sGems.Keys){
				gems[t.x, t.y] = sGems[t];
			}


		}
Exemple #18
0
    public void BuildGame()
    {
        board = new Gem[width, height];

        score      = 0;
        moves      = 0;
        multiplier = 1;

        InitializeBoard();
        InstantiateBoard();

        CleanBoard();
    }
Exemple #19
0
 public Game(Panel panelGame)
 {
     gem  = new Gem[sumRow, sumCol];
     rand = new Random();
     for (int i = 0; i < sumRow; i++)
     {
         for (int j = 0; j < sumCol; j++)
         {
             gem[i, j]      = new Gem(i, j, rand.Next(1, 7), size_gem);
             gem[i, j].game = this;
             panelGame.Controls.Add(gem[i, j]);
         }
     }
 }
Exemple #20
0
        void expand()
        {
            cells = new Cell[width, height];
            gems  = new Gem[width, height];
            foreach (TwoTuple t in sCells.Keys)
            {
                cells[t.x, t.y] = sCells[t];
            }

            foreach (TwoTuple t in sGems.Keys)
            {
                gems[t.x, t.y] = sGems[t];
            }
        }
Exemple #21
0
    List <Gem> matchesFour(Gem[,] gemmall, int row, int col)//
    {
        List <Gem> match = new List <Gem>();

        if (col <= 2 && gemmall[row, col].match3(gemmall[row, col - 1]))
        {
            if (row < GetArrays.SizeY - 2 && col >= 2 && gemmall[row, col].match3(gemmall[row + 1, col - 2]))
            {
                match.Add(gemmall[row, col]);
                match.Add(gemmall[row, col + 1]);
                match.Add(gemmall[row + 1, col - 2]);
                print("gem:" + gemmall[row, col].x + gemmall[row, col].y);
            }
        }
        return(match);
    }
Exemple #22
0
    private void SpawnInitialGems()
    {
        dropLayer = new Gem[width];

        gems = new Gem[width, height];
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                Gem gem = Instantiate(gemPrefabs[Random.Range(0, gemPrefabs.Length)], new Vector2(x, y), Quaternion.identity);
                gem.name = string.Format("{0}, {1}", x, y);
                gem.transform.SetParent(transform);
                gems[x, y] = gem;
            }
        }
    }
Exemple #23
0
        /* Constructor */
        internal Board(int gems)
        {
            data = new Gem[8, 8];

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    data[i, j] = new Gem();
                }
            }

            isEmpty   = true;
            numOfGems = gems + 1;
            gemCount  = new GemCount(numOfGems);
        }
 void Start()
 {
     grid = new Gem[width, height];
     for (int i = 0; i < height; i++)
     {
         for (int j = 0; j < width; j++)
         {
             int index = Random.Range(0, gems.Length);
             Gem gem   = gems[index];                                                //picks a random item
             grid[i, j] = Instantiate(gem);                                          //makes it
             grid[i, j].transform.position = new Vector2(i, j);                      //positions
             grid[i, j].x = i;                                                       //location fields
             grid[i, j].y = j;
         }
     }
     checkMatches();                                                                                                 //gets rid of any starting matches
 }
Exemple #25
0
    List <Gem> matches1(Gem[,] gemmall)
    {
        List <List <Gem> > match = new List <List <Gem> >();

        for (int row = 0; row < GetArrays.SizeY; row++)
        {
            for (int col = 0; col < GetArrays.SizeX; col++)
            {
                match.Add(matchesOne(gemmall, row, col));
                match.Add(matchesTwo(gemmall, row, col));
                //match.Add(matchesThree(gemmall, row, col));
                //match.Add(matchesFour(gemmall, row, col));
                match.Add(matchesFive(gemmall, row, col));
                match.Add(matchesSix(gemmall, row, col));
            }
        }
        ylist2 = xlist1[Random.Range(0, xlist1.Count)];//
        return(match[Random.Range(0, match.Count)]);
    }
Exemple #26
0
        public void ResetMap()
        {
            ClearAllCellState();
            ScoreBlue = ScoreRed = 3;

            gems.ClearChildren();

            Gems = new Gem[nRows, nCols];

            AddGem(4, 0, Gem.Team.Blue);
            AddGem(16, 4, Gem.Team.Blue);
            AddGem(4, 8, Gem.Team.Blue);

            AddGem(0, 4, Gem.Team.Red);
            AddGem(12, 0, Gem.Team.Red);
            AddGem(12, 8, Gem.Team.Red);

            State    = MapState.RedTurn;
            winState = WinState.None;
        }
Exemple #27
0
 // Start is called before the first frame update
 void Start()
 {
     allTiles    = new Gem[width, height];
     allDots     = new GameObject[width, height];
     gemsDest    = new int[GameManager.GM.actualColors.Length];
     gFSatisfied = new bool[GameManager.GM.actualColors.Length];
     matchMaker  = GetComponent <FindMatches>();
     if (challengeOverride)
     {
         ChallengeSetup();
     }
     else
     {
         Setup();
     }
     if (autoPlay)
     {
         InvokeRepeating("DestroyAuto", 1f, 1f);
     }
 }
Exemple #28
0
        public static void ReadInGameArray()
        {
            int longestLine = 0;
            var lines       = new List <string>();

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(Level_01)))
                using (var sr = new StreamReader(ms))
                {
                    do
                    {
                        var l = sr.ReadLine();
                        longestLine = Math.Max(longestLine, l.Length);
                        lines.Add(l);
                    } while (!sr.EndOfStream);
                }

            _level      = new char[longestLine, lines.Count];
            _levelCells = new Gem[longestLine, lines.Count];

            if (Console.WindowWidth >= longestLine)
            {
                //int xindent = (Console.WindowWidth - longestLine) / 2;
                //int yindent = (Console.WindowHeight - lines.Count) / 2;
                int xindent = 0, yindent = 0;
                for (int j = 0; j < lines.Count; j++)
                {
                    var l = lines[j];
                    for (int i = 0; i < l.Length; i++)
                    {
                        int x = xindent + i, y = yindent + j;
                        _level[x, y] = l[i];
                        switch (l[i])
                        {
                        case 'S':
                            _spawners.Add(new Point(x, y));
                            break;
                        }
                    }
                }
            }
        }
Exemple #29
0
 void Init()
 {
     gems        = new Gem[maxX + 1, maxY + 1];
     timeLeft    = 60;
     movesLeft   = 20;
     gemsCount   = 0;
     canClear    = false;
     isGameStart = true;
     for (int y = 0; y <= maxY; y++)
     {
         for (int x = 0; x <= maxX; x++)
         {
             GameObject go = Instantiate(gemPrefab, gemContainer);
             go.GetComponent <RectTransform>().sizeDelta        = new Vector2(108, 108);
             go.GetComponent <RectTransform>().anchoredPosition = new Vector2(originPos.x + x * 108, originPos.y + y * 108);
             gems[x, y]   = go.GetComponent <Gem>();
             gems[x, y].x = x;
             gems[x, y].y = y;
         }
     }
 }
Exemple #30
0
    List <Gem> matchesSix(Gem[,] gemmall, int row, int col)
    {
        List <Gem> match = new List <Gem>();

        if (row < GetArrays.SizeY - 2 && gemmall[row, col].match3(gemmall[row + 1, col]))
        {
            if (row < GetArrays.SizeY - 2 && col < GetArrays.SizeX - 2 && gemmall[row, col].match3(gemmall[row + 2, col + 1]))
            {
                match.Add(gemmall[row, col]);
                match.Add(gemmall[row + 1, col]);
                match.Add(gemmall[row + 2, col + 1]);
                vslist.Add("match:" + row + "," + col + ";" + (row + 1) + "," + col + ";" + (row + 2) + "," + (col + 1) + ";");
                List <Vector2> vsadd = new List <Vector2>();
                vsadd.Add(new Vector2(-2.37f, -4.27f) + (new Vector2(col * 0.6f, row * 0.6f)));
                vsadd.Add(new Vector2(-2.37f, -4.27f) + (new Vector2((col) * 0.6f, (row + 1) * 0.6f)));
                vsadd.Add(new Vector2(-2.37f, -4.27f) + (new Vector2((col + 1) * 0.6f, (row + 2) * 0.6f)));
                xlist1.Add(vsadd);
            }
        }
        return(match);
    }
Exemple #31
0
    void AddGemRandomlyInRows()
    {
        Gems = new Gem[Def.Width, Def.Depth + 2];

        int spacing = Def.Index * 2;

        for (int y = 0; y <= Gems.GetLength(1); y += spacing)
        {
            spacing++;
            var x = PRNG.Int(Def.Width);
            Gems[x, y] = CreateGem(x, y);
        }

        Gems.ForEach(item => {
            if (!item)
            {
                return;
            }
            DestroyBlock(item.Cell, false);
        });
    }
 void Awake()
 {
     m_gems = new Gem[gridWidth, gridHeight];
 }
Exemple #33
0
        public void ResetMap()
        {
            ClearAllCellState();
            ScoreBlue = ScoreRed = 3;

            gems.ClearChildren();

            Gems = new Gem[nRows, nCols];

            AddGem(4, 0, Gem.Team.Blue);
            AddGem(16, 4, Gem.Team.Blue);
            AddGem(4, 8, Gem.Team.Blue);

            AddGem(0, 4, Gem.Team.Red);
            AddGem(12, 0, Gem.Team.Red);
            AddGem(12, 8, Gem.Team.Red);

            State = MapState.RedTurn;
            winState = WinState.None;
        }