Beispiel #1
0
    public void playCard()

    /* Check that there is enough ium to play this Card, perform this Card's Action, then discard it
     *  and unset the selected Card.
     */
    {
        bool isAbleToPlay = getIsAbleToPlay();

        if (!isAbleToPlay)
        {
            return;
        }

        int  costToPlay      = getCostToPlay();
        bool canAffordToPlay = TrialLogic.currentIum >= costToPlay;

        if (!canAffordToPlay)
        {
            return;
        }

        TrialLogic.gainIum(-costToPlay);
        cardAction();
        TrialLogic.discardCard(cardId);
        TrialLogic.selectedCardId = null;
    }
Beispiel #2
0
    public override bool getIsAbleToPlay()

    /* Return true if there was a block where the mouse went down, and no block where the mouse went
     *  up.
     *
     * See getIsAbleToPlay on base class Card.
     */
    {
        // Make sure mouse up was on the grid at all.
        if (TrialLogic.mouseUpGridIndices == null)
        {
            return(false);
        }
        // Make sure the mouse up was 1 away from the mouse down.
        bool isValidInstruction = (
            (Vector2)TrialLogic.mouseDownGridIndices - (Vector2)TrialLogic.mouseUpGridIndices
            ).magnitude == 1;

        if (!isValidInstruction)
        {
            return(false);
        }

        BlockType?blockTypeDown =
            TrialLogic.getBlockTypeOfSquare((Vector2)TrialLogic.mouseDownGridIndices);
        bool blockIsClicked = blockTypeDown != null;

        BlockType?blockTypeUp =
            TrialLogic.getBlockTypeOfSquare((Vector2)TrialLogic.mouseUpGridIndices);
        bool isAvailableSpace = blockTypeUp == null;

        bool isAbleToPlay = blockIsClicked && isAvailableSpace;

        return(isAbleToPlay);
    }
Beispiel #3
0
    /* HELPERS */

    private static List <BlockCombo> productionLineCombosAnchoredAt(Vector2 gridIndices)

    /* Look for the production line combo at this square.
     *
     * :param Vector2 gridIndices:
     *
     * :returns List<BlockCombo>:
     */
    {
        List <BlockCombo> combos = new List <BlockCombo>();

        BlockType?blockTypeHere = TrialLogic.getBlockTypeOfSquare(gridIndices);

        if (Block.isProductive(blockTypeHere))
        {
            // Check from here going down.
            List <Block> sameTypeBlocksDown = new List <Block>();
            foreach (int yIdx in Enumerable.Range((int)gridIndices.y - 3, 4))
            {
                Vector2   otherSquare    = new Vector2(gridIndices.x, yIdx);
                BlockType?blockTypeThere = TrialLogic.getBlockTypeOfSquare(otherSquare);
                if (blockTypeThere == blockTypeHere)
                {
                    Block block = TrialLogic.placedBlocks[otherSquare];
                    sameTypeBlocksDown.Add(block);
                }
            }
            if (sameTypeBlocksDown.Count == 4)
            {
                BlockCombo combo = new BlockCombo(
                    sameTypeBlocksDown,
                    BlockComboType.PRODUCTION_LINE
                    );
                combos.Add(combo);
            }

            // Check from here going right.
            List <Block> sameTypeBlocksRight = new List <Block>();
            foreach (int xIdx in Enumerable.Range((int)gridIndices.x, 4))
            {
                Vector2   otherSquare    = new Vector2(xIdx, gridIndices.y);
                BlockType?blockTypeThere = TrialLogic.getBlockTypeOfSquare(otherSquare);
                if (blockTypeThere == blockTypeHere)
                {
                    Block block = TrialLogic.placedBlocks[otherSquare];
                    sameTypeBlocksRight.Add(block);
                }
            }
            if (sameTypeBlocksRight.Count == 4)
            {
                BlockCombo combo = new BlockCombo(
                    sameTypeBlocksRight,
                    BlockComboType.PRODUCTION_LINE
                    );
                combos.Add(combo);
            }
        }

        return(combos);
    }
Beispiel #4
0
    public override void cardAction()
    /* See cardAction on base class Card. */
    {
        Vector2 gridIndices          = (Vector2)TrialLogic.mouseDownGridIndices;
        Vector2 directionGridIndices = (Vector2)TrialLogic.mouseUpGridIndices;

        // The mouse down square, the mouse up square, and the square in line with them but on the
        // other side of the clicked square.
        List <Vector2> squaresHit = new List <Vector2>
        {
            gridIndices,
            directionGridIndices,
            gridIndices + (gridIndices - directionGridIndices)
        };

        foreach (Vector2 target in squaresHit)
        {
            BlockType?blockType = TrialLogic.getBlockTypeOfSquare(target);
            if (blockType != null)
            {
                Block block = TrialLogic.placedBlocks[target];
                block.destroy();
            }
        }
    }
