Exemple #1
0
    public MixAndMatch(int width, int height, int pieceCount) : base(width, height)
    {
        Sprite background = new Sprite("mixMatchFrame.png");

        AddChild(background);
        _amountOfPieces = pieceCount;
        IDs             = new int[_amountOfPieces];

        click1 = new ClickablePiece("memoryTiles.png", new Vec2(0, 0), 0);

        loadPieces(_horizontalPieces, _verticalPieces);

        string fileNameInfo = "memoryTiles.png";

        if (pieceCount <= 8)
        {
            fileNameInfo = "INFOeasyMixmatch.png";
        }
        else if (pieceCount > 8 && pieceCount <= 12)
        {
            fileNameInfo = "INFOmediumMixmatch.png";
        }
        else if (pieceCount > 12)
        {
            fileNameInfo = "INFOhardMixmatch.png";
        }

        _collection = new CollectedMM(new Vec2(0, 0), ((MyGame)game).width, ((MyGame)game).height, _amountOfPieces / 2, fileNameInfo);
        AddChild(_collection);
    }
Exemple #2
0
    private void loadPieces(int colmns, int rows)
    {
        int i           = 0;
        int pieceWidth  = click1.width + _distanceBetweenPieces;
        int pieceHeight = click1.height + _distanceBetweenPieces;

        for (int j = 0; j < IDs.Length; j++)
        {
            IDs[j] = j / 2;
        }

        for (int x = _startXGrid; x < _startXGrid + pieceWidth * colmns; x += pieceWidth)
        {
            for (int y = _startYGrid; y < _startYGrid + pieceHeight * rows; y += pieceHeight)
            {
                points[i] = new Vec2(x, y);
                i++;
            }
        }

        Randomizer.Randomize(points);
        Randomizer.Randomize(IDs);

        for (int l = 0; l < _amountOfPieces; l++)
        {
            ClickablePiece click = new ClickablePiece("memoryTiles.png", points[l], IDs[l]);
            AddChild(click);
            pieces.Add(click);
            Console.WriteLine("i = {0}, ID = {1}", l, IDs[l]);
        }
    }
Exemple #3
0
    private void checkMatches()
    {
        for (int i = 0; i < pieces.Count; i++)
        {
            if (pieces[i].Pressed)
            {
                if (_firstPiece == -1)
                {
                    _firstPiece = i;
                    _piecesSelected++;
                    Console.WriteLine("A index = {1}, ID = {0}", pieces[_firstPiece].ID, i);
                }
                else if (_secondPiece == -1 && i != _firstPiece)
                {
                    _secondPiece = i;
                    _piecesSelected++;
                    Console.WriteLine("B index = {1}, ID = {0}", pieces[_secondPiece].ID, i);
                }

                //Console.WriteLine("Pressed"+i);
            }
        }

        if (_firstPiece != -1 && _secondPiece != -1)
        {
            if (pieces[_firstPiece].ID == pieces[_secondPiece].ID)
            {
                ClickablePiece firstPiece  = pieces[_firstPiece];
                ClickablePiece secondPiece = pieces[_secondPiece];

                _collection.Collected(firstPiece.ID);

                _firstPiece  = -1;
                _secondPiece = -1;
                pieces.Remove(firstPiece);
                pieces.Remove(secondPiece);
                firstPiece.SelfDestroy();
                secondPiece.SelfDestroy();

                _reset = true;
            }
            else
            {
                _reset = true;
            }
        }
    }