Пример #1
0
        public void drawMap(bool newMap) //if bool is true, it creates NEW instances. If false, it redraws them instead.
        {
            int pacdotCount = 0;
            int bigdotCount = 0;
            int tilesCount  = 0;

            for (int rows = 0; rows < WorldModel.Map2D.GetLength(0); rows++)
            {
                for (int colls = 0; colls < WorldModel.Map2D.GetLength(1); colls++)
                {
                    switch (WorldModel.Map2D[rows, colls])
                    {
                    case 0:

                        PacDotController pacDot = new PacDotController();
                        player.subscribeObserver(pacDot);         //subscribes to player
                        pacDot.subscribeObserverToPacDot(score);
                        pacDot.subscribeObserverToPacDot(this);   //subscribes the worldcontroller to pacdot
                        pacDot.view.Top  = rows * 16;
                        pacDot.view.Left = colls * 16;
                        pacDot.Model.X   = colls;
                        pacDot.Model.Y   = rows;
                        this.pacdots.Add(pacDot);
                        this.view.Controls.Add(pacDot.view);

                        break;

                    case 1:
                        if (newMap)
                        {
                            TileController wall = new TileController();
                            wall.Model.X   = colls;
                            wall.Model.Y   = rows;
                            wall.View.Top  = rows * 16;
                            wall.View.Left = colls * 16;
                            wall.View.pictureBox1.Image = Pacman.Properties.Resources.wall2;    //wallsprite;
                            this.tiles.Add(wall);
                            this.view.Controls.Add(wall.View);
                        }
                        else
                        {
                            if (WorldModel.FlashWhite)
                            {
                                tiles[tilesCount].View.pictureBox1.Image = Pacman.Properties.Resources.wall3;
                                tiles[tilesCount].View.pictureBox1.Refresh();
                            }
                            else
                            {
                                tiles[tilesCount].View.pictureBox1.Image = Pacman.Properties.Resources.wall2;
                                tiles[tilesCount].View.pictureBox1.Refresh();
                            }
                            tilesCount++;
                        }

                        break;

                    case 3:
                        if (newMap)
                        {
                            BigDotController bigDot = new BigDotController();
                            bigdots.Add(bigDot);     //add to the list
                            player.subscribeObserver(bigDot);
                            bigDot.subscribeObserverToBigDot(score);
                            bigDot.view.Top  = rows * 16;
                            bigDot.view.Left = colls * 16;
                            bigDot.Model.X   = colls;
                            bigDot.Model.Y   = rows;
                            this.view.Controls.Add(bigDot.view);
                        }
                        else
                        {
                            bigdots[bigdotCount].Model.isEaten = false;
                            bigdotCount++;
                        }
                        break;

                    case 4:
                        if (newMap)
                        {
                            TileController blackTile1 = new TileController();    //blacktile
                            blackTile1.Model.X   = colls;
                            blackTile1.Model.Y   = rows;
                            blackTile1.View.Top  = rows * 16;
                            blackTile1.View.Left = colls * 16;
                            tiles.Add(blackTile1);
                            this.view.Controls.Add(blackTile1.View);
                        }
                        else
                        {
                            tilesCount++;
                        }

                        break;

                    case 5:
                        DoorTileController doorTile = new DoorTileController();
                        doorTile.Model.X   = colls;
                        doorTile.Model.Y   = rows;
                        doorTile.View.Top  = rows * 16;
                        doorTile.View.Left = colls * 16;
                        this.view.Controls.Add(doorTile.View);
                        break;
                    }
                }
            }
        }
Пример #2
0
 public DoorTileUI(DoorTileController controller)
 {
     doorTileController = controller;
     InitializeComponent();
 }