from tkinter import Tk, Label, BOTH, Frame
import threading


class Space:
    def __init__(self):
        self.max_width = 500
        self.max_height = 500


class Bullet(Label):
    def __init__(self, x, y, space):
        self.space = space
        self.bullet_timer = 0.01
        self.bullet_indicator = "."
        Label.__init__(self, text=self.bullet_indicator)
        self.pack()
        process = threading.Thread(target=self.place_bullet(x=x, y=y))
        process.start()

    def place_bullet(self, x, y):
        if y > 0:
            y -= 1
            self.place(x=x, y=y)
            process = threading.Timer(self.bullet_timer, self.place_bullet, [x, y])
            process.start()
        else:
            y += self.space.max_height
            self.place(x=x, y=y)
            process = threading.Timer(self.bullet_timer, self.place_bullet, [x, y])
            process.start()


class SpaceShip(Label):
    def __init__(self, space):
        self.ship_indicator = ","
        Label.__init__(self, text=self.ship_indicator)
        # initial coordinates
        self.space = space
        self.x = space.max_width/2
        self.y = space.max_height/2
        self.pack()
        self.place_ship()
        self.life = 100
        self.bullet_count = 3

    def left_key(self, event):
        self.x -= 10
        self.place_ship()

    def right_key(self, event):
        self.x += 10
        self.place_ship()

    def up_key(self, event):
        self.y -= 10
        self.place_ship()

    def down_key(self, event):
        self.y += 10
        self.place_ship()

    def space_key(self, event):
        self.shoot()

    def hit(self, object):
        pass

    def place_ship(self):
        if self.x > self.space.max_width:
            self.x -= self.space.max_width
        if self.x < 0:
            self.x += self.space.max_width
        if self.y > self.space.max_height:
            self.y -= self.space.max_height
        if self.y < 0:
            self.y += self.space.max_height
        self.place(x=self.x, y=self.y)

    def shoot(self):
        if self.bullet_count > 0:
            Bullet(x=self.x, y=self.y, space=self.space)
            self.bullet_count -= 1


class DummyGame(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)

        # Set space ship.
        self.space = Space()
        self.space_ship = SpaceShip(space=self.space)
        parent.bind('<Left>', self.space_ship.left_key)
        parent.bind('<Right>', self.space_ship.right_key)
        parent.bind('<Up>', self.space_ship.up_key)
        parent.bind('<Down>', self.space_ship.down_key)
        parent.bind('<space>', self.space_ship.space_key)

        # Set game window arguments.
        self.parent = parent
        self.pack(fill=BOTH, expand=1)
        self.set_title()

    def set_title(self):
        self.parent.title("Dummy Ship Game")



            

def main():
    root = Tk()
    root.geometry("500x500+300+300")
    app = DummyGame(parent=root)
    app.mainloop() 
    
if __name__ == '__main__':
    main()
    


@@ -304,17 +304,17 @@
 ator = %22
-.
+%60
 %22%0A      
@@ -1243,32 +1243,62 @@
 00%0A        self.
+_observers = %5B%5D%0A        self._
 bullet_count = 3
@@ -1296,17 +1296,17 @@
 count = 
-3
+0
 %0A%0A    de
@@ -2226,107 +2226,608 @@
 unt 
--= 1%0A%0A%0Aclass DummyGame(Frame):%0A    def __init__(self, parent):%0A        Frame.__init__(self, parent)
+= -1%0A%0A    def get_bullet_count(self):%0A        return self._bullet_count%0A%0A    def set_bullet_count(self, value):%0A        self._bullet_count += value%0A        for callback in self._observers:%0A            callback(self._bullet_count)%0A%0A    bullet_count = property(get_bullet_count, set_bullet_count)%0A%0A    def bind_to(self, callback):%0A        self._observers.append(callback)%0A%0A%0Aclass DummyGame(Frame):%0A    def __init__(self, parent):%0A        Frame.__init__(self, parent)%0A%0A        # Set game window arguments.%0A        self.parent = parent%0A        self.pack(fill=BOTH, expand=1)%0A        self.bullet_count = 0
 %0A%0A  
@@ -2925,32 +2925,122 @@
 ace=self.space)%0A
+        self.space_ship.bind_to(self.set_title)%0A        self.space_ship.bullet_count = 3%0A%0A
         parent.b
@@ -3312,69 +3312,67 @@
     
-    # Set game window arguments.%0A        self.parent = pare
+def set_title(self, bullet_count):%0A        if bullet_cou
 nt
+:
 %0A   
@@ -3380,150 +3380,127 @@
     
-self.pack(fill=BOTH, expand=1)%0A        self.set_title()%0A%0A    def set_title(self):%0A        self.parent.title(%22Dummy Ship Game%22)%0A%0A%0A%0A            
+    self.bullet_count = bullet_count%0A        self.parent.title(%22Dummy Space Ship - Bullet: %22 + str(self.bullet_count))%0A
 %0A%0Ade
@@ -3657,15 +3657,10 @@
   main()
-%0A    
 %0A%0A

Add bullet counter to window title.