Ejemplo n.º 1
0
 public MapHandler(int mapWidth, int mapHeight, Block[,] map, int percentWalls = 40)
 {
     this.MapWidth = mapWidth;
     this.MapHeight = mapHeight;
     this.PercentAreWalls = percentWalls;
     this.Map = map;
 }
Ejemplo n.º 2
0
        public BlockManager(int x, int y, int width, int height, int gapX, int gapY)
        {
            Blocks = new Block[x, y];

            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    Blocks[i, j] = new Block(width, height);
                }
            }

            this.x     = x; this.y = y;
            this.width = width; this.height = height;
            this.gapX  = gapX; this.gapY = gapY;

            CreateControl();
            SetRandomValue(2);

            d = new debuger();
            d.Show();
            Debug(Arrow.NONE);

            //Blocks[0, 0].Value = 4; Blocks[0, 1].Value = 0; Blocks[0, 2].Value = 2; Blocks[0, 3].Value = 2;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Konstruktör för storleken av 2d arrayn av typen block. Initiera blockarray.
        /// </summary>
        /// <param name="numberOfXRows">Hur många block i x axis</param>
        /// <param name="numberOfYRows">Hur många block i y axis</param>
        public BlockArray(int numberOfXRows, int numberOfYRows)
        {
            x = numberOfXRows;
            y = numberOfYRows;

            blockArray = new Block[x, y];
        }
