Welcome to Tiny Blog

【第九创意组文章推送】游戏相关开发准备-面向对象的概念性说明

前言:本文仅仅是对OOP(面向对象)的概念性说明,不保证严谨性,不保证全面性,目的是为了让没有编程基础的人对OOP有个大概印象。

一。简单的比喻

如果把一个软件、游戏比作成一个不停运作的工厂,那玩家就是大老板,负责告诉这个工厂顾客想要什么(输入),然后检查成品(输出)。可惜大老板终究是大老板,不知道怎么干活,工厂里具体的指挥还是得靠经理(开发者/程序员)。

显然,这种高科技的工厂干的事情不可能是几千年前那种简单的手工劳动,是很多部分结合在一起的,那我们就可以把这个工厂分成很多小组,每组负责一块,比如这一组专门负责显示图片(图像管理),这一组负责收集大老板说的话(输入管理),另外一组负责放大喇叭(音乐/音效管理)。如果这个小组已经准备好了,那么他们要提交给经理一张表(成员表),上面写了他们这个组能干哪些事情、能告诉经理哪些数据。经理在管理工作的时候只需要按照这个表来告诉小组它们需要干什么,具体这个小组怎么干的,经理不需要知道。

这里我们要引入一个很重要的概念,黑箱。想必大家对这个词早有耳闻。简单说一下,计算机中的黑箱就是类似于具有输入洞和输出洞的一个箱子,但是它是黑的,里面有啥别人都不知道,其实也不需要知道,别人要关注的只是箱子上对这个箱子用法的说明而已。看看,是不是上面的小组很像?

所以游戏开发并不是什么需要高技术的东西,很多东西都是现成的,你想要显示图片,就告诉游戏引擎一声,你想要显示个自定义的窗口,就可以找现成的或者自己写一个,然后只管用就好了。OOP对于这种比较大型的开发提升了很多效率。

 

二。具体点的例子?

#—————————————————————

# ● 开始处理

#—————————————————————

def start

super

SceneManager.clear

Graphics.freeze

create_background

create_foreground

create_command_window

play_title_music

end

引自 RPG Maker VXAce- Scene_Title

这一段是Scene_Title的核心,一句一句来说,就是它先告诉场景管理者(SceneManager)清空其他的场景信息,然后告诉游戏引擎冻结画面(Graphics.freeze),之后就是设置背景(一个小组),设置前景(一个小组),设置命令窗(一个小组),顺便告诉音效组放一下标题背景音乐。

可以看到这段代码(语言是Ruby)基本不涉及什么复杂语法,只是非常简单的一步一步来,按照其他组给的使用方法来一个一个用,要是在以前的面向过程时代,这一部分的工作可就麻烦咯。

 

三。准确点的解释

虽然说OOP的核心是“万物皆对象”,但我这里还是简单介绍一下常用的对象概念——类(class)好了。所谓类,定义上说是 定义了一组数据和对这组数据的操作方法的抽象数据结构。 <_<这样说是不是很迷?所以说,用上面提到的黑箱就可以解释了,类就是一种黑箱,你可以让它干各种各样的事情,而不需要知道它是怎么干的。

 

结尾:感觉说了半天还是说得不明不白的,希望对大家理解对象有帮助。下一次我会说一些有关类的定义及继承方面的东西,当然,如果有下一次的话。

Mon Dec 08 2014 18:03:44 GMT+0000 (UTC)

head icon

Yezersky

23333333

Wed Dec 10 2014 11:43:46 GMT+0000 (UTC)

head icon

Kan Xuan

66666666666

Wed Dec 10 2014 16:51:02 GMT+0000 (UTC)

head icon

Yezersky

I agree with you!

Wed Dec 10 2014 16:59:05 GMT+0000 (UTC)

head icon

Test

TEST

Thu Dec 11 2014 06:13:32 GMT+0000 (UTC)

head icon

