Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

It may be a fun game...But What Do I Have to Improve this code ?? (Sorry, I'm not a American...)

+8 votes
asked Apr 23, 2023 by 쫄라맨과 초록 종이 (240 points)

# Jumping Ball

import time, os, sys, threading


print("Please Enter the Ball's form")

game_over_text = "GAME OVER"

wall = '#'*32
guide = '#' + ' '*30 + '#'

rock = 'A'
ball = sys.stdin.readline(1)
ball_x = 5
ball_y = 9
rock1_x = 30           
rock2_x = 42           
score = 0
jump = False
jump_count = 0
end = False

def clear():
    os.system('cls' if os.name == 'ct' else 'clear')
    
def set():
    print(wall)
    print('#'+' score: ',end='')
    str_score = str(score)
    score_len = len(str_score)
    print(  str_score + ' ' * ( 30 - ( 8 + score_len ) ) + '#' )
    for yy in range(2,10):      
        for xx in range(0, len(guide)): #
            
            if yy == ball_y and xx == ball_x :
                print(ball, end='')
                
            elif ( xx == rock1_x or xx == rock2_x ) and yy == 9 :
                print(rock, end='')
                
            else :
                print(guide[xx],end='')
        print()
    print(wall)
    
class SYSTEM(threading.Thread):
    
    def __init__(self, var):
        threading.Thread.__init__(self)
        self.put = var
        
    def run(self):
        global score, rock1_x, rock2_x, ball_x, ball_y, jump, jump_count, end
        if self.put :
            while 1:
                input('>>>')
                jump = True
        
        else :
            while 1:
                set()
                
                if jump :
                    if jump_count <= 5:
                        jump_count += 1
                        ball_y = 4
                        
                    else :
                        jump_count = 0
                        jump = False
                        ball_y = 9
                        
                elif rock1_x == ball_x or rock1_x == ball_x:
                    end = True
                    print(game_over_text)
                    print('\nYou scored %d points' % score)
                    break
                
                if rock1_x == 1:
                    rock1_x = 30
                    score += 1
                    
                if rock2_x == 1:
                    rock2_x = 30
                    score += 1
                
                rock1_x -= 1    
                rock2_x -= 1
                
                time.sleep(0.1)
                clear()
    
a = SYSTEM(True)  
b = SYSTEM(False)       

b.start()
a.start()

5 Answers

0 votes
answered Apr 24, 2023 by WHITELIGHT UNSEEN (370 points)
lol i want to know how the game works
commented Apr 24, 2023 by Peter Minarik (88,520 points)
You have to jump over obstacles denoted by 'A' by pressing ENTER at the right time. The more you dodge the more score you get.
+1 vote
answered Apr 24, 2023 by Peter Minarik (88,520 points)

Here are some gameplay ideas

  • randomize the distance between the two rocks.
  • randomize how many rocks you have (1, 2, 3, etc)
  • with time, increase difficulty (more rocks, higher speed)
  • add double jump
  • add tree branches (or something in the air) that you're not supposed to hit. So jump over the rocks, but don't hit your head in the tree branches.
Here are some code ideas
  • use classes for encapsulation
  • move from "interactive console game" to Pygame or Unity (C#).
0 votes
answered Apr 24, 2023 by vansh (140 points)

print ball size 

mailand jump again and again

0 votes
answered May 19, 2023 by Eidnoxon (5,270 points)
For how long have you've been learning python? I have learnt python for a year, and I still don't understand this code! Impressive!
0 votes
answered May 20, 2023 by TAHA MOHAMMED ANSARI 160422735057 (140 points)
Now that was impressive. How long did it take you to successfully write and execute this code correcting the errors and all too?
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...