联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2018-07-26 09:39

from graphics import *

import random

import time


def main():

   win = GraphWin("Bug-template",600,600)

   win.setCoords(0,0,6,6)


   #Times left information

   numTry = 0

   

   #draw grid

   for i in range(3):

       index = i+1

       p1 = Point(index,1)

       p2 = Point(index,3)

       Line(p1,p2).draw(win)

       p3 = Point(1,index)

       p4 = Point(3,index)

       Line(p3,p4).draw(win)


   # initialize position of bug and show it

   initPnt = Point(1.5,1.5)

   bug = Image(initPnt,"bug.gif")

   bug.draw(win)


   #repeat until 5 times

   gC = win.getMouse()

   while ((gC.x>=1)and (gC.x<=3) and (gC.y>=1)and (gC.y<=3)):

       # move the bug

       

       # convert user click and mark the grid

       converted_x = int(gC.x)

       converted_y = int(gC.y)

       redGridPnt1 = Point(converted_x,converted_y)

       redGridPnt2 = Point(converted_x+1,converted_y+1)

       redGrid = Rectangle(redGridPnt1,redGridPnt2)

       redGrid.setFill("lightblue")

       redGrid.draw(win)

       # check if bug is there, break if so

       

       numTry = numTry+1

       if numTry >= 5:

           break

 #     timesText.setText("Moves: "+str(numTry))

       gC = win.getMouse()

       redGrid.undraw()

               

   click = win.getMouse()

   win.close()

   

main()


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp