2010年12月28日 星期二

XNA work

首先找好圖片 利用簡單的去背程式去背

參考:
http://blog.xuite.net/jin117/blog/29655829  "去背程式教學附下載網址"
http://create.msdn.com/en-US/education/catalog/tutorial/2d_chapter_9  "2D範例"
http://msdn.microsoft.com/zh-tw/dd310332#XNA   "MSDN邊做邊學系列-XBOX遊戲開發教學"
邊做邊學系列1 圖十六.教學在畫面中產生中文

修改處以下介紹

紅字可更改數值   不同顏色底是有互相關聯

------------------------------------------------------------------------------------

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;
using XnaBreakout.Helpers;
namespace WindowsGame7
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        bool lostGame = false;                 //*一開始不會出現*       
       Texture2D backgroundTexture;   //背景
        Rectangle viewportRect;             //視野 
        SpriteBatch spriteBatch;
        GameObject flyingsaucer;       //炮
        const int maxmissiles = 5;     //*子彈數量*       
       GameObject[] missiles;
        GamePadState previousGamePadState = GamePad.GetState(PlayerIndex.One);
        KeyboardState previousKeyboardState = Keyboard.GetState();
        const int maxEnemies = 5;            
        const float maxTankHeight = 0.8f;     //*設定坦克出現位置*
        const float minTankHeight =  0.6f;
       
        const float maxTankVelocity = 5.0f;   //*坦克速度*
        const float minTankVelocity = 1.0f; 
       
        Random random = new Random();
        GameObject[] tanks;
        int score;        
        int miss;       
        SpriteFont font;
        Vector2 scoreDrawPoint = new Vector2(0.4f, 0.0f);    //*得分記數位置*        
        Vector2 missDrawPoint = new Vector2(0.2f, 0.0f);      //*失分記數位置*  
                                                                                                                                                             
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }
                                                                                                                                                             
        protected override void Initialize()
        {
            base.Initialize();
        }
                                                                                                                                                             
        protected override void LoadContent()
        {
           
            spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
           
            backgroundTexture = Content.Load<Texture2D>("models\\background");
            flyingsaucer = new GameObject(Content.Load<Texture2D>("models\\flyingsaucer"));
            flyingsaucer.position = new Vector2(150, graphics.GraphicsDevice.Viewport.Height - 550);//*設定
           飛碟的高度*           
            missiles = new GameObject[maxmissiles];
            for (int i = 0; i < maxmissiles; i++)        //子彈增加
            {
                missiles[i] = new GameObject(Content.Load<Texture2D>("models\\missile"));
            }
            tanks = new GameObject[maxEnemies];
            for (int i = 0; i < maxEnemies; i++)         //敵人增加
            {
                tanks[i] = new GameObject(
                    Content.Load<Texture2D>("models\\tank1"));
            }
            font = Content.Load<SpriteFont>("Fonts\\GameFont");
            //drawable area of the game screen.
            viewportRect = new Rectangle(0, 0,
                graphics.GraphicsDevice.Viewport.Width,
                graphics.GraphicsDevice.Viewport.Height);
            Window.Title = "外星人入侵!!!";              //*標題*           
            base.LoadContent();
        }
        public void UpdateMissiles()
        {
            foreach (GameObject missile in missiles)
            {
                if (missile.alive)
                {
                    missile.position += missile.velocity;
                    if (!viewportRect.Contains(new Point(
                        (int)missile.position.X,
                        (int)missile.position.Y)))
                    {
                        missile.alive = false;
                        continue;
                    }
                    Rectangle missileRect = new Rectangle(
                        (int)missile.position.X,
                        (int)missile.position.Y,
                        missile.sprite.Width,
                        missile.sprite.Height);
                    foreach (GameObject tank in tanks)
                    {
                        Rectangle enemyRect = new Rectangle(
                            (int)tank.position.X,
                            (int)tank.position.Y,
                            tank.sprite.Width,
                            tank.sprite.Height);
                        if (missileRect.Intersects(enemyRect))
                        {
                            missile.alive = false;
                            tank.alive = false;
                            score += 1;
                            break;
                        }
                    }
                }
            }
        }

                                                                                                                                                             

        protected override void UnloadContent()
        {
            base.UnloadContent();
        }
                                                                                                                                                             

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);
            flyingsaucer.rotation += gamePadState.ThumbSticks.Left.X * 0.1f;
            if (gamePadState.Buttons.A == ButtonState.Pressed &&
                previousGamePadState.Buttons.A == ButtonState.Released)
            {
                FireCannonBall();
            }
