SlideShare a Scribd company logo
1 of 78
Beyond the Basics
Learn To Code 2 - Claire Chang
開始之前
高中時喜愛玩RPG遊戲
夢想開發出一款自己的遊戲
不會安裝C語言的IDE,只好先學java script
大學念了資管系,真正走上程式開發的路
到現在為止的感覺
女生與男生在思考上的不同
收到異性的訊息後男女反應的差異
男女玩遊戲也有不同。
看到男生玩遊戲,女生
會覺得他是宅男、魯
蛇。
但男生看到女生擅長玩
遊戲卻覺得很有魅力。
寫程式也是一樣喔!
從上面的圖片中,我們可以了解到,男孩子的思考較
偏直線式,而女孩子則較迂迴
男孩子一般對技術研究有很大的熱忱,並積極運用在
專案中
有關Over Design,男孩子技術狂熱者的線性思考導
致的額外營運成本
女孩子提供不同的思考面向,讓程式開發與討論上有
更多元的思考層面
撰寫程式的IDE - 5 BEST IDE FOR SWIFT
PROGRAMMING
https://www.dunebook.com/5-best-ide-swift-
programming/
編譯工具
測試平台
APP上架所需資源
https://www.youtube.com/watch?v=p_IFBmkoW_w
上網尋找解答
David的公司提供實習機會!
歡迎來和我詢問!
聯絡方式
LineID: Claire318
E mail: cochia0318@hotmail.com
撰寫程式最重要的概念
藉由練習,了解如何去分析問題、拆解問題
很重要的思考三步驟
了解問題
拆解分析問題
思考要如何撰寫程式
來源: https://twweeb.org/c-language-hello_c/
寫程式7步驟
1. 了解問題、了解需求
2. 分析、拆解步驟1的問題
3. 規劃程式內容
4. 撰寫程式碼
5. 編譯執行
6. 偵錯與測試
7. 程式交付
https://www.youtube.com/watch?v=Tz7I_HP1xEI
前面的影片中,什麼是變數呢?
如果是你,你會怎麼設計這些變數的名字呢?
想看看,你的手機裡的連絡資訊裡儲存的姓名和電話等的資
訊,是不是比我們能記得的更多呢?
我們稱這些被用來儲存資訊的為變數(Variables),當我們
將資料記在變數裡,它不會任意被改變,除非我們改變它。
想想看,下面的圖片裡有記著那些變數呢?
每種變數有自己的型別、名字、以及它的值
以右圖來說,name的型別為字串(string),名
字是name,值為Chris。
而=(等於)則為指定符號(assignment operator)
我們可以用”=“來賦予一個變數新的值,假如
Chris的年齡要加一歲,可以用
age = age + 1
變數的型別在初始後是不可改變的,如age一
開始的類別是數字(int),就不能改成字串
(string)
電腦程式=指令(Instructions)+資料(Data)
指令就是程式的語法(Function) > 在之前課堂有教過。
為了讓電腦識別資料(Variables),所有的資料都會有個名稱Name(
識別字Identifier),而資料的內容是值(Value)。
命名規則:函數命名通常會以動詞開頭,屬性命名跟變數則偏向以
名詞或形容詞開頭,一般以英文字母為開頭,與單字之間不用任何
符號隔開,而是利用大小寫區別
練習時間
collectGem():Function > 蒐集紅色寶石(Gems)
isBlocked:Boolean > 前方是否被檔住了
isBlockedLeft:Boolean > 左邊是否被檔住了
isBlockRight:Boolean > 右邊是否被檔住了
isOnClosedSwitch:Boolean > 是否站在關掉的開關上
isOnOpenSwitch:Boolean > 是否站在打開的開關上
isOnGem:Boolean > 是否站在紅色寶石上
moveForward():Function > 往前走一步
toggleSwitch():Function > 開開關或關開關
turnLeft():Function > 向左轉
turnRight():Function > 向右轉
想想看,Lession 1的練習中所使用的資料之中
,有那些是函數,那些是變數呢?
他們的命名特色有那些呢?
目標:創造一個變數去追蹤吃掉的紅
色寶石的數目
此變數的初始值應該為零,在撿起第
一顆紅色寶石後,這個變數的值會變
為1
分析問題
拆解問題
需要往前走,拿起寶石
規劃怎麼撰寫程式
走幾步? 在那裡拾取?
var gemCounter =0
moveForward()
moveForward()
collectGem()
gemCounter = 1
目標:每次拾取紅色寶石之後都要紀錄在
gemCounter之中。並集滿5個紅色寶石
創造一個變數並更改它的值
1. 了解問題
2. 拆解分析問題
3. 思考要如何撰寫程式
目標:增加gemCounter的值去追蹤
拿到了幾個紅色寶石
在先前的題目中,我們直接將新的
值設定到gemCounter中,使用下面
的寫法,則會遞增他本身的值
在這個題目中,每一次執行都會有
隨機數量的紅色寶石,我們無法得
知紅色寶石確切的位置。但假如我
們拾起了一個紅色寶石,則需要將
gemCounter的值+1
了解問題:隨機位置出現隨機個紅色寶石
拆解分析問題:
那些位置可能出現寶石,有什麼共通點
1. 要走的路徑有那些?
2. 有什麼方法可以讓程式碼更聰明?
如何克服這個轉彎,這個轉彎的
動作有何共通點?
3. 該使用那種工具? while? for? if?
目標:搜集剛好7個紅色寶石
我們已經學會了如何根據原有的值去做遞增
。在這一次的練習中,我們要搜集剛好七個
紅色寶石,寶石不僅是隨機位置也是隨機數
目
使用while迴圈去比較已搜集的數目和目標要
搜集的數目是否相同
1. 了解問題: 一條直線上會不停的出
現紅色寶石,但我們需要撿取剛好
數量的寶石
2. 拆解分析問題
> 可能需要不停來回走
> 如何在剛好數量時停下來?
> 計算檢寶石的數量
3. 思考要如何撰寫程式
為什麼較不適合使用for迴圈?
搜集剛好三個紅色寶石並打開四個開關
去搜集正確數量的寶石和打開開關,將會
需要兩個不同的變數去紀錄。當開開關或
搜集寶石時將值加一
宣告一個搜集寶石的變數以及一個打開開
關數量的變數
命名規則
1. 以小寫為開頭,並將每一個單字的第一
個字母變成大寫
2. 從變數中要讓人能理解此變數的意義
目標:搜集到和開關相同數目
的紅色寶石
在這個練習裡,我們創建了一
個常數代表開關的數量。
宣告常數的方法為:let,變數
則為var。常數的值是不可被更
動的,而變數則是可以常常被
變動的
使用比較字元如:<, >, ==, !=
1. 了解問題:
可以由numberOfSwitch獲得開關數目
需拾取和numberOfSwitch相同數目的寶石
2. 拆解分析問題
> 如何在剛好數量時停下來?
> 計算檢寶石的數量
> 如何讓角色能夠轉彎?
3. 思考要如何撰寫程式
> 有那些動作可拆解為可重覆使用的
function?
> 如何使用那些function達成目標
目標:開啟與拾取的紅色寶石相同數量的
開關
解題步驟:
1. 了解問題
> 有不定數量的紅寶石
> 控制開啟開關的數量與寶石數相同
2. 分析問題
> 同時計算撿的寶石和開的開關的數量
> 克服轉彎
> 設計撿寶石與開開關的方法
3. 思考如何撰寫程式
Round Up the Switche
根據totalGems的值,搜集
指定數目的紅色寶石。
先指定let totalGems =
eandomNumberOfGems
totalGems將會是隨機從
1~12的數字。使用這個常數
來搜集正確數量的紅色寶石
Collect the Total
類別(Type)
當我們建築一間房子時,我們會需要藍圖。一個藍圖,在藍圖中會顯
示出這個房子的樣式,例如廚房、浴室、臥室
當我們使用這份藍圖來建造房子,我們會發現每一間房子都長的很像
對程式而言,type(型別)就像藍圖,instance(實例)就像是依照藍圖
所真正建出來的房子。
我們會在藍圖裡面規劃行為以及特性
藍圖描述的特性我們稱為屬性(properties),行為稱為方法(method)
假如我們要打開這些房子的車庫門,首先我們要先找到這個被
建出來的房子的物件,然後告訴他你希望他做什麼。
現在我們要操控程式,將綠色的車庫門打開
物件圖片上,三角型旁的資料描述,那些是屬性?那
些是方法呢?
設計一個完整的程式,就好像蓋房子一樣 。需要事先規劃
,分析我們的需求,將類似的、重覆的部份抽分出來
這就好比在建房子時,我們需要先將房屋的鋼骨建出來,
也需要將承重的樑柱的位置計算出來,並精密計算房屋所
需承受的可能壓力(如地震、颱風),以設計出有足夠安
全性的房子
我們在寫程式之前也是這樣,先去思考需求,分析需求,
規劃架構,並要考量到是否未來可以足夠應付可能所需的
變動及彈性。
練習時間
現在在新的章節裡,我們可以控制地上傳送點的開關
使用前一頁所教的方法,我們可以用isActive屬性來控制遊戲世界中傳送點的開關
在開關上時再打開/關閉開關是無用的,需在走到那格之前就開/關好
greenPortal.isActive = true greenPortal.isActive = false
目標:關掉傳送點以到達開
關處
到目前為止,我們用了許多
的函數去操控角色,但這些
函數無法操控傳送點的開關
現在我們可以利用
greenPortal.isActive = true
來控制不同傳送點的開關
1. 了解問題
> 如果不關掉傳送點,會被傳送到孤島
> 要在走到傳送點之前就關掉傳送點
2. 拆解分析問題
> 以中間傳送點來看,我們觀察到從中心走
到最邊角需要走三步
> 打開開關後需要轉身走回去
> 同樣的步驟要做三次
3. 思考要如何撰寫程式
> 有那些動作可以抽出成為函數
Deactivating a Porta
目標:透過開啟/關閉開關搜集完七個寶石並開啟開關
1. 了解問題
> 需搜集所有的寶石打開所有的開關
> 避免在不該被傳送的時後被傳走
2. 拆解分析問題
> 要先關掉傳送點,將第一部份的寶石
搜集完成再打開,才能傳到第二部份
> 傳到第二部份後,要先關起來,才能
在撿完寶石後去打開開關
3. 思考要如何撰寫程式
Portal On And Off
目標:藉著更動傳送點的狀態來拾取畫面的寶石
這個練習裡面有兩個傳送點pinkPortal和bluePortal,請
藉著開關這兩個傳送點,將四個寶石都撿拾起來。
Setting the Right Port
目標:開啟所有的開關並搜集完所有的寶石
1. 了解問題
> 需搜集所有的寶石打開所有的開關
> 避免在不該被傳送的時後被傳走
2. 拆解分析問題
> 觀察路徑有何重覆性?
> 有時要搜集寶石,有時要打
開開關
> 能否讓角色以十字型方向去
打開開關或拾取寶石?
3. 思考要如何撰寫程式
Corners of the World
搜集完隨機數目的全部寶石
思考如何讓程式更有效率
結構化你的程式
1. 了解問題
> 有兩個傳送點要去操作
> 一共有三個部份要去拾取紅寶石
> 寶石數量為隨機的
2. 拆解分析問題
> 觀察寶石可能出現的地
方有何共通性?
> 是否能一次拾取完一整
條線的寶石
> 兩個傳送點能否有個簡
單的方式被開關
3. 思考要如何撰寫程式
Random Gems Everywh
初始化(INITIALIZATION)
還記得在TYPE的章節中,我們講到房屋的藍圖的事
嗎?
藍圖叫做型別(Type)、而被建造出來的房子則為實體
(instance)
那麼,依照藍圖,把房子建出來的這個動作
就稱為【初始化】
下圖告訴我們,以之前的遊戲世界來看,那些是類別、那些是
實體
在這一章節中,Character多了一個好朋友! Expert和
Character都是角色,也都是Character所初始化出來的的實體
在TYPE的練習題中,有兩個傳送點,一個是藍色
的,一個是綠色的。
其實他們的類別都屬於PORTAL,藍色傳送點與
綠色傳送點都是PORTAL,只是是不同的實體
在這一章中,我們會有兩個角色,一個是之前的
獨眼龍,一個是在這一章新出來的紅色解鎖怪
哈摟!大家好!我是新朋友!
遊戲世界裡為我們寫好了
一個FUNCTION名叫
Expert(),在這個函數裡面
,做了初始化設定紅色角
色的能力
這個角色比前一個角色多
擁有了開鎖、把開關降下
、升起的能力。
設定這個新角色的動作都
是在expert()裡做完
練習時間
turnLockDown():Function > 將石塊往下移
turnLockUp() :Function > 將石塊往上移
目標: 初始化Expert並且利用他的能力
來拾取所有的紅色寶石
在這個題目中,我們要增加面對這個
大鎖,我們會需要轉動這個鎖來控制
石頭平台的上下
這個紅色解鎖怪擁有之前角色的所有
能力,像是往前移動、搜集寶石、開
啟關閉開關等。但之前的角色沒有轉
動開關的能力
我們可以將expert宣告為一個常數,並
且利用Expert()來初始化這個新角色
let expert = Expert()
1. 了解問題
> 創立解鎖怪後,他在那格出現?
> 解鎖怪面向那邊?
2. 拆解分析問題
> 觀察去取寶石時的路徑的共通性
> 角色出現的地方離目的地的距離
的共通性
> 前往下個目的地需要那些動作?
3. 思考要如何撰寫程式
Initializing Your Expe
目標: 創建一個
Expert的實體,然
後用他來拾取所有
的紅色寶石
這邊的石塊的位置
是比地面還要高的
,因此應該要在解
鎖石將石塊降下
Train Your Exper
初始化一個Expert一個
Character
在大部份的時候,我們若要開
發一個較大的專案,通常會需
要多個物件及實例去完成工作
,例如一個照相APP,會同時
需要相機功能以及濾鏡功能
在這個練習中,紅色解鎖怪的
能力會幫助土色角色去完成他
的工作
1. 了解問題
> 透過解鎖怪的升降控制,幫
助角色能夠順利吃到兩個寶石
2. 拆解分析問題
> 角色應該先拾取前面的寶石
,然後前往藍色傳送點
> 再下降平台,然後拾取第二
顆寶石
3. 思考要如何撰寫程式
初始化一個Expert一個Character
利用兩種不同角色互助一起完成工作

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Learn to code 2 - Beyond the Basics

Editor's Notes

  1. Key Point : Show how to increment the value of the variable Why do we increment the value? Go through thought process of while loop