Ejemplo n.º 4
0
    void CreatePuzzle()
    {
        blocks = new Block[blocksPerLine, blocksPerLine];
        Texture2D[,] imageSlices = ImageSlicer.GetSlices(image, blocksPerLine);
        for (int y = 0; y < blocksPerLine; y++)
        {
            for (int x = 0; x < blocksPerLine; x++)
            {
                GameObject blockObject = GameObject.CreatePrimitive(PrimitiveType.Quad);
                blockObject.transform.position = -Vector2.one * (blocksPerLine - 1) * .5f + new Vector2(x, y);
                blockObject.transform.parent   = transform;

                Block block = blockObject.AddComponent <Block>();
                block.OnBlockPressed   += PlayerMoveBlockInput;
                block.OnFinishedMoving += OnBlockFinishedMoving;
                block.Init(new Vector2Int(x, y), imageSlices[x, y]);
                blocks[x, y] = block;

                if (y == blocksPerLine - 1 && x == 0)
                {
                    emptyBlock = block;
                }
            }
        }

        Camera.main.orthographicSize = blocksPerLine * .55f;
        inputs = new Queue <Block>();
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Loads and instantiates given level
    /// </summary>
    public void LoadLevel(Level newLevel)
    {
        level            = newLevel;
        movesThisAttempt = 0;
        if (LevelData != null)
        {
            foreach (Block block in LevelData)
            {
                block.RemoveObjectDisplay();
            }
        }

        tilesX    = OriginalLevelData.GetLength(0);
        tilesY    = OriginalLevelData.GetLength(1);
        LevelData = new Block[tilesX, tilesY];
        for (int x = 0; x < tilesX; x++)
        {
            for (int y = 0; y < tilesY; y++)
            {
                LevelData[x, y] = new Block(OriginalLevelData[x, y]);
                LevelData[x, y].SetType(OriginalLevelData[x, y].getType());
            }
        }
        lc = new LevelController(LevelData);

        DrawContents();

        Camera.main.transform.position = new Vector3((float)(tilesX) / 2f - 0.5f, (float)(tilesY) / 2f - 0.5f, -1.5f);
        CameraController.ResizeMainCamTo(tilesX, tilesY);
    }
Ejemplo n.º 6
0
    public Playfield(int rows, int columns)
    {
        Block[,] grid = new Block[rows, columns];

        _Rows    = rows;
        _Columns = columns;

        // Making a 2D array of blocks
        for (int row = 0; row < rows; row++)
        {
            for (int col = 0; col < columns; col++)
            {
                // Defining wall blocks
                if ((row == rows - 1) || (col == 0) || (col == columns - 1))
                {
                    // Default colour should never show
                    grid[row, col]      = new Block(Color.Black, col, row);
                    grid[row, col].Type = BlockType.Wall;
                }
                else
                {
                    grid[row, col]      = new Block(Color.Gray, col, row);
                    grid[row, col].Type = BlockType.Empty;
                }
            }
        }
        _Grid = grid;
    }
Ejemplo n.º 7
0
        private void LoadAssets()
        {
            this.lines = new List<string>();
            StreamReader reader = new StreamReader(this.levelPath);
            string line = reader.ReadLine();
            int width = line.Length;
            while (line != null)
            {
                lines.Add(line);
                line = reader.ReadLine();

            }
            int height = lines.Count;
            this.block = new Block[width, height];
            reader.Close();

            for (int row = 0; row < height; row++)
            {
                for (int colum = 0; colum < width; colum++)
                {
                    char blockElement = this.lines[row][colum];
                    this.block[colum, row] = LoadBlock(blockElement, row * GRIDWIDTH, colum * GRIDHEIGHT);
                }

            }
        }
Ejemplo n.º 8
0
        // 맵 텍스트 파일 불러오기
        private Block[,] LoadMap(Block[,] block)
        {
            string line;
            int    y = 0;

            System.IO.StreamReader file =
                new System.IO.StreamReader(Path + "map1.txt");
            while ((line = file.ReadLine()) != null)
            {
                int len = line.Length;
                for (int x = 0; x < len; ++x)
                {
                    string str   = Convert.ToString(line[x]);
                    int    shape = 0;
                    switch (str)
                    {
                    case "A":
                        shape = 10;
                        break;

                    default:
                        shape = Convert.ToInt32(str);
                        break;
                    }
                    //line[x] - '0'
                    block[y, x].setBlock(x * blockSize, y * blockSize, blockSize, shape);
                }
                if (y < MHEIGHT - 1)
                {
                    y++;
                }
            }
            file.Close();
            return(block);
        }
Ejemplo n.º 9
0
    public void updateMatch(Block[,] blocks)
    {
        int count = 0;

        if (type == XMLHandler.XMLMATCHTYPE.R)
        {
            for (int c = 0; c < Level.instance.Sides; c++)
            {
                if ((blocks[position, c].filled == true))
                {
                    count++;
                }
            }
        }
        else
        {
            for (int r = 0; r < Level.instance.Sides; r++)
            {
                if ((blocks[r, position].filled == true))
                {
                    count++;
                }
            }
        }

        setMatch(count == value);
    }
Ejemplo n.º 10
0
    void createGrid()
    {
        Debug.Log("Create Grid");

        /*
         * grid = new GridElement[16, 9];
         *
         * for (int x = 0; x < grid.GetLength(0); x++)
         * {
         *  for (int y = 0; y < grid.GetLength(1); y++)
         *  {
         *      GameObject go = Instantiate(gridPrefab, new Vector3((float)x - 7.5f, 0f, (float)y - 4f), Quaternion.identity);
         *      grid[x, y] = go.GetComponent<GridElement>();
         *      go.transform.SetParent(this.transform);
         *  }
         * }
         */


        // fluent grid creator test
        gridBlocks = new GridCreator()
                     .create(16, 9)
                     .randomWalls(1f)
                     .definePath(2f)
                     .grab();
    }
Ejemplo n.º 11
0
    //level set up+++++++++++++++++++++++++++++++++++++++++++++++++++++++++


    private void generateBlocks()
    {
        Debug.Log("generate blocks");
        GameObject blockHolder = new GameObject("blocks");
        GameObject go;

        allBlocks = new Block[rows, cols];

        float xpos, ypos, zpos = 89;

        for (int r = 0; r < rows; r++)
        {
            for (int c = 0; c < cols; c++)
            {
                xpos = -leftOffset + c * (scale + gap);
                ypos = -topOffset + r * (scale + gap);
                go   = Instantiate(blockPreFab, new Vector3(xpos, ypos, zpos), Quaternion.identity) as GameObject;
                go.transform.parent     = blockHolder.transform;
                go.transform.localScale = new Vector3(scale, scale, scale);
                //update block script data
                Block block = go.GetComponent <Block>();

                // block.SpriteRenderer.sprite = sprites[SPRITE.HIDDEN];
                block.Row = r;
                block.Col = c;

                //add cube cut matrix
                allBlocks[r, c] = block;
            }
        }
    }
Ejemplo n.º 12
0
    //Init
    public GameField(Config config, IPool pool)
    {
        _config = config;
        _pool   = pool;

        //Generate random colors
        _colors = new Color[config.countOfColors];
        GenerateColors(config.countOfColors);

        //generate base field structure and checking colors
        _gamefield = new Block[config.fieldWidth, config.fieldHeight];
        for (int i = 0; i < config.fieldWidth; i++)
        {
            for (int j = 0; j < config.fieldHeight; j++)
            {
                _gamefield[i, j] = _pool.GetBlock();
                _gamefield[i, j].block.transform.position = new Vector3(i * BLOCK_SIZE, -j * BLOCK_SIZE);
                GetColor(_gamefield[i, j], i, j);
                _gamefield[i, j].block.SetActive(true);
            }
        }

        //Set camera to center based on blocks count
        Camera.main.transform.position = new Vector3(_gamefield[(int)config.fieldWidth / 2, (int)config.fieldHeight / 2].block.transform.position.x, _gamefield[(int)config.fieldWidth / 2, (int)config.fieldHeight / 2].block.transform.position.y, Camera.main.transform.position.z);
        Camera.main.fieldOfView        = config.fieldWidth * 90 / 10;
    }
Ejemplo n.º 13
0
    public Chunk(Block[,] inputBlocks, int height, int width)
    {
        MaxWorldHeight = height;
        MaxWorldWidth  = width;
        Blocks         = inputBlocks;

        for (int x = 0; x < 10; x++)
        {
            for (int y = 0; y < 10; y++)
            {
                Block.BlockType type = Blocks[x, y].Type;

                switch (type)
                {
                case Block.BlockType.NULL:
                    OpenBlocks.Add(Blocks[x, y]);
                    break;

                case Block.BlockType.Indescructible:
                    IndestructibleBlocks.Add(Blocks[x, y]);
                    break;

                case Block.BlockType.Destructible:
                    DestuctibleBlocks.Add(Blocks[x, y]);
                    break;

                default:
                    break;
                }
            }
        }
        Type = ChunkType.Empty;
    }
Ejemplo n.º 14
0
        //Constructor
        public GameOverseer(int test_level, int screen_width, int screen_height, ContentManager content, Viewport viewport)
        {
            //Set up camera
            camera = new Camera(viewport);

            //Load a level
            level        = content.Load <Texture2D>("Levels/lvl" + current_level + ".png");
            level_width  = level.Width;
            level_height = level.Height;
            blocks       = new Block[level_width, level_height];
            generate_level();

            player             = new Player(new Vector2(350, 100));
            particle_manager   = new ParticleManager();
            this.current_level = test_level;
            if (test_level == 0)
            {
                //Debug mode
            }

            map                  = new MapPortal(Vector2.Zero);
            starfield            = new Starfield(1000, 800);
            asteroid             = new Asteroid(Constant.asteroid, player);
            past_player_position = Vector2.Zero;

            solar_systems = new List <SolarSystem>();
            generate_planetary_systems();

            rogue        = new Rogue(new Vector2(0, 0), player);
            mother_ships = new List <MotherShip>();
            score        = 0;
        }
Ejemplo n.º 15
0
        private void pictureMaze_MouseUp(object sender, MouseEventArgs e)
        {
            Point location = new Point(e.X, e.Y);

            if (radioCreateWall.Checked)
            {
                Block[,] blocks = maze.BlockList;
                if (radioCreateWall.Checked)
                {
                    int rowCount = MazeSolver.BLOCKS_ROW;
                    int colCount = MazeSolver.BLOCKS_COLUMN;
                    for (int i = 0; i < rowCount; i++)
                    {
                        for (int j = 0; j < colCount; ++j)
                        {
                            Block     b = blocks[i, j];
                            Rectangle r = b.SquareBlock;
                            if (r.Contains(location.X, location.Y) && !b.IsCurrentPosition)
                            {
                                b.IsWall = !b.IsWall;
                                break;
                            }
                        }
                    }
                }
            }
            else if (radioTraversal.Checked)
            {
                ClearVisited();
                objectTimer.Start();
            }
            pictureMaze.Refresh();
        }
Ejemplo n.º 16
0
        protected override void Initialize()
        {
            _random      = new Random();
            _blocks      = CreateBlocks();
            _totalBlocks = Rows * Columns;

            for (int i = 0; i < Rows; i++)
            {
                for (int j = 0; j < Columns; j++)
                {
                    if (i > 0)
                    {
                        _blocks[i, j].Up = _blocks[i - 1, j];
                    }
                    if (i < Rows - 1)
                    {
                        _blocks[i, j].Down = _blocks[i + 1, j];
                    }
                    if (j > 0)
                    {
                        _blocks[i, j].Left = _blocks[i, j - 1];
                    }
                    if (j < Columns - 1)
                    {
                        _blocks[i, j].Right = _blocks[i, j + 1];
                    }
                }
            }

            Content.RootDirectory = "Resources";
            IsMouseVisible        = true;
            base.Initialize();
        }
Ejemplo n.º 17
0
        public MainView(Vector2 startingPosition, int blocksAcross, int blocksDown)
        {
            this.blocksAcross = blocksAcross;
            this.blocksDown = blocksDown;

            theMainView = new Block[blocksAcross, blocksDown];

            bound0 = theMainView.GetUpperBound(0);
            bound1 = theMainView.GetUpperBound(1);

            this.startingPosition = startingPosition;

            for (int i = 0; i <= bound0; i++)
            {
                for (int j = 0; j <= bound1; j++)
                {

                    Vector2 position = new Vector2(startingPosition.X + i * blockWidth, startingPosition.Y + j * blockHeight);
                    theMainView[i, j] = new Block(position);

                }
            }

            buildings = new List<Building>();
        }
Ejemplo n.º 18
0
	void Start () {
		float r = ((32.0F /Mathf.PI));
		float theta = 0.0F;
		float dT = (2*Mathf.PI)/64;
		blocks = new Block[COLUMNS, ROWS];
		for (int i = 0; i < COLUMNS; i++) {
			for (int j = 0; j < ROWS; j++) {
				float x = r * Mathf.Cos (theta);
				float y = r * Mathf.Sin (theta);
				Transform bl = (Transform) Instantiate(blockPrefab, new Vector3(x, j, y), Quaternion.identity);
				bl.eulerAngles = new Vector3(0, -theta * (180 / Mathf.PI), 0);
				blocks[i,j] = bl.gameObject.GetComponent<Block>();
				blocks[i,j].SetState("empty");
			}
			theta += dT;
		}

		InitiateNewPlayerBlock ();

		posx [0] = playerBlockLocation [0]; 
		posx [1] = playerBlockLocation [0] + lu [playerBlockId, playerOrient, 0];
		posx [2] = playerBlockLocation [0] + lu [playerBlockId, playerOrient, 2];
		posx [3] = playerBlockLocation [0] + lu [playerBlockId, playerOrient, 4]; 

		posy [0] = playerBlockLocation [1]; 
		posy [1] = playerBlockLocation [1] + lu [playerBlockId, playerOrient, 1];
		posy [2] = playerBlockLocation [1] + lu [playerBlockId, playerOrient, 3];
		posy [3] = playerBlockLocation [1] + lu [playerBlockId, playerOrient, 5];
	}
Ejemplo n.º 19
0
        public MultiBlockDef(Vector2 Size, Vector2 Center)
        {
            this._Size = Size;
            this.Center = Center;

            BlockTable = new Block[(int)Size.X, (int)Size.Y];
        }
Ejemplo n.º 20
0
        public void save(Map map)
        {
            string path = getPathFromName(map.name);

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            using (StreamWriter sw = File.AppendText(path))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(sw.BaseStream, map.getMapInfo());

                BinaryWriter binaryWriter = new BinaryWriter(sw.BaseStream, Encoding.Default, true);

                Block[,] blocks = map.map;
                int xLen = blocks.GetLength(0);
                int yLen = blocks.GetLength(1);

                binaryWriter.Write(xLen);
                binaryWriter.Write(yLen);

                for (int i = 0; i < xLen; i++)
                {
                    for (int j = 0; j < yLen; j++)
                    {
                        Block block = blocks[i, j];
                        binaryWriter.Write(block.filled);
                        binaryWriter.Write(block.type);
                    }
                }
            }
        }
