アットウィキロゴ

cs0408

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace game0306
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        private GraphicsDeviceManager graphics = null;
        int gtime;
        int sc;

        Texture2D[] om = new Texture2D[10];

        private SpriteBatch spriteBatch = null;

        int[,] data = new int[11, 11];


        int m,n;



        public Game1()
        {
            // グラフィックデバイス管理クラスの作成
            this.graphics = new GraphicsDeviceManager(this);

            // ゲームコンテンツのルートディレクトリを設定
            this.Content.RootDirectory = "Content";

          



        }


        protected override void Initialize()
        {

            for (m = 1; m < 10; m++)
            {
                for (n = 1; n < 10; n++)
                {
                    if(data[m,n-1]==0)data[m, n] = 100;
                    if (data[m, n - 1] == 100) data[m, n] = 0;
                }
            }
            sc = 1;
            gtime = 0;
            base.Initialize();
        }


        protected override void LoadContent()
        {
            // テクスチャーを描画するためのスプライトバッチクラスを作成します
            this.spriteBatch = new SpriteBatch(this.GraphicsDevice);

            // フォントをコンテンツパイプラインから読み込む



            om[1] = Content.Load<Texture2D>("maeda");
            om[2] = Content.Load<Texture2D>("gun");

        }


        protected override void UnloadContent()
        {
            // TODO: ContentManager で管理されていないコンテンツを
            //       ここでアンロードしてください
        }


        protected override void Update(GameTime gameTime)
        {
            // Xbox 360 コントローラ、Windows Phone の BACK ボタンを押したときに
            // ゲームを終了させます
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }
            gtime = gtime + 1;

            if (gtime > 200) sc = sc + 1;
            if (gtime > 200) gtime = 0;
            if (sc > 9) sc = 1;
            base.Update(gameTime);
        }


        protected override void Draw(GameTime gameTime)
        {
            // 画面を指定した色でクリアします
            this.GraphicsDevice.Clear(Color.White);

            // スプライトの描画準備
            this.spriteBatch.Begin();
            for (m = 1; m < 10; m++)
            {
                for (n = 1; n < 10; n++)
                {
                   if(data[m,n]>50) spriteBatch.Draw(om[1], new Rectangle(50 * m, 50 * n, 50, 50), Color.White);
                  if (data[m, n] < 50) spriteBatch.Draw(om[2], new Rectangle(50 * m, 50 * n, 50, 50), Color.White);

                }
            }

            // スプライトの一括描画
            this.spriteBatch.End();

            // 登録された DrawableGameComponent を描画する
            base.Draw(gameTime);
        }
    }
}
最終更新:2011年03月06日 14:22