2013年3月30日 星期六

Scratch程式設計

Scratch是2007年由美國麻省理工學院(MIT)的Mitchel Resnick教授所發表的教學軟體,主要目的是幫助6~16歲的兒童們學習程式設計。它提供圖形化的介面,使用者不太需要使用鍵盤來輸入各項指令,而是用滑鼠拖曳程式區塊到腳本區,以組合積木的方式來撰寫程式碼。
如果你對Scratch有興趣,可以參考高慧君老師編寫的教材進行學習。

http://blog.yjps.tp.edu.tw/blog/csm/files/2012/04/scratchbook.doc


Scratch Taipei網站中有互動遊戲創作競賽題目可參考,有好幾個不錯的例子(如打磚塊....)

http://scratch.tp.edu.tw/

2013年3月28日 星期四

C#遊戲程式設計教學課程

Gary Lin的C#遊戲程式設計教學, 有完整的教學錄影及程式碼下載,作者持續更新中,極力推薦

2013年3月7日 星期四

Kinect實作練習(一):控制Kinect垂直角度

1. 新增一個Visual Studio C# WPF專案。
2. 在頁面上加入UP、DOWN二個操作按鈕。
3. 在專案中加入Microsoft.Kinect命名空間(Namespace)。

 4. 程式一開始取得Kinect感測器,啟用Kinect感測器並重置仰角為0。

5. 撰寫作業按鈕之click事件程序。當按下UP按鈕,使Kinect感測器仰角上昇2度;當按下DOWN按鈕,使Kinect感測器仰角下降2度。
6. 加入結束程式事件框架 
 7. 結束程式時,重置Kinect感測器仰角為0,並停用Kinect感測器

2013年3月5日 星期二

PHP陣列資料(2)


建立二維陣列

直接賦值
$score['學生1']['國文']=78;
$score['學生1']['英文']=95;
$score['學生1']['數學']=83;

使用array()函式
$score = array (array(78, 95, 83),
array(80, 78, 91),
array(72, 65, 76));

使用array()函式嵌套
$score1 = array(78, 95, 83);
$score2 = array(80, 78, 91);
$score3 = array(72, 65, 76);
$score = array($score1, $score2, $score3);

2013年3月3日 星期日

PHP陣列資料(1)


一維陣列
陣列名稱[索引鍵] = 元素值;

沒有指定索引鍵值時,自動由0開始做為索引鍵值
$myArray[]='a'; //相當於$myArray[0] = 'a';
$myArray[]='b'; //相當於$myArray[1] = 'b';
$myArray[]='c'; //相當於$myArray[2] = 'c';

若指定某個索引值,其後陣列項目之索引鍵值會自動接續
$myArray[5] = 'a';
$myArray[] = 'b'; //相當於$myArray[6] = 'b';
$myArray[] = 'c'; //相當於$myArray[7] = 'c';

也可使用字串做為索引鍵
$myProfile['name'] = 'Wu, ShyiShiou';
$myProfile['affiliation'] = 'Nankai University of Technology';
echo $myProfile['name'].'<br />";
echo $myProfile['affiliation']."<br />";

陣列變數在雙引號字串中要在前後加上大括弧({、})才能正確解譯變數值
echo "Hello, my name is {$myProfile['name']}";

使用array()函式建立一維陣列
陣列名稱 = array(索引鍵1=>元素值1,索引鍵2=>元素值2, …索引鍵n=>元素值n );
如果沒有指定索引鍵值,自動由0開始做為索引鍵值
$myArray = array('a', 'b', 'c');
也可使用字串做為索引鍵,稱為結合式陣列
$myProfile = array('name'=>'Wu, ShyiShiou', 'affiliation' =>'NKUT, Dept. of E.E.');



2013年2月9日 星期六

使用GCM服務(六) 設計GCM應用程式(2)

在使用GCM服務(五) 設計GCM應用程式(1)文中已建立GCMIntentService程式框架,接著必須實作GCMIntentService類別程式碼。
(1). 在建構元中將在Google APIs Console建立Project編號當做Sender ID,傳給GCMBaseIntentService類別。

  public GCMIntentService(){
     super("Your_Sender_ID");
  }

(2). 向GCM Server註冊並取得裝置的registration Id後,GCMBroadcastReceiver會調用onRegistered(),在此須同步向訊息推播伺服器登錄裝置的registration Id。

  @Override
  protected void onRegistered(Context context, String regId) {
        /**
         * 撰寫程式碼向訊息推播伺服器登錄regId,例如
         * register(context, regId);
         * */       
        GCMRegistrar.setRegisteredOnServer(context, true);
  }

(3). 向GCM Server註銷裝置後,GCMBroadcastReceiver會調用onUnregistered(),在此須同步向訊息推播伺服器取消登錄裝置的registration Id。

  @Override
  protected void onUnregistered(Context context, String regId) {
        /**
         * 在此應撰寫程式碼向訊息推播伺服器取消登錄regId,例如
         * unregister(context, regId);
         * */       
        GCMRegistrar.setRegisteredOnServer(context, false);
  }

(4). 收到GCM Server送來的推播訊息時,GCMBroadcastReceiver會調用onMessage(),在此透過Notification通知用戶。

  @Override
  protected void onMessage(Context context, Intent intent) {
     //取出訊息payload內容
     String contentTitle = intent.getStringExtra("contentTitle");  
     String contentText = intent.getStringExtra("contentText");
    //在裝置狀態列顯示Notification通知用戶
     generateNotification(context, contentTitle, contentText); 
    }
  private static void generateNotification(Context context,
     String contentTitle, String contentText) {
     NotificationManager notificationManager = (NotificationManager)
          context.getSystemService(Context.NOTIFICATION_SERVICE);
     Notification notification = new Notification(
       R.drawable.ic_launcher,
       contentTitle,
       System.currentTimeMillis());
     //設定notification要喚醒的Activity      
     Intent notificationIntent = new Intent(context, MainActivity.class);
     notificationIntent.setFlags(
       Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
     PendingIntent intent = PendingIntent.getActivity(
       context,
       0,
       notificationIntent,
       PendingIntent.FLAG_UPDATE_CURRENT);
     //設定notification內容
     notification.setLatestEventInfo(context, contentTitle, contentText, intent);
     //自動移除看過的notification
     notification.flags |= Notification.FLAG_AUTO_CANCEL;
     //發送notification
     notificationManager.notify( 0, notification);     
  }

最後是撰寫MainActivity類別程式碼,在onCreate()方法中進行以下作業:
  protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
     //檢查裝置是否支援GCM
     GCMRegistrar.checkDevice(this);
     //檢查應用程式之AndroidMainfest.xml設定是否正確
     GCMRegistrar.checkManifest(this);
     //取得registration id
     final String regId = GCMRegistrar.getRegistrationId(this);
     if (regId.equals("")) {        //尚未註冊
       //向GCM server註冊以取得registration id
       GCMRegistrar.register(this, "Your_Sender_ID");
     }
  }