简体   繁体   English

如何在网络应用中构建游戏树

[英]How to build a game tree in a web app

OK - I've searched all over and can't find anything that really answers this: 好的-我到处搜索了,找不到任何能真正回答这个问题的内容:

I'm building a game which runs in the browser with HTML and Javascript. 我正在构建一个使用HTML和Javascript在浏览器中运行的游戏。

The game is a football/soccer game which unfolds through a series of user choices - eg 该游戏是橄榄球/足球游戏,它通过一系列用户选择进行展开-例如

"opponent slides in for a tackle" do you: “对手会滑入水中”是您:

a) dodge left b) stop running c) pass the ball a)躲闪b)停止奔跑c)传球

The game continues to unfold in this manner - divs are shown/hidden depending on buttons clicked. 游戏继续以这种方式展开-根据单击的按钮显示/隐藏div。

But this game is actually quite comprehensive - which means that the probability tree underpinning it is now very large (like 20 layers deep). 但是此游戏实际上非常全面-这意味着支撑它的概率树现在非常大(例如20层深度)。 I'm currently representing it in Excel - but then have to basically manually recreate it in HTML. 我目前在Excel中表示它-但随后必须基本上手动在HTML中重新创建它。 This is massively unwieldy. 这非常笨拙。

Is there a smarter way of doing this? 有更聪明的方法吗?

Ideally, I'd like to be able to make changes in Excel, and have them immediately take effect on the page - but the only way I can see that working is using the ActiveX object which comes with a whole host of issues I don't want to touch. 理想情况下,我希望能够在Excel中进行更改,并使它们立即在页面上生效-但我看到工作的唯一方法是使用ActiveX对象,该对象带有很多我不希望看到的问题。不想碰。

Should I resign myself to creating huge javascript arrays? 我应该辞职去创建巨大的JavaScript数组吗?

You can make some functions seperate from the game 'tree'. 您可以将某些功能与游戏“树”分开。 For example if you have buttons in HTML like 例如,如果您有类似HTML的按钮,

| | Dodge left | 道奇左| | | Stop Running | 停止运行| | | Pass the ball | 传球|

Clicking the first one would run the function dodgeLeft(); 单击第一个将运行函数dodgeLeft();

In the function you would calculate all sorts off outcomes which you can return as a JSON object from which you can go on to the next 'obstacle' in the game. 在该函数中,您将计算所有排序结果,这些结果可以作为JSON对象返回,从中可以继续进行游戏中的下一个“障碍”。

This way you can reuse 'actions' all over the place and the game 'tree' stays readable. 这样,您可以在各处重复使用“动作”,并且游戏“树”保持可读性。

Note that you can pass variables to each function to manipulate the outcome of it and take the reusable thing to a whole new level. 请注意,您可以将变量传递给每个函数以操纵其结果,并将可重用的事物提升到一个全新的水平。

Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM