里面的调用方法不好吗? [英] calling method inside itself bad?

查看:87
本文介绍了里面的调用方法不好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在编写文字冒险游戏.在游戏开始时,将调用Menu(字符串选择,bool takeDump).有几种其他方法可以让用户遇到不同的场景,例如,遇到宠物小精灵等.如果用户死亡,那么他们将在Menu()处重新启动,这意味着将从自身内部再次调用它.有什么办法可以避免这种情况? 程序源

I've been coding a text adventure game. On game start, Menu(string Choice, bool takenDump) is called. There are several few other methods that have different scenarios that the user can run into, such as a pokemon encounter and such. If the user dies, then they restart at Menu(), meaning it is called again from within itself. Is there any way to avoid this? Source of program

推荐答案

只要有退出循环的条件,就没有问题.如果没有,则基本上是一个无限循环(直到发生StackoverflowException).

As long as there is a condition to exit the loop, there's no problem. If there's not, you basically have an endless loop (until a StackoverflowException occurs).

从纯粹的技术角度来看,只要在发生stackoverflowexception之前中断循环就没有问题.

From a pure technical point of view, there's no problem as long as you break the loop before a stackoverflowexception occurs.

这篇关于里面的调用方法不好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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