python大全-iwanna

大家好,我是涵子码农,今天我要分享一个游戏:iwanna——python版本。

链接: https://pan.baidu.com/s/1V2Ajw6j1YBhqr8HRiR87jQ?pwd=xx4j 提取码: xx4j 

百度网盘文件提取

CSDN文库文件提取

python大全-iwanna_第1张图片 坑爹的游戏,打了好几遍都赢不了,一开始就有一个坑爹陷阱
python大全-iwanna_第2张图片 文件放法:py文件在最外面,里面要有一个文件images,里面都是图片

 iwanna开始!

下面是源代码,百度网盘里面也有。

一、iwanna.py

# -*- coding: utf-8 -*-
import pygame
goodBoard=[]
brokeBoard=[]
board=[]
state=1
pygame.init()
canvas=pygame.display.set_mode((1750,750))
font_name = pygame.font.match_font('KaiTi')
bigFont = pygame.font.Font(font_name, 250)
font = pygame.font.Font(font_name, 20)
pygame.display.set_caption("iwanna")
def loadPng(name):
    return pygame.image.load('images/'+name+'.png')
air=loadPng('air')
water=loadPng('water')
fire=loadPng('bad')
ground=loadPng('ground')
floor=loadPng('floor')
grass=loadPng('grass')
man=loadPng('man')
manLeft1=loadPng('manLeft1')
manLeft2=loadPng('manLeft2')
manRight1=loadPng('manRight1')
manRight2=loadPng('manRight2')
finisher=loadPng('finish')
jumpp=loadPng('jump')
jump=1
class Person():
    def __init__(self):
        self.x=500
        self.y=50
        self.fall=0
        self.faller=1
        self.jump=2
        self.stand=1
    def paint(self):
        canvas.blit(man,(self.x,self.y))
    def up(self):
        if self.jump>0:
            self.fall=-3
            self.jump-=1
            self.y-=3
            self.stand=0
    def left(self):
        #if self.fall==0:
            self.x-=2
    def right(self):
        #if self.fall==0:
            self.x+=2
    def check(self):
        global state
        if self.y>=(750-20) or self.y<=0 or self.x>=(1750-13) or self.x<=0:
            state=2
        a=0
        for i in floors:
            if i.x<=self.x+13 and i.x>=self.x-20 and i.y<=self.y+20 and i.y>=self.y-2 and i.y>=self.y-1 and self.stand:
                a=1
                self.y=i.y-20
        if a:
            self.faller=0
            self.fall=0
            self.jump=2
        else:
            self.faller=1
    def move(self):
        if self.faller:
            self.fall+=0.1
            self.stand=1
        self.y+=self.fall
    def shut(self):
        pass
class Floor:
    def __init__(self,x,y):
        self.x=x
        self.y=y
    def paint(self):
        canvas.blit(floor,(self.x,self.y))
class Jump:
    def __init__(self,x,y):
        self.x=x
        self.y=y
    def paint(self):
        canvas.blit(jumpp,(self.x,self.y))
class Fire:
    def __init__(self,x,y):
        self.x=x
        self.y=y
    def paint(self):
        canvas.blit(fire,(self.x,self.y))
    def check(self):
        global state
        if self.x<=person.x+13 and self.x>=person.x-20 and self.y<=person.y+20 and self.y>=person.y-20:
            state=2
class Finish():
    def __init__(self,x,y):
        self.x=x
        self.y=y
    def paint(self):
        canvas.blit(finisher,(self.x,self.y))
    def check(self):
        global state
        if self.x<=person.x+13 and self.x>=person.x-20 and self.y<=person.y+20 and self.y>=person.y-20:
            state=4
person=Person()
canvas.fill((255,255,255))
fires=[]
def createFire(x,y):
    fires.append(Fire(x,y))
floors=[]
def createFloor(x,y):
    floors.append(Floor(x,y))
jumps=[]
def createJump(x,y):
    floors.append(Jump(x,y))
