Пример #1
0
        QueryShapeInfo IsRepeatedInShape(Vector2 pos, int index)
        {
            QueryShapeInfo result = new QueryShapeInfo();

            for (int i = 0; i < this.count; ++i)
            {
                Vector2 shapePos = this.blocks[i].pos;
                if (i != index && (int)pos.x == (int)shapePos.x && (int)pos.y == (int)shapePos.y)
                {
                    result.result = true;
                    result.index  = i;
                    Assert.IsTrue(i != index);
                    break;
                }
            }
            return(result);
        }
Пример #2
0
        bool MoveShape(BoardLogic board, MoveType moveType)
        {
            bool result = canShapeMove(board, moveType);

            if (result)
            {
                Vector2 moveVec = GetMoveVec(moveType);

                Assert.IsTrue(!this.wasHitByExplosive);
                // CHECK FOR EXPLOSIVES HIT
                int   idsHitCount = 0;
                int[] idsHit      = new int[BoardLogic.MAX_SHAPE_COUNT];

                for (int i = 0; i < this.count; ++i)
                {
                    Vector2 oldPos = this.blocks[i].pos;
                    Vector2 newPos = oldPos + moveVec;

                    BoardValue val = board.GetBoardValue(oldPos);
                    val.color = Color.white;

                    BoardValue newVal = board.GetBoardValue(newPos);
                    newVal.color = Color.white;

                    BoardState state = board.GetBoardState(newPos);
                    if (state == BoardState.BOARD_EXPLOSIVE)
                    {
                        Assert.IsTrue(board.lifePointsMax > 0);
                        board.lifePoints      -= 1;
                        this.wasHitByExplosive = true;
                        board.PlayExplosiveSound();
                        //remove from shape
                        Assert.IsTrue(idsHitCount < idsHit.Length);
                        idsHit[idsHitCount++] = this.blocks[i].id;
                        board.SetBoardState(oldPos, BoardState.BOARD_NULL, BoardValType.BOARD_VAL_NULL);      //this is the shape
                        board.SetBoardState(newPos, BoardState.BOARD_NULL, BoardValType.BOARD_VAL_TRANSIENT); //this is the bomb position
                    }
                }

                //NOTE: we have this since our findBlockById wants to search the original shape with the
                //full count so we can't change it in the loop
                int newShapeCount = this.count;
                for (int hitIndex = 0; hitIndex < idsHitCount; ++hitIndex)
                {
                    int id         = idsHit[hitIndex];
                    int blockIndex = this.FindBlockById(id);

                    this.blocks[--newShapeCount].Copy(this.blocks[blockIndex]);
                }
                this.count = newShapeCount;

                for (int i = 0; i < this.count; ++i)
                {
                    Vector2 oldPos = this.blocks[i].pos;
                    Vector2 newPos = oldPos + moveVec;

                    // printf("boardState: %d, index: %d\n", getBoardState(params, oldPos), i);
                    Assert.IsTrue(board.GetBoardState(oldPos) == BoardState.BOARD_SHAPE);

                    BoardState newPosState = board.GetBoardState(newPos);
                    Assert.IsTrue(newPosState == BoardState.BOARD_SHAPE || newPosState == BoardState.BOARD_NULL);

                    QueryShapeInfo info = this.IsRepeatedInShape(oldPos, i);
                    if (!info.result)
                    { //dind't just get set by the block in shape before.
                        board.SetBoardState(oldPos, BoardState.BOARD_NULL, BoardValType.BOARD_VAL_NULL);
                    }
                    board.SetBoardState(newPos, BoardState.BOARD_SHAPE, this.blocks[i].type);
                    this.blocks[i].pos = newPos;
                }
                board.playMoveSound();
            }
            return(result);
        }