13贪心鸟
玩法:有点类似那个炸弹人,控制好走位 问题不大 好吧
14井字棋888
玩法:我打赌大家在课堂上肯定玩过这个,想想当年和同桌玩这个费了好几个本子.
源代码分享:
from tkinter import *
import tkinter.messagebox as msg
root = Tk()
root.title('TIC-TAC-TOE---Project Gurukul')
labels
Label(root, text="player1 : X", font="times 15").grid(row=0, column=1)
Label(root, text="player2 : O", font="times 15").grid(row=0, column=2)
digits = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for player1 sign = X and for player2 sign= Y
mark = ''
counting the no. of click
count = 0
panels = ["panel"] * 10
def win(panels, sign):
return ((panels[1] == panels[2] == panels[3] == sign)
or (panels[1] == panels[4] == panels[7] == sign)
or (panels[1] == panels[5] == panels[9] == sign)
or (panels[2] == panels[5] == panels[8] == sign)
or (panels[3] == panels[6] == panels[9] == sign)
or (panels[3] == panels[5] == panels[7] == sign)
or (panels[4] == panels[5] == panels[6] == sign)
or (panels[7] == panels[8] == panels[9] == sign))
def checker(digit):
global count, mark, digits
# Check which button clicked
if digit == 1 and digit in digits:
digits.remove(digit)
##player1 will play if the value of count is even and for odd player2 will play
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
button1.config(text=mark)
count = count + 1
sign = mark
if (win(panels, sign) and sign == 'X'):
msg.showinfo("Result", "Player1 wins")
root.destroy()
elif (win(panels, sign) and sign == 'O'):
msg.showinfo("Result", "Player2 wins")
root.destroy()
if digit == 2 and digit in digits:
digits.remove(digit)
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
button2.config(text=mark)
count = count + 1
sign = mark
if (win(panels, sign) and sign == 'X'):
msg.showinfo("Result", "Player1 wins")
root.destroy()
elif (win(panels, sign) and sign == 'O'):
msg.showinfo("Result", "Player2 wins")
root.destroy()
if digit == 3 and digit in digits:
digits.remove(digit)
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
button3.config(text=mark)
count = count + 1
sign = mark
if (win(panels, sign) and sign == 'X'):
msg.showinfo("Result", "Player1 wins")
root.destroy()
elif (win(panels, sign) and sign == 'O'):
msg.showinfo("Result", "Player2 wins")
root.destroy()
if digit == 4 and digit in digits:
digits.remove(digit)
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
button4.config(text=mark)
count = count + 1
sign = mark
if (win(panels, sign) and sign == 'X'):
msg.showinfo("Result", "Player1 wins")
root.destroy()
elif (win(panels, sign) and sign == 'O'):
msg.showinfo("Result", "Player2 wins")
root.destroy()
if digit == 5 and digit in digits:
digits.remove(digit)
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
button5.config(text=mark)
count = count + 1
sign = mark
if (win(panels, sign) and sign == 'X'):
msg.showinfo("Result", "Player1 wins")
root.destroy()
elif (win(panels, sign) and sign == 'O'):
msg.showinfo("Result", "Player2 wins")
root.destroy()
if digit == 6 and digit in digits:
digits.remove(digit)
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
button6.config(text=mark)
count = count + 1
sign = mark
if (win(panels, sign) and sign == 'X'):
msg.showinfo("Result", "Player1 wins")
root.destroy()
elif (win(panels, sign) and sign == 'O'):
msg.showinfo("Result", "Player2 wins")
root.destroy()
if digit == 7 and digit in digits:
digits.remove(digit)
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
button7.config(text=mark)
count = count + 1
sign = mark
if (win(panels, sign) and sign == 'X'):
msg.showinfo("Result", "Player1
到此这篇关于14 个Python小游戏 源码分享的文章就介绍到这了,更多相关14 个Python小游戏内容请搜索政胤工作室 以前的文章或继续浏览下面的相关文章 希望大家以后多多支持政胤工作室!
到今天为止已经写代码20几天了,从无到有 从0浏览到现在上热榜 从0粉丝到500粉 感谢大家一路以来的支持. 以后会给大家带来更多的干货 希望大家多多提意见 我会一一回复 爱你们