Beispiel #5
0
    /* PUBLIC API */

    public void clickEndTurn()
    /* Click handler for button that ends the turn. */
    {
        if (TrialLogic.isGameplayUserInputsFrozen)
        {
            return;
        }

        StartCoroutine(TrialLogic.endTurn());
    }
 private void mouseClick()
 {
     if (Input.GetMouseButtonDown(1))
     {
         TrialLogic.setRapidMode(true);
     }
     else if (Input.GetMouseButtonUp(1))
     {
         TrialLogic.setRapidMode(false);
     }
 }
 private void spacebarPress()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         TrialLogic.setPauseMode(true);
     }
     else if (Input.GetKeyUp(KeyCode.Space))
     {
         TrialLogic.setPauseMode(false);
     }
 }
Beispiel #8
0
    public override void cardAction()

    /* Simply place a single block in the targeted square.
     *
     * See cardAction on base class Card.
     */
    {
        Vector2 gridIndices = (Vector2)TrialLogic.mouseDownGridIndices;

        TrialLogic.placeBlock(blockType, gridIndices);
    }
Beispiel #9
0
    /* PUBLIC API */

    public void produce()
    /* Depending on the blockType, perform any production effects. */
    {
        if (blockType == BlockType.BLUE)
        {
            TrialLogic.gainIum(1);
        }
        else if (blockType == BlockType.YELLOW)
        {
            TrialLogic.drawCard();
        }

        EventLog.LogEvent($"Produced for blockType {blockType} at {gridIndices}.");
    }
Beispiel #10
0
 public void destroyNeighboringMass()
 /* Remove mass Blocks that neighbor this Block. */
 {
     Vector2[] neighbors = MiscHelpers.getNeighbors(gridIndices);
     foreach (Vector2 neighborIndices in neighbors)
     {
         BlockType?neighborBlockType = TrialLogic.getBlockTypeOfSquare(neighborIndices);
         if (neighborBlockType == BlockType.MASS)
         {
             Block neighborBlock = TrialLogic.placedBlocks[neighborIndices];
             neighborBlock.destroy();
         }
     }
 }
    public override void cardAction()

    /* Place blocks in a 3-cube shape of the number "7" or letter "L".
     *
     * See cardAction on base class Card.
     */
    {
        Vector2 mouseDownSquare = (Vector2)TrialLogic.mouseDownGridIndices;
        Vector2 mouseUpSquare   = (Vector2)TrialLogic.mouseUpGridIndices;

        foreach (Vector2 square in getSquaresToPlaceOn(mouseDownSquare, mouseUpSquare))
        {
            TrialLogic.placeBlock(blockType, square);
        }
    }
Beispiel #12
0
    public override void cardAction()
    /* See cardAction on base class Card. */
    {
        Vector2 gridIndices = (Vector2)TrialLogic.mouseDownGridIndices;

        foreach (int yIdx in Enumerable.Range(0, TrialLogic.numGridSquaresDeep))
        {
            Vector2   target    = new Vector2(gridIndices.x, yIdx);
            BlockType?blockType = TrialLogic.getBlockTypeOfSquare(target);
            if (blockType != null)
            {
                Block block = TrialLogic.placedBlocks[target];
                block.destroy();
            }
        }
    }
Beispiel #13
0
    public void onBlockDestroy(Block block)

    /* Run this destroy function if any block in this combo gets destroyed.
     *
     * :param Block block: Block that was destroyed to trigger this block combo action.
     */
    {
        if (blockComboType == BlockComboType.CHECKER_BLUE_RED)
        {
            TrialLogic.gainIum(1);
            block.destroyNeighboringMass();
        }
        else if (blockComboType == BlockComboType.CHECKER_YELLOW_RED)
        {
            TrialLogic.drawCard();
            block.destroyNeighboringMass();
        }
    }
    public override bool getIsAbleToPlay()

    /* Return true if there is no block in the targeted square.
     *
     * See getIsAbleToPlay on base class Card.
     */
    {
        // Make sure the mouse down and up were on the same square.
        Vector2 gridIndices = (Vector2)TrialLogic.mouseDownGridIndices;

        if (TrialLogic.mouseUpGridIndices != gridIndices)
        {
            return(false);
        }

        BlockType?blockType = TrialLogic.getBlockTypeOfSquare(gridIndices);
        bool      isEmpty   = blockType == null;

        return(isEmpty);
    }