Yeah

啦啦啦

Thu Dec 11 2014 06:44:06 GMT+0000 (UTC)

head icon

2333

嘿嘿

Thu Dec 11 2014 07:38:04 GMT+0000 (UTC)

head icon

456

23333333

Thu Dec 11 2014 10:29:13 GMT+0000 (UTC)

head icon

Jess

It’s perfect time to make a few plans for the long run and it is time to be happy. I’ve learn this post and if I could I wish to counsel you few attention-grabbing things or tips. Perhaps you could write next articles regarding this article. I want to learn even more issues approximately it! Ahaa, its good conversation on the topic of this piece of writing here at this webpage, I have read all that, so at this time me also commenting at this place. I could not resist commenting. Perfectly written! http://apple.com

Fri Aug 23 2019 10:11:18 GMT+0000 (UTC)

head icon

Koby

I simply couldn't go away your web site prior to suggesting that I actually loved the usual information an individual provide in your visitors? Is going to be back often in order to check up on new posts Ahaa, its pleasant conversation on the topic of this article here at this webpage, I have read all that, so now me also commenting at this place. I am sure this paragraph has touched all the internet users, its really really nice post on building up new website. http://www.cspan.net/

Fri Aug 23 2019 10:41:32 GMT+0000 (UTC)

head icon

Rodger

I could not refrain from commenting. Exceptionally well written! I've been browsing online more than three hours today, yet I by no means discovered any attention-grabbing article like yours. It's lovely price sufficient for me. Personally, if all web owners and bloggers made excellent content as you probably did, the net will likely be a lot more useful than ever before. Way cool! Some very valid points! I appreciate you penning this article and the rest of the website is really good. http://Foxnews.org/

Thu Aug 29 2019 04:42:16 GMT+0000 (UTC)

head icon

Yolanda

Hi would you mind letting me know which web host you're utilizing? I've loaded your blog in 3 completely different web browsers and I must say this blog loads a lot faster then most. Can you suggest a good internet hosting provider at a fair price? Thank you, I appreciate it! I’ll right away clutch your rss feed as I can’t find your e-mail subscription hyperlink or newsletter service. Do you’ve any? Kindly permit me recognise so that I could subscribe. Thanks. I have been browsing online more than 4 hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. Personally, if all webmasters and bloggers made good content as you did, the web will be much more useful than ever before. http://house.com

Thu Aug 29 2019 13:03:28 GMT+0000 (UTC)

head icon

Parthenia

I'll right away grab your rss feed as I can not to find your e-mail subscription hyperlink or e-newsletter service. Do you have any? Please allow me realize so that I may subscribe. Thanks. Everyone loves what you guys tend to be up too. This kind of clever work and coverage! Keep up the excellent works guys I've included you guys to my own blogroll. I am sure this article has touched all the internet viewers, its really really pleasant piece of writing on building up new webpage. http://Marketing.com

Sun Sep 01 2019 00:16:52 GMT+0000 (UTC)

head icon

Aisha

I truly love your website.. Great colors & theme. Did you create this amazing site yourself? Please reply back as I'm trying to create my own personal website and would like to learn where you got this from or exactly what the theme is named. Thanks! There's definately a great deal to learn about this issue. I love all the points you've made. I am sure this paragraph has touched all the internet viewers, its really really fastidious paragraph on building up new webpage. http://marketing.com/

Mon Sep 02 2019 06:24:04 GMT+0000 (UTC)

head icon

Penny

I could not refrain from commenting. Exceptionally well written! I am sure this post has touched all the internet visitors, its really really pleasant piece of writing on building up new blog. I seriously love your blog.. Great colors & theme. Did you make this website yourself? Please reply back as I'm looking to create my own blog and want to learn where you got this from or what the theme is called. Appreciate it! http://marketing.com/

Tue Sep 03 2019 00:01:06 GMT+0000 (UTC)

Recent posts