#if !XBOX
            KeyboardState keyboardState = Keyboard.GetState();            //*移動飛碟*
            if (keyboardState.IsKeyDown(Keys.Left))
            {
                flyingsaucer.position.X -= 5.0f;
            }
            if (keyboardState.IsKeyDown(Keys.Right))
            {
                flyingsaucer.position.X += 5.0f;
            }
            if (keyboardState.IsKeyDown(Keys.Space) &&
                previousKeyboardState.IsKeyUp(Keys.Space))
            {
                FireCannonBall();
            }
#endif

            UpdateMissiles();
            UpdateEnemies();

            previousGamePadState = gamePadState;
#if !XBOX
            previousKeyboardState = keyboardState;
#endif
            base.Update(gameTime);
        }
        public void UpdateEnemies()
        {
            foreach (GameObject tank in tanks)
            {
                if (tank.alive)
                {
                    tank.position += tank.velocity;
                    if (!viewportRect.Contains(new Point(
                        (int)tank.position.X,
                        (int)tank.position.Y)))
                    {
                        tank.alive = false;
                        miss += 1;               //*被進攻坦克+1*
                        if (miss > 5)            //*超過5台坦克就輸了*        
                        {                           
                       lostGame = true;                       
                        }                       
                    }
                }
                else
                {
                    tank.alive = true;
                    tank.position = new Vector2(
                        viewportRect.Right,
                        MathHelper.Lerp(
                        (float)viewportRect.Height * minTankHeight,
                        (float)viewportRect.Height * maxTankHeight,
                        (float)random.NextDouble()));
                    tank.velocity = new Vector2(
                        MathHelper.Lerp(
                        -minTankVelocity,
                        -maxTankVelocity,
                        (float)random.NextDouble()), 0);
                }
            }
        }
        public void FireCannonBall()
        {
            foreach (GameObject ball in missiles)
            {
                if (!ball.alive)
                {
                    ball.alive = true;
                    ball.position = flyingsaucer.position - ball.center;
                    ball.velocity = new Vector2(
                        (float)Math.Sin(flyingsaucer.rotation),
                        (float)Math.Cos(flyingsaucer.rotation)) * 5.0f;      //*飛碟速度,砲彈方向 Sin跟Cos對換*
                    return;
                }
            }
        }
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
                                                                                                                                                             
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend);

            spriteBatch.Draw(backgroundTexture, viewportRect,
                Color.White);
            foreach (GameObject ball in missiles)
            {
                if (ball.alive)
                {
                    spriteBatch.Draw(ball.sprite,
                        ball.position, Color.Gold);
                }
            }
            spriteBatch.Draw(flyingsaucer.sprite,
                flyingsaucer.position, null, Color.White, flyingsaucer.rotation, flyingsaucer.center, 1.5f,          SpriteEffects.None, 0);//*飛碟位置大小*
            foreach (GameObject enemy in tanks)
            {
                if (enemy.alive)
                {
                    spriteBatch.Draw(enemy.sprite,
                        enemy.position, Color.White);

                }
            }
            spriteBatch.DrawString(font,"殲滅坦克數 : " + score.ToString()+"台", new Vector2
           (scoreDrawPoint.X * viewportRect.Width,scoreDrawPoint.Y * viewportRect.Height),               
            Color.Yellow);                                                                            //畫出打擊坦克數
           
            spriteBatch.DrawString(font,"進攻坦克數 : " + miss.ToString() + "台"
            ,Vector2.Zero,Color.Red);                                        //畫出進攻坦克數
               
            if (lostGame==true)                   
               spriteBatch.DrawString(font,                                      //*失敗條件及字幕出現位置*                 
              " 超過五台坦克你失敗了!",new Vector2(250,250),Color.Black);               
         
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}

