2021년 파이썬 배울때 만든 게임입니다.
두더지잡기게임...업무시간에 심심하면 할까 만들었지만
사실 이것보단 웹서핑이 더 재밌네요 ㅋㅋ.

from tkinter import*
from random import*
NUM_MOLES=3
window=Tk()
window.title("쥐를잡자쥐를잡자찍찍찍")
moleFrame=Frame(window)
moleFrame.grid(row=0,column=0)
statusFrame=Frame(window)
statusFrame.grid(row=0,column=1)
hitsLabel=Label(statusFrame,text="0 히트")
hitsLabel.pack()
missedLabel=Label(statusFrame, text="0 놓침")
missedLabel.pack()
mole_image=PhotoImage(file="c:/mole.png",master=window)
no_mole_image=PhotoImage(file="c:/no_mole.png",master=window)
numHits=0
numMissed=0
def mole_hit(c) :
global numHits, numMissed, moleList, missedLabel, hitsLabel
if molesList[c]["text"] == "mole":
numHits +=1
hitsLabel["text"]=str(numHits) +"히트"
else :
numMissed +=1
missedLabel["text"] = str(numMissed)+"놓침"
molesList=[]
def init():
count=0
for r in range(NUM_MOLES) :
for c in range(NUM_MOLES) :
button = Button(moleFrame, command=lambda c=count: mole_hit(c))
button["image"] = no_mole_image
button["text"]="no mole"
button.grid(row=r,column=c)
molesList.append(button)
count +=1
def update() :
global molesList
for i in range(NUM_MOLES*NUM_MOLES) :
button = molesList[i]
button["text"]="no mole"
button["image"]=no_mole_image
x = randint(0,NUM_MOLES*NUM_MOLES -1)
molesList[x]["image"] = mole_image
molesList[x]["text"]="mole"
window.after(1000,update)
init()
update()
window.mainloop()
뭐 다른건 없고
C 드라이버에 이 그림 두개만 넣어두고(위에 붉은색 글씨로 위치 표기해놨음)
주피터에 위 코딩 복사해서 붙여넣은후에 실행하면 됩니다.
'파이썬' 카테고리의 다른 글
엑셀과 파이썬 001 (0) | 2023.07.19 |
---|---|
파이선으로 계산기 만들기 (0) | 2022.09.13 |
크루스칼(Kruskal) 알고리즘 (0) | 2022.09.12 |
댓글