a=0
b=0
c=0
d=0
e=0
f=0
g=0
h=0
j=0
k=0
l=0
m=0
n=0
o=0
p=0
q=0
r=0
s=0
t=0
u=0
v=0
w=0
x=0
y=0
z=0
A=0
B=0
C=0
D=0
E=0
F=0
G=0
H=0
I=0
J=0
K=0
L=0
M=0
N=0
O=0
P=0
Q=0
R=0
S=0
T=0
U=0
V=0
W=0
X=0
Y=0
Z=0
timer=0
time=0
finish=0
def setup():
    global a,b,c,d,e,f,g,h,finish,j,k,l,m,n,o,p,q,timer,time,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
    createFloor(500,100)
    createFloor(540,100)
    createFloor(560,100)
    createFloor(580,100)
    createFloor(600,100)
    createFloor(620,100)
    createFire(950,100)
    createFire(950,120)
    createFire(950,140)
    createFire(950,160)
    createFire(950,180)
    finish=Finish(1260,220)
    a=1
    b=1
    c=1
    d=1
    e=1
    f=1
    g=1
    h=1
    j=1
    k=1
    l=1
    m=1
    n=1
    o=1
    p=1
    q=1
    timer=0
    time=1
    r=1
    s=1
    t=1
    u=1
    v=1
    w=1
    x=1
    y=1
    z=1
    A=1
    B=1
    C=1
    D=1
    E=1
    F=1
    G=1
    H=1
    I=1
    J=1
    K=1
    L=1
    M=1
    N=1
    O=1
    P=1
    Q=1
    R=1
    S=1
    T=1
    U=1
    V=1
    W=1
    X=1
    Y=1
    Z=1
