Esempio n. 1
0
        public void readMapObject()
        {
            levelModel.Tiles.Clear();
            levelModel.AmountOfTargets = 0;
            for (int y = 0; y < levelModel.RowLenght; y++)
            {
                List<Tile> row = new List<Tile>();

                for (int x = 0; x < levelModel.ColumnLenght; x++)
                {
                    if (levelModel.StringList[y][x] == "#")
                    {
                        Wall m = new Wall();
                        m.X = x;
                        m.Y = y;
                        row.Add(m);
                    }
                    else if (levelModel.StringList[y][x] == " ")
                    {
                        Floor f = new Floor();
                        f.X = x;
                        f.Y = y;
                        row.Add(f);
                    }
                    else if (levelModel.StringList[y][x] == "@")
                    {
                        Floor f = new Floor();
                        f.X = x;
                        f.Y = y;
                        row.Add(f);

                        //Add player
                        Forklift fork = new Forklift();
                        fork.X = x;
                        fork.Y = y;
                        levelModel.TilesBpt[y,x] = fork;
                        levelModel.Forklift = fork;
                    }
                    else if (levelModel.StringList[y][x] == "o")
                    {
                        Floor f = new Floor();
                        f.X = x;
                        f.Y = y;
                        row.Add(f);

                        //Add box
                        Box b = new Box();
                        b.X = x;
                        b.Y = y;
                        levelModel.TilesBpt[y,x] = b;
                    }
                    else if (levelModel.StringList[y][x] == "x")
                    {
                        levelModel.AmountOfTargets++;
                        Target t = new Target();
                        t.X = x;
                        t.Y = y;
                        row.Add(t);
                    }
                }
                levelModel.Tiles.Add(row);
            }
        }
Esempio n. 2
0
        private void placeTile(int x, int y)
        {
            int width = levelGrid.ColumnDefinitions.Count();
            int height = levelGrid.RowDefinitions.Count();

            if (x == 0 || y == 0 || x == width - 1 || y == height - 1)
            {
                return;
            }

            Tile newTile;
            switch (tilesListBox.SelectedItem.ToString())
            {
                case "Sokoban.Wall":
                    newTile = new Wall();
                    break;
                case "Sokoban.Target":
                    newTile = new Target();
                    break;
                case "Sokoban.Box":
                    newTile = new Box();
                    break;
                case "Sokoban.Forklift":
                    newTile = new Forklift();
                    break;
                default:
                    newTile = new Floor();
                    break;
            }
            newTile.SetValue(Grid.ColumnProperty, x);
            newTile.SetValue(Grid.RowProperty, y);

            levelGrid.Children.Remove(tiles[y][x]);
            tiles[y][x] = newTile;
            levelGrid.Children.Add(tiles[y][x]);
        }
Esempio n. 3
0
        private void verticalPlus_Click(object sender, RoutedEventArgs e)
        {
            if (levelGrid.RowDefinitions.Count() >= maxGridHeight)
            {
                return;
            }

            //Add a new row to the grid.
            RowDefinition gridRow = new RowDefinition();
            gridRow.Height = new GridLength(levelModel.CellSize);
            levelGrid.RowDefinitions.Add(gridRow);

            //Get the new total width and height.
            int width = levelGrid.ColumnDefinitions.Count();
            int height = levelGrid.RowDefinitions.Count();

            //Move the wall row one down in both the tiles array and grid.
            foreach (Tile tile in tiles[height - 2])
            {
                tile.SetValue(Grid.RowProperty, height - 1);
            }
            tiles.Add(tiles[height-2]);

            //Create a new row that will be inserted in the old wall row.
            List<Tile> row = new List<Tile>();
            for (int i = 0; i < width; i++)
            {
                //Walls left and right. The rest is floor.
                if (i == 0 || i == width - 1)
                {
                    Wall wall = new Wall();
                    wall.SetValue(Grid.ColumnProperty, i);
                    wall.SetValue(Grid.RowProperty, height-2);

                    row.Add(wall);
                    levelGrid.Children.Add(wall);
                }
                else
                {
                    Floor floor = new Floor();
                    floor.SetValue(Grid.ColumnProperty, i);
                    floor.SetValue(Grid.RowProperty, height-2);

                    row.Add(floor);
                    levelGrid.Children.Add(floor);
                }
            }
            tiles[height - 2] = row;
        }
