14个py小游戏第四弹

简介: 政胤.于 2022-05-04 21:30:47 发布1789 已收藏 17文章标签: python版权13贪心鸟玩法:有点类似那个炸弹人,控制好走位 问题不大 好吧 14井字棋888玩法:我打赌大家在课堂上肯定玩过这个,想想当年和同桌玩这个费了好几个本子. 源代码分享:from tkinter import *import tkinter.messagebox as msg root = Tk()root.title('TIC-TAC-TOE---Project Gurukul')# lab

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粉 感谢大家一路以来的支持. 以后会给大家带来更多的干货 希望大家多多提意见 我会一一回复 爱你们

目录
相关文章
|
7月前
|
Python
Python满屏飘字表白完整代码
Python满屏飘字表白完整代码
315 0
|
7月前
|
定位技术 Python
【python】pygame实现植物大战僵尸小游戏(附源码 有注释)
【python】pygame实现植物大战僵尸小游戏(附源码 有注释)
1622 1
|
7月前
|
程序员 C# Python
100行python代码,轻松完成贪吃蛇小游戏_c#游戏100行代码(2)
100行python代码,轻松完成贪吃蛇小游戏_c#游戏100行代码(2)
|
7月前
|
存储 程序员 C#
100行python代码,轻松完成贪吃蛇小游戏_c#游戏100行代码
100行python代码,轻松完成贪吃蛇小游戏_c#游戏100行代码
|
7月前
|
机器人 C语言 Python
Python满屏飘字表白代码
Python满屏飘字表白代码
127 0
|
7月前
|
Python
【python】pygame实现贪吃蛇小游戏(附源码,带注释)
【python】pygame实现贪吃蛇小游戏(附源码,带注释)
630 1
|
Python
Python满屏表白代码
人生苦短,我用Python!又是新的一周啦,本期博主给大家带来了一个全新的作品:满屏表白代码,无限弹窗版!快快收藏起来送给她吧~
1265 0
Python满屏表白代码
|
Python
python小游戏——贪吃蛇游戏
python小游戏——贪吃蛇游戏
142 0
|
Python
python小游戏——贪吃蛇游戏2.0版本の得分功能实现
python小游戏——贪吃蛇游戏2.0版本の得分功能实现
210 0
|
Python
python小游戏———拼图代码开源
python小游戏———拼图代码开源
248 0

相关实验场景

更多