2015年12月9日 星期三

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace game_00
{
    public partial class Form1 : Form
    {
        //宣告變數(基本類型)
        //x,y變數的名稱
        private int x;
        private int y;
        private int x2;
        private int y2;

        //method,方法
        //Form1,名稱
        public Form1()
        {
            InitializeComponent();
            x = 100;//設定x的值
            y = 100;
            x2= 200;//設定y的值
            y2= 200;
            timer1.Interval = 1000 / 30;//1/30秒
            timer1.Start();
        }
        //method,方法
        //onpaint,名稱
        private void onpaint(object sender,
                                PaintEventArgs e)
        {
            //PaintEventArgs e是一個類別 繪圖參數
            //e是類別的實體(物件)

            //.取出物件的資料
            //.呼叫物件的功能
           
            //e.Graphics
            //取出e這個物件的Graphics這個附屬物件

            //Graphics是一個物件,提供繪圖功能的物件
            //其中一個功能(方法)叫做DrawEllipse

            //劃出遊戲畫面
            e.Graphics.DrawEllipse(Pens.Black,
                            x,y, 50,20);
            e.Graphics.DrawEllipse(Pens.Red,
                            x2,y2,50, 20);
        }

        //定時呼叫onTimer
        private void onTimer(object sender, EventArgs e)
        {
         // x++;
        Invalidate();
        }
        //按下某個按鍵的時候,會呼叫這個方法
        private void onKeyPress(object sender, KeyPressEventArgs e)
        {
            //event事件
            //args參數
            //KeyPressEventArgs e

            //e.KeyChar 按鍵編號
            if (e.KeyChar == 100)
                x++;
           if (e.KeyChar == 97)
                    x--;
           if (e.KeyChar == 119)
               y--;
           if (e.KeyChar == 115)
               y++;
        }
    }
}
//form1設定起始座標
//ontimer修改座標
//onpaint畫畫面
//一秒鐘做三十次)