예제 #1
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;
        }
예제 #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);
            }
        }
예제 #3
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);
            }
        }
예제 #4
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]);
        }
예제 #5
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);
                }
            }
        }
예제 #6
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);
            }
        }
예제 #7
0
        private List<List<MapObject>> refreshMap(List<List<MapObject>> map, int up, int down, int left, int right)
        {
            MapObject help;
            MapObject help2;
            MapObject toRemove;
            List<List<MapObject>> toReturn = new List<List<MapObject>>();
            int[] heroPosition = findHeroPosition(map);

            if (up != 0)
            {

                if (map[heroPosition[0] - 1][heroPosition[1]].GetType() == typeof(Wall)) //gdy na gorze bedzie sciana
                {
                    toReturn = map;

                }
                if (map[heroPosition[0] - 1][heroPosition[1]].GetType() == typeof(Floor)) //gdy na gorze bedzie podloga
                {
                    help = map[heroPosition[0] - 1][heroPosition[1]];
                    map[heroPosition[0] - 1][heroPosition[1]] = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]] = help;

                    map[heroPosition[0] - 1][heroPosition[1]].setPosition(map[heroPosition[0] - 1][heroPosition[1]].getX(), (map[heroPosition[0] - 1][heroPosition[1]].getY() - heightElement));
                    map[heroPosition[0]][heroPosition[1]].setPosition(map[heroPosition[0]][heroPosition[1]].getX(), (map[heroPosition[0]][heroPosition[1]].getY() + heightElement));

                    numberSteps++;
                    toReturn = map;

                }
                if (map[heroPosition[0] - 1][heroPosition[1]].GetType() == typeof(Box)) //gdy na gorze bedzie skrzynka
                {
                    if (map[heroPosition[0] - 2][heroPosition[1]].GetType() == typeof(Floor) || map[heroPosition[0] - 2][heroPosition[1]].GetType() == typeof(EndPoint)) //sprawdz czy mozna przesunac skrzynke(podloga lub punkt)
                    {

                        help = map[heroPosition[0]][heroPosition[1]];
                        map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                        this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);
                        help2 = map[heroPosition[0] - 1][heroPosition[1]];// = 5;
                        map[heroPosition[0] - 1][heroPosition[1]] = help;
                        toRemove = map[heroPosition[0] - 2][heroPosition[1]];

                        map[heroPosition[0] - 2][heroPosition[1]] = help2;

                        map[heroPosition[0] - 1][heroPosition[1]].setPosition(map[heroPosition[0] - 1][heroPosition[1]].getX(), (map[heroPosition[0] - 1][heroPosition[1]].getY() - heightElement));
                        map[heroPosition[0] - 2][heroPosition[1]].setPosition(map[heroPosition[0] - 2][heroPosition[1]].getX(), (map[heroPosition[0] - 2][heroPosition[1]].getY() - heightElement));

                        this.Controls.Remove(toRemove.picturebox);

                        numberSteps++;
                        numberShiftsBoxes++;
                        toReturn = map;
                    }
                    else
                    {
                        toReturn = map;
                    }
                }

                if (map[heroPosition[0] - 1][heroPosition[1]].GetType() == typeof(EndPoint)) //gdy na gorze bedzie punkt
                {

                    help = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                    this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);

                    toRemove = (map[heroPosition[0] - 1][heroPosition[1]]);
                    map[heroPosition[0] - 1][heroPosition[1]] = help;
                    map[heroPosition[0] - 1][heroPosition[1]].setPosition(map[heroPosition[0] - 1][heroPosition[1]].getX(), (map[heroPosition[0] - 1][heroPosition[1]].getY() - heightElement));
                    this.Controls.Remove(toRemove.picturebox);

                    numberSteps++;
                    toReturn = map;
                }
            }

            if (down != 0)
            {

                if (map[heroPosition[0] + 1][heroPosition[1]].GetType() == typeof(Wall)) //gdy na dole bedzie sciana
                {
                    toReturn = map;

                }
                if (map[heroPosition[0] + 1][heroPosition[1]].GetType() == typeof(Floor)) //gdy na dole bedzie podloga
                {
                    help = map[heroPosition[0] + 1][heroPosition[1]];
                    map[heroPosition[0] + 1][heroPosition[1]] = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]] = help;

                    map[heroPosition[0] + 1][heroPosition[1]].setPosition(map[heroPosition[0] + 1][heroPosition[1]].getX(), (map[heroPosition[0] + 1][heroPosition[1]].getY() + heightElement));
                    map[heroPosition[0]][heroPosition[1]].setPosition(map[heroPosition[0]][heroPosition[1]].getX(), (map[heroPosition[0]][heroPosition[1]].getY() - heightElement));

                    numberSteps++;

                    toReturn = map;
                }
                if (map[heroPosition[0] + 1][heroPosition[1]].GetType() == typeof(Box)) //gdy na dole bedzie skrzynka
                {
                    if (map[heroPosition[0] + 2][heroPosition[1]].GetType() == typeof(Floor) || map[heroPosition[0] + 2][heroPosition[1]].GetType() == typeof(EndPoint)) //sprawdz czy mozna przesunac skrzynke(podloga lub punkt)
                    {

                        help = map[heroPosition[0]][heroPosition[1]];
                        map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                        this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);
                        help2 = map[heroPosition[0] + 1][heroPosition[1]];// = 5;
                        map[heroPosition[0] + 1][heroPosition[1]] = help;
                        toRemove = (map[heroPosition[0] + 2][heroPosition[1]]);
                        map[heroPosition[0] + 2][heroPosition[1]] = help2;

                        map[heroPosition[0] + 1][heroPosition[1]].setPosition(map[heroPosition[0] + 1][heroPosition[1]].getX(), (map[heroPosition[0] + 1][heroPosition[1]].getY() + heightElement));
                        map[heroPosition[0] + 2][heroPosition[1]].setPosition(map[heroPosition[0] + 2][heroPosition[1]].getX(), (map[heroPosition[0] + 2][heroPosition[1]].getY() + heightElement));

                        this.Controls.Remove(toRemove.picturebox);

                        numberSteps++;
                        numberShiftsBoxes++;

                        toReturn = map;
                    }
                    else
                    {
                        toReturn = map;
                    }
                }

                if (map[heroPosition[0] + 1][heroPosition[1]].GetType() == typeof(EndPoint)) //gdy na dole bedzie punkt
                {

                    help = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                    this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);
                    this.Controls.Remove(map[heroPosition[0] + 1][heroPosition[1]].picturebox);
                    toRemove = (map[heroPosition[0] + 1][heroPosition[1]]);
                    map[heroPosition[0] + 1][heroPosition[1]] = help;
                    map[heroPosition[0] + 1][heroPosition[1]].setPosition(map[heroPosition[0] + 1][heroPosition[1]].getX(), (map[heroPosition[0] + 1][heroPosition[1]].getY() + heightElement));
                    this.Controls.Remove(toRemove.picturebox);

                    numberSteps++;

                    toReturn = map;
                }
            }

            if (left != 0)
            {

                if (map[heroPosition[0]][heroPosition[1] - 1].GetType() == typeof(Wall)) //gdy na lewo bedzie sciana
                {
                    toReturn = map;

                }
                if (map[heroPosition[0]][heroPosition[1] - 1].GetType() == typeof(Floor)) //gdy na lewo bedzie podloga
                {
                    help = map[heroPosition[0]][heroPosition[1] - 1];
                    map[heroPosition[0]][heroPosition[1] - 1] = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]] = help;

                    map[heroPosition[0]][heroPosition[1] - 1].setPosition(map[heroPosition[0]][heroPosition[1] - 1].getX() - widthElement, (map[heroPosition[0]][heroPosition[1] - 1].getY()));
                    map[heroPosition[0]][heroPosition[1]].setPosition(map[heroPosition[0]][heroPosition[1]].getX() + widthElement, (map[heroPosition[0]][heroPosition[1]].getY()));

                    numberSteps++;

                    toReturn = map;
                }
                if (map[heroPosition[0]][heroPosition[1] - 1].GetType() == typeof(Box)) //gdy na lewo bedzie skrzynka
                {
                    if (map[heroPosition[0]][heroPosition[1] - 2].GetType() == typeof(Floor) || map[heroPosition[0]][heroPosition[1] - 2].GetType() == typeof(EndPoint)) //sprawdz czy mozna przesunac skrzynke(podloga lub punkt)
                    {

                        help = map[heroPosition[0]][heroPosition[1]];
                        map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                        this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);
                        help2 = map[heroPosition[0]][heroPosition[1] - 1];// = 5;
                        map[heroPosition[0]][heroPosition[1] - 1] = help;

                        toRemove = map[heroPosition[0]][heroPosition[1] - 2];
                        map[heroPosition[0]][heroPosition[1] - 2] = help2;

                        map[heroPosition[0]][heroPosition[1] - 1].setPosition(map[heroPosition[0]][heroPosition[1] - 1].getX() - widthElement, (map[heroPosition[0]][heroPosition[1] - 1].getY()));
                        map[heroPosition[0]][heroPosition[1] - 2].setPosition(map[heroPosition[0]][heroPosition[1] - 2].getX() - widthElement, (map[heroPosition[0]][heroPosition[1] - 2].getY()));

                        this.Controls.Remove(toRemove.picturebox);

                        numberSteps++;
                        numberShiftsBoxes++;

                        toReturn = map;
                    }
                    else
                    {
                        toReturn = map;
                    }
                }

                if (map[heroPosition[0]][heroPosition[1] - 1].GetType() == typeof(EndPoint)) //gdy na lewo bedzie punkt
                {

                    help = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                    this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);
                    toRemove = map[heroPosition[0]][heroPosition[1] - 1];
                    map[heroPosition[0]][heroPosition[1] - 1] = help;
                    map[heroPosition[0]][heroPosition[1] - 1].setPosition(map[heroPosition[0]][heroPosition[1] - 1].getX() - widthElement, (map[heroPosition[0]][heroPosition[1] - 1].getY()));
                    this.Controls.Remove(toRemove.picturebox);

                    numberSteps++;

                    toReturn = map;
                }
            }

            if (right != 0)
            {

                if (map[heroPosition[0]][heroPosition[1] + 1].GetType() == typeof(Wall)) //gdy na prawo bedzie sciana
                {
                    toReturn = map;

                }
                if (map[heroPosition[0]][heroPosition[1] + 1].GetType() == typeof(Floor)) //gdy na prawo bedzie podloga
                {
                    help = map[heroPosition[0]][heroPosition[1] + 1];
                    map[heroPosition[0]][heroPosition[1] + 1] = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]] = help;

                    map[heroPosition[0]][heroPosition[1] + 1].setPosition(map[heroPosition[0]][heroPosition[1] + 1].getX() + widthElement, (map[heroPosition[0]][heroPosition[1] + 1].getY()));
                    map[heroPosition[0]][heroPosition[1]].setPosition(map[heroPosition[0]][heroPosition[1]].getX() - widthElement, (map[heroPosition[0]][heroPosition[1]].getY()));

                    numberSteps++;

                    toReturn = map;
                }
                if (map[heroPosition[0]][heroPosition[1] + 1].GetType() == typeof(Box)) //gdy na prawo bedzie skrzynka
                {
                    if (map[heroPosition[0]][heroPosition[1] + 2].GetType() == typeof(Floor) || map[heroPosition[0]][heroPosition[1] + 2].GetType() == typeof(EndPoint)) //sprawdz czy mozna przesunac skrzynke(podloga lub punkt)
                    {

                        help = map[heroPosition[0]][heroPosition[1]];
                        map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                        this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);

                        help2 = map[heroPosition[0]][heroPosition[1] + 1];// = 5;
                        map[heroPosition[0]][heroPosition[1] + 1] = help;
                        toRemove = map[heroPosition[0]][heroPosition[1] + 2];
                        map[heroPosition[0]][heroPosition[1] + 2] = help2;

                        map[heroPosition[0]][heroPosition[1] + 1].setPosition(map[heroPosition[0]][heroPosition[1] + 1].getX() + widthElement, (map[heroPosition[0]][heroPosition[1] + 1].getY()));
                        map[heroPosition[0]][heroPosition[1] + 2].setPosition(map[heroPosition[0]][heroPosition[1] + 2].getX() + widthElement, (map[heroPosition[0]][heroPosition[1] + 2].getY()));

                        this.Controls.Remove(toRemove.picturebox);

                        numberSteps++;
                        numberShiftsBoxes++;

                        toReturn = map;
                    }
                    else
                    {
                        toReturn = map;
                    }
                }

                if (map[heroPosition[0]][heroPosition[1] + 1].GetType() == typeof(EndPoint)) //gdy na prawo bedzie punkt
                {

                    help = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                    this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);
                    toRemove = map[heroPosition[0]][heroPosition[1] + 1];
                    map[heroPosition[0]][heroPosition[1] + 1] = help;
                    map[heroPosition[0]][heroPosition[1] + 1].setPosition(map[heroPosition[0]][heroPosition[1] + 1].getX() + widthElement, (map[heroPosition[0]][heroPosition[1] + 1].getY()));
                    this.Controls.Remove(toRemove.picturebox);

                    numberSteps++;

                    toReturn = map;
                }

            }

            foreach (PointPosition p in PointsList)
            {
                if (Map[p.X][p.Y].GetType() == typeof(Floor))
                {
                    int x = Map[p.X][p.Y].getX();
                    int y = Map[p.X][p.Y].getY();
                    toRemove = Map[p.X][p.Y];

                    Map[p.X][p.Y] = new EndPoint(heightElement, widthElement, x, y);
                    this.Controls.Add(Map[p.X][p.Y].picturebox);
                    this.Controls.Remove(toRemove.picturebox);
                }
            }

            return toReturn;
        }
