public void LoadLevel(int n)
        {
            Canvas.Children.Clear();
            String[] lines = System.IO.File.ReadAllLines("Level" + n + ".txt");
            int      h     = lines.Length;
            int      w     = lines[0].Length;

            game = new Sprite[h, w];
            for (int j = 0; j < h; j++)
            {
                for (int i = 0; i < w; i++)
                {
                    char letter = lines[j][i];
                    if (letter == 'X')
                    {
                        ImageSprite a = new ImageSprite(Image.FromFile("acorn.png"), i * unitSize, j * unitSize);
                        game[j, i] = a;
                        a.Width    = unitSize;
                        a.Height   = unitSize;
                        Canvas.Children.Add(a);
                    }
                    if (letter == 'B')
                    {
                        bulldozer        = new PhysicsSprite(Image.FromFile("acorn.png"), i * unitSize, j * unitSize);
                        game[j, i]       = bulldozer;
                        bulldozer.Width  = unitSize * .5;
                        bulldozer.Height = unitSize * .5;
                        Canvas.Children.Add(bulldozer);
                        bulldozerX = i;
                        bulldozerY = j;
                    }
                }
            }
        }
예제 #2
0
        public void LoadLevel(int lvl)
        {
            paused        = true;
            lines         = System.IO.File.ReadAllLines("Level" + lvl + ".txt");
            Canvas        = new Sprite(0, 0, -255, -255, true);
            Canvas.Width  = lines[0].Length * unitSize;
            Canvas.Height = lines.Length * unitSize;
            firstPause    = true;
            ninja         = new Player(Image.FromFile("ninja.png"), unitSize, unitSize, unitSize, unitSize, 1, 1, true);
            Animation move = new Animation();

            move.IList    = new int[] { 0, 1, 2, 3, 4 };
            move.JList    = new int[] { 0, 0, 0, 0, 0 };
            move.TimeList = new int[] { 1, 1, 1, 1, 1 };
            ninja.Animations.Add("move", move);
            Animation stand = new Animation();

            stand.IList    = new int[] { 0, 0, 0, 0, 0 };
            stand.JList    = new int[] { 0, 0, 0, 0, 0 };
            stand.TimeList = new int[] { 1, 1, 1, 1, 1 };
            ninja.Animations.Add("stand", stand);
            for (int j = 0; j < lines.Length; j++)
            {
                for (int i = 0; i < lines[j].Length; i++)
                {
                    char letter = lines[j][i];
                    if (letter == 'X')
                    {
                        ImageSprite a = new ImageSprite(Image.FromFile("wall.png"), i * unitSize, j * unitSize, i, j, true);
                        a.Width  = unitSize;
                        a.Height = unitSize;
                        Canvas.Children.Add(a);
                    }
                    else if (letter == 'G')
                    {
                        ImageSprite a = new GoalSprite(Image.FromFile("green.png"), i * unitSize, j * unitSize, i, j, false);
                        a.Width  = unitSize;
                        a.Height = unitSize;
                        Canvas.Children.Add(a);
                    }
                    else if (letter == 'M')
                    {
                        ImageSprite a = new PhysicsSprite(Image.FromFile("crate.jpg"), i * unitSize, j * unitSize, i, j, false);
                        a.Width  = unitSize;
                        a.Height = unitSize;
                        Canvas.Children.Add(a);
                    }
                }
            }
            Canvas.Children.Add(ninja);
            Width         = lines[0].Length * unitSize;
            Height        = lines.Length * unitSize;
            Canvas.XScale = (float)Width / (float)Canvas.Width;
            Canvas.YScale = (float)Height / (float)Canvas.Height;
        }
예제 #3
0
        public SokobanGame() : base()
        {
            jumpSound.Open(new System.Uri(@"c:\Windows\Media\chimes.wav"));
            bulldozer        = new Character(Image.FromFile("acorn.png"), 100, 100);
            bulldozer.Width  = 100;
            bulldozer.Height = 100;
            Canvas.Children.Add(bulldozer);
            Random r = new Random();

            for (int i = 0; i < 100; i++)
            {
                PhysicsSprite block = new PhysicsSprite(Image.FromFile("acorn.png"), i * 100, r.Next(200, 350), true);
                block.Width  = 100;
                block.Height = 100;
                Canvas.Children.Add(block);
            }
        }
 public SokobanGame() : base()
 {
     bulldozer        = new PhysicsSprite(Image.FromFile("acorn.png"), unitSize, unitSize);
     bulldozer.Width  = unitSize;
     bulldozer.Height = unitSize;
     String[] lines = System.IO.File.ReadAllLines("Level1.txt");
     for (int j = 0; j < lines.Length; j++)
     {
         for (int i = 0; i < lines[j].Length; i++)
         {
             char letter = lines[j][i];
             if (letter == 'X')
             {
                 ImageSprite a = new ImageSprite(Image.FromFile("acorn.png"), i * unitSize, j * unitSize);
                 a.Width  = unitSize;
                 a.Height = unitSize;
                 Canvas.Children.Add(a);
             }
         }
     }
     Canvas.Children.Add(bulldozer);
 }