Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Your App to Make Decisions: Conditional Blocks 靜宜大學資管系 楊子青

Similar presentations


Presentation on theme: "Programming Your App to Make Decisions: Conditional Blocks 靜宜大學資管系 楊子青"— Presentation transcript:

1 Programming Your App to Make Decisions: Conditional Blocks 靜宜大學資管系 楊子青

2 Decision-making capability
is the key ingredient (關鍵因素) of what people think of as artificial intelligence In this chapter, we’ll explore how to build decision-making logic into your apps.

3 An event handler that tests for a condition and branches accordingly
When the event1 occurs, function A is performed no matter what. Then a decision test is performed. If the test is true, B1 is performed. If it is false, B2 is performed. In either case, the rest of the event handler (C) is completed.

4 Testing Conditions with if and ifelse Blocks
App Inventor provides conditional blocks which are found in the Control drawer of the Built-In palette.

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

6 實例:隨機撥號

7 This ifelse block generates one of two universities based on the randomly generated integer

8 An ifelse condition is placed within the else-do of an outer condition
Placing one control construct within another is called nesting. In this case, you’d say the blocks had a “nested if-else.”

9 加入PhoneCall元件 (撥打電話)

10 隨機撥號程式碼 (需用手機測試程式)

11 撥打電話及分機

12 Programming Complex Conditions
You can build complex tests using the logical operators and, or, and not, which are found in the Logic drawer.

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

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

15 執行實例

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


Download ppt "Programming Your App to Make Decisions: Conditional Blocks 靜宜大學資管系 楊子青"

Similar presentations


Ads by Google