text-based

Python: How to end a while loop while it is running if the while condition changes during the loop?

喜夏-厌秋 提交于 2020-01-22 02:06:55
问题 I need some help with code in a text based game I am trying to make. My game uses health, and the code starts off with "while health>0:", and in another point in the game, when health eventually =0, the loop still continues. How do I make the loop end when health=0, without finishing the whole loop. Here is an example: health=100 while health>0: print("You got attacked") health=0 print("test") Should the code not be stopping when health=0, and not print "test"? How to I get it to stop when

How do I get realtime keyboard input in Python?

こ雲淡風輕ζ 提交于 2020-01-21 12:14:06
问题 Is this possible? Every answer I have looked at isn't what I want. What I do though is something like in omega-rpg (which is an awesome little text-based debian rpg), but in Python instead of C. I have poked around and found some things, but nothing that's relevant to what I'm doing. Is it just easier to use raw_input() / input , or would it be more efficient to use some kind of API for doing so? TO CLEAR UP: I need a system of realtime keyboard input in Python, but I don't know whether it's

Want to print text char by char for my textbased game, but it prints out the whole text after the summed delay

混江龙づ霸主 提交于 2019-12-24 11:35:52
问题 Im trying to print out some text char by char with some delay, the problem is that it waits and waits and then prints the whole sentence out. It's like it's printing char by char to a string and then printing that string out once its finished: public static void printWithDelay(String data, TimeUnit unit, long delay) throws InterruptedException { for (char ch : data.toCharArray()) { System.out.print(ch); unit.sleep(delay); } } please help (: 回答1: Why don't you use Thread.sleep()? import java

Converting bytes retrieved over a php socket to a integer

ぃ、小莉子 提交于 2019-12-24 07:35:28
问题 I am using the netty API to create a Java server which sends if a client programm sends anything to the server a number like 5. It is a integer with 4 bytes. I think it should be the same like writing an integer into an OutputStream. So I want to receive the integer now by php. But if I call socket_read it outputs nothing helpfull because it does not convert the 4 bytes into a integer. It just uses this as text. If I send a char it works so I need a way in php to convert it. Or would it be

Converting bytes retrieved over a php socket to a integer

邮差的信 提交于 2019-12-24 07:34:46
问题 I am using the netty API to create a Java server which sends if a client programm sends anything to the server a number like 5. It is a integer with 4 bytes. I think it should be the same like writing an integer into an OutputStream. So I want to receive the integer now by php. But if I call socket_read it outputs nothing helpfull because it does not convert the 4 bytes into a integer. It just uses this as text. If I send a char it works so I need a way in php to convert it. Or would it be

while loop not ending when required

房东的猫 提交于 2019-12-02 18:46:41
问题 So some background information, I'm new to programming and am still learning, so I apologize for my trivial error making. I am making my own text based game just to further practice etc. Here is the link to everything on dropbox for more context: https://www.dropbox.com/sh/uxy7vafzt3fwikf/B-FQ3VXfsR I am currently trying to implement the combat system for my game, and I am running into the issue of the combat sequence not ending when required. The 'combat sequence' is a while loop as follows:

while loop not ending when required

早过忘川 提交于 2019-12-02 08:19:35
So some background information, I'm new to programming and am still learning, so I apologize for my trivial error making. I am making my own text based game just to further practice etc. Here is the link to everything on dropbox for more context: https://www.dropbox.com/sh/uxy7vafzt3fwikf/B-FQ3VXfsR I am currently trying to implement the combat system for my game, and I am running into the issue of the combat sequence not ending when required. The 'combat sequence' is a while loop as follows: public void startCombat() { inCombat = true; while(inCombat != false)// && herohealth > 0 &&

How do I get realtime keyboard input in Python?

雨燕双飞 提交于 2019-12-01 21:40:43
Is this possible? Every answer I have looked at isn't what I want. What I do though is something like in omega-rpg (which is an awesome little text-based debian rpg), but in Python instead of C. I have poked around and found some things, but nothing that's relevant to what I'm doing. Is it just easier to use raw_input() / input , or would it be more efficient to use some kind of API for doing so? TO CLEAR UP: I need a system of realtime keyboard input in Python, but I don't know whether it's easier to use an API or just raw_input() / input() . If it IS better to use an API, which is the best