Enviar pesquisa
Carregar
Object-Oriented Programming Design with Greenfoot 01
•
Transferir como ODP, PDF
•
1 gostou
•
723 visualizações
imacat .
Seguir
接龍遊戲—由上而下的物件導向程式設計(上) 發表於:Greenfoot教師工作坊(五) 時間:2012/6/15(五) 14:00 地點:南港高中 (還有下集,請續點閱)
Leia menos
Leia mais
Tecnologia
Denunciar
Compartilhar
Denunciar
Compartilhar
1 de 50
Baixar agora
Recomendados
Solitaire with Greenfoot #1
Solitaire with Greenfoot #1
imacat .
Solitaire with Greenfoot #4
Solitaire with Greenfoot #4
imacat .
Solitaire with Greenfoot #2
Solitaire with Greenfoot #2
imacat .
神州泰岳测试试题(笔试)
神州泰岳测试试题(笔试)
yiditushe
Unity遊戲程式設計 - 3D物件與光源設定
Unity遊戲程式設計 - 3D物件與光源設定
吳錫修 (ShyiShiou Wu)
Roll a ball遊戲專案
Roll a ball遊戲專案
吳錫修 (ShyiShiou Wu)
Unity遊戲程式設計 - 2D運動與碰撞處理I
Unity遊戲程式設計 - 2D運動與碰撞處理I
吳錫修 (ShyiShiou Wu)
funkciju skaiciavimas ir ju grafikai
funkciju skaiciavimas ir ju grafikai
ddaiva
Recomendados
Solitaire with Greenfoot #1
Solitaire with Greenfoot #1
imacat .
Solitaire with Greenfoot #4
Solitaire with Greenfoot #4
imacat .
Solitaire with Greenfoot #2
Solitaire with Greenfoot #2
imacat .
神州泰岳测试试题(笔试)
神州泰岳测试试题(笔试)
yiditushe
Unity遊戲程式設計 - 3D物件與光源設定
Unity遊戲程式設計 - 3D物件與光源設定
吳錫修 (ShyiShiou Wu)
Roll a ball遊戲專案
Roll a ball遊戲專案
吳錫修 (ShyiShiou Wu)
Unity遊戲程式設計 - 2D運動與碰撞處理I
Unity遊戲程式設計 - 2D運動與碰撞處理I
吳錫修 (ShyiShiou Wu)
funkciju skaiciavimas ir ju grafikai
funkciju skaiciavimas ir ju grafikai
ddaiva
Janet marstine - Museum ethics and museum change
Janet marstine - Museum ethics and museum change
Association of Danish Museums / Organisationen Danske Museer
43 Lars Ewald Jensen, Mesolitisk bebyggelse i et neolitisk landskab
43 Lars Ewald Jensen, Mesolitisk bebyggelse i et neolitisk landskab
Association of Danish Museums / Organisationen Danske Museer
Enhancing SugarCRM with Addons
Enhancing SugarCRM with Addons
Atcore Systems
Kate Chatfield Comminity Gallery exhib.
Kate Chatfield Comminity Gallery exhib.
Association of Danish Museums / Organisationen Danske Museer
Egyptian Society of Cardiology,Thrombosis conference 2014 final program
Egyptian Society of Cardiology,Thrombosis conference 2014 final program
Alexandria University, Egypt
Crossing Office Applications
Crossing Office Applications
imacat .
Mathilde Schytz Marvit - co produktioner
Mathilde Schytz Marvit - co produktioner
Association of Danish Museums / Organisationen Danske Museer
Jakob Walløe Hansen geopark odsherred
Jakob Walløe Hansen geopark odsherred
Association of Danish Museums / Organisationen Danske Museer
Medicinsk Museion - Ikke bare et museum med ting
Medicinsk Museion - Ikke bare et museum med ting
Association of Danish Museums / Organisationen Danske Museer
Ned med våbnene
Ned med våbnene
Association of Danish Museums / Organisationen Danske Museer
steen hvass
steen hvass
Association of Danish Museums / Organisationen Danske Museer
Charlie Christensen
Charlie Christensen
Association of Danish Museums / Organisationen Danske Museer
Title sequences
Title sequences
Dylan Conti
Democraciasinpartidos
Democraciasinpartidos
jaime taboaca castro
Informatica jeka
Informatica jeka
GaznatiiTha
Anders Hartvig
Anders Hartvig
Association of Danish Museums / Organisationen Danske Museer
OpenOffice.org Magic Sandbox
OpenOffice.org Magic Sandbox
imacat .
LOphoto dic2010
LOphoto dic2010
LOphoto
Hans Mikkelsen - ferslev kirke
Hans Mikkelsen - ferslev kirke
Association of Danish Museums / Organisationen Danske Museer
16 jens chrmoesgaard_danef+ªm+©nter2016
16 jens chrmoesgaard_danef+ªm+©nter2016
Association of Danish Museums / Organisationen Danske Museer
Solitaire with Greenfoot #2/4
Solitaire with Greenfoot #2/4
imacat .
Object-Oriented Programming Design with Greenfoot 02
Object-Oriented Programming Design with Greenfoot 02
imacat .
Mais conteúdo relacionado
Destaque
Janet marstine - Museum ethics and museum change
Janet marstine - Museum ethics and museum change
Association of Danish Museums / Organisationen Danske Museer
43 Lars Ewald Jensen, Mesolitisk bebyggelse i et neolitisk landskab
43 Lars Ewald Jensen, Mesolitisk bebyggelse i et neolitisk landskab
Association of Danish Museums / Organisationen Danske Museer
Enhancing SugarCRM with Addons
Enhancing SugarCRM with Addons
Atcore Systems
Kate Chatfield Comminity Gallery exhib.
Kate Chatfield Comminity Gallery exhib.
Association of Danish Museums / Organisationen Danske Museer
Egyptian Society of Cardiology,Thrombosis conference 2014 final program
Egyptian Society of Cardiology,Thrombosis conference 2014 final program
Alexandria University, Egypt
Crossing Office Applications
Crossing Office Applications
imacat .
Mathilde Schytz Marvit - co produktioner
Mathilde Schytz Marvit - co produktioner
Association of Danish Museums / Organisationen Danske Museer
Jakob Walløe Hansen geopark odsherred
Jakob Walløe Hansen geopark odsherred
Association of Danish Museums / Organisationen Danske Museer
Medicinsk Museion - Ikke bare et museum med ting
Medicinsk Museion - Ikke bare et museum med ting
Association of Danish Museums / Organisationen Danske Museer
Ned med våbnene
Ned med våbnene
Association of Danish Museums / Organisationen Danske Museer
steen hvass
steen hvass
Association of Danish Museums / Organisationen Danske Museer
Charlie Christensen
Charlie Christensen
Association of Danish Museums / Organisationen Danske Museer
Title sequences
Title sequences
Dylan Conti
Democraciasinpartidos
Democraciasinpartidos
jaime taboaca castro
Informatica jeka
Informatica jeka
GaznatiiTha
Anders Hartvig
Anders Hartvig
Association of Danish Museums / Organisationen Danske Museer
OpenOffice.org Magic Sandbox
OpenOffice.org Magic Sandbox
imacat .
LOphoto dic2010
LOphoto dic2010
LOphoto
Hans Mikkelsen - ferslev kirke
Hans Mikkelsen - ferslev kirke
Association of Danish Museums / Organisationen Danske Museer
16 jens chrmoesgaard_danef+ªm+©nter2016
16 jens chrmoesgaard_danef+ªm+©nter2016
Association of Danish Museums / Organisationen Danske Museer
Destaque
(20)
Janet marstine - Museum ethics and museum change
Janet marstine - Museum ethics and museum change
43 Lars Ewald Jensen, Mesolitisk bebyggelse i et neolitisk landskab
43 Lars Ewald Jensen, Mesolitisk bebyggelse i et neolitisk landskab
Enhancing SugarCRM with Addons
Enhancing SugarCRM with Addons
Kate Chatfield Comminity Gallery exhib.
Kate Chatfield Comminity Gallery exhib.
Egyptian Society of Cardiology,Thrombosis conference 2014 final program
Egyptian Society of Cardiology,Thrombosis conference 2014 final program
Crossing Office Applications
Crossing Office Applications
Mathilde Schytz Marvit - co produktioner
Mathilde Schytz Marvit - co produktioner
Jakob Walløe Hansen geopark odsherred
Jakob Walløe Hansen geopark odsherred
Medicinsk Museion - Ikke bare et museum med ting
Medicinsk Museion - Ikke bare et museum med ting
Ned med våbnene
Ned med våbnene
steen hvass
steen hvass
Charlie Christensen
Charlie Christensen
Title sequences
Title sequences
Democraciasinpartidos
Democraciasinpartidos
Informatica jeka
Informatica jeka
Anders Hartvig
Anders Hartvig
OpenOffice.org Magic Sandbox
OpenOffice.org Magic Sandbox
LOphoto dic2010
LOphoto dic2010
Hans Mikkelsen - ferslev kirke
Hans Mikkelsen - ferslev kirke
16 jens chrmoesgaard_danef+ªm+©nter2016
16 jens chrmoesgaard_danef+ªm+©nter2016
Semelhante a Object-Oriented Programming Design with Greenfoot 01
Solitaire with Greenfoot #2/4
Solitaire with Greenfoot #2/4
imacat .
Object-Oriented Programming Design with Greenfoot 02
Object-Oriented Programming Design with Greenfoot 02
imacat .
Solitaire with Greenfoot #3
Solitaire with Greenfoot #3
imacat .
Behind Tetris5
Behind Tetris5
Junwen Sun
HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享
Chong-Kuan Chen
XNA遊戲程式框架
XNA遊戲程式框架
吳錫修 (ShyiShiou Wu)
Unity遊戲程式設計(05) 2D移動與碰撞處理II
Unity遊戲程式設計(05) 2D移動與碰撞處理II
吳錫修 (ShyiShiou Wu)
Unity遊戲程式設計(09) 3D物件與光源設定
Unity遊戲程式設計(09) 3D物件與光源設定
吳錫修 (ShyiShiou Wu)
Python入門:5大概念初心者必備
Python入門:5大概念初心者必備
Derek Lee
Pycontw2013x
Pycontw2013x
weijr
Keep your code clean
Keep your code clean
macrochen
从问题开始,谈前端架构
从问题开始,谈前端架构
裕波 周
Effective java 摘選條目分享 1 - 物件、複合、可變性、leak
Effective java 摘選條目分享 1 - 物件、複合、可變性、leak
Kane Shih
Python速成指南
Python速成指南
March Liu
Semelhante a Object-Oriented Programming Design with Greenfoot 01
(14)
Solitaire with Greenfoot #2/4
Solitaire with Greenfoot #2/4
Object-Oriented Programming Design with Greenfoot 02
Object-Oriented Programming Design with Greenfoot 02
Solitaire with Greenfoot #3
Solitaire with Greenfoot #3
Behind Tetris5
Behind Tetris5
HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享
XNA遊戲程式框架
XNA遊戲程式框架
Unity遊戲程式設計(05) 2D移動與碰撞處理II
Unity遊戲程式設計(05) 2D移動與碰撞處理II
Unity遊戲程式設計(09) 3D物件與光源設定
Unity遊戲程式設計(09) 3D物件與光源設定
Python入門:5大概念初心者必備
Python入門:5大概念初心者必備
Pycontw2013x
Pycontw2013x
Keep your code clean
Keep your code clean
从问题开始,谈前端架构
从问题开始,谈前端架构
Effective java 摘選條目分享 1 - 物件、複合、可變性、leak
Effective java 摘選條目分享 1 - 物件、複合、可變性、leak
Python速成指南
Python速成指南
Mais de imacat .
A Room of WikiWomen's Own
A Room of WikiWomen's Own
imacat .
Office寶可夢GO IV計算機
Office寶可夢GO IV計算機
imacat .
OpenOffice Application with Python
OpenOffice Application with Python
imacat .
從doc、docx、odt到Google Docs
從doc、docx、odt到Google Docs
imacat .
More Girls – Creating a Community of Diversity
More Girls – Creating a Community of Diversity
imacat .
Welcome to Apache OpenOffice 4
Welcome to Apache OpenOffice 4
imacat .
OpenOffice, Open Business
OpenOffice, Open Business
imacat .
Multimedia Fun with OpenOffice Calc
Multimedia Fun with OpenOffice Calc
imacat .
Welcome to Apache OpenOffice 3.4 COSCUP 2012
Welcome to Apache OpenOffice 3.4 COSCUP 2012
imacat .
Mosaic Fun with OpenOffice Calc
Mosaic Fun with OpenOffice Calc
imacat .
GNU Autoconf / Automake #4
GNU Autoconf / Automake #4
imacat .
GNU Autoconf / Automake #1
GNU Autoconf / Automake #1
imacat .
Welcome to Apache OpenOffice 3.4
Welcome to Apache OpenOffice 3.4
imacat .
OpenOffice UNO Application on Android
OpenOffice UNO Application on Android
imacat .
Mailing Lists and IRC
Mailing Lists and IRC
imacat .
GNU Build System
GNU Build System
imacat .
patch和diff
patch和diff
imacat .
OpenOffice.org UNO Magic
OpenOffice.org UNO Magic
imacat .
autoconf
autoconf
imacat .
用OpenOffice.org加速企業生產力!
用OpenOffice.org加速企業生產力!
imacat .
Mais de imacat .
(20)
A Room of WikiWomen's Own
A Room of WikiWomen's Own
Office寶可夢GO IV計算機
Office寶可夢GO IV計算機
OpenOffice Application with Python
OpenOffice Application with Python
從doc、docx、odt到Google Docs
從doc、docx、odt到Google Docs
More Girls – Creating a Community of Diversity
More Girls – Creating a Community of Diversity
Welcome to Apache OpenOffice 4
Welcome to Apache OpenOffice 4
OpenOffice, Open Business
OpenOffice, Open Business
Multimedia Fun with OpenOffice Calc
Multimedia Fun with OpenOffice Calc
Welcome to Apache OpenOffice 3.4 COSCUP 2012
Welcome to Apache OpenOffice 3.4 COSCUP 2012
Mosaic Fun with OpenOffice Calc
Mosaic Fun with OpenOffice Calc
GNU Autoconf / Automake #4
GNU Autoconf / Automake #4
GNU Autoconf / Automake #1
GNU Autoconf / Automake #1
Welcome to Apache OpenOffice 3.4
Welcome to Apache OpenOffice 3.4
OpenOffice UNO Application on Android
OpenOffice UNO Application on Android
Mailing Lists and IRC
Mailing Lists and IRC
GNU Build System
GNU Build System
patch和diff
patch和diff
OpenOffice.org UNO Magic
OpenOffice.org UNO Magic
autoconf
autoconf
用OpenOffice.org加速企業生產力!
用OpenOffice.org加速企業生產力!
Object-Oriented Programming Design with Greenfoot 01
1.
接龍遊戲 由上而下的物件導向程 式設計(上)
依瑪貓/楊士青 imacat@mail.imacat.idv.tw 2012/6/15
2.
「接龍遊戲—由上而下的物件導向程式設計」簡報由 依瑪貓╱楊士青 製作,
以 創用CC Attribution-ShareAlike 3.0 Unported 授權條款 釋出。
3.
自我介紹 依瑪貓╱楊士青 臺灣師範大學資訊教育研究所碩一研究生
4.
物件導向程式設計 Object-Oriented Programming
(OOP)
5.
物件導向程式設計的特色 「物件導向程式設計」的設計單位是「物
件」,貼近我們對實體世界的概念理解。 「程序性程式設計 Procedural Programming 」的設計單位是「程序 Procedures 」: 流程 Flow 函式 Functions 副程式 Subroutines Pokkunuri, B. P. (1989, November). Object oriented programming. ACM SIGPLAN Notices, 24(11), 96-101. doi:10.1145/71605.71612
6.
物件導向程式設計的特色 「物件導向程式設計」的設計單位是「物 件」,貼近我們對實體世界的概念理解, 比較容易把我們的概念理解,直接轉換為
程式碼。 「程序性程式設計」的設計單位是「程序」,比 物件抽象,較難由設計理解的概念,轉換為程 式碼。
7.
物件導向程式設計的特色 程序性程式設計的單
開始 結束 位是程序。 輸 判 入 斷 處理 3 1 2 程式 1 程式 2 程式 3 …… …… …… …… …… ……
8.
物件導向程式設計的特色 物件導向程式設計,
物 較容易支援由上 件2 (觀念)而下(程 物 件1 物 件3 式碼)的程式設計 。 程式 1 程式 2 程式 3 …… …… …… …… …… ……
9.
實例說明
10.
請新建專案「 solitaire 」, 並將隨附圖片複製到
images 目錄下。
11.
請先回憶一下接龍怎麼玩。 上網搜尋 Solitaire Flash
遊戲試玩, 回憶一下。
12.
接龍遊戲
13.
如何撰寫接龍遊戲的程式?
14.
一、設計類別 (Class) 和物件
(Object)
15.
接龍的牌桌
16.
牌桌上有什麼?
17.
牌桌上有什麼? 52 張撲克牌 未翻開的牌疊 已翻開的牌疊 暫放的牌疊(共七疊) 歸整好的牌疊(共四疊)
18.
牌桌上有什麼?
19.
牌桌上有什麼?
20.
牌桌上有什麼?
21.
牌桌上有什麼? 撲克牌 未翻開的牌疊(共一疊) 已翻開的牌疊(共一疊) 暫放的牌疊(共七疊) 歸整好的牌疊(共四疊)
22.
牌桌上有什麼? 撲克牌 撲克牌疊 未翻開的牌疊(共一疊) 已翻開的牌疊(共一疊)
暫放的牌疊(共七疊) 歸整好的牌疊(共四疊)
23.
步驟一:建立類別 牌桌 撲克牌 撲克牌疊 未翻開的牌疊 已翻開的牌疊
暫放的牌疊 歸整好的牌疊
24.
步驟一:建立類別 牌桌上的每個東西,都對應到我們建立的一 個 class
。 物件導向程式設計,把我們理解的抽象概念,直 接對應到 class ,寫成 class 。
25.
接下來為方便進行分享, 請載入隨附的 solitaire-start 專案。
26.
建好類別後,接下來要建立物件。 我們把剛剛建好的牌疊,
產生物件加到牌桌上。
27.
步驟二:加上撲克牌疊 import greenfoot.*;
// ( World 、 Actor 、 GreenfootImage 、 GreenfootSound 、 Greenfoot 及 MouseInfo ) import java.util.ArrayList; /** * 牌桌。 * * @author 依瑪貓 * @version 2012/6/15 */ public class Table extends World { /** 未翻開的撲克牌疊。 */ public UnflippedPile unflippedPile = null; /** 已翻開的撲克牌疊。 */ public FlippedPile flippedPile = null; /** 暫放區的撲克牌疊。 */ public ArrayList<WorkingPile> workingPiles = new ArrayList<WorkingPile>(); /** 歸整區的撲克牌疊。 */ public ArrayList<ResultPile> resultPiles = new ArrayList<ResultPile>();
28.
步驟二:加上撲克牌疊(續)
public Table() { // 建立 600x400 方格的新世界,方格大小為 1x1 像素。 super(600, 400, 1); unflippedPile = new UnflippedPile(); // 加上未翻開的撲克牌疊。 addObject(unflippedPile, 48, 60); flippedPile = new FlippedPile(); // 加上已翻開的撲克牌疊。 addObject(flippedPile, 132, 60); workingPiles = new ArrayList<WorkingPile>(); // 加上暫放區的撲克牌疊。 for (int i = 1; i <= 7; i++) { WorkingPile pile = new WorkingPile(); workingPiles.add(pile); addObject(pile, -36 + 84 * i, 168); } resultPiles = new ArrayList<ResultPile>(); // 加上歸整區的撲克牌疊。 for (int i = 1; i <= 4; i++) { ResultPile pile = new ResultPile(); resultPiles.add(pile); addObject(pile, 216 + i * 84, 60); } } }
29.
步驟二:加上撲克牌疊
(結果)
30.
接下來我們要加上撲克牌。 撲克牌洗牌後,放在未翻開的牌疊上。
31.
先看 Card 撲克牌和
Pile 牌疊的文件, 看看有哪些方法可以用。
32.
Card 撲克牌的文件說明
33.
Pile 牌疊的文件說明
34.
步驟三:加上撲克牌 用 Card(Card.Suit suit,
int value) 建立撲 克牌。 用 addCard(Card card) 把牌放到牌堆。
35.
步驟三:加上撲克牌 import greenfoot.*;
// ( World 、 Actor 、 GreenfootImage 、 GreenfootSound 、 Greenfoot 及 MouseInfo ) import java.util.ArrayList; import java.util.Collections; …… public Table() { …… // 加上撲克牌。 ArrayList<Card> cards = new ArrayList<Card>(); // 建立撲克牌 for (Card.Suit suit : Card.Suit.values()) { for (int value = 1; value <= 13; value++) { cards.add(new Card(suit, value)); } } Collections.shuffle(cards); // 洗牌 for (Card card : cards) { // 放在未翻開的牌疊上 unflippedPile.addCard(card); } } }
36.
步驟三:加上撲克牌
37.
放好牌後, 下面的暫放區,要先發好一些牌。
38.
發牌的時候 第一疊發一張,第二疊發兩張, 第三疊發三張,依此類推發七疊。
每疊最後一張牌要翻開。
39.
步驟四:發牌到下面的暫放區 用 takeTopCard() 抽出最上面的撲克牌。 用
turnFaceUp() 翻正面,或用 turnFaceDown() 翻背面。 用 addCard(Card card) 把牌放到暫放區的 牌堆。
40.
步驟四:發牌到下面的暫放區 public Table() {
…… // 發牌到暫放區。 for (int i = 1; i <= workingPiles.size(); i++) { WorkingPile pile = workingPiles.get(i - 1); for (int j = 1; j <= i; j++) // 第幾疊,就發幾張牌。 { Card card = unflippedPile.takeTopCard(); pile.addCard(card); } Card card = pile.getTopCard(); // 最後一張牌要翻開。 card.turnFaceUp(); } }
41.
步驟四:發牌到下面的暫放區
42.
問題
43.
暫放區的撲克牌, 下面的牌被上面的牌蓋掉了,
怎麼辦?
44.
第二張牌要放在第一張下面一點, 第三張牌要放在第二張下面一點, 第四張牌要放在第三張下面一點,
依此類推。
45.
繼承 (Inheritance) 和覆寫
(Override) 子類別 (subclass) 要是沒有覆寫掉父類別 (superclass) 的方法,就會繼承 (inherit) 父類別的方法。 我們原來在 WorkingPile 沒有覆寫 addCard() ,所以會繼承自 Pile 的 addCard() ,新加的牌會放到牌疊的正上方。
46.
繼承 (Inheritance) 和覆寫
(Override) 子類別可以覆寫 (override) 父類別的方法。 這樣可以在不改寫呼叫者程式的情況下, 子類別做一些自己特有的調整。 現在我們要在 WorkingPile 覆寫 addCard() , 來蓋掉父類別 Pile 的 addCard() 方法,把新 加的牌往下面放一點,露出前面的牌。
47.
繼承 (Inheritance) 和覆寫
(Override) 覆寫時,子類別 (subclass) 可以呼叫 super ,呼叫父類別 (superclass) 中被覆 寫掉的方法,例如 super.addCard() 。 要呼叫父類別 (superclass) 的父類別 (superclass) 時,則用 super.super.addCard() 。 super() 則是指父類別的建構子。 super(600,400,1) 為 World 的建構子,可查 World 的 API 文件說明。
48.
步驟五:覆寫 addCard() 方法 /**
* 暫存區的撲克牌疊。 */ public class WorkingPile extends Pile { /** * 加一張撲克牌。覆寫(蓋掉)繼承的方法。 * * @param card 要加上去的撲克牌 */ public void addCard(Card card) { super.addCard(card); // 把新加上的牌放下面一點,露出前面的牌。 card.setLocation(card.getX(), card.getY() + (getSize() - 1) * 16); } }
49.
步驟五:覆寫 addCard() 方法
50.
中場休息 歡迎提出問題
Baixar agora