2011-09-20 80 views
1

現在一定是很簡單的,我沒有得到,但這裏是我的代碼:C#XNA可訪問性不一致

public class Game1 : Microsoft.Xna.Framework.Game 
{ 
    GraphicsDeviceManager graphics; 
    SpriteBatch spriteBatch;   
    WorldManager worldManager; 
    Player m_player = new Player(new Point(30, 15)); 

    protected override void Initialize() 
    { 
     worldManager = new WorldManager(this, m_player); 
     Components.Add(worldManager); 
     base.Initialize(); 
    } 

...

現在WorldManage:

public class WorldManager : Microsoft.Xna.Framework.DrawableGameComponent 
{ 
    SpriteBatch spriteBatch; 
    //UserControlledTile player; 
    Player player; 
    List<Tile> tileList = new List<Tile>(); 

    World world; 

    SpriteFont testFont; 

    public WorldManager(Game game, Player player) 
     : base(game) 
    { 
     this.player = player; 
     world = new World();    
    } 

我得到這個錯誤:

Error 1 Inconsistent accessibility: parameter type 'WindowsGame2.Player' is less accessible than method 'WindowsGame2.WorldManager.WorldManager(Microsoft.Xna.Framework.Game, WindowsGame2.Player)' D:\dropbox\Dropbox\Projects\WindowsGame2\WindowsGame2\WindowsGame2\WorldManager.cs 28 16 WindowsGame2 

這裏的Player類:

class Player : Character 
{ 

    public Player(Point startLoc)    
    { 
     base.Position = startLoc; 
     base.CharacterTile = new UserControlledTile(new Point(20, 15), Color.Yellow, "X"); 
     base.Name = "Hero"; 
     base.Attack = 1; 
     base.Defense = 1; 
     base.HP = 20; 
     base.Level = 1;    
    } //end constructor 

    public override void Update(GameTime gameTime) 
    { 
     //player has already moved 
     if (hasMoved) 
     { 
      prevGameTime += gameTime.ElapsedGameTime.Milliseconds; 

      if (prevGameTime > timeBetweenMove) 
      { 
       hasMoved = false; 
       prevGameTime = 0; 
      } 
      return; 
     } 

     KeyboardState keyboardState = Keyboard.GetState(); 
     if (keyboardState.IsKeyDown(Keys.Left)) 
     { 
      m_position.X--; 
      hasMoved = true; 
     } 
     else if (keyboardState.IsKeyDown(Keys.Right)) 
     { 
      m_position.X++; 
      hasMoved = true; 
     } 
     else if (keyboardState.IsKeyDown(Keys.Up)) 
     { 
      m_position.Y--; 
      hasMoved = true; 
     } 
     else if (keyboardState.IsKeyDown(Keys.Down)) 
     { 
      m_position.Y++; 
      hasMoved = true; 
     } 

     if (m_position.X < 0) 
      m_position.X = 0; 
     if (m_position.X > 56) 
      m_position.X = 56; 
     if (m_position.Y < 0) 
      m_position.Y = 0; 
     if (m_position.Y > 32) 
      m_position.Y = 32; 


     m_CharacterTile.Update(gameTime, m_position); 
    } 

    public override void Draw(GameTime gameTime, SpriteBatch spriteBatch, SpriteFont font) 
    { 
     m_CharacterTile.Draw(gameTime, spriteBatch, font); 
    } 


}//end class 

我還在學習C#,但似乎從Java來了,我不明白是什麼原因造成這個問題...

回答

2

可惜你不顯示Player的代碼,但很可能您已將其定義爲內部的,而WorldManager及其構造函數是公開的。

請仔細閱讀並理解Access Modifiers

+0

好的,謝謝,我會閱讀。 – Alex

5

這意味着你Player類是不公開的,你宣佈有Player類型的參數的公共類的公共方法。

該方法的可訪問性不一致,因爲有人可能會調用您的構造函數,因爲它是公共的,但無法傳遞其中一個參數,因爲它不是。