Ejemplo n.º 21
0
    // Look at all the 8 neighboring cells. If any of them are solid,
    // then the cell is traversable.
    private bool IsTraversable(int x, int y, Block[,] seedMap)
    {
        for (int nx = -1; nx <= 1; nx++)
        {
            for (int ny = -1; ny <= 1; ny++)
            {
                // Don't check the cell itself, or corners if not counting floating corners.
                // If counting corners, just don't check itself.
                if ((!traversableFloatingCorners && Mathf.Abs(nx) == Mathf.Abs(ny)) || (nx == 0 && ny == 0))
                {
                    continue;
                }

                int checkX = x + nx;
                int checkY = y + ny;

                // Don't go out of bounds!
                if (checkX >= 0 && checkX < seedMap.GetLength(0) && checkY >= 0 && checkY < seedMap.GetLength(1))
                {
                    if (seedMap[checkX, checkY] != Block.Air && seedMap[x, y] == Block.Air)
                    {
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Ejemplo n.º 22
0
        public Grid(Game1 game, String layoutFile, int gridHeight, int gridWidth)
        {
            this.gridHeight = gridHeight;
            this.gridWidth = gridWidth;

            //Load out the text file into a string
            sr = new StreamReader(layoutFile);
            strLayout = sr.ReadToEnd();
            sr.Close();

            //Get number of columns
            sr = new StreamReader(layoutFile);
            numCellsWide = sr.ReadLine().Length;
            sr.Close();

            cellWidth = this.gridWidth / numCellsWide;

            //Get number of rows
            numCellsHigh = strLayout.Length / numCellsWide;
            cellHeight = this.gridHeight / numCellsHigh;

            //Create your grid array
            grid = new Block[numCellsHigh, numCellsWide];

            //Initialize your grid
            this.Init(game);
        }
Ejemplo n.º 23
0
        //Controller Methods===============================================================
        public static void GenerateABlock(ref Block[,] blks)
        {
            int k      = Block.CountBlocksNumberZero(blks);
            var ran    = new Random();
            int RanPos = ran.Next(0, k);
            int RanNum = ran.Next(1, 2) * 2;

            int temp_count = -1;

            for (int row = 0; row < 4; row++)
            {
                for (int col = 0; col < 4; col++)
                {
                    if (blks[row, col].num == 0)
                    {
                        temp_count++;
                        if (temp_count == RanPos)
                        {
                            blks[row, col].num      = RanNum;
                            blks[row, col].NewBlock = true;
                        }
                    }
                }
            }
        }
Ejemplo n.º 24
0
        public BlockGrid(int cellWidth, int cellHeight, int rows, int cols)
        {
            _FreeBlocks = new List<BlockGroup>();
            _ExplodeBlocks = new List<BlockGroup>();
            _SuspendBlocks = new List<BlockGroup>();
            _SwapBlocks = new List<BlockGroup[]>();

            InactiveFreeGroups = new List<BlockGroup>();
            InactiveExplodeGroups = new List<BlockGroup>();
            InactiveSuspendGroups = new List<BlockGroup>();
            InactiveSwapGroups = new List<BlockGroup[]>();

            ExplodeQueue = new List<int[]>();

            _Blocks = new Block[rows, cols];

            _NumRows = rows;
            _NumCols = cols;
            _CellWidth = cellWidth;
            _CellHeight = cellHeight;

            _SelectorRow = rows / 2 - 1;
            _SelectorCol = cols / 2 - 1;

            Animation frame = AnimationFactory.GenerateAnimation(@"Block", 48, 48, 5, 0);
            blockSprite = new Sprite(frame, new Vector2(200, 200));

            frame = AnimationFactory.GenerateAnimation(@"Selector", 104, 56, 1, 0);
            selectorSprite = new Sprite(frame, new Vector2(200, 200));
        }
Ejemplo n.º 25
0
        public SnakeGame(int height, int width)
        {
            inputAmount  = 26;
            outputAmount = 3;
            this.height  = height;
            this.width   = width;
            board        = new Block[height, width];
            random       = new Random();

            SPoint snakeLoc  = new SPoint(random.Next(1, width - 1), random.Next(1, height - 1));
            SPoint leftSnake = new SPoint(snakeLoc.x - 1, snakeLoc.y);

            board[snakeLoc.y, snakeLoc.x]   = Block.Snake;
            board[leftSnake.y, leftSnake.x] = Block.Snake;
            snake = new LinkedList <SPoint>();
            snake.AddLast(leftSnake);
            snake.AddLast(snakeLoc);

            GenFood();

            isEnd = false;

            foodDuration = 0;
            starve       = 150;
        }
Ejemplo n.º 26
0
        public GameDetail()
        {
            // players = new Player[5];
            colours = new Color[] { Color.MistyRose, Color.LightCyan, Color.DarkBlue, Color.Khaki, Color.PaleVioletRed };
            players = new List<Player>();
            for (int i = 0; i < 5; i++)
            {
                players.Add(new Player());
                players[i].colour = colours[i];
            }

            thisPlayer = new Player();
            coins = new List<Coin>();
            lifePacks = new List<LifePack>();
            blocks = new Block[10, 10];

            grid = new string[10, 10];

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    grid[i, j] = "N";
                    blocks[i, j] = new EmptyBlock(i, j);
                }

            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Инициализация массива блоков
        /// </summary>
        /// <param name="block"></param>
        /// <param name="settings"></param>
        public void InitializeBlocksArray(Block block, Settings settings)
        {
            var currentBlockNumber = 0;

            //var positionsArray = GeneratePositionsArray(settings);

            BlocksArray = new Block[settings.RowsCount, settings.ColumnsCount];

            for (var i = 0; i < settings.RowsCount; i++)
            {
                block.Position = ChangeBlockPosition(block, false, i);
                block.Position = new Point(0, block.Position.Y);

                for (var j = 0; j < settings.ColumnsCount; j++)
                {
                    block.Position = ChangeBlockPosition(block, true, j);
                    //Если номер текущего блока содержится в массиве номеров блоков на заполнение, создание новго блока
                    if (settings.PositionsArray.Any(x => x == currentBlockNumber))
                    {
                        BlocksArray[i, j] = GetBlock(block);
                    }
                    currentBlockNumber++;
                }
            }
        }
Ejemplo n.º 28
0
 public Block[,] createLevel1()
 {
     String[,] Testlevel1File  = readTextFile(Constants.testLevel1TextFilePath);
     Block[,] TestLevel1Blocks = makeBlocks(Testlevel1File);
     //printArray(Testlevel1File);
     return(TestLevel1Blocks);
 }
Ejemplo n.º 29
0
        public Level(int levelWidth, int levelHeight)
        {
            m_levelWidth  = levelWidth;
            m_levelHeight = levelHeight;
            m_blockGrid   = new Block[levelWidth, levelHeight];
            m_objects     = new List <Tuple <string, Vector3> >();

            Random rnd = new Random();

            for (int i = 0; i < m_levelWidth; i++)
            {
                for (int j = 0; j < m_levelHeight; j++)
                {
                    if (i < 4 || i > levelWidth - 4 || j < 4 || j > levelHeight - 4)
                    {
                        int v = rnd.Next(0, 3);
                        m_blockGrid[i, j] = new Block(Material.Dirt, Shape.Block, v);
                    }

                    if (i > 11 && j == 10 && (i % 8 == 0 || i % 8 == 1 || i % 8 == 2 || i % 8 == 3))
                    {
                        int v = rnd.Next(0, 3);
                        m_blockGrid[i, j] = new Block(Material.Dirt, Shape.Block, v);
                    }

                    if (i == j && i < 11)
                    {
                        int v = rnd.Next(0, 3);
                        m_blockGrid[i, j] = new Block(Material.Dirt, Shape.Block, v);
                    }
                }
            }
        }
Ejemplo n.º 30
0
        public BlockGrid(int cellWidth, int cellHeight, int rows, int cols)
        {
            _FreeBlocks    = new List <BlockGroup>();
            _ExplodeBlocks = new List <BlockGroup>();
            _SuspendBlocks = new List <BlockGroup>();
            _SwapBlocks    = new List <BlockGroup[]>();

            InactiveFreeGroups    = new List <BlockGroup>();
            InactiveExplodeGroups = new List <BlockGroup>();
            InactiveSuspendGroups = new List <BlockGroup>();
            InactiveSwapGroups    = new List <BlockGroup[]>();

            ExplodeQueue = new List <int[]>();

            _Blocks = new Block[rows, cols];

            _NumRows    = rows;
            _NumCols    = cols;
            _CellWidth  = cellWidth;
            _CellHeight = cellHeight;

            _SelectorRow = rows / 2 - 1;
            _SelectorCol = cols / 2 - 1;

            Animation frame = AnimationFactory.GenerateAnimation(@"Block", 48, 48, 5, 0);

            blockSprite = new Sprite(frame, new Vector2(200, 200));

            frame          = AnimationFactory.GenerateAnimation(@"Selector", 104, 56, 1, 0);
            selectorSprite = new Sprite(frame, new Vector2(200, 200));
        }
Ejemplo n.º 31
0
    void createPuzzle()
    {
        blocks = new Block[ammountBlockPerLine, ammountBlockPerLine];
        Texture2D[,] imageSlices = ImageSlicer.GetSlicer(image, ammountBlockPerLine);
        for (int y = 0; y < ammountBlockPerLine; y++)
        {
            for (int x = 0; x < ammountBlockPerLine; x++)
            {
                GameObject blockObject = GameObject.CreatePrimitive(PrimitiveType.Quad);
                blockObject.transform.position = -Vector2.one * (ammountBlockPerLine - 1) * 0.5f + new Vector2(x, y);
                blockObject.transform.parent   = transform;

                Block block = blockObject.AddComponent <Block>();
                block.OnBlockPressed += PlayerMoveBlockInput;
                block.OnFinishMoving += OnBlockFinishedMove;

                block.initial(new Vector2Int(x, y), imageSlices[x, y]);
                blocks[x, y] = block;
                if (y == 0 && x == ammountBlockPerLine - 1)
                {
                    emptyBlock = block;
                }
            }
        }
        Camera.main.orthographicSize = ammountBlockPerLine;
        inputs = new Queue <Block>();

        //Vector2 newPos = gameObject.transform.position;
        //newPos.y += -1;
        //transform.position = newPos;
    }
Ejemplo n.º 32
0
        public OrientationField(int[,] bytes, int blockSize, bool isPixelwise)
        {
            BlockSize = blockSize;
            int maxX = bytes.GetUpperBound(1) + 1;
            int maxY = bytes.GetUpperBound(0) + 1;

            double[,] filterX = new double[, ] {
                { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 }
            };
            double[,] filterY = new double[, ] {
                { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 }
            };
            double[,] doubleBytes = new double[maxY, maxX];
            for (int row = 0; row < maxY; row++)
            {
                for (int column = 0; column < maxX; column++)
                {
                    doubleBytes[row, column] = (double)bytes[row, column];
                }
            }
            // градиенты
            double[,] Gx = ConvolutionHelper.Convolve(doubleBytes, filterX);
            double[,] Gy = ConvolutionHelper.Convolve(doubleBytes, filterY);
            // разделение на блоки
            this._blocks = new Block[(int)Math.Floor((float)(maxY / BlockSize)), (int)Math.Floor((float)(maxX / BlockSize))];
            for (int row = 0; row < _blocks.GetUpperBound(0) + 1; row++)
            {
                for (int column = 0; column < _blocks.GetUpperBound(1) + 1; column++)
                {
                    _blocks[row, column] = new Block(BlockSize, Gx, Gy, row * BlockSize, column * BlockSize);
                }
            }
        }
Ejemplo n.º 33
0
 void Awake()
 {
     Movable    = false;
     blocks     = new Block[4, 4];
     blockcount = 0;
     moveflag   = false;
 }
Ejemplo n.º 34
0
Archivo: Form1.cs Proyecto: koutcha/bo
        private void LineUpBlocks(int BlockInterval, Block copySource, int[,] blockLifeMatrix)
        {
            int x = copySource.X;
            int y = copySource.Y;

            int blockRowNumber    = blockLifeMatrix.GetLength(1);
            int blockColumnNumber = blockLifeMatrix.GetLength(0);

            this.blocks = new Block[blockColumnNumber, blockRowNumber];
            {
                for (int i = 0; i < blockColumnNumber; i++)
                {
                    for (int j = 0; j < blockRowNumber; j++)
                    {
                        if (i == 0 && j == 0)
                        {
                            blocks[i, j] = copySource;
                        }
                        else
                        {
                            blocks[i, j] = new Block(x, y, copySource.Width, copySource.Height, copySource.Life);
                        }
                        x += (copySource.Width + BlockInterval);
                    }
                    x  = copySource.X;
                    y += (copySource.Height + BlockInterval);
                }
            }
        }
Ejemplo n.º 35
0
        private void pictureMaze_Paint(object sender, PaintEventArgs e)
        {
            g = e.Graphics;

            Block[,] block = maze.BlockList;

            int rowCount = MazeSolver.BLOCKS_ROW;
            int colCount = MazeSolver.BLOCKS_COLUMN;

            for (int i = 0; i < rowCount; i++)
            {
                for (int j = 0; j < colCount; j++)
                {
                    Block b = block[i, j];
                    g.DrawRectangle(MazeSolver.SQUARE_CORNER, b.SquareBlock);
                    if (b.IsWall)
                    {
                        Rectangle rect = new Rectangle(b.SquareBlock.X + 1, b.SquareBlock.Y + 1, b.SquareBlock.Width - 1, b.SquareBlock.Height - 1);
                        g.FillRectangle(Brushes.Gray, rect);
                    }
                    else if (b.BlockColor != null)
                    {
                        Rectangle rect = new Rectangle(b.SquareBlock.X + 1, b.SquareBlock.Y + 1, b.SquareBlock.Width - 1, b.SquareBlock.Height - 1);
                        g.FillRectangle(b.BlockColor, rect);
                    }
                }
            }

            g.FillEllipse(Brushes.Blue, objEllipse);
        }
Ejemplo n.º 36
0
 public Block[,] createLevelFromFile(String fileName)
 {
     String[,] Testlevel1File  = readTextFile(fileName);
     Block[,] TestLevel1Blocks = makeBlocks(Testlevel1File);
     //printArray(Testlevel1File);
     return(TestLevel1Blocks);
 }
Ejemplo n.º 37
0
    // Passes in the grid it should be added to and the top left coordinate
    // where the piece should be placed
    public bool addToGrid(Block[,] grid, GridCoord topLeft)
    {
        initializeBlocks();
        this.grid    = grid;
        this.topLeft = topLeft;
        GridCoord[] tests = { new GridCoord(topLeft.row - 3, topLeft.col),
                              new GridCoord(topLeft.row - 2, topLeft.col),
                              new GridCoord(topLeft.row - 1, topLeft.col), topLeft };
        GridCoord   resultCoord = null;

        foreach (GridCoord coord in tests)
        {
            if (canAddAt(coord))
            {
                resultCoord = coord;
            }
        }
        if (resultCoord != null)
        {
            addAt(resultCoord);
        }
        if (resultCoord != topLeft)
        {
            return(false);
        }
        return(true);
    }
Ejemplo n.º 38
0
        // The click event handler for Generating blocks
        private void buttonGenerate_Click(object sender, EventArgs e)
        {
            try
            {
                int row    = int.Parse(textBoxRow.Text);
                int column = int.Parse(textBoxColumn.Text);

                pb = new Block[row, column];

                for (int i = 0; i < row; i++)
                {
                    for (int j = 0; j < column; j++)
                    {
                        pb[i, j]             = new Block();
                        pb[i, j].Location    = new Point((j * BLOCKWIDTH) + STARTX, (i * BLOCKHEIGHT) + STARTY);
                        pb[i, j].Width       = BLOCKWIDTH;
                        pb[i, j].Height      = BLOCKHEIGHT;
                        pb[i, j].Visible     = true;
                        pb[i, j].BorderStyle = BorderStyle.Fixed3D;
                        pb[i, j].SizeMode    = PictureBoxSizeMode.StretchImage;
                        pb[i, j].BringToFront();
                        this.Controls.Add(pb[i, j]);
                        pb[i, j].Row    = i;
                        pb[i, j].Column = j;
                        pb[i, j].Type   = 0;

                        pb[i, j].Click += PB_Click;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error occurd:{ex.Message}");
            }
        }
Ejemplo n.º 39
0
        public Terrain(Block[,] map)
        {
            Map = map;

            GameModel.Instance.MouseInput.OnClick += onClickHandler;

            Init();
        }
Ejemplo n.º 40
0
        public Board(IScreenParser parser, int width = 30, int height = 16)
        {
            this.parser = parser;
            algorithms.Add(new SimpleSolver());
            algorithms.Add(new MacroSolver());

            Grid = new Block[width, height];
        }
Ejemplo n.º 41
0
 public MapHandler(int mapWidth, int mapHeight, int percentWalls = 40)
 {
     this.MapWidth = mapWidth;
     this.MapHeight = mapHeight;
     this.PercentAreWalls = percentWalls;
     Map = new Block[MapWidth, MapHeight];
     RandomFillMap();
 }
Ejemplo n.º 42
0
        public World(int sizeX, int sizeY, Grid grid, TextureCollection a)
        {
            blockArray = new Block[sizeX, sizeY];
            targetGrid = grid;
            textures = a;

            Generate();
            AddPlayer();
        }
        public ResetBoardAnimationManager(GameManager gameManager, Block[,] board)
        {
            volume = Convert.ToSingle(gameManager.GameData.GameSettings.SoundVolume / 100);

            using (Stream stream = TitleContainer.OpenStream("swoosh2.wav"))
                _swooshSound = SoundEffect.FromStream(stream);

            _gameManager = gameManager;
            _board = board;
        }
Ejemplo n.º 44
0
        public MapHandler()
        {
            MapWidth = 40;
            MapHeight = 21;
            PercentAreWalls = 40;

            Map = new Block[MapWidth, MapHeight];

            RandomFillMap();
        }
Ejemplo n.º 45
0
 public ShadowMap(ContentManager Content, Block[,] grid)
 {
     shadow_u = Content.Load<Texture2D>("shadow_u");
     shadow_l = Content.Load<Texture2D>("shadow_l");
     shadow_ul = Content.Load<Texture2D>("shadow_ul");
     shadow_c = Content.Load<Texture2D>("shadow_c");
     shadow_cu = Content.Load<Texture2D>("shadow_cu");
     shadow_cl = Content.Load<Texture2D>("shadow_cl");
     this.grid = grid;
 }
Ejemplo n.º 46
0
 internal BlockArea(Texture2D blockTexture, Texture2D ghostBlockTexture)
 {
     _blocks = new Block[Constants.BlockAreaSizeX,Constants.BlockAreaSizeY];
     _blockTexture = blockTexture;
     _ghostBlockTexture = ghostBlockTexture;
     _moveTimeElapsed = 0.0f;
     _random = new Random();
     _shapeTypes = new[] {0, 1, 2, 3, 4, 5, 6};
     ShuffleShapeTypes();
 }
Ejemplo n.º 47
0
 public Playground(int x, int y, int bs)
 {
     int height = y/bs;
     int width = x/bs;
     this.arr = new Block[height,width];
     this.bs = bs;
     this.x=width;
     this.y=height;
     this.maxY = y;
 }
Ejemplo n.º 48
0
 public GhostShape(World world, Shape shape)
 {
     this.world = world;
     this.shape = shape;
     this.grid = shape.Grid;
     gridCenter = new Vector2(grid.GetLength(0) - 1, grid.GetLength(1) - 1) / 2;
     location = new Point(world.Columns / 2 - 1, (int)gridCenter.Y);
     //If can't spawn. kill world
     if (!CanMove(new Point(0, 0), world, shape.Grid))
         world.Kill();
 }
Ejemplo n.º 49
0
 //Added possibility for 4x4 field with 3 players
 public Field(int size)
 {
     if (size == 4)
     {
         this.BlocksArray = new Block[4,4];
         this.size = 4;
     }
     else
     {
         this.BlocksArray = new Block[3, 3];
     }
 }
Ejemplo n.º 50
0
        //creates random block map
        public RandomMap(Game game, int mapWidth, int mapHeight)
        {
            this.game = game;
            this.mapWidth = mapWidth;
            this.mapHeight = mapHeight;
            this.xNumBlocks = mapWidth / GameSettings.BLOCK_WIDTH;
            this.yNumBlocks = mapHeight / GameSettings.BLOCK_HEIGHT;

            this.map = new Block[xNumBlocks, yNumBlocks];

            this.initMap();
        }
Ejemplo n.º 51
0
        public GameField(GameTab gameTab)
        {
            this.gameTab = gameTab;

            field = Block.getBlinkArray(Constants.FIELDBLOCKZISE);
            movingFigure = new MovingFigure();
            setNewFigure();

            ticktimer = 0;
            movetimer = 0;
            isMoved = false;
        }
Ejemplo n.º 52
0
        public BlockProvider(int dimensionX, int dimensionZ)
        {
            DimensionX = dimensionX;
            DimensionZ = dimensionZ;

            _blocks = new Block[dimensionX, dimensionZ];

            // Create some dummy tiles
            for (int x = 0; x < DimensionX; ++x)
                for (int z = 0; z < DimensionZ; ++z)
                    _blocks[x, z] = new Block(x, z, TileType.Grass, (Noise.Generate(x / 1000f, z / 1000f) + 1f) / 2f);
        }
Ejemplo n.º 53
0
 public Board()
 {
     players = new Player[5];
     blocks = new Block[10, 10];
     for (int a = 0; a < 10; a++)
     {
         for (int b = 0; b < 10; b++)
         {
             blocks[a, b] = new Block(a, b);
         }
     }
 }
Ejemplo n.º 54
0
        public Court(int width, int height) {
            this.COURT_WIDTH = width;
            this.COURT_HEIGHT = height;
            this.grid = new Block[width, height];
            // Initialize empty grid
            for (int x = 0; x < width; x++) {
                for (int y = 0; y < height; y++) {
                    this.grid[x, y] = null;
                }
            }


        }
Ejemplo n.º 55
0
 public Model()
 {
     empty = new List<Block>();
     board = new Block[4, 4];
     for (int i = 0; i < 4; i++)
     {
         for (int j = 0; j < 4; j++)
         {
             board[i, j] = new Block();
             empty.Add(board[i, j]);
         }
     }
 }
Ejemplo n.º 56
0
 public Entity(Arman game, PositionInGrid positionInGrid, Texture2D texture, Block[,] gameArray, int oneBlockSize, int timeForMove, List<Entity> movableObjects)
 {
     Blocked = false;
     this.game = game;
     PositionInGrid = positionInGrid;
     this.Texture = texture;
     this.gameArray = gameArray;
     isMoving = false;
     this.timeForMove = timeForMove;
     this.oneBlockSize = oneBlockSize;
     this.movableObjects = movableObjects;
     movingDifference = 0.0F;
     movingDirection = Direction.up;
 }
Ejemplo n.º 57
0
 public PlayerAvatar(Texture2D4D aTextures, Vector2 initialGridPos, Block[,] grid, IEnumerable<Laserbeam> laserBeams, MainGame game, bool isSilverBot = false)
 {
     gridPos = initialGridPos;
     animPos = gridPos * 32.0f;
     animTarget = animPos;
     textures = aTextures;
     facing = Direction4D.Right;
     this.grid = grid;
     this.laserBeams = laserBeams;
     this.game = game;
     explosionTexture = game.textures.explosion;
     Arrive += PlayerAvatar_Arrive;
     this.isSilverBot = isSilverBot;
 }
Ejemplo n.º 58
0
 public Map(int width = 900, int height = 500)
 {
     // Init
     SizeX = width;
     SizeY = height;
     Types = new BlockType[30];
     WallTypes = new WallType[10];
     Blocks = new Block[SizeX, SizeY];
     Walls = new Wall[SizeX, SizeY];
     DroppedItems = new DroppedItemCollection();
     Fluids = new Fluid.FluidCollection();
     Entities = new EntityPackage();
     Flora = new FloraPackage();
     WallTypes[0] = new WallType(1, "Standard Wall", new Rectangle(0,0,24,24));
 }
Ejemplo n.º 59
0
 public AI(Block[,] blocks, int size, String player_id)
 {
     this.blocks = blocks;
     this.grid_size = size;
     this.player_id = player_id;
     grid = new Node[size, size];
     // initializing grid for the  a strat algorithm
     for (int i = 0; i < size; i++)
     {
         for (int j = 0; j < size; j++)
         {
             grid[i, j] = new Node();
         }
     }
 }
Ejemplo n.º 60
0
        /// <summary>
        /// Construct the board
        /// </summary>
        /// <param name="graphicsDevice"></param>
        public Board(Screen screen)
        {
            Screen = screen;   

            // Create the board
            Blocks = new Block[Rows, Columns];
            for (int row = 0; row < Rows; row++)
            {
                for (int column = 0; column < Columns; column++)
                {
                    Blocks[row, column] = new Block(this, Screen, row, column);

                    // Only fill the first bottom Rows
                    if (row < initialEmptyRows)
                    {
                        Blocks[row, column].Empty();
                    }
                    else
                    {
                        Blocks[row, column].Create();
                    }
                }
            }

            // Create the next row of Blocks
            NextBlocks = new Block[Columns];
            for (int column = 0; column < Columns; column++)
            {
                NextBlocks[column] = new Block(this, Screen, Rows, column);
                NextBlocks[column].Create();
                NextBlocks[column].State = Block.BlockState.Preview;
            }

            CelebrationManager = new CelebrationManager(this);

            Renderer = new BoardRenderer(this);
            controller = new BoardController(this);
            Stats = new BoardStats(this);

            RaiseRate = (double)Stats.Level / 4;

            // Initialize buttons
            retryButton = new Button(screen, "Retry", Color.White, new Rectangle(Renderer.Rectangle.X + Renderer.Rectangle.Width / 4 - 50, Renderer.Rectangle.Y + Renderer.Rectangle.Height - 150, Renderer.Rectangle.Width / 4, 100), Color.Orange);
            retryButton.Selected += retryButton_Selected;

            doneButton = new Button(screen, "Done", Color.White, new Rectangle(Renderer.Rectangle.X + Renderer.Rectangle.Width / 2 + 50, Renderer.Rectangle.Y + Renderer.Rectangle.Height - 150, Renderer.Rectangle.Width / 4, 100), Color.Orange);
            doneButton.Selected += doneButton_Selected;
        }