+ 1
what's wrong with my code?
22 odpowiedzi
+ 3
How about this?
https://code.sololearn.com/csUViD8yqD3N/?ref=app
Some typo error and floor division as suggested by other members here to get int instead of float values. See comments.
I slowed it down for debugging.Plus I am not a good player...
Never explored curses-based games. I also copy-pasted another version I found online. Seems easier to understand.
Copy-paste to Pydroid3 to play.
You cannot run this in Sololearn playground.
Lots of code cannot run in Sololearn.
https://code.sololearn.com/cgDhxzmR0s6y/?ref=app
+ 1
Switch the float for int
+ 1
Paul K Sadler
Yeah
+ 1
OK I'll try if it's work
+ 1
Bob_Li thanks it worked
0
I still don't get please do tell me more
0
Why is it not working?
0
If I do that the line 56 will be wrong how do I correct that?
0
You sit down and think it through. You can do it. Look at the error carefully. Look at the spec you are writing the code to match and refer to the python documentation.
0
OK thanks
0
You were helpful
0
You're welcome 😊
0
Mohadek
Hmmmm...
Before, You want to do?
0
Well int(12.0) is 12...
0
Bob_Li that's true the game runs but with no keyboard control and then exits after that
0
Men pythonda hakerlik qila olamanmi
0
After digging around, I saw a suggestion to try executing the python code in command prompt, not the idle shell. Make sure you installed windows-curses.
Yes, I can confirm this works.
This link:
https://www.devdungeon.com/content/curses-windows-python
As the topic is about curses and console games, here is an interesting module:
https://pypi.org/project/blessed/
Their version of snake game
https://github.com/jquast/blessed/blob/master/bin/worms.py
I installed it in Pydroid3 on my phone and ran the worms.py program.
Colors to blow your mind...😁
- 1
You have type errors, for example on line 20
w.addch(food[0], food[1], curses.ACS_PI)
food[0] and food[1] are floats from the math on the line above, but int's are expected. The errors in the console are valuable troubleshooting tools. It tells you what's not working.
At line 56 a similar issue exists.
- 1
When the program gets to line 19 sh=24 and sw=80
Line 19 does division on each, dividing by 2
24/2=12.0 80/2=40.0 <--those are floats not int's
If you do floor division // then the result is
24//2=12 and 80//2=40 <--both are int's
I have not sat down and examined if the code meets the requirements of your task. I am just telling you why the code fails at line 20. This will hopefully get you started down the right track.
- 1
How?