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]);
        }
Beispiel #2
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);
            }
        }
        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);
            }
        }