• 大小: 6KB
    文件类型: .py
    金币: 1
    下载: 0 次
    发布日期: 2021-05-28
  • 语言: Python
  • 标签: python  

资源简介

上海交通大学程序设计思想与方法大作业啊。

资源截图

代码片段和文件信息

# -*- coding: cp936 -*-预处理
from visual import*
        
scene.range=11.5

square=curve(pos=((-1010.2)(1010.2)(10-10)(-10-10)(-1010.2)))  #creat bundary
square.color=color.white
square.radius=0.1

myball=sphere()    #creat ball
myball.color=(011)
myball.pos=(0-8.50)
myball.radius=0.5

life1=sphere()    #creat life ball
life1.color=(011)
life1.pos=(-11110)
life1.radius=0.3    

life2=sphere()    
life2.color=(011)
life2.pos=(-10110)
life2.radius=0.3

mybox=box()        #creat box
mybox.color=(010.5)
mybox.pos=(0-9.250)
mybox.size=(60.50.6)

bricks=[]          #creat bricks for lv1
x=-11.3
y=9.5
for i in range (15):
    for i in range(18):
        x=x+2.8
        bricks.append(box(pos=(xy0)size=(2.510.5)color=color.white))
    x=-11.3
    y=y-1.5    

leftwall=-9.5      #creat wall
rightwall=9.5
upwall=9.5
dead=-9.5

vx=vector(0.0500)#creat position
vy=vector(00.10)
v=vx+vy
###############################################################################################鼠标兼容
pick=None          #main
T=true
broken=0
life=2
lv=1
r=300
while T and (lv<=3):
    if scene.mouse.events:      #mouse avalible
        m1=scene.mouse.getevent()
        if m1.drag:
            pick=m1.pick
        if m1.drop:
            pick=None
    if pick and (scene.mouse.pos.x>=-7)and(scene.mouse.pos.x<=7):
        mpos=scene.mouse.pos
        mybox.x=mpos.x
    rate(r)                     #pause time
    myball.pos=myball.pos+v
######################################################################################砖块打击    
    for i in range(len(bricks)):
        if T==false:
            break
        if (myball.x>=bricks[i].x-1.25)and(myball.x<=bricks[i].x+1.25)and(myball.y>=bricks[i].y-1):    #if myball touches the bricks:red-->blue-->white
            if bricks[i].color==color.white:
                v.y=-0.1
                bricks[i].x=-12
                bricks[i].y=-12
                bricks[i].size=(000)
                bricks[i].color=(000)
                broken=broken+1
            elif bricks[i].color==color.blue:
                bricks[i].color=color.white
                v.y=-0.1
            elif bricks[i].color==color.red:
                bricks[i].color=color.blue
                v.y=-0.1

        if broken==28:           #if the brickes are all broken
           
          
            if lv==1:
                print “You Win level1“
                
                myball.pos=(0-8.50)#set ball&box
                mybox.pos=(0-9.250)
                v.y=0.1
                v.x=0.05
                rate(0.5)
                
                lv=2
                r=350#
                broken=0
                
                bricks=[]          #creat bricks for lv2
                x=-11.3
                y=9.5
                for i in range (13):
                    for i in range(18):
                        x

评论

共有 条评论