2016年11月14日 星期一

Unity 學習02 基本範例Space Shooter

Space Shooter



流程


One:Game setup, Player and Camera
1.Setting up the project
2.The Player Game Object
3.Background
4.Lighting
5.Move Player
6.Shots

Two:Boundaries, hazard and Enemies
1.Boundary
2.Hazard
3.Explosion
4.Audio
5.Game Controller
6.Setting up Spawning waves

Three:GUI and building the game
1.GUI
2.Ending the Game
3.Building the Game


2016年11月11日 星期五

OOP-物件導向程式概念

物件導向程式概念


OOP (Object Oriented Programming)
整個程式由一些相關的物件所組成
物件之間可以相互運作,以達成整個系統的完整功能

物件的基本元件


物件中通常具備有屬性與方法兩種基本元件

屬性(Properties, Attributes)
變數
記錄物件的重要資料

方法(methods, member function)
物件的活動(Activity)
事件處理器(Event Handler) :透過特定事件來觸發

物件導向程式設計階段


建模 (Modeling)
塑造模型
定義並設計 Class
變數宣告(variables)
設計方法(methods)

產生物件實體(Instant)
以事先建立好的class建立物件實體
new
可以大量生產


Unity 學習01 基本範例Amazing Racer

Amazing Racer

目的


一個矩型的地型
    由事先設計的出發點到終點之間,設計一些挑戰性
使用 Unity 的紋理貼圖與環境效果
使用 Unity 實做出發點、終點、深水池
角色控制器
GUI
遊戲控制器


場景





Terrain : Raw、Texture、Tree、Grass

Directional light

Skybox : window -> lighting

FPSController

Spawn point : empty

Water Harzrd Detecto : plane+trigger collider

Target zone (Finish) : empty+light+capsule collider

Game control : empty


2016年11月7日 星期一

C# 學習06 類別與物件


圖一、使用物件成員


圖二之一、類別物件綜合練習

圖二之二、類別物件綜合練習



圖二之三、類別物件綜合練習

2016年11月3日 星期四

C# 學習05 方法函數練習 日期輸出

圖一、建立方法 函數

圖二、日期輸出練習

C# 學習04 陣列練習

圖一、陣列

圖二、泡沫排序


圖三、二維陣列


圖四、System.Array常用方法

筆記


陣列

class TestArraysClass
{
    static void Main()
    {
        // Declare a single-dimensional array 
        int[] array1 = new int[5];

        // Declare and set array element values
        int[] array2 = new int[] { 1, 3, 5, 7, 9 };

        // Alternative syntax
        int[] array3 = { 1, 2, 3, 4, 5, 6 };

        // Declare a two dimensional array
        int[,] multiDimensionalArray1 = new int[2, 3];

        // Declare and set array element values
        int[,] multiDimensionalArray2 = { { 1, 2, 3 }, { 4, 5, 6 } };

        // Declare a jagged array
        int[][] jaggedArray = new int[6][];

        // Set the values of the first array in the jagged array structure
        jaggedArray[0] = new int[4] { 1, 2, 3, 4 };
    }
}
 
 

搭配陣列使用 foreach

int[] numbers = { 4, 5, 6, 1, 2, 3, -2, -1, 0 };
foreach (int i in numbers)
{
    System.Console.Write("{0} ", i);
}
// Output: 4 5 6 1 2 3 -2 -1 0
 

C# 學習03 流程判斷

圖一、單向雙向if else

圖二、多向if-else if-else

圖三、switch

圖四、for迴圈 九九乘法

圖五、do while判斷

筆記


try-catch-finally 

 C#
public class EHClass
{
    void ReadFile(int index)
    {
        // To run this code, substitute a valid path from your local machine
        string path = @"c:\users\public\test.txt";
        System.IO.StreamReader file = new System.IO.StreamReader(path);
        char[] buffer = new char[10];
        try
        {
            file.ReadBlock(buffer, index, buffer.Length);
        }
        catch (System.IO.IOException e)
        {
            Console.WriteLine("Error reading from {0}. Message = {1}", path, e.Message);
        }

        finally
        {
            if (file != null)
            {
                file.Close();
            }
        }
        // Do something with buffer...
    }

}

C# 學習02 程式的一般結構和簡易讀取、逸出字元

圖一、簡易讀取
圖二、逸出字元

筆記

程式的一般結構

namespace ProgrammingGuide
{
    // Class definition.
    public class MyCustomClass
    {
        // Class members:
        // Property.
        public int Number { get; set; }

        // Method.
        public int Multiply(int num)
        {
            return num * Number;
        }

        // Instance Constructor.
        public MyCustomClass()
        {
            Number = 0;
        }
    }
    // Another class definition. This one contains
    // the Main method, the entry point for the program.
    class Program
    {
        static void Main(string[] args)
        {
            // Create an object of type MyCustomClass.
            MyCustomClass myClass = new MyCustomClass();

            // Set the value of a public property.
            myClass.Number = 27;

            // Call a public method.
            int result = myClass.Multiply(4);
        }
    }
}

C# 學習01 簡單Console輸出



圖一、Console

筆記

第一行包含註解。 字元 // 可以將這行的後面部分轉換成註解。
// A Hello World! program in C#.
您也可以藉由將文字區塊封入 /* 和 */ 字元,將該文字區塊標記為註解。 這在下列範例中顯示。
/* A "Hello World!" program in C#.
This program displays the string "Hello World!" on the screen. */ 
 
 

Main 方法

對於任一種傳回類型,都可使用引數。
static void Main(string[] args)
{
    //...
}
 

輸入和輸出

  using System;
Console.WriteLine("Hello World!");