XNA
学校の授業のXNAで、3×3の升目に入力した数字を表示させるものなのですが、プログラムの例をもらったので作って見たのですが入力しても表示されません。(実行してもエラーは出ません)
Initializeメソッドのtile[i, j] = -1;の-1を1に変えると最初から1が表示された状態になるので、定義や画像指定、Drawメソッドは大丈夫だと思うのですが、原因が分かりません。どなたか分かる方はいらっしゃらないでしょうか?
public class Nine : Microsoft.Xna.Framework.Game
{
const int MaxColumn = 3;
const int MaxRow = 3;
const int LetterWidth = 48;
const int LetterHeight = 80;
const int TileWidth = 100;
const int TileHeight = 100;
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D tileTexture;
Texture2D highlightTexture;
Texture2D numbersTexture;
Point currPosition;
KeyboardState lastKeyboardState;
int[,] tile;
bool completed;
public Nine()
{
(割愛)
}
protected override void Initialize()
{
currPosition = new Point(1, 1);
lastKeyboardState = Keyboard.GetState();
tile = new int[MaxColumn, MaxRow];
for (int j = 0; j < MaxRow; j++)
for (int i = 0; i < MaxColumn; i++)
tile[i, j] = -1;
completed = false;
base.Initialize();
}
protected override void LoadContent()
{
(割愛(画像のロードを定義))
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
KeyboardState currentKeyboardState = Keyboard.GetState();
if (lastKeyboardState.IsKeyUp(Keys.Down) && currentKeyboardState.IsKeyDown(Keys.Down))
{
if (++currPosition.Y >= MaxRow)
currPosition.Y = MaxRow - 1;
}
(割愛(上記のDownと同様なUp, Left, Right)
lastKeyboardState = currentKeyboardState;
if (tile[currPosition.X, currPosition.Y] < 0)
{
int num = CheckNumKeys(currentKeyboardState);
if (num >= 0)
{
tile[currPosition.X, currPosition.Y] = num;
if (CheckComplete())
completed = true;
}
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
for (int row = 0; row < MaxRow; row++)
{
for (int column = 0; column < MaxColumn; column++)
{
spriteBatch.Draw((currPosition == new Point(column, row)) ? highlightTexture : tileTexture, new Vector2(TileWidth * column, TileWidth * row), Color.White);
if (tile[column, row] >= 0)
spriteBatch.Draw(numbersTexture, new Vector2(TileWidth * column + (TileWidth - LetterWidth) / 2, TileHeight * row + (TileHeight - LetterHeight) / 2), new Rectangle(LetterWidth * tile[column, row], 0, LetterWidth, LetterHeight), Color.White);
}
}
spriteBatch.End();
}
int CheckNumKeys(KeyboardState keyboardState)
{
int keyCode = (int)Keys.D0;
for (int i = 0; i <= 9; i++)
{
if (lastKeyboardState.IsKeyUp((Keys)keyCode) && keyboardState.IsKeyDown((Keys)keyCode))
return i;
keyCode++;
}
return -1;
}
bool CheckComplete()
{
for (int j = 0; j < MaxRow; j++)
{
for (int i = 0; i < MaxColumn; i++)
{
if (tile[i, j] < 0)
return false;
}
}
return true;
}
}