예제 #8
0
파일: Parser.cs 프로젝트: A3vk/Sokoban
        public void ConnectHorizontal()
        {
            for (int outer = 0; outer < _lines.Count; outer++)
            {
                char[] currentLine = _lines[outer];
                for (int inner = 0; inner < currentLine.Length; inner++)
                {
                    Tile temp;
                    switch (currentLine[inner])
                    {
                    case '#':
                        temp = new Wall(false);
                        break;

                    case '.':
                        temp = new Floor(false);
                        break;

                    case 'x':
                        temp = new Floor(true);
                        break;

                    case 'o':
                        Floor crateFloor = new Floor(false);
                        Crate crate      = new Crate(crateFloor);
                        crateFloor.Crate = crate;
                        _maze.Crates.Add(crate);
                        temp = crateFloor;
                        break;

                    case '@':
                        Floor    forkliftFloor = new Floor(false);
                        Forklift forklift      = new Forklift(forkliftFloor);
                        forkliftFloor.Forklift = forklift;
                        _maze.Forklift         = forklift;
                        temp = forkliftFloor;
                        break;

                    case '~':
                        temp = new BrokenFloor();
                        break;

                    case '$':
                        Floor    employeeFloor = new Floor(false);
                        Employee employee      = new Employee(employeeFloor);
                        employeeFloor.Employee = employee;
                        _maze.Employee         = employee;
                        temp = employeeFloor;
                        break;

                    default:
                        temp = new Wall(true);
                        break;
                    }

                    if (inner == 0)
                    {
                        _heads[outer] = temp;
                    }
                    else
                    {
                        _heads[outer].AddEast(temp);
                    }
                }
            }
        }