setup()
while 1:
    pygame.time.Clock().tick(100)
    event = pygame.event.poll()
    if event.type == pygame.QUIT:
        pygame.quit()
        exit()
    if state==1:
        finish.check()
        person.check()
        if person.x>=500-13 and person.x<=540 and person.y>=90-20 and person.y<=95-20 and a==1:
            createFire(500,100)
            a=0
        if person.x>=600-13 and person.x<=620 and person.y>=90-20 and person.y<=100 and b==1:
            createFire(620,80)
            createFloor(640,120)
            b=0
        if person.x>=640-13 and person.x<=660 and person.y>=100-20 and person.y<=120 and c==1 and b==0:
            createFloor(700,120)
            createFloor(740,120)
            createFloor(760,120)
            createFloor(820,120)
            createFloor(880,120)
            createFire(850,100)
            c=0
        if person.x>=730-13 and person.x<=750 and d==1 and c==0:
            floors.pop(7)
            floors.pop(7)
            d=0
        if person.x>=790-13 and person.x<=810 and e==1 and d==0:
            createFire(790,120)
            createFire(790,100)
            createFire(790,80)
            e=0
        if person.x>=880-13 and person.x<=900 and person.y>=100-20 and person.y<=120 and f==1 and e==0:
            for i in range(800,1300,20):
                if i==860 or i==840:
                    continue
                createFloor(i,240)
            f=0
        if person.x>=800-13 and person.x<=820 and person.y>=160-20 and person.y<=260 and g==1 and f==0:
            createFire(800,180)
            createFloor(780,240)
            createFloor(760,230)
            createFloor(740,220)
            createFloor(720,220)
            createFloor(700,220)
            for i in range(240,500,20):
                createFloor(780,i)
                createFloor(720,i)
            g=0
        if person.x>=1100-13 and person.x<=1160 and person.y>=160-20 and person.y<=260 and h==1 and f==0:
            for i in range(0,240,20):
                createFire(1200,i)
                createFire(1000,i)
            h=0
        if person.x>=740-13 and person.x<=760 and person.y>=220-20 and person.y<=240 and j==1 and g==0:
            for i in floors:
                if i.x==740 and i.y==220:
                    floors.remove(i)
                    break
            createFire(740,480)
            for i in floors:
                if i.x==760 and i.y==230:
                    floors.remove(i)
                    break
            createFire(760,480)
            j=0
        if person.x>=700-13 and person.x<=705 and person.y>=220-20 and person.y<=240 and k==1 and g==0:
            for i in floors:
                if i.x==700 and i.y==220:
                    floors.remove(i)
                    break
            createFire(660,180)
            for i in range(100,680,20):
                createFloor(i,200)
            k=0
        if person.x>=620-13 and person.x<=640 and l==1 and k==0:
            for i in fires:
                if i.x==620 and i.y==80:
                    fires.remove(i)
                    break
            createFire(600,180)
            l=0
        if person.x>=500-13 and person.x<=520 and m==1 and k==0:
            createFire(500,120)
            createFire(450,180)
            m=0
        if person.x>=340-13 and person.x<=380 and n==1 and k==0:
            for i in floors:
                if i.x==340:
                    floors.remove(i)
                    break
            for i in floors:
                if i.x==360:
                    floors.remove(i)
                    break
            n=0
            while 1:
                pygame.time.Clock().tick(100)
                timer+=1
                if timer//100%3==0 and time:
                    for i in range(100,500):
                        if i==320 or i==340 or i==360 or i==380:
                            continue
                        createFire(i,340)
                    time=0
                elif timer//100%3!=0 and not time:
                    for i in range(100,600):
                        if i==320 or i==340 or i==360 or i==380:
                            continue
                        createFloor(i,340)
                        try:
                            if i<500:
                                fires.pop()
                        except:
                            pass
                    time=1
                if person.x>=550 or state!=1:
                    break
                canvas.fill((255,255,255))
                person.paint()
                finish.check()
                event = pygame.event.poll()
                if event.type == pygame.QUIT:
                    pygame.quit()
                    exit()
                keys=pygame.key.get_pressed()
                if keys[pygame.K_w] or keys[pygame.K_UP] or keys[pygame.K_SPACE]:
                    if jump:
                        person.up()
                    jump=0
                else:
                    jump=1
                if keys[pygame.K_a] or keys[pygame.K_LEFT]:
                    person.left()
                if keys[pygame.K_d] or keys[pygame.K_RIGHT]:
                    person.right()
                if keys[pygame.K_s] or keys[pygame.K_DOWN]:
                    person.shut()
                if keys[pygame.K_r]:
                    state=3
                person.move()
                person.check()
                for i in floors:
                    i.paint()
                for i in fires:
                    i.paint()
                    i.check()
                finish.paint()
                pygame.display.update()
        if person.x<=200 and o==1 and n==0:
            for i in range(0,300,20):
                for z in range(0,1000,20):
                    createFire(i,z)
            o=0
        if person.x<=540 and p==1 and k==0:
            createFire(600,320)
            for i in range(0,500):
                createFire(660,i)
            p=0
        if person.x>=540 and q==1 and n==0:
            for i in range(400,640):
                createFloor(i,440)
            q=0
        if person.x<=600 and r==1 and q==0:
            createFire(570,420)
            createFire(500,420)
            r=0
        if person.x<=500 and s==1 and q==0:
            createFire(450,420)
            s=0
        if person.x<=400 and t==1 and q==0:
            for i in range(0,1750,20):
                createFloor(i,580)
                createFloor(i,740)
            t=0
        if person.x>=1370 and u==1 and t==0:
            for i in range(0,1750):
                createFire(i,570)
            u=0
        if person.y>=420 and v==1 and x==0:
            for i in range(0,800,20):
                for z in range(0,2000,20):
                    createFire(z,i)
            v=0
        if person.x<=1120 and w==1 and y==0 and h==0:
            for i in floors:
                if i.x==1020 and i.y==240:
                    floors.remove(i)
                    break
            for i in floors:
                if i.x==1040 and i.y==240:
                    floors.remove(i)
                    break
            for i in floors:
                if i.x==1060 and i.y==240:
                    floors.remove(i)
                    break
            createFire(1010,240)
            createFire(1070,240)
            w=0
        if person.x<=1300 and x==1 and y==0:
            finish=Finish(1200,400)
            x=0
        if person.x>=1325 and person.y<=775 and y==1 and t==0:
            for i in range(220,750,60):
                createJump(1350,i)
            y=0
        if person.y>=250 and A==1 and w==0:
            for i in range(1000,1200,20):
                createFloor(i,300)
            A=0
        if person.y>=375 and B==1 and A==0:
            createFire(1160,370)
            createFire(1180,370)
            createFire(1200,370)
            createFire(1220,370)
            createFire(1240,370)
            B=0
        if person.y>=320 and person.x<=990 and C==1 and A==0 and B==1:
            for i in range(900,1200,20):
                createFloor(i,350)
            C=0
        if person.y>=350 and person.x<=990 and D==1 and C==0:
            for i in range(800,2000,20):
                createFloor(i,435)
            D=0
        if person.x>=760 and E==1 and t==0:
            for i in floors:
                if i.x==740 and i.y==580:
                    floors.remove(i)
                    break
            for i in floors:
                if i.x==760 and i.y==580:
                    floors.remove(i)
                    break
            for i in floors:
                if i.x==780 and i.y==580:
                    floors.remove(i)
                    break
            for i in floors:
                if i.x==800 and i.y==580:
                    floors.remove(i)
                    break
            E=0
        if person.x>=830 and F==1 and t==0:
            for i in range(400,520,20):
                createFire(820,i)
            F=0
        if person.x>=885 and G==1 and t==0:
            createFire(890,580)
            G=0
        if person.x>=950 and H==1 and t==0:
            for i in range(400,520,20):
                createFire(908,i)
            H=0
        if person.x>=1000 and I==1 and t==0:
            for i in range(400,580,20):
                createFire(978,i)
            I=0
        if person.x>=1300 and J==1 and t==0:
            for i in range(0,1280,20):
                createFire(i,580)
                createFire(i,560)
                createFire(i,540)
                createFire(i,520)
                createFire(i,500)
            J=0
        if person.x>=1320 and M==1 and t==0:
            for i in floors:
                if i.x==1240 and i.y==580:
                    floors.remove(i)
                    break
            for i in floors:
                if i.x==1260 and i.y==580:
                    floors.remove(i)
                    break
            for i in floors:
                if i.x==1280 and i.y==580:
                    floors.remove(i)
                    break
            for i in floors:
                if i.x==1300 and i.y==580:
                    floors.remove(i)
                    break
            for i in floors:
                if i.x==1320 and i.y==580:
                    floors.remove(i)
                    break
            M=0
        canvas.fill((255,255,255))
        person.paint()
        keys=pygame.key.get_pressed()
        if keys[pygame.K_w] or keys[pygame.K_UP] or keys[pygame.K_SPACE]:
            if jump:
                person.up()
            jump=0
        else:
            jump=1
        if keys[pygame.K_a] or keys[pygame.K_LEFT]:
            person.left()
        if keys[pygame.K_d] or keys[pygame.K_RIGHT]:
            person.right()
        if keys[pygame.K_s] or keys[pygame.K_DOWN]:
            person.shut()
        if keys[pygame.K_r]:
            state=3
        person.move()
        for i in floors:
            i.paint()
        for i in fires:
            i.paint()
            i.check()
        finish.paint()
        pygame.display.update()
    elif state==2:
        font_surface = bigFont.render('Game over', True, 'red')
        canvas.blit(font_surface, (250, 30))
        font_surface = font.render('\'c\' for exit', True, 'red')
        canvas.blit(font_surface, (800, 450))
        font_surface = font.render('\'r\' for again', True, 'red')
        canvas.blit(font_surface, (800, 550))
        pygame.display.update()
        event = pygame.event.poll()
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()
        keys=pygame.key.get_pressed()
        if keys[pygame.K_r]:
            state=3
        if keys[pygame.K_c]:
            pygame.quit()
            exit()
    elif state==3:
        person=0
        person=Person()
        floors=[]
        fires=[]
        setup()
        state=1
    elif state==4:
        font_surface = bigFont.render('You win!', True, 'red')
        canvas.blit(font_surface, (300, 150))
        pygame.display.update()
        break