----------------------------------------------------------------------------------------
完成圖~
中文字~

2010年12月3日 星期五

fbx



http://www.wirecase.com/?section=5&id=1848


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 WindowsGame2
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Model myModel;
        float aspectRatio;
        Vector3 modelPosition = Vector3.Zero;
        float modelRotation = 1.0f;
        Vector3 cameraPosition = new Vector3(0.0f, 50.0f, 5000.0f);



        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            base.Initialize();
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            myModel = Content.Load<Model>("model\\Chorus");
            aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
            // TODO: use this.Content to load your game content here
        }
        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==
        ButtonState.Pressed)
                this.Exit();
            modelRotation += (float)gameTime.ElapsedGameTime.TotalMilliseconds *
                MathHelper.ToRadians(0.1f);

            base.Update(gameTime);
        }
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            // TODO: Add your drawing code here
            Matrix[] transforms = new Matrix[myModel.Bones.Count];
            myModel.CopyAbsoluteBoneTransformsTo(transforms);
            // Draw the model. A model can have multiple meshes, so loop.
            foreach (ModelMesh mesh in myModel.Meshes)
            {
                // This is where the mesh orientation is set, as well
                // as our camera and projection.
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] *
                        Matrix.CreateRotationY(modelRotation)
                        * Matrix.CreateTranslation(modelPosition);
                    effect.View = Matrix.CreateLookAt(cameraPosition,
                        Vector3.Zero, Vector3.Up);
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.ToRadians(45.0f), aspectRatio,
                1.0f, 10000.0f);
                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }
            base.Draw(gameTime);
        }
    }
}

2010年11月12日 星期五

計算機

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int cal, temp, logic;
        Boolean a = false;
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (a == false)
            {
                textBox1.Text += 1;
            }
            else
            {
                textBox1.Text = "1";
                a = false;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (a == false)
            {
                textBox1.Text += 2;
            }
            else
            {
                textBox1.Text = "2";
                a = false;
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (a == false)
            {
                textBox1.Text += 3;
            }
            else
            {
                textBox1.Text = "3";
                a = false;
            }
        }
        private void button4_Click(object sender, EventArgs e)
        {
            if (a == false)
            {
                textBox1.Text += 4;
            }
            else
            {
                textBox1.Text = "4";
                a = false;
            }
        }
        private void button5_Click(object sender, EventArgs e)
        {
            if (a == false)
            {
                textBox1.Text += 5;
            }
            else
            {
                textBox1.Text = "5";
                a = false;
            }
        }
        private void button6_Click(object sender, EventArgs e)
        {
            if (a == false)
            {
                textBox1.Text += 6;
            }
            else
            {
                textBox1.Text = "6";
                a = false;
            }
        }
        private void button7_Click(object sender, EventArgs e)
        {
            if (a == false)
            {
                textBox1.Text += 7;
            }
            else
            {
                textBox1.Text = "7";
                a = false;
            }
        }
        private void button8_Click(object sender, EventArgs e)
        {
            if (a == false)
            {
                textBox1.Text += 8;
            }
            else
            {
                textBox1.Text = "8";
                a = false;
            }
        }
        private void button9_Click(object sender, EventArgs e)
        {
            if (a == false)
            {
                textBox1.Text += 9;
            }
            else
            {
                textBox1.Text = "9";
                a = false;
            }
        }
        private void button10_Click(object sender, EventArgs e)
        {
            if (a == false)
            {
                textBox1.Text += 0;
            }
            else
            {
                textBox1.Text = "0";
                a = false;
            }
        }
        private void button11_Click(object sender, EventArgs e)
        {
            temp = int.Parse(textBox1.Text);
            logic = 1;
            a = true;
        }
        private void button12_Click(object sender, EventArgs e)
        {
            temp = int.Parse(textBox1.Text);
            logic = 2;
            a = true;
        }
        private void button13_Click(object sender, EventArgs e)
        {
            temp = int.Parse(textBox1.Text);
            logic = 3;
            a = true;
        }
        private void button14_Click(object sender, EventArgs e)
        {
            temp = int.Parse(textBox1.Text);
            logic = 4;
            a = true;
        }
        private void button15_Click(object sender, EventArgs e)
        {
            switch (logic)
            {
                case 1:
                    cal = temp + int.Parse(textBox1.Text);
                    textBox1.Text = cal.ToString();
                    break;
                case 2:
                    cal = temp - int.Parse(textBox1.Text);
                    textBox1.Text = cal.ToString();
                    break;
                case 3:
                    cal = temp * int.Parse(textBox1.Text);
                    textBox1.Text = cal.ToString();
                    break;
                case 4:
                    if (int.Parse(textBox1.Text) != 0)
                    {
                        cal = temp / int.Parse(textBox1.Text);
                        textBox1.Text = cal.ToString();
                    }
                    else
                    {
                        MessageBox.Show("除數不得為零!");
                    }
                    break;
            }
            a = true;
        }
    }
}

