예제 #1
0
        public void goUp(Map map, Control.ControlCollection Controls)
        {
            int[] heroPosition = map.findHeroPosition();
            Part  help;
            Part  help2;
            Part  toRemove;

            if (map.getPart(heroPosition[0] - 1, heroPosition[1]).GetType() == typeof(Wall)) //gdy na prawo bedzie sciana
            {
                return;
            }

            if (map.getPart(heroPosition[0] - 1, heroPosition[1]).GetType() == typeof(Floor)) //gdy na prawo bedzie podloga
            {
                help = map.getPart(heroPosition[0] - 1, heroPosition[1]);
                map.setPart(map.getPart(heroPosition[0], heroPosition[1]), heroPosition[0] - 1, heroPosition[1]);
                map.setPart(help, heroPosition[0], heroPosition[1]);
                map.getPart(heroPosition[0] - 1, heroPosition[1]).setPosition(map.getPart(heroPosition[0] - 1, heroPosition[1]).getX(), map.getPart(heroPosition[0] - 1, heroPosition[1]).getY() - 64);
                map.getPart(heroPosition[0], heroPosition[1]).setPosition(map.getPart(heroPosition[0], heroPosition[1]).getX(), map.getPart(heroPosition[0], heroPosition[1]).getY() + 64);

                incrementNumberSteps();
            }


            if (map.getPart(heroPosition[0] - 1, heroPosition[1]).GetType() == typeof(Box))                                                                                          //gdy na prawo bedzie skrzynka
            {
                if (map.getPart(heroPosition[0] - 2, heroPosition[1]).GetType() == typeof(Floor) || map.getPart(heroPosition[0] - 2, heroPosition[1]).GetType() == typeof(BoxPoint)) //sprawdz czy mozna przesunac skrzynke(podloga lub punkt)
                {
                    help = map.getPart(heroPosition[0], heroPosition[1]);
                    map.setPart(Factory.produceFloor(heroPosition[1] * 64, heroPosition[0] * 64, map.getStyle()), heroPosition[0], heroPosition[1]);
                    Controls.Add(map.getPart(heroPosition[0], heroPosition[1]).picturebox);
                    help2 = map.getPart(heroPosition[0] - 1, heroPosition[1]);// = 5;
                    map.setPart(help, heroPosition[0] - 1, heroPosition[1]);
                    toRemove = map.getPart(heroPosition[0] - 2, heroPosition[1]);
                    map.setPart(help2, heroPosition[0] - 2, heroPosition[1]);
                    map.getPart(heroPosition[0] - 1, heroPosition[1]).setPosition(map.getPart(heroPosition[0] - 1, heroPosition[1]).getX(), map.getPart(heroPosition[0] - 1, heroPosition[1]).getY() - 64);
                    map.getPart(heroPosition[0] - 2, heroPosition[1]).setPosition(map.getPart(heroPosition[0] - 2, heroPosition[1]).getX(), map.getPart(heroPosition[0] - 2, heroPosition[1]).getY() - 64);
                    Controls.Remove(toRemove.picturebox);

                    incrementNumberSteps();
                }
                else
                {
                }
            }

            if (map.getPart(heroPosition[0] - 1, heroPosition[1]).GetType() == typeof(BoxPoint)) //gdy na prawo bedzie punkt
            {
                help = map.getPart(heroPosition[0], heroPosition[1]);
                map.setPart(Factory.produceFloor(heroPosition[1] * 64, heroPosition[0] * 64, map.getStyle()), heroPosition[0], heroPosition[1]);
                Controls.Add(map.getPart(heroPosition[0], heroPosition[1]).picturebox);
                toRemove = map.getPart(heroPosition[0] - 1, heroPosition[1]);
                map.setPart(help, heroPosition[0] - 1, heroPosition[1]);
                map.getPart(heroPosition[0] - 1, heroPosition[1]).setPosition(map.getPart(heroPosition[0] - 1, heroPosition[1]).getX(), map.getPart(heroPosition[0] - 1, heroPosition[1]).getY() - 64);
                Controls.Remove(toRemove.picturebox);

                incrementNumberSteps();
            }
            addBoxPoints(map, Controls);
        }
예제 #2
0
파일: Game.cs 프로젝트: zaba37/Sokoban_ZTP
        private List <List <Part> > convertMapFromMemento(List <List <int> > map)
        {
            List <List <Part> > state = new List <List <Part> >();
            int            posX       = 0;
            int            posY       = 0;
            FactoryMapPart factory    = new FactoryMapPart();

            foreach (List <int> list in map)
            {
                int         lineElementCounter = 0;
                List <Part> singleLine         = new List <Part>();

                foreach (int part in list)
                {
                    if (part == 5)
                    {
                        lineElementCounter++;
                        singleLine.Add(factory.produceHero(posX, posY, newMap.getStyle()));
                    }


                    if (part == 6)
                    {
                        singleLine.Add(factory.produceBox(posX, posY, newMap.getStyle()));
                        lineElementCounter++;
                    }


                    if (part == 1)
                    {
                        singleLine.Add(factory.produceEmpty(posX, posY, newMap.getStyle()));
                        lineElementCounter++;
                    }


                    if (part == 2)
                    {
                        singleLine.Add(factory.produceWall(posX, posY, newMap.getStyle()));
                        lineElementCounter++;
                    }


                    if (part == 4)
                    {
                        singleLine.Add(factory.produceBoxPoint(posX, posY, newMap.getStyle()));
                        lineElementCounter++;
                    }


                    if (part == 3)
                    {
                        singleLine.Add(factory.produceFloor(posX, posY, newMap.getStyle()));
                        lineElementCounter++;
                    }

                    posX = posX + 64;
                }
                posY = posY + 64;
                posX = posX - (64 * lineElementCounter);

                state.Add(singleLine);
            }

            return(state);
        }