コード例 #1
0
    def append_wb(self, number):
        last_waffle = len(self.waffle_list)
        for i in range(0, 2* number, 2):
            w = Waffle(self.bottom_box, height=self.no_bits, width=1, grid=[last_waffle + i, 0])
            w.hide()
            w.when_clicked = self.process_waffle
            self.waffle_list.append(w)

            b = Box(self.bottom_box, grid=[i + 1, 0])
            b.hide()
            self.box_list.append(b)
コード例 #2
0
aiSearchLocations = []  # Locations ai will search
mHistory = "" #Stores ai missile attempts

#Windows and Boxes
battleBoard = App(title="Ship Shooter",width=700,height=700,layout="grid")
playerBoard = Box(battleBoard,layout="grid",grid=[0,0])
compBoard = Box(battleBoard,layout="grid",grid=[1,0])
textBoxes = Box(battleBoard,layout="grid",grid=[0,1],align='left')
missileBox = Box(battleBoard,layout="grid",grid=[0,2],align='right')
menubar = MenuBar(battleBoard,
                  toplevel=["Game"],
                  options=[
                      [ ["Easy", reInitialise], ["Normal", reInitialise], ["Hard", reInitialise] ]
                  ])

#Game boards for ships
playerWaffle = Waffle(playerBoard,height=10,width=10,dim=29,grid=[0,0],color="blue",command=pClicked)
computerWaffle = Waffle(compBoard,height=10,width=10,dim=29,grid=[0,0],color="aqua",command=cClicked)

#Text information
Text(textBoxes,text="Missiles remaining: ",size=18,color="blue",grid=[0,0],align='left')
playerText = Text(textBoxes,text="Players ship is at: ",size=18,color="blue",grid=[0,1],align='left')
missilesText = Text(textBoxes,text=missiles,size=18,grid=[1,0],color="blue")
compText = Text(textBoxes,text=compShip,size=18,color="green",grid=[0,2])
missileHistory = Text(textBoxes,text=mHistory,size=12,color="red",grid=[0,3])

#starting settings
computerWaffle.hide()

#Show game
battleBoard.display()
コード例 #3
0
    xTarget = random.randint(0, myWaffle.height - 1)
    yTarget = random.randint(0, myWaffle.width - 1)
    myWaffle.set_pixel(xTarget, yTarget, "red")
    start = time.time()
    print("Target is ", xTarget, yTarget)


def setDifficulty(d):
    if d == "Easy":
        myWaffle.height = 5
        myWaffle.width = 5
    elif d == "Medium":
        myWaffle.height = 10
        myWaffle.width = 10
    else:
        myWaffle.height = 20
        myWaffle.width = 20
    #Carry out action after 3 seconds
    myWaffle.show()
    myWaffle.after(300, pickPixel)


#Make a window
window1 = App(title="Waffle", width=600, height=600)
#Make a waffle and set properties
myWaffle = Waffle(window1, 20, 20, 20, 3, "red", command=clicked)
myWaffle.hide()
#Display options for game
gameOptions = Combo(window1, ["Easy", "Medium", "Hard"], command=setDifficulty)
#display the window
window1.display()