Esempio n. 4
0
        private void loadMap()
        {
            //Reset the grid.
            levelGrid.Children.Clear();
            levelGrid.ColumnDefinitions.Clear();
            levelGrid.RowDefinitions.Clear();
            tiles.Clear();

            //Create the grid columns.
            for (int i = 0; i < levelModel.ColumnLenght; i++)
            {
                ColumnDefinition GridColumn = new ColumnDefinition();
                GridColumn.Width = new GridLength(levelModel.CellSize);
                levelGrid.ColumnDefinitions.Add(GridColumn);
            }

            for (int i = 0; i < levelModel.RowLenght; i++)
            {
                RowDefinition gridRow = new RowDefinition();
                gridRow.Height = new GridLength(levelModel.CellSize);
                levelGrid.RowDefinitions.Add(gridRow);
            }

            List<List<String>> map = levelModel.StringList;

            for (int y = 0; y < levelModel.RowLenght; y++)
            {
                List<Tile> row = new List<Tile>();
                for (int x = 0; x < levelModel.ColumnLenght; x++)
                {
                    Tile newTile = new Tile();
                    switch (map[y][x])
                    {
                        case "#":
                            newTile = new Wall();
                            break;
                        case "x":
                            newTile = new Target();
                            break;
                        case "o":
                            newTile = new Box();
                            break;
                        case "@":
                            newTile = new Forklift();
                            break;
                        default:
                            newTile = new Floor();
                            break;
                    }

                    newTile.SetValue(Grid.ColumnProperty, x);
                    newTile.SetValue(Grid.RowProperty, y);

                    row.Add(newTile);
                    levelGrid.Children.Add(newTile);
                }
                tiles.Add(row);
            }
        }
Esempio n. 5
0
        private void initGrid()
        {
            int width = levelGrid.ColumnDefinitions.Count();
            int height = levelGrid.RowDefinitions.Count();

            for (int y = 0; y < height; y++)
            {
                List<Tile> row = new List<Tile>();
                for (int x = 0; x < width; x++)
                {
                    if (x == 0 || y == 0 || x == width - 1 || y == height - 1)
                    {
                        Wall wall = new Wall();
                        wall.SetValue(Grid.ColumnProperty, x);
                        wall.SetValue(Grid.RowProperty, y);

                        row.Add(wall);
                        levelGrid.Children.Add(wall);
                    }
                    else
                    {
                        Floor floor = new Floor();
                        floor.SetValue(Grid.ColumnProperty, x);
                        floor.SetValue(Grid.RowProperty, y);

                        row.Add(floor);
                        levelGrid.Children.Add(floor);
                    }
                }
                tiles.Add(row);
            }
        }
Esempio n. 6
0
        private void horizontalPlus_Click(object sender, RoutedEventArgs e)
        {
            if (levelGrid.ColumnDefinitions.Count() >= maxGridWidth)
            {
                return;
            }

            //Add a new column to the grid.
            ColumnDefinition GridColumn = new ColumnDefinition();
            GridColumn.Width = new GridLength(levelModel.CellSize);
            levelGrid.ColumnDefinitions.Add(GridColumn);

            //Get the new total width and height.
            int width = levelGrid.ColumnDefinitions.Count();
            int height = levelGrid.RowDefinitions.Count();

            foreach(List<Tile> row in tiles)
            {
                row.Add(row[width-2]);
                row[width - 1].SetValue(Grid.ColumnProperty, width - 1);
            }

            //Add new tiles to the new column.
            for (int i = 0; i < height; i++)
            {
                //Walls up and down. The rest is floor.
                if (i == 0 || i == height - 1)
                {
                    Wall wall = new Wall();
                    wall.SetValue(Grid.ColumnProperty, width - 2);
                    wall.SetValue(Grid.RowProperty, i);

                    tiles[i][width-2] = wall;
                    levelGrid.Children.Add(wall);
                }
                else
                {
                    Floor floor = new Floor();
                    floor.SetValue(Grid.ColumnProperty, width -2);
                    floor.SetValue(Grid.RowProperty, i);

                    tiles[i][width - 2] = floor;
                    levelGrid.Children.Add(floor);
                }
            }
        }
