如何为控件设置值? [英] how do I set a value to controls?

查看:106
本文介绍了如何为控件设置值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为蛇游戏进行测试.为了对蛇产生身体效果,我想为吃完该点后获得的每个身体分配一个值.例如,我吃了一点我获得了一个身体,该身体被分配了一个值,例如1,2,3,依此类推.然后,我要使新获得的身体的值小于其自身的值1.因此,这有望给它带来典型蛇游戏所具有的效果.有人知道该怎么做吗?

注意:我没有使用XNA

谢谢.

Hi, I''m working on a test for a snake game. To make the body effect for the snake I want to assign a value for every body gained after eating the point. For example I eat a point I gain a body, that body is assigned a value like 1,2,3 and so forth. Then I want to make the newly gained body follow the value 1 less then it''s own. So this hopefully gives it the effects that a typical snake game has. Anyone knows how to do this?

NOTE: I''m not using XNA

thanks.

推荐答案

有很多解决此问题的方法.

您想让它简单易懂!

尝试先编写伪代码,然后在纸上进行遍历,然后再进行编码,以查看是否真正了解它的工作原理.如果您的伪代码不起作用,则将其清除,直到在纸上起作用为止.然后,一旦您在纸上有了一个清晰的了解,那么您将在编写实际代码时有一个更好的主意.

*注意*如果您的伪代码是错误的,那么您的实际代码也将是错误的!

因此,请花点时间首先完全理解问题.

---

尝试定义如下问题:

1.仅允许4个方向,以保持简单.左,右,上和下,分别指定为L,R,U和D.

2.尾巴没有字母,因为它只跟在后面.

3.如果您只是向左移动,您将无法立即向右走,因为您会撞到身体下一部分.从右到左,从上到下,从上到下也是如此.

4.在字符串中使用简单的字母数组.例如,对于路径的前4个部分使用"ULDR".

5.将Snakes的长度限制为50,这样您的字符串最多只能包含50个字符.

然后,只需沿下一个方向(如左")移动头部即可.然后按如下所示更新您的字符串:新方向字符串中的第一个字符为"L",然后说前面的4个方向为"ULDR",因此您可以将字符串中的这1个字符中的每个字符向右移,然后删除最后一个字符,然后您将把4个位置更新为"LULD".

最后,您将使用从1到最后一个位置的循环"来减少1.(或者,您不需要在移动字符串上使用-1 ...您将需要自行确定!)

或至少这是一种想象的方式...最后,您将不得不对该程序进行编码.

另一个好方法是查找现有的Snake程序,看看它们是如何做的,以便您可以学习新知识!

享受吧!

Bill G.
计算机程序员/系统分析师/高级软件系统工程师,超过34年.
There are many solutions to this problem.

You want to keep it simple and easy to understand!

Try writing the pseudo code first then walk through it on paper before you code it to see if you really understand how it works. If your pseudo code does not work, then clean it up until it does work on paper. Then once you have a clear understanding on paper then you will have a better idea how to do it when you write the actual code.

* Note * If your pseudo code is wrong, then your actual code will be wrong too!

So take your time to understand the problem fully first.

---

Try defining the problem such as this:

1. Keep it simple by only allowing 4 directions. Left, Right, Up, and Down which would be designated as L, R, U, and D respectively.

2. The tail would not have a letter since it is only following.

3. If you just moved left you cannot immediately go right because you would bump into your next segment of the body part. Same goes for right to left, up to down, and down to up.

4. Use a simple array of letters in a string. Such as "ULDR" for the first 4 parts of the trail for example.

5. Limit the Snakes'' length to say 50 so your character string would only allow 50 characters maximum.

Then it is just a matter of moving the head in the next direction such as Left. Then updating your character string as follows: First character in the New Direction String would be "L" then say that the previous 4 directions were "ULDR" so you would shift each one of those 1 character to the right in your character string then dropping the last character which then you would update the 4 positions to "LULD".

Lastly you would use a "loop" from 1 to last position to move less 1. (Or perchance you wouldn''t need to use -1 on the move string... You will have to determine this yourself!)

Or at least that is one way to imagine doing it... Lastly you would then have to code the program.

Another good way would be to FIND an existing Snake Program and see how they did it so that you can learn something new!

Enjoy!

Bill G.
Computer Programmer / Systems Analyst / Senior Software Systems Engineer for over 34 years.


这篇关于如何为控件设置值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