昆虫生命模拟(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/insect-life-simulation-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 3 分钟阅读 - 1384 个词 阅读量 0昆虫生命模拟(译文)
原文地址:https://www.codeproject.com/Articles/5757/Insect-Life-Simulation
原文作者:ashvin
译文由本站 robot-v1.0 翻译
前言
An article on insect life simulation.
关于昆虫生命模拟的文章.
介绍(Introduction)
该程序模拟昆虫(错误或病毒)的生命周期.所有昆虫都有一定的生命周期.他们出生后,将终其一生,或者由于某种原因而在其生命前死亡.这是一个使用某些生命规则的昆虫生命周期模拟程序.规则在规则部分列出.该程序在C#中实现.(This program simulates Insect (Bugs or Virus) life cycle. All Insects have some life cycle. They are born, then live for their life period, or die before their life period because of some reason. Here is one Insect life cycle simulation program using some life rules. The rules are listed in the rule section. The program is implemented in C#.)
怎么运行的(How it works)
一旦运行演示程序并按Insect » Draw菜单,它将在屏幕上创建所有可能的绿色框.每个框代表昆虫.绿色表示昆虫已经死亡,红色表示昆虫还活着. (我选择红色作为实时状态,是因为最初我确定标题为" Virus Life Simulation",而病毒在实时状态下并不好,但是后来我更改了标题,以为" Virus"一词总是给人以计算机病毒的印象. (供程序员使用.)您可以通过单击来更改昆虫的状态.如果使一些彼此靠近的昆虫活着,则会生成遵循生命周期规则的模式.(Once you will run demo program and press Insect»Draw menu, it will create all possible green boxes on screen. Each box represents Insects. Green color indicates Insect is dead and Red color indicates Insect is alive. (I chose red color for live status because initially I decided the title “Virus Life simulation”, and virus are not good whenever they are live, but then I changed the title thinking that the word “Virus” always makes the impression of computer virus for programmers.) You can change the state of an Insect by clicking on it. If you make some Insects live which are near of each other it will generate a pattern followed by life cycle rule.)
生命周期规则.(Life cycle rule.)
- 昆虫将永远死于生命的尽头.使用寿命为10秒(硬编码以获得良好的图案).(Insect will always die on end of life. End of life is 10 second (hard coded to get good pattern).)
- 如果有两个昆虫活着,则会导致新的昆虫诞生.(If two Insects are live then it will result in new Insect birth.)
- 如果附近住着三个或三个以上的昆虫,那么一个昆虫会因人群过多而死亡.(If three or more Insects live near, then one Insect will die because of over crowd.)
内存需求.(Memory requirement.)
该演示程序为每个昆虫绘制了16 * 16像素的可能框.每个昆虫都是(This demo program draws 1616 pixel possible box for each Insect. Each Insect is an instance of the*) InsectControl
类,它保存内存.在我的计算机上,我的屏幕分辨率为1152 * 864,这使我可以创建约4000个昆虫,并占用22MB内存.因此,内存需求取决于此应用程序的屏幕分辨率.(*class and it holds memory. In my computer, I have 1152*864 screen resolution, which allows me to create ~ 4000 Insects and takes 22MB memory. So, memory requirement depends on screen resolution for this application.*)
代码说明.(Code description.)
我创建了一个名为(I created a user control called) InsectControl
.此控件有一个间隔为1秒的计时器,用于更新昆虫的状态.每个昆虫都拥有有关其子代的信息.每个昆虫最多可育有8个孩子(见图).拐角处的昆虫会少生一些孩子.每隔一秒钟,每个昆虫都会检查其子状态,并按照上述规则确定其自身状态.(. This control has a timer with 1 sec interval to update the status of the Insect. Each Insect holds information about its children. Each Insect will have maximum 8 children (see in figure). Insects which are on the corner will have less children. Every second, each Insect will check their child status and follow the above rules to decide its own status.)
已知的问题:(Known Issues:)
- 在完成所有昆虫创建之前,无法接受任何命令.(Cannot accept any command until all Insect creation is finished.)
- 最后,它不会清除应用程序实例,因此请使用任务管理器对其进行清理.(On close, it is not clearing instance of application, so clean it using task manager.) 享受模拟.(Enjoy simulation.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ C# VC7.1 Win2K WinXP Win2003 .NET1.1 Visual-Studio VS.NET2003 Dev 新闻 翻译