Esempio n. 7
0
        //POSTAC: 5
        //PUDELKO:6
        //PODLOGA:3
        //SCIANA:2
        //PUNKT:4
        void initMap(string pathFileMap)
        {
            this.Controls.Add(cbStart);
            cbStart.Show();
            this.Controls.Add(startScreen[mapNumber - 1]);
            startScreen[mapNumber - 1].Show();
            initButtons();
            PointsList = null;

            numberSteps = 0;
            numberShiftsBoxes = 0;

            previousnumberShiftsBoxes = 0;
            previousNumberSteps = 0;

            SetBoxes = 0;
            posX = 0;
            posY = 0;
            initLabels();

            readNumbers = readFile(pathFileMap);
            Map = new List<List<MapObject>>();
            PointsList = findPositionPoints(readNumbers);

            for (int i = 0; i < readNumbers.Count(); i++)
            {

                List<MapObject> initList = new List<MapObject>();

                for (int j = 0; j < readNumbers[i].Count(); j++)
                {

                    if (readNumbers[i][j] == 5)
                    {
                        Hero newHero = new Hero(heightElement, widthElement, posX, posY);
                        initList.Add(newHero);
                        this.Controls.Add(newHero.picturebox);
                    }

                    if (readNumbers[i][j] == 6)
                    {
                        Box newBox = new Box(heightElement, widthElement, posX, posY);
                        initList.Add(newBox);
                        this.Controls.Add(newBox.picturebox);
                    }

                    if (readNumbers[i][j] == 1)
                    {
                        NullElement newNullElement = new NullElement();
                        initList.Add(newNullElement);

                    }

                    if (readNumbers[i][j] == 2)
                    {
                        Wall newWall = new Wall(heightElement, widthElement, posX, posY);
                        initList.Add(newWall);
                        this.Controls.Add(newWall.picturebox);
                    }

                    if (readNumbers[i][j] == 4)
                    {
                        EndPoint newEndPoint = new EndPoint(heightElement, widthElement, posX, posY);
                        initList.Add(newEndPoint);
                        this.Controls.Add(newEndPoint.picturebox);
                    }

                    if (readNumbers[i][j] == 3)
                    {

                        Floor newFloor = new Floor(heightElement, widthElement, posX, posY);
                        initList.Add(newFloor);
                        this.Controls.Add(newFloor.picturebox);
                    }

                    posX = posX + 64;

                }
                posY = posY + 64;
                posX = posX - (64 * initList.Count());

                Map.Add(initList);
            }

            timer = new System.Timers.Timer(100);
            timer.Elapsed += (s, e) => UpdateTime(e);
        }
Esempio n. 8
0
        public void fillBord(String filepath)
        {
            try {
                using (StreamReader sr = new StreamReader(filepath)) {
                    rows = 0;
                    cols = 0;
                    List<String> regels = new List<String>();
                    while (sr.ReadLine() != null) {
                        rows++;
                    }

                    sr.BaseStream.Position = 0;
                    sr.DiscardBufferedData();

                    cols = sr.ReadLine().ToCharArray().Length;

                    sr.BaseStream.Position = 0;
                    sr.DiscardBufferedData();

                    bordje = new char[rows, cols];
                    bord = new Hokje[rows, cols];

                   int rownumber = 0;
                    while (!sr.EndOfStream && rownumber < rows) {
                        String currentLine = sr.ReadLine();
                        char[] characters = currentLine.ToCharArray();

                        for (int i = 0; i < cols; i++) {
                            bordje[rownumber, i] = characters[i];
                        }
                        rownumber++;
                    }
                }
            }
            catch (Exception e) {
                MessageBox.Show("File could not be read");
                MessageBox.Show(e.Message);
            }

            for (int j = 0; j < rows; j++) {
                for (int i = 0; i < cols; i++) {
                    switch (bordje[j, i]) {
                        case '#':
                            bord[j, i] = new Wall();
                            break;
                        case 'o':
                            bord[j, i] = new Box();
                            break;
                        case 'x':
                            bord[j, i] = new Destination();
                            break;
                        case ' ':
                            bord[j, i] = new Empty();
                            break;
                        case '@':
                            bord[j, i] = new Player();
                            break;
                    }
                    Console.Write(bordje[j, i]);
                }
                Console.Write("\n");
            }
        }