二、文件python大全-iwanna_第3张图片 

因为文件过多,所以大家最好到百度网盘下载。链接在上方。

三、推荐文章

python也能开发minecraft启动器

python-minecraft启动器要在网址里面的链接下载。


github链接

gitee链接
 


python-pygame小游戏之球球大作战

球球大作战源码(可以去网址复制,也可以在这里复制,也可以用csdn文库):

csdn文库-这个文件是关于我最火热的文章:球球大作战的py文件

# import pygame, random and math
import pygame as pg
import random as rd
import math
 
# init program
pg.init()
# set screen
screen = pg.display.set_mode((1000, 500))
screen.fill((255, 255, 255))
# set title
pg.display.set_caption("BallFight_Avaritia", "4.0")
# Chinese:pg.display.set_caption("球球大作战_无尽贪婪", "4.0")
 
# def circle
def circle(color, point, r, size):
    pg.draw.circle(screen, color, point, r, size)
 
# class ball
class Ball():
    def __init__(self):
        self.color = (rd.randint(0, 255), rd.randint(0, 255), rd.randint(0, 255))
        self.x =rd.randint(0, 1000)
        self.y = rd.randint(0, 500)
        self.r = rd.randint(5, 15)
        self.size = rd.randint(5, 15)
 
# make a balllist
balllist = []
for i in range(600):
    balllist.append(Ball())
 