예제 #9
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);
        }
예제 #10
0
 public Player(char type, Floor floor)
 {
     ObjectType = type;
     this.floor = floor;
 }
예제 #11
0
        private List <List <MapObject> > refreshMap(List <List <MapObject> > map, int up, int down, int left, int right)
        {
            MapObject help;
            MapObject help2;
            MapObject toRemove;
            List <List <MapObject> > toReturn = new List <List <MapObject> >();

            int[] heroPosition = findHeroPosition(map);

            if (up != 0)
            {
                if (map[heroPosition[0] - 1][heroPosition[1]].GetType() == typeof(Wall)) //gdy na gorze bedzie sciana
                {
                    toReturn = map;
                }
                if (map[heroPosition[0] - 1][heroPosition[1]].GetType() == typeof(Floor)) //gdy na gorze bedzie podloga
                {
                    help = map[heroPosition[0] - 1][heroPosition[1]];
                    map[heroPosition[0] - 1][heroPosition[1]] = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]]     = help;


                    map[heroPosition[0] - 1][heroPosition[1]].setPosition(map[heroPosition[0] - 1][heroPosition[1]].getX(), (map[heroPosition[0] - 1][heroPosition[1]].getY() - heightElement));
                    map[heroPosition[0]][heroPosition[1]].setPosition(map[heroPosition[0]][heroPosition[1]].getX(), (map[heroPosition[0]][heroPosition[1]].getY() + heightElement));

                    numberSteps++;
                    toReturn = map;
                }
                if (map[heroPosition[0] - 1][heroPosition[1]].GetType() == typeof(Box))                                                                                  //gdy na gorze bedzie skrzynka
                {
                    if (map[heroPosition[0] - 2][heroPosition[1]].GetType() == typeof(Floor) || map[heroPosition[0] - 2][heroPosition[1]].GetType() == typeof(EndPoint)) //sprawdz czy mozna przesunac skrzynke(podloga lub punkt)
                    {
                        help = map[heroPosition[0]][heroPosition[1]];
                        map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                        this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);
                        help2 = map[heroPosition[0] - 1][heroPosition[1]];// = 5;
                        map[heroPosition[0] - 1][heroPosition[1]] = help;
                        toRemove = map[heroPosition[0] - 2][heroPosition[1]];

                        map[heroPosition[0] - 2][heroPosition[1]] = help2;


                        map[heroPosition[0] - 1][heroPosition[1]].setPosition(map[heroPosition[0] - 1][heroPosition[1]].getX(), (map[heroPosition[0] - 1][heroPosition[1]].getY() - heightElement));
                        map[heroPosition[0] - 2][heroPosition[1]].setPosition(map[heroPosition[0] - 2][heroPosition[1]].getX(), (map[heroPosition[0] - 2][heroPosition[1]].getY() - heightElement));

                        this.Controls.Remove(toRemove.picturebox);

                        numberSteps++;
                        numberShiftsBoxes++;
                        toReturn = map;
                    }
                    else
                    {
                        toReturn = map;
                    }
                }

                if (map[heroPosition[0] - 1][heroPosition[1]].GetType() == typeof(EndPoint)) //gdy na gorze bedzie punkt
                {
                    help = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                    this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);

                    toRemove = (map[heroPosition[0] - 1][heroPosition[1]]);
                    map[heroPosition[0] - 1][heroPosition[1]] = help;
                    map[heroPosition[0] - 1][heroPosition[1]].setPosition(map[heroPosition[0] - 1][heroPosition[1]].getX(), (map[heroPosition[0] - 1][heroPosition[1]].getY() - heightElement));
                    this.Controls.Remove(toRemove.picturebox);

                    numberSteps++;
                    toReturn = map;
                }
            }

            if (down != 0)
            {
                if (map[heroPosition[0] + 1][heroPosition[1]].GetType() == typeof(Wall)) //gdy na dole bedzie sciana
                {
                    toReturn = map;
                }
                if (map[heroPosition[0] + 1][heroPosition[1]].GetType() == typeof(Floor)) //gdy na dole bedzie podloga
                {
                    help = map[heroPosition[0] + 1][heroPosition[1]];
                    map[heroPosition[0] + 1][heroPosition[1]] = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]]     = help;

                    map[heroPosition[0] + 1][heroPosition[1]].setPosition(map[heroPosition[0] + 1][heroPosition[1]].getX(), (map[heroPosition[0] + 1][heroPosition[1]].getY() + heightElement));
                    map[heroPosition[0]][heroPosition[1]].setPosition(map[heroPosition[0]][heroPosition[1]].getX(), (map[heroPosition[0]][heroPosition[1]].getY() - heightElement));

                    numberSteps++;

                    toReturn = map;
                }
                if (map[heroPosition[0] + 1][heroPosition[1]].GetType() == typeof(Box))                                                                                  //gdy na dole bedzie skrzynka
                {
                    if (map[heroPosition[0] + 2][heroPosition[1]].GetType() == typeof(Floor) || map[heroPosition[0] + 2][heroPosition[1]].GetType() == typeof(EndPoint)) //sprawdz czy mozna przesunac skrzynke(podloga lub punkt)
                    {
                        help = map[heroPosition[0]][heroPosition[1]];
                        map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                        this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);
                        help2 = map[heroPosition[0] + 1][heroPosition[1]];// = 5;
                        map[heroPosition[0] + 1][heroPosition[1]] = help;
                        toRemove = (map[heroPosition[0] + 2][heroPosition[1]]);
                        map[heroPosition[0] + 2][heroPosition[1]] = help2;


                        map[heroPosition[0] + 1][heroPosition[1]].setPosition(map[heroPosition[0] + 1][heroPosition[1]].getX(), (map[heroPosition[0] + 1][heroPosition[1]].getY() + heightElement));
                        map[heroPosition[0] + 2][heroPosition[1]].setPosition(map[heroPosition[0] + 2][heroPosition[1]].getX(), (map[heroPosition[0] + 2][heroPosition[1]].getY() + heightElement));

                        this.Controls.Remove(toRemove.picturebox);

                        numberSteps++;
                        numberShiftsBoxes++;

                        toReturn = map;
                    }
                    else
                    {
                        toReturn = map;
                    }
                }

                if (map[heroPosition[0] + 1][heroPosition[1]].GetType() == typeof(EndPoint)) //gdy na dole bedzie punkt
                {
                    help = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                    this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);
                    this.Controls.Remove(map[heroPosition[0] + 1][heroPosition[1]].picturebox);
                    toRemove = (map[heroPosition[0] + 1][heroPosition[1]]);
                    map[heroPosition[0] + 1][heroPosition[1]] = help;
                    map[heroPosition[0] + 1][heroPosition[1]].setPosition(map[heroPosition[0] + 1][heroPosition[1]].getX(), (map[heroPosition[0] + 1][heroPosition[1]].getY() + heightElement));
                    this.Controls.Remove(toRemove.picturebox);

                    numberSteps++;


                    toReturn = map;
                }
            }

            if (left != 0)
            {
                if (map[heroPosition[0]][heroPosition[1] - 1].GetType() == typeof(Wall)) //gdy na lewo bedzie sciana
                {
                    toReturn = map;
                }
                if (map[heroPosition[0]][heroPosition[1] - 1].GetType() == typeof(Floor)) //gdy na lewo bedzie podloga
                {
                    help = map[heroPosition[0]][heroPosition[1] - 1];
                    map[heroPosition[0]][heroPosition[1] - 1] = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]]     = help;

                    map[heroPosition[0]][heroPosition[1] - 1].setPosition(map[heroPosition[0]][heroPosition[1] - 1].getX() - widthElement, (map[heroPosition[0]][heroPosition[1] - 1].getY()));
                    map[heroPosition[0]][heroPosition[1]].setPosition(map[heroPosition[0]][heroPosition[1]].getX() + widthElement, (map[heroPosition[0]][heroPosition[1]].getY()));

                    numberSteps++;

                    toReturn = map;
                }
                if (map[heroPosition[0]][heroPosition[1] - 1].GetType() == typeof(Box))                                                                                  //gdy na lewo bedzie skrzynka
                {
                    if (map[heroPosition[0]][heroPosition[1] - 2].GetType() == typeof(Floor) || map[heroPosition[0]][heroPosition[1] - 2].GetType() == typeof(EndPoint)) //sprawdz czy mozna przesunac skrzynke(podloga lub punkt)
                    {
                        help = map[heroPosition[0]][heroPosition[1]];
                        map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                        this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);
                        help2 = map[heroPosition[0]][heroPosition[1] - 1];// = 5;
                        map[heroPosition[0]][heroPosition[1] - 1] = help;

                        toRemove = map[heroPosition[0]][heroPosition[1] - 2];
                        map[heroPosition[0]][heroPosition[1] - 2] = help2;


                        map[heroPosition[0]][heroPosition[1] - 1].setPosition(map[heroPosition[0]][heroPosition[1] - 1].getX() - widthElement, (map[heroPosition[0]][heroPosition[1] - 1].getY()));
                        map[heroPosition[0]][heroPosition[1] - 2].setPosition(map[heroPosition[0]][heroPosition[1] - 2].getX() - widthElement, (map[heroPosition[0]][heroPosition[1] - 2].getY()));

                        this.Controls.Remove(toRemove.picturebox);

                        numberSteps++;
                        numberShiftsBoxes++;

                        toReturn = map;
                    }
                    else
                    {
                        toReturn = map;
                    }
                }

                if (map[heroPosition[0]][heroPosition[1] - 1].GetType() == typeof(EndPoint)) //gdy na lewo bedzie punkt
                {
                    help = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                    this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);
                    toRemove = map[heroPosition[0]][heroPosition[1] - 1];
                    map[heroPosition[0]][heroPosition[1] - 1] = help;
                    map[heroPosition[0]][heroPosition[1] - 1].setPosition(map[heroPosition[0]][heroPosition[1] - 1].getX() - widthElement, (map[heroPosition[0]][heroPosition[1] - 1].getY()));
                    this.Controls.Remove(toRemove.picturebox);

                    numberSteps++;

                    toReturn = map;
                }
            }

            if (right != 0)
            {
                if (map[heroPosition[0]][heroPosition[1] + 1].GetType() == typeof(Wall)) //gdy na prawo bedzie sciana
                {
                    toReturn = map;
                }
                if (map[heroPosition[0]][heroPosition[1] + 1].GetType() == typeof(Floor)) //gdy na prawo bedzie podloga
                {
                    help = map[heroPosition[0]][heroPosition[1] + 1];
                    map[heroPosition[0]][heroPosition[1] + 1] = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]]     = help;

                    map[heroPosition[0]][heroPosition[1] + 1].setPosition(map[heroPosition[0]][heroPosition[1] + 1].getX() + widthElement, (map[heroPosition[0]][heroPosition[1] + 1].getY()));
                    map[heroPosition[0]][heroPosition[1]].setPosition(map[heroPosition[0]][heroPosition[1]].getX() - widthElement, (map[heroPosition[0]][heroPosition[1]].getY()));

                    numberSteps++;

                    toReturn = map;
                }
                if (map[heroPosition[0]][heroPosition[1] + 1].GetType() == typeof(Box))                                                                                  //gdy na prawo bedzie skrzynka
                {
                    if (map[heroPosition[0]][heroPosition[1] + 2].GetType() == typeof(Floor) || map[heroPosition[0]][heroPosition[1] + 2].GetType() == typeof(EndPoint)) //sprawdz czy mozna przesunac skrzynke(podloga lub punkt)
                    {
                        help = map[heroPosition[0]][heroPosition[1]];
                        map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                        this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);

                        help2 = map[heroPosition[0]][heroPosition[1] + 1];// = 5;
                        map[heroPosition[0]][heroPosition[1] + 1] = help;
                        toRemove = map[heroPosition[0]][heroPosition[1] + 2];
                        map[heroPosition[0]][heroPosition[1] + 2] = help2;


                        map[heroPosition[0]][heroPosition[1] + 1].setPosition(map[heroPosition[0]][heroPosition[1] + 1].getX() + widthElement, (map[heroPosition[0]][heroPosition[1] + 1].getY()));
                        map[heroPosition[0]][heroPosition[1] + 2].setPosition(map[heroPosition[0]][heroPosition[1] + 2].getX() + widthElement, (map[heroPosition[0]][heroPosition[1] + 2].getY()));

                        this.Controls.Remove(toRemove.picturebox);

                        numberSteps++;
                        numberShiftsBoxes++;


                        toReturn = map;
                    }
                    else
                    {
                        toReturn = map;
                    }
                }

                if (map[heroPosition[0]][heroPosition[1] + 1].GetType() == typeof(EndPoint)) //gdy na prawo bedzie punkt
                {
                    help = map[heroPosition[0]][heroPosition[1]];
                    map[heroPosition[0]][heroPosition[1]] = new Floor(heightElement, widthElement, heroPosition[1] * widthElement, heroPosition[0] * heightElement);
                    this.Controls.Add(map[heroPosition[0]][heroPosition[1]].picturebox);
                    toRemove = map[heroPosition[0]][heroPosition[1] + 1];
                    map[heroPosition[0]][heroPosition[1] + 1] = help;
                    map[heroPosition[0]][heroPosition[1] + 1].setPosition(map[heroPosition[0]][heroPosition[1] + 1].getX() + widthElement, (map[heroPosition[0]][heroPosition[1] + 1].getY()));
                    this.Controls.Remove(toRemove.picturebox);

                    numberSteps++;

                    toReturn = map;
                }
            }

            foreach (PointPosition p in PointsList)
            {
                if (Map[p.X][p.Y].GetType() == typeof(Floor))
                {
                    int x = Map[p.X][p.Y].getX();
                    int y = Map[p.X][p.Y].getY();
                    toRemove = Map[p.X][p.Y];

                    Map[p.X][p.Y] = new EndPoint(heightElement, widthElement, x, y);
                    this.Controls.Add(Map[p.X][p.Y].picturebox);
                    this.Controls.Remove(toRemove.picturebox);
                }
            }

            return(toReturn);
        }
