Presentation is loading. Please wait.

Presentation is loading. Please wait.

變數與選擇判斷 靜宜大學資管系 楊子青.

Similar presentations


Presentation on theme: "變數與選擇判斷 靜宜大學資管系 楊子青."— Presentation transcript:

1 變數與選擇判斷 靜宜大學資管系 楊子青

2 1. 變數(Variables) A variable is a named storage location, that stores a value of a particular data type. It is called variable because you can change the value stored. App Inventor不用 設定資料型態, 會自動進行轉換

3 (1) 宣告變數 1. 拖曳出 initialize global name to 全域數域 區域數域

4 宣告變數 2. 設定變數名稱 3. 設定初值

5 (2) 取得變數值 選擇變數名稱

6 (3) 設定(變更)變數值 選擇變數名稱

7 Setting a Variable to an Expression
Incrementing a Variable Building Complex Expressions

8 Math drawer In the Math drawer, App Inventor provides a wide range of mathematical functions.

9 (4) 顯示變數值 Changing a variable has no direct effect on the app’s appearance. When you modify a component property, the user interface is directly affected. This is not true for variables. This is one of the advantages of storing data in a variable as opposed to a component property it allows you to show just the data you want when you want to show it. It also allows you to separate the computational part of your app from the user interface, making it easier to change that user interface later.

10 2. 選擇判斷 App Inventor provides conditional blocks which are found in the Control drawer of the Built-In palette.

11 Relational and logical operator blocks used in conditional tests
You can plug any Boolean expression into the “test” slot of these blocks.

12 鱷魚拔牙整人玩具 http://www.i-gamer.net/play/2978.html

13 修改專案,短按圖片第6次出現獅子

14 修改專案,隨機於第2-6次出現獅子

15 自行練習:請設計一個擲筊的App 擲筊(擲爻) 凸起部份稱為「陰面」(也就是反面),平面的部份則稱為「陽面」(也就是正面)。
會出現三種情況: 聖杯:一正一反,表示神明同意你的請求 笑杯:兩個平面向上,表示神明在笑,還未決定同不同意 蓋杯(陰杯):兩個平面朝下,表示請求駁回

16 提示 拉一個Button,讓使用者開始擲筊 設定變數Divination1, Divination2,以及Rnd
假設1表示正面:Divination變數值設為True 假設2表示背面:Divination變數值設為False 先用一個Label,暫時顯示兩個筊杯的數字 根據Divination1, Divination2判斷擲筊結果,於手機螢幕顯示出相關的圖片

17 執行實例

18 練習: 結合加速器,一次擲一個筊杯 擲完兩次之後,再判斷結果 (聖杯/笑杯/蓋杯)
練習: 結合加速器,一次擲一個筊杯 擲完兩次之後,再判斷結果 (聖杯/笑杯/蓋杯)


Download ppt "變數與選擇判斷 靜宜大學資管系 楊子青."

Similar presentations


Ads by Google