python 특정 좌표에서 게임을 발생시키고 싶습니다.
글쓴이: ksm5318 / 작성시간: 화, 2016/04/12 - 10:28오전
안녕하세요. 파이썬 공부를 하는 학생입니다.
이번에 간단한 게임을 만들고자 파이썬으로 프로그래밍 도중
특정 좌표에서 for문과 if문을 써서 사건을 발생시키고 싶은데.
무엇이 문제인지 안되네요...
그래서 사각형처리해서 그 내부에 들어오면 사건이라도 발생시키고 싶은데
사각형 그리고 그 주변위치를 어찌 잡아야할지 모르겠네요;;
import turtle import random wn=turtle.Screen() t1=turtle.Turtle() size=50 nMax=0 level="low" wn.bgpic(Users\KimSungMoGram\Documents\p161+Maze.jpg) //제가 그린 미로입니다. def setPosition(pos): //위치를 잡아서 별을 그리기 위함.(특정위치 지정) t1.penup() t1.setpos(pos) t1.pendown() t1.right(72) t1.fd(20) for k in range (0,4): t1.right(144) t1.fd(20) def drawStars(): setPosition((200,200)) setPosition((-200,200)) setPosition((-200,-200)) setPosition((200,-200)) t1.penup() oldpos=t1.pos() oldhead=t1.heading() t1.home() t1.pendown() drawStars() level=raw_input("Choose level : high, mid, low ") if (level=="high"): //이동 횟수를 제한시켜서 난이도 조절 nMax=20 elif (level=="mid"): nMax=35 elif(level=="low"): nMax=50 for i in range(0,nMax): curser=raw_input() position = t1.pos() if t1.pos()==(200.00,200.00): ///문제의 부분입니다. 입력을 받고 좌표를 반환시켜서 만약좌표 print "Let the game begin" //가 이와 같다면 게임을 시작시키고 싶습니다.. player = raw_input("Enter your choice (rock/paper/scissors): ") player = player.lower() computer = random.randint(1,3) if (computer == 1): computer = "rock" elif (computer == 2): computer = "paper" elif (computer == 3): computer = "scissors" else: print ("Error. Enter your choice from rock, paper, scissors.") if (player == computer): print ("Draw!") elif (player == "rock"): if (computer == "paper"): print ("You won."); if (computer == "scissors"): print ("You lost."); elif (player == "paper"): if (computer == "rock"): print ("You won."); if (computer == "scissors"): print ("You lost."); elif (player == "scissors"): if (computer == "rock"): print ("You lost."); if (computer == "paper"): print ("You won."); #restart userInput = raw_input("Finish? Yes or No: ") userInput = userInput.lower() if (userInput == "yes"): play = False print ("See you again.") else: play = True else: if (curser=="w"): t1.left(90) t1.fd(size) elif (curser=="d"): t1.fd(size) elif(curser=="s"): t1.right(90) t1.fd(size) elif(curser=="a"): t1.left(180) t1.fd(size) else: print("Error") position = t1.pos() print position t1.setheading(0) //입력받아서 이동후 좌표 출력 ## 만약 위치가 200,200 즉 별의 위치라면 이벤트 발생시키기. ## 근데 200,200인데도 이벤트가 안뜹니다 ## 근데 이 코드로 게임을 시작한다해도 그 다음에 wdas의 입력을 다시 받을 수 있나요? 아니면 다시 저 함수를 써서 되돌아가야하나요???
Forums:
댓글 달기