Beispiel #1
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(Game.GraphicsDevice);

            font = Game.Content.Load<SpriteFont>(@"font");
            img_head = Game.Content.Load<Texture2D>(@"images/head");
            img_straightBody = Game.Content.Load<Texture2D>(@"images/straightBody");
            img_cornerBody = Game.Content.Load<Texture2D>(@"images/cornerBody");
            img_tail = Game.Content.Load<Texture2D>(@"images/tail");
            img_food = Game.Content.Load<Texture2D>(@"images/objects/bug");
            img_background = Game.Content.Load<Texture2D>(@"images/background");
            Texture2D img_wall = Game.Content.Load<Texture2D>(@"images/objects/wall");

            #region 填充场景

            contains = new Contain[sceneWidth, sceneHeight];
            growPoints = new bool[sceneWidth, sceneHeight];
            food_eaten = true;
            for (int i = 0; i < sceneWidth; i++)
                for (int j = 0; j < sceneHeight; j++)
                {
                    contains[i, j] = Contain.empty;
                    growPoints[i, j] = false;
                }

            for (int i = 0; i < sceneWidth; i++)
            {
                Stone stone = new Stone(img_wall, origin, new Point(i, 0));
                stones.Add(stone);
                contains[i, 0] = Contain.stone;
            }
            for (int i = 0; i < sceneWidth; i++)
            {
                Stone stone = new Stone(img_wall, origin, new Point(i, sceneHeight-1));
                stones.Add(stone);
                contains[i, sceneHeight - 1] = Contain.stone;
            }
            for (int i = 1; i < sceneHeight - 1; i++)
            {
                Stone stone = new Stone(img_wall, origin, new Point(0, i));
                stones.Add(stone);
                contains[0,i] = Contain.stone;
            }
            for (int i = 1; i < sceneHeight; i++)
            {
                Stone stone = new Stone(img_wall, origin, new Point(sceneWidth - 1, i));
                stones.Add(stone);
                contains[sceneWidth - 1, i] = Contain.stone;
            }

            #endregion

            #region 初始化蛇的位置
            player = new Snake.Sprites.Snake(origin, new Point(3, 15), img_head, img_straightBody, img_cornerBody, img_tail);
            contains[3, 15] = Contain.snake;
            contains[3, 16] = Contain.snake;
            contains[3, 17] = Contain.snake;

            img_head = Game.Content.Load<Texture2D>(@"images/AIhead");
            img_straightBody = Game.Content.Load<Texture2D>(@"images/AIstraightBody");
            img_cornerBody = Game.Content.Load<Texture2D>(@"images/AIcornerBody");
            img_tail = Game.Content.Load<Texture2D>(@"images/AItail");

            AI = new Snake.Sprites.Snake(origin, new Point(10, 10), img_head, img_straightBody, img_cornerBody, img_tail);
            contains[10, 10] = Contain.snake;
            contains[10, 11] = Contain.snake;
            contains[10, 12] = Contain.snake;
            #endregion

            base.LoadContent();
        }
Beispiel #2
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(Game.GraphicsDevice);

            img_head = Game.Content.Load<Texture2D>(@"images/head");
            img_straightBody = Game.Content.Load<Texture2D>(@"images/straightBody");
            img_cornerBody = Game.Content.Load<Texture2D>(@"images/cornerBody");
            img_tail = Game.Content.Load<Texture2D>(@"images/tail");
            img_food = Game.Content.Load<Texture2D>(@"images/objects/meat");
            Texture2D img_wall = Game.Content.Load<Texture2D>(@"images/objects/wall");

            contains = new Contain[20, 20];
            growPoints = new bool[20, 20];
            food_eaten = true;
            for (int i = 0; i < 20; i++)
                for (int j = 0; j < 20; j++)
                {
                    contains[i, j] = Contain.empty;
                    growPoints[i, j] = false;
                }

            for (int i = 0; i < 20; i++)
            {
                Stone stone = new Stone(img_wall, origin, new Point(i, 0));
                stones.Add(stone);
                contains[i, 0] = Contain.stone;
            }
            for (int i = 0; i < 20; i++)
            {
                Stone stone = new Stone(img_wall, origin, new Point(i, 19));
                stones.Add(stone);
                contains[i, 19] = Contain.stone;
            }
            for (int i = 1; i < 19; i++)
            {
                Stone stone = new Stone(img_wall, origin, new Point(0, i));
                stones.Add(stone);
                contains[0,i] = Contain.stone;
            }
            for (int i = 1; i < 19; i++)
            {
                Stone stone = new Stone(img_wall, origin, new Point(19, i));
                stones.Add(stone);
                contains[19, i] = Contain.stone;
            }

            player = new Snake.Sprites.Snake(origin, new Point(3, 3), img_head, img_straightBody, img_cornerBody, img_tail);
            contains[3, 3] = Contain.snake;
            contains[3, 4] = Contain.snake;
            contains[3, 5] = Contain.snake;

            img_head = Game.Content.Load<Texture2D>(@"images/AIhead");
            img_straightBody = Game.Content.Load<Texture2D>(@"images/AIstraightBody");
            img_cornerBody = Game.Content.Load<Texture2D>(@"images/AIcornerBody");
            img_tail = Game.Content.Load<Texture2D>(@"images/AItail");

            AI = new Snake.Sprites.Snake(origin, new Point(10, 10), img_head, img_straightBody, img_cornerBody, img_tail);
            contains[10, 10] = Contain.snake;
            contains[10, 11] = Contain.snake;
            contains[10, 12] = Contain.snake;

            base.LoadContent();
        }