예제 #12
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);
        }
예제 #13
0
        public Maze ReadFile()
        {
            _maze = new Maze();

            String LevelPath = @"Doolhof\doolhof" + _level + ".txt";

            String[] readString = System.IO.File.ReadAllLines(LevelPath);

            int width  = 0;
            int height = readString.Length;

            for (int i = 0; i < height; i++) // Pak de langste lengte die een lijn in het tekstbestand heeft
            {
                if (readString[i].Length > width)
                {
                    width = readString[i].Length;
                }
            }

            NonMoveableGameObject[,] levelArray = new NonMoveableGameObject[width, height];
            for (int y = 0; y < height; y++) // Full Multidimensional Array
            {
                for (int x = 0; x < width; x++)
                {
                    try
                    {
                        NonMoveableGameObject tempObject = null;
                        switch (readString[y].ElementAt(x))
                        {
                        case '.':
                            tempObject = new Floor();
                            break;

                        case '#':
                            tempObject = new Wall();
                            break;

                        case 'o':
                            tempObject       = new Floor(); // Plaats crate hierin
                            tempObject.Crate = new Crate();
                            break;

                        case 'x':
                            tempObject = new Destination();
                            break;

                        case '@':
                            tempObject        = new Floor();
                            tempObject.Player = new Player();
                            break;

                        default:
                            tempObject = new Empty();
                            break;
                        }
                        levelArray[x, y] = tempObject;
                    }
                    catch
                    {
                        NonMoveableGameObject tempObject = new Empty();
                        levelArray[x, y] = tempObject;
                    }
                }
            }
            _maze.InitMaze(levelArray, width, height);
            return(_maze);
        }