益智遊戲+隨機亂數1

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        System.Windows.Forms.Button[] Buttons;
        System.Windows.Forms.TextBox[] TextBoxs;
        int[,] a = new int[4, 4];
        int[] arr = new int[9];
        int[] score = new int[9];
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            Buttons = new System.Windows.Forms.Button[9];
            TextBoxs = new System.Windows.Forms.TextBox[9];
            for (int i = 0; i < 9; ++i)
            {
                Buttons[i] = new Button();
                Buttons[i].Click += new System.EventHandler(Buttons_Click);
                this.Controls.Add(Buttons[i]);
                if (i <= 2)
                    Buttons[i].Location = new System.Drawing.Point(10 + i * 80, 10 + 100);
                else if (i > 2 && i <= 5)
                    Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 80, 40 + 100);
                else if (i > 5 && i <= 9)
                    Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 80, 70 + 100);
            }
            for (int i = 0; i < 9; ++i)
            {
                TextBoxs[i] = new TextBox();
                this.Controls.Add(TextBoxs[i]);
                if (i <= 2)
                    TextBoxs[i].Location = new System.Drawing.Point(10 + i * 100, 10);
                else if (i > 2 && i <= 5)
                    TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 3) * 100, 40);
                else if (i > 5 && i <= 9)
                    TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 6) * 100, 70);
            }
            TextBoxs[0].Text = "7";
            TextBoxs[1].Text = "2";
            TextBoxs[2].Text = "4";
            TextBoxs[3].Text = "5";
            TextBoxs[4].Text = "0";
            TextBoxs[5].Text = "6";
            TextBoxs[6].Text = "8";
            TextBoxs[7].Text = "3";
            TextBoxs[8].Text = "1";
        }
        public void Buttons_Click(object sender, EventArgs e)
        {
            // System.Windows.Forms.MessageBox.Show("You have clicked button " +
            //   ((System.Windows.Forms.Button)sender).Tag.ToString());
            String tnum = sender.ToString();
            int tlen = tnum.Length;
            String no = tnum.Substring(tlen - 1);
            int n = int.Parse(no);
            for (int i = 0; i < 9; i++)
            {
                if (Buttons[i].Text == no)
                    n = i;
            }
            switch (n)
            {
                case 0:
                    if (Buttons[1].Text == "0")
                    {
                        string temp;
                        temp = Buttons[1].Text;
                        Buttons[1].Text = Buttons[0].Text;
                        Buttons[0].Text = temp;
                    }
                    if (Buttons[3].Text == "0")
                    {
                        string temp;
                        temp = Buttons[3].Text;
                        Buttons[3].Text = Buttons[0].Text;
                        Buttons[0].Text = temp;
                    }

                    break;
                case 1:
                    if (Buttons[0].Text == "0")
                    {
                        string temp;
                        temp = Buttons[0].Text;
                        Buttons[0].Text = Buttons[1].Text;
                        Buttons[1].Text = temp;
                    }
                    if (Buttons[4].Text == "0")
                    {
                        string temp;
                        temp = Buttons[4].Text;
                        Buttons[4].Text = Buttons[1].Text;
                        Buttons[1].Text = temp;
                    }
                    if (Buttons[2].Text == "0")
                    {
                        string temp;
                        temp = Buttons[2].Text;
                        Buttons[2].Text = Buttons[1].Text;
                        Buttons[1].Text = temp;
                    }
                    break;
                case 2:
                    if (Buttons[1].Text == "0")
                    {
                        string temp;
                        temp = Buttons[1].Text;
                        Buttons[1].Text = Buttons[2].Text;
                        Buttons[2].Text = temp;
                    }
                    if (Buttons[5].Text == "0")
                    {
                        string temp;
                        temp = Buttons[5].Text;
                        Buttons[5].Text = Buttons[2].Text;
                        Buttons[2].Text = temp;
                    }

                    break;
                case 3:
                    if (Buttons[0].Text == "0")
                    {
                        string temp;
                        temp = Buttons[0].Text;
                        Buttons[0].Text = Buttons[3].Text;
                        Buttons[3].Text = temp;
                    }
                    if (Buttons[4].Text == "0")
                    {
                        string temp;
                        temp = Buttons[4].Text;
                        Buttons[4].Text = Buttons[3].Text;
                        Buttons[3].Text = temp;
                    }
                    if (Buttons[6].Text == "0")
                    {
                        string temp;
                        temp = Buttons[6].Text;
                        Buttons[6].Text = Buttons[3].Text;
                        Buttons[3].Text = temp;
                    }
                    break;
                case 4:
                    if (Buttons[1].Text == "0")
                    {
                        string temp;
                        temp = Buttons[1].Text;
                        Buttons[1].Text = Buttons[4].Text;
                        Buttons[4].Text = temp;
                    }
                    if (Buttons[3].Text == "0")
                    {
                        string temp;
                        temp = Buttons[3].Text;
                        Buttons[3].Text = Buttons[4].Text;
                        Buttons[4].Text = temp;
                    }
                    if (Buttons[5].Text == "0")
                    {
                        string temp;
                        temp = Buttons[5].Text;
                        Buttons[5].Text = Buttons[4].Text;
                        Buttons[4].Text = temp;
                    }
                    if (Buttons[7].Text == "0")
                    {
                        string temp;
                        temp = Buttons[7].Text;
                        Buttons[7].Text = Buttons[4].Text;
                        Buttons[4].Text = temp;
                    }
                    break;
                case 5:
                    if (Buttons[2].Text == "0")
                    {
                        string temp;
                        temp = Buttons[2].Text;
                        Buttons[2].Text = Buttons[5].Text;
                        Buttons[5].Text = temp;
                    }
                    if (Buttons[4].Text == "0")
                    {
                        string temp;
                        temp = Buttons[4].Text;
                        Buttons[4].Text = Buttons[5].Text;
                        Buttons[5].Text = temp;
                    }
                    if (Buttons[8].Text == "0")
                    {
                        string temp;
                        temp = Buttons[8].Text;
                        Buttons[8].Text = Buttons[5].Text;
                        Buttons[5].Text = temp;
                    }
                    break;
                case 6:
                    if (Buttons[3].Text == "0")
                    {
                        string temp;
                        temp = Buttons[3].Text;
                        Buttons[3].Text = Buttons[6].Text;
                        Buttons[6].Text = temp;
                    }
                    if (Buttons[7].Text == "0")
                    {
                        string temp;
                        temp = Buttons[7].Text;
                        Buttons[7].Text = Buttons[6].Text;
                        Buttons[6].Text = temp;
                    }
                    break;
                case 7:
                    if (Buttons[4].Text == "0")
                    {
                        string temp;
                        temp = Buttons[4].Text;
                        Buttons[4].Text = Buttons[7].Text;
                        Buttons[7].Text = temp;
                    }
                    if (Buttons[6].Text == "0")
                    {
                        string temp;
                        temp = Buttons[6].Text;
                        Buttons[6].Text = Buttons[7].Text;
                        Buttons[7].Text = temp;
                    }
                    if (Buttons[8].Text == "0")
                    {
                        string temp;
                        temp = Buttons[8].Text;
                        Buttons[8].Text = Buttons[7].Text;
                        Buttons[7].Text = temp;
                    }
                    break;
                case 8:
                    if (Buttons[5].Text == "0")
                    {
                        string temp;
                        temp = Buttons[5].Text;
                        Buttons[5].Text = Buttons[8].Text;
                        Buttons[8].Text = temp;
                    }
                    if (Buttons[7].Text == "0")
                    {
                        string temp;
                        temp = Buttons[7].Text;
                        Buttons[7].Text = Buttons[8].Text;
                        Buttons[8].Text = temp;
                    }
                    break;
            }
        }
      
        private void button1_Click_1(object sender, EventArgs e)
        {
            //讀入  input
            a[1, 1] = Convert.ToInt16(TextBoxs[0].Text);
            a[1, 2] = Convert.ToInt16(TextBoxs[1].Text);
            a[1, 3] = Convert.ToInt16(TextBoxs[2].Text);
            a[2, 1] = Convert.ToInt16(TextBoxs[3].Text);
            a[2, 2] = Convert.ToInt16(TextBoxs[4].Text);
            a[2, 3] = Convert.ToInt16(TextBoxs[5].Text);
            a[3, 1] = Convert.ToInt16(TextBoxs[6].Text);
            a[3, 2] = Convert.ToInt16(TextBoxs[7].Text);
            a[3, 3] = Convert.ToInt16(TextBoxs[8].Text);
            //輸出  output
            for (int i = 0; i < 9; i++)
            {
                if (i < 3)
                {
                    Buttons[i].Text = Convert.ToString(a[1, i + 1]);
                }
                else if (i >= 3 && i < 6)
                {
                    Buttons[i].Text = Convert.ToString(a[2, (i - 3) + 1]);
                }
                else
                {
                    Buttons[i].Text = Convert.ToString(a[3, (i - 3 * 2) + 1]);
                }
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            //讀入  input
            Random rd = new Random();
            int temp ;
            int rdno ;
          

            for (int i = 8; i >= 0; --i)
            {
                rdno = rd.Next(0, i);
                temp = score[rdno];
                score[rdno] = score[i];
                score[i] = temp;
            }
            a[1, 1] = Convert.ToInt16(Buttons[0].Text);
            a[1, 2] = Convert.ToInt16(Buttons[1].Text);
            a[1, 3] = Convert.ToInt16(Buttons[2].Text);
            a[2, 1] = Convert.ToInt16(Buttons[3].Text);
            a[2, 2] = Convert.ToInt16(Buttons[4].Text);
            a[2, 3] = Convert.ToInt16(Buttons[5].Text);
            a[3, 1] = Convert.ToInt16(Buttons[6].Text);
            a[3, 2] = Convert.ToInt16(Buttons[7].Text);
            a[3, 3] = Convert.ToInt16(Buttons[8].Text);
            //輸出  output
            for (int i = 0; i < 9; ++i)
            {
                Buttons[i].Text = Convert.ToString(score[i]);
               score[i] = i;
            }  
        }
    }
}