SlideShare a Scribd company logo
1 of 10
Refine my code 小结我的任务逻辑代码 by Phay Tsukiming Twitter:@phaytsukiming Gtalk/email:moonsolo@gmail.com
从需求说起 我们假设一个场景,有3个npc,king,princess, dragon, 玩家刚进场 1.骑士初来乍到,看谁都新鲜,和三个npc逐一对话, 公主:“龙要吃我” 恶龙:“我要吃她” 国王:“啊,你要救我的女儿吗?            1.愿意效劳             2.我还怕龙吃我呢
选择1 这时候,再和npc对话, 公主:“你是来救我的吗,英雄~~” 国王:“我的女儿,命好苦哇~~” 恶龙:“我晕,这国王都2到啥程度了,派你来救公主,这不小看哥么”–切入战斗
第一幕结束 任务,游戏里的一种状态,不同任务下相同实体会有不同的行为,对话自然也算—“多态” 我们就从公主开始说,
class Prince:     def chat(self, player):         self.say(player, "ah~help me") class Prince:     def chat(self, player):         if player.get_task()=="first_meet":             self.say(player, "oh~are your here to save my soul")         elif player.get_task()=="second_meet":             self.say(player, "oh~you need a sword, my hero")         elif player.get_task()=="beated_boss":             self.say(player, "will u marry me, my hero")             #...... 但是,好像这样写,似乎有点丑。。。。
Data/table-driven class Prince:     TaskChat = {         "first_meet":"oh~are your here to save my soul",         "second_meet":"oh~you need a sword, my hero",         "beated_boss":"will u marry me, my hero",         }     def chat(self, player):         self.say(player, self.TaskChat[player.get_task()]) Well, 静态对话满足了,如果动态数据,额。。。用lambda? ………… “first_meet”:(lambda data:”oh~are you here to save my soul, are you %s” % data), ……….. 如果点击了npc,以后有的要战斗,有的要发奖,有的要播动画
Responsbility Driven class Prince:     def trigger(self, player):         player.get_task().princess_trigger(self, player) class FirstMeet:     def princess_trigger(self, player):         self.say(player, "oh~are you here to save my soul")         #blablabla...... 额。。。。这样只有公主,那老丈人会有意见,老丈人可是国王啊,还有各种七大姑八大姨,这样写内聚度会越来越低,所以我们放一个大招:
Responsbility Driven class Princess:     def trigger(self, player):         get_task_mod(player.get_task(), "Princess").trigger(player) class Princess:     def trigger(self, player):         self.say(player, "oh~are your here to save my soul") class King:     def trigger(self, player):         self.say(player, “I‘m so appreciated for you saving my daughter’s life”) 差不多了,但事件触发的管理方式,事件触发么。。
用一个简化到极致observer轻松搞定 class FirstMeet:     def acquired(self, player):         player.add_task("FirstMeet")         npc_trigger_mgr.add_listener(player, "princess", Princess) class NpcTriggerMgr:     def trigger(self, npc, player):         if npc.get_name() in player_trigger_dict[player.id]:             task_handle = player_trigger_dict[player.id]["princess"]             task_handle[npc.get_name()].trigger(player)     def add_listener(self, player, npc_name, class_handle):         player_trigger_dict[player.id]["princess"] = class_handle
Fin

More Related Content

Featured

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
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

Featured (20)

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...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

refine my code

  • 1. Refine my code 小结我的任务逻辑代码 by Phay Tsukiming Twitter:@phaytsukiming Gtalk/email:moonsolo@gmail.com
  • 2. 从需求说起 我们假设一个场景,有3个npc,king,princess, dragon, 玩家刚进场 1.骑士初来乍到,看谁都新鲜,和三个npc逐一对话, 公主:“龙要吃我” 恶龙:“我要吃她” 国王:“啊,你要救我的女儿吗? 1.愿意效劳 2.我还怕龙吃我呢
  • 3. 选择1 这时候,再和npc对话, 公主:“你是来救我的吗,英雄~~” 国王:“我的女儿,命好苦哇~~” 恶龙:“我晕,这国王都2到啥程度了,派你来救公主,这不小看哥么”–切入战斗
  • 5. class Prince: def chat(self, player): self.say(player, "ah~help me") class Prince: def chat(self, player): if player.get_task()=="first_meet": self.say(player, "oh~are your here to save my soul") elif player.get_task()=="second_meet": self.say(player, "oh~you need a sword, my hero") elif player.get_task()=="beated_boss": self.say(player, "will u marry me, my hero") #...... 但是,好像这样写,似乎有点丑。。。。
  • 6. Data/table-driven class Prince: TaskChat = { "first_meet":"oh~are your here to save my soul", "second_meet":"oh~you need a sword, my hero", "beated_boss":"will u marry me, my hero", } def chat(self, player): self.say(player, self.TaskChat[player.get_task()]) Well, 静态对话满足了,如果动态数据,额。。。用lambda? ………… “first_meet”:(lambda data:”oh~are you here to save my soul, are you %s” % data), ……….. 如果点击了npc,以后有的要战斗,有的要发奖,有的要播动画
  • 7. Responsbility Driven class Prince: def trigger(self, player): player.get_task().princess_trigger(self, player) class FirstMeet: def princess_trigger(self, player): self.say(player, "oh~are you here to save my soul") #blablabla...... 额。。。。这样只有公主,那老丈人会有意见,老丈人可是国王啊,还有各种七大姑八大姨,这样写内聚度会越来越低,所以我们放一个大招:
  • 8. Responsbility Driven class Princess: def trigger(self, player): get_task_mod(player.get_task(), "Princess").trigger(player) class Princess: def trigger(self, player): self.say(player, "oh~are your here to save my soul") class King: def trigger(self, player): self.say(player, “I‘m so appreciated for you saving my daughter’s life”) 差不多了,但事件触发的管理方式,事件触发么。。
  • 9. 用一个简化到极致observer轻松搞定 class FirstMeet: def acquired(self, player): player.add_task("FirstMeet") npc_trigger_mgr.add_listener(player, "princess", Princess) class NpcTriggerMgr: def trigger(self, npc, player): if npc.get_name() in player_trigger_dict[player.id]: task_handle = player_trigger_dict[player.id]["princess"] task_handle[npc.get_name()].trigger(player) def add_listener(self, player, npc_name, class_handle): player_trigger_dict[player.id]["princess"] = class_handle
  • 10. Fin