# creat myball
myball = Ball()
myball.color = (0, 0, 0)
myball.x = 500
myball.y = 250
myball.size = 5
myball.speed = 10
 
# def check touch
# use the pythagorean theorem
def touch(myX, myY, fX, fY, myR, fR):
    distance = math.sqrt((myX - fX) ** 2 + (myY - fY) ** 2)
    if distance <= myR + fR:
        # just return True
        return True
    else:
        # return False
        return False
 
# def foodDelivery
def foodDelivery():
    time = pg.time.get_ticks()
    # every 10 seconds put 30 foods
    if time % 10000 >= 9000 and time % 10000 <= 9020:
        for i in range(30):
            balllist.append(Ball())
 
# def draw
# use "Ball" and for range to append in the balllist
def draw():
    for ball in balllist:
        if touch(myball.x, myball.y, ball.x, ball.y, myball.size, ball.size):
            balllist.remove(ball)
            myball.size += 0.1
            # make the speed to be smaller than the last one
            # use the multiplier scale decreases and inverse proportional function
            myball.speed *= 0.992
        else:
            circle(ball.color, (ball.x, ball.y), ball.size, 0)
    circle(myball.color, (myball.x, myball.y), myball.size, 0)
 
# check fps, do not quit program
fps = pg.time.Clock()
# check quit and play program
while True:
    # do not make the fps so high
    # if the fps is high, the computer will ~"bomb!"
    fps.tick(60)
    event = pg.event.poll()
    if event.type == pg.QUIT:
        pg.quit()
        exit()
    keys = pg.key.get_pressed()
    # make the ball to move
    # I use the "wasd"
    # also can use up down right left
    if keys[pg.K_w]:
        myball.y -= myball.speed
    if keys[pg.K_a]:
        myball.x -= myball.speed
    if keys[pg.K_s]:
        myball.y += myball.speed
    if keys[pg.K_d]:
        myball.x += myball.speed
    if keys[pg.K_UP]:
        myball.y -= myball.speed
    if keys[pg.K_DOWN]:
        myball.y += myball.speed
    if keys[pg.K_LEFT]:
        myball.x -= myball.speed
    if keys[pg.K_RIGHT]:
        myball.x += myball.speed
    # the e is to update ball's xy
    elif keys[pg.K_e]:
        myball.x, myball.y = 500, 250
    # draw and check
    draw()
    foodDelivery()
    # display program
    pg.display.update()
    screen.fill((255, 255, 255))
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

四、总结和玩法

w,s,a,d,上下左右都可以移动。空格跳跃,可以两段跳。十分坑爹。r重新开始,c退出。

这个游戏代码很长,内容很多。里面涉及到了很多知识。大家可以边学边玩。希望大家玩得快乐,学得快乐。祝所有学生暑假快乐!

你可能感兴趣的:(python大全,编程,学习,python,青少年编程)