Beispiel #15
0
    public override bool getIsAbleToPlay()

    /* Return true if there is a player's block in the targeted square.
     *
     * See getIsAbleToPlay on base class Card.
     */
    {
        // Make sure the mouse down and up were on the same square.
        Vector2 gridIndices = (Vector2)TrialLogic.mouseDownGridIndices;

        if (TrialLogic.mouseUpGridIndices != gridIndices)
        {
            return(false);
        }

        BlockType?blockType          = TrialLogic.getBlockTypeOfSquare(gridIndices);
        bool      playerBlockIsThere = blockType != null && blockType != BlockType.MASS;

        return(playerBlockIsThere);
    }
    public override bool getIsAbleToPlay()

    /* Return true as long as there is no block already in the squares the blocks would be placed.
     *
     * See getIsAbleToPlay on base class Card.
     */
    {
        // Make sure mouse up was on the grid at all.
        if (TrialLogic.mouseUpGridIndices == null)
        {
            return(false);
        }
        // Make sure the mouse up was 1 away from the mouse down.
        bool isValidInstruction = (
            (Vector2)TrialLogic.mouseDownGridIndices - (Vector2)TrialLogic.mouseUpGridIndices
            ).magnitude == 1;

        if (!isValidInstruction)
        {
            return(false);
        }

        Vector2 mouseDownSquare = (Vector2)TrialLogic.mouseDownGridIndices;
        Vector2 mouseUpSquare   = (Vector2)TrialLogic.mouseUpGridIndices;

        bool allSquaresAvailable = true;

        foreach (Vector2 square in getSquaresToPlaceOn(mouseDownSquare, mouseUpSquare))
        {
            bool isBlockInTheWay = TrialLogic.getBlockTypeOfSquare(square) != null;
            bool isOutOfBounds   = !TrialLogic.floorSquaresMap.ContainsKey(square);

            if (isBlockInTheWay || isOutOfBounds)
            {
                allSquaresAvailable = false;
            }
        }

        return(allSquaresAvailable);
    }
Beispiel #17
0
    public override void cardAction()
    /* See cardAction on base class Card. */
    {
        Vector2 gridIndices = (Vector2)TrialLogic.mouseDownGridIndices;

        int centerX = (int)gridIndices.x;
        int centerY = (int)gridIndices.y;

        foreach (int xIdx in Enumerable.Range(centerX - 1, 3))
        {
            foreach (int yIdx in Enumerable.Range(centerY - 1, 3))
            {
                Vector2   target    = new Vector2(xIdx, yIdx);
                BlockType?blockType = TrialLogic.getBlockTypeOfSquare(target);
                if (blockType != null)
                {
                    Block block = TrialLogic.placedBlocks[target];
                    block.destroy();
                }
            }
        }
    }
Beispiel #18
0
 public override void cardAction()
 /* See cardAction on base class Card. */
 {
     TrialLogic.gainIum(3);
 }
Beispiel #19
0
    private static List <BlockCombo> checkerCombosAnchoredAt(Vector2 gridIndices, BlockComboType blockComboType)

    /* Look for the checker combos at this square, for a certain pair of block types.
     *
     * :param Vector2 gridIndices:
     * :param BlockType[] blockTypes: Pair of block types we are checking for. Must be length 2.
     *
     * :returns List<BlockCombo>:
     */
    {
        List <BlockCombo> combos = new List <BlockCombo>();

        BlockType[] blockTypes;
        if (blockComboType == BlockComboType.CHECKER_BLUE_YELLOW)
        {
            blockTypes = new BlockType[2] {
                BlockType.BLUE, BlockType.YELLOW
            };
        }
        else if (blockComboType == BlockComboType.CHECKER_BLUE_RED)
        {
            blockTypes = new BlockType[2] {
                BlockType.BLUE, BlockType.RED
            };
        }
        else if (blockComboType == BlockComboType.CHECKER_YELLOW_RED)
        {
            blockTypes = new BlockType[2] {
                BlockType.YELLOW, BlockType.RED
            };
        }
        else
        {
            // Invalid BlockComboType was passed in.
            return(combos);
        }

        BlockType?blockTypeA = TrialLogic.getBlockTypeOfSquare(gridIndices);

        // If this square doesn't have one of the block types we're checking for, return no combos.
        if (blockTypeA == null || !blockTypes.Contains((BlockType)blockTypeA))
        {
            return(combos);
        }

        BlockType blockTypeB = blockTypeA == blockTypes[0] ? blockTypes[1] : blockTypes[0];

        Vector2 topRight    = new Vector2(gridIndices.x + 1, gridIndices.y);
        Vector2 bottomLeft  = new Vector2(gridIndices.x, gridIndices.y - 1);
        Vector2 bottomRight = new Vector2(gridIndices.x + 1, gridIndices.y - 1);

        bool isAMatch = (
            TrialLogic.getBlockTypeOfSquare(topRight) == blockTypeB &&
            TrialLogic.getBlockTypeOfSquare(bottomLeft) == blockTypeB &&
            TrialLogic.getBlockTypeOfSquare(bottomRight) == blockTypeA
            );

        // If the 4 squares aren't the combo we're looking for, return no combos.
        if (!isAMatch)
        {
            return(combos);
        }

        List <Block> blocks = new List <Block>
        {
            TrialLogic.placedBlocks[gridIndices],
            TrialLogic.placedBlocks[topRight],
            TrialLogic.placedBlocks[bottomLeft],
            TrialLogic.placedBlocks[bottomRight]
        };
        BlockCombo combo = new BlockCombo(blocks, blockComboType);

        combos.Add(combo);

        return(combos);
    }