桥梁设计游戏(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/a-bridge-design-game-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 5 分钟阅读 - 2397 个词 阅读量 0桥梁设计游戏(译文)
原文地址:https://www.codeproject.com/Articles/16867/A-Bridge-Design-Game
原文作者:fdachille
译文由本站 robot-v1.0 翻译
前言
An article describing the design and techniques used to develop a bridge design game.
一篇文章,描述用于开发桥梁设计游戏的设计和技术.
介绍(Introduction)
本文介绍了一个小型但可扩展的桥梁设计游戏的开发.它给用户带来了一系列设计挑战,要求他们在预算紧张的情况下建造越来越大的桥梁,跨越更长的距离.设计人员必须使用诸如梁,电缆和销钉之类的小型结构部件来创建桥梁.桥梁必须使用有限数量的支撑点来跨越间隙.为了向用户提供提示并使其在视觉上更令人愉悦,可以为每个拼图指定背景图片.(This article describes the development of a small, but extensible bridge design game. It presents the user with a series of design challenges that require them to build increasingly larger bridges that span longer distances under a tight budget. The designer must create the bridge out of small structural components such as beams, cables, and pins. The bridge must span a gap using a limited number of support points. To provide a hint to the user and make it more visually pleasing, a background picture can be specified for each puzzle.)
背景(Background)
有一些桥牌设计游戏可以提供一组免费试用级别.这些游戏很有趣,但是您需要支付额外的费用,我更愿意自己编写软件.另外,该项目使我有机会试用.NET 2.0中的新功能,例如泛型和新功能.(There are a few bridge design games available that are provided with a set of free trial levels. These games are fun, but you have to pay for additional levels, and I prefer the challenge of writing software myself. Also, this project gave me a chance to try out the new features in .NET 2.0 such as generics and the new) TabStrip
UI控件.(UI control.)
使用代码(Using the code)
提供完整的源代码,作为您自己修改或版本的起点.我想在其他人的帮助下扩大它.(The entire source code is provided as a starting point for your own modifications or versions of it. I would like to expand it with the help of others' contributions.)
设计要素(Elements of the design)
该项目中使用的第一个设计元素是弹簧.模拟中的每个结构元素都是弹簧或销钉(用于连接弹簧).钢只是一个非常非常硬的弹簧(它具有很高的弹簧常数).电缆是弹簧的另一种形式,只能支撑张力.正如我的大学物理教授打趣的那样:“你不能用力推.“因此,我首先创建了(The first design element used in this project is the springs. Every structural element in the simulation is either a spring or a pin (used to connect springs). Steel is just a very, very stiff spring (it has a high spring constant). Cable is another form of spring that can only support tension. As my college Physics professor quipped, “You can’t push on a rope.” So I started by creating the) Spring
类,为其提供一些属性,并为其定义一些方法.然后,我将其子类化以提供用于(class, giving it some properties, and defining a few methods for it. Then, I subclassed it to provide the concrete classes for) LightSteel
,(,) HeavySteel
和(, and) Cable
:(:)
的一些更有趣的属性(Some of the more interesting properties of the) Spring
对象在以下代码中定义.(object are defined in the following code.)
public virtual float MaxSpringLength { get { return 90.0f; } }
public virtual float MaximumForce { get { return 1.0f; } }
public virtual float CostPerFoot { get { return 10.0f; } }
public virtual float SpringConstant { get { return 5.0f; } }
public virtual float WeightPerFoot { get { return 1.0f; } }
这些属性都是虚拟的,可以在子类中覆盖它们以专门化不同建筑组件的行为.(Each of these properties, being virtual, can be overridden in subclasses to specialize the behavior of the different building components.) HeavySteel
,例如,类似于(, for instance, is similar to) LightSteel
除了比较重(更高(except that it is heavier (higher) WeightPerFoot
),更强(更高(), stronger (higher) SpringConstant
),且价格较高(较高(), and more expensive (higher) CostPerFoot
).().)
根据需要创建销以提供弹簧之间的连接点.每个引脚只是游戏板上的2D位置.它被定义为2D点的通用集合,如下所示:(Pins are created as needed to provide connection points between springs. Each pin is simply a 2D location on the game board. It is defined as a generic collection of 2D points as follows:)
System.Collections.Generic.List< System.Drawing.PointF > m_pins;
整个桥都存储在(The entire bridge is stored in the) Bridge
类.值得注意的是,它包含销的集合,弹簧的集合,当前的相互作用模式和锚定销.锚定销通过提供环境中唯一的坚固连接点来帮助定义难题.无论有多少其他弹簧连接到固定点,它都可以支撑其重量而不会移动.的(class. It contains, notably, the collection of pins, the collection of springs, the current interaction mode, and the anchor pins. The anchor pins help to define the puzzle problem by providing the only solid connection points in the environment. No matter how many other springs are connected to an anchor point, it supports their weight without moving. The) Bridge
该类还支持以下方法:(class also supports methods for:)
- 清除桥结构(Clearing the bridge structure)
- 加载新拼图(Loading a new puzzle)
- 在结构上添加新的弹簧或销钉(Adding a new spring or pin to the structure)
- 从结构上卸下弹簧或销钉(Removing a spring or pin from the structure)
- 计算结构成本(Calculating the cost of a structure)
- 计算结构中的力(Calculating the forces in the structure)
- 偏转桥(移动销的位置)(Deflecting the bridge (moving the pin locations))
- 画桥(Painting the bridge)
各种拼图级别均受(The various puzzle levels are supported by the) Level
类.它们由XML定义,并存储在磁盘上某个文件夹中的级别文件夹中.这样,用户只需添加关卡文件夹即可定义自己的关卡.为了使此过程更加方便,有一个简单的关卡编辑器可以管理关卡文件夹的创建.每个级别定义锚点列表,背景图像和预算(允许的材料总成本).(class. They are defined by XML, and stored in a level folder in a certain folder on disk. This allows the user to define their own levels just by adding a level folder. To make this process more convenient, there is a simple level editor that manages the creation of the level folder. Each level defines the list of anchor points, the background image, and the budget (the total cost of materials allowed).)
模拟(Simulation)
物理模拟也许是最有趣的部分.它在单独的线程中发生,以便允许图形更新(交互式用户体验)和用户对仿真过程的控制.主仿真循环遵循此迭代算法,以便对重量和重力提供动态响应:(The physical simulation is perhaps the most interesting part. It occurs in a separate thread in order to allow graphical updates (an interactive user experience) and user control of the simulation process. The main simulation loop follows this iterative algorithm in order to provide a dynamic response to the weights and gravity:)
white ( simulating )
calculate all the forces for all the springs
find the maximum force
scale all the forces to prevent moving to quickly or too slowly
apply the forces to all the pins to move them
未来的计划(Future plans)
该项目的计划是根据读者的评论进一步完善游戏的设计,然后提供一个中央在线位置,用户可以在其中上传和下载游戏关卡.为了使其易于使用,应将其集成到用户界面中,使其更加有趣和动态.另一个有趣的事情是允许可能是可定义的可扩展组件,尤其是对于每个级别.(The plan for this project is to refine the design of the game more according to reader comments, then provide a central online location where users can upload and download game levels. To make it easy, it should be integrated into the user interface, making it more fun and dynamic. Another interesting thing would be to allow extensible components, perhaps definable, especially for each level.)
历史(History)
- 2006年12月22日-首次提交给CodeProject.(12/22/06 - Initial submission to CodeProject.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C# WinXP Windows .NET .NET2.0 Visual-Studio GDI+ VS2005 Dev 新闻 翻译