U E D R , A S I H C RSS

방울뱀스터디/만두4개

'만두 4개'란? 파이썬으로 만들 게임 이름입니다. 일종의 땅따먹기 게임이라 생각하시면 됩니다.

만두 4개 게임 요구 사항

  • 3가지 모드 (1p, 2p, 1 vs 2)
  • P2P 플레이 가능
  • 높은 점수순으로 5위까지 저장

  • 화면 인터페이스는 각 플레이어 위쪽 모서리에 '점수, 목숨, 내땅' 출력
  • 게임 진행 시간 - 60초
  • 목숨 3번
  • 아이템
    • 플레이어 속도 높이기
    • 진행 시간 5초 늘리기
    • 목숨 늘리기
    • 업그레이드
    • 3초간 멈추기
    • 미사일

소스 코드

Upload='ManDu0.2.py'
~cpp 
from Tkinter import *

MAX_WIDTH, MAX_HEIGHT = 314, 314
GAP = 7

CELL = 15
speed = 5
ovalSize = 1
rightLimit = 10

traceList = []

def keypress(event = None):
    
    global key
    key = event.keysym
    print key

    global i,direction
    

    
    if key in ['Right', 'Left', 'Up', 'Down', 'Space']:
        global dir
        global x, y
        global row, col

        
        
        if i == 0:
            row, col = GAP, GAP
            direction ='NONE'
            
        print row, col
             
        
        dir = key
        
        #traceList = []
        
        if direction == 'Right' and key != 'Right':
           traceList.append((row,col))
        elif direction == 'Left' and key != 'Left':
            traceList.append((row,col))
        elif direction == 'Up' and key != 'Up':
            traceList.append((row,col))
        elif direction == 'Down' and key != 'Down':
            traceList.append((row,col))
            
        print traceList
                
        #ball = canvas.create_oval(x - 1, y - 1, x + CELL + 1, y + CELL + 1, fill='white', outline = 'white')
        #canvas.coords(ball, x - 1, y - 1, x + CELL + 1, y + CELL + 1)
        #img2 = canvas.create_oval(1, 1, 13, 13, fill='white', outline = 'white')
       
        #Right =0, Left=1, Up=2, Down=3

               
        if dir == 'Right'and'Space' and x <= MAX_WIDTH-GAP-10 :
            x += speed
            canvas.move("oval", speed,0)
            canvas.create_line(row, col, row+speed, col, fill="red")
            row=row+speed
            direction='Right'
        elif dir == 'Left' and x >2:
            x -= speed
            canvas.move("oval", -speed,0)
            canvas.create_line(row, col, row-speed, col, fill="red")
            #canvas.create_line(x, y, row, col, fill="red")
            #print row, col, x, y
            row=row-speed
            direction='Left'
        elif dir == 'Up' and y > 2:
            y -= speed
            canvas.move("oval", 0,-speed)
            canvas.create_line(row, col, row, col-speed, fill="red")
            col=col-speed
            direction='Up'
        elif dir == 'Down' and y <= MAX_HEIGHT - GAP - 10:
            y += speed
            canvas.move("oval", 0,speed)
            canvas.create_line(row, col, row, col+speed, fill="red")
            col=col+speed
            direction='Down'
        #canvas.create_rectangle(GAP, GAP, MAX_WIDTH - GAP, MAX_HEIGHT - GAP)
        #canvas.create_image(x, y, anchor=NW, image=playerImg)
            


        #if dir == 'Right' and x < MAX_WIDTH - GAP - 10:
        #    canvas.create_line(row, col+8, row + speed, col+8, fill="red")
        #elif dir == 'Left' and x > 2:
        #    canvas.create_line(row + speed + 8, col+8, row + 8, col+8, fill="red")
        #elif dir == 'Up' and y > 2:
        #    canvas.create_line(row + 8, col+ speed + 8, row + 8, col + 8 , fill="red")
        #elif dir == 'Down' and y < MAX_HEIGHT - GAP - 10:
        #    canvas.create_line(row + 8, col, row + 8, col +speed, fill="red")

        i = i + 1
        print i
    #elif key  in ['Space']:
    #    if key  in ['Right', 'Left', 'Up', 'Down']:
    #        print 'aaa'
        
             
if __name__ == '__main__':
    root = Tk()
    root.title('Python Ground Eat')
    canvas = Canvas(root, width = MAX_WIDTH, height = MAX_HEIGHT, bg='white')
    canvas.create_rectangle(GAP, GAP, MAX_WIDTH - GAP, MAX_HEIGHT - GAP)
    canvas.pack(expand=YES, fill=BOTH)
    
    x = 2
    y = 2

    i = 0

    
    
    #playerImg = PhotoImage(file='images/worm.gif')
    img = canvas.create_oval(x,y,x+10,y+10,width = 0, fill="red", tags="oval")
    
    #canvas.create_image(x, y, anchor=NW, image=playerImg)
    #canvas.create_image(x, y, anchor=NW, image=oval)
    

    root.bind("<Key>", keypress)
    root.mainloop()


~cpp 
import Tkinter
import Image
import ImageTk

root = Tkinter.Tk()
canvas = Tkinter.Canvas(root, width = 400, height = 300)
canvas.pack()

backImg = Image.open("wall.gif")
frontImg = ImageTk.PhotoImage(Image.open("background.gif"))

CELL = 10
(WIDTH, HEIGHT) = backImg.size

imgList = [[None for i in range(WIDTH / CELL)] for j in range(HEIGHT / CELL)]

row = 0
while(row != HEIGHT / CELL):
    col = 0
    while(col != WIDTH / CELL):
        box = (col * CELL, row * CELL, col * CELL + CELL, row * CELL + CELL)
        imgList[row][col] = ImageTk.PhotoImage(backImg.crop(box))
        col += 1
    row += 1

canvas.create_image(0, 0 , anchor=Tkinter.NW, image = frontImg)

row = 0
while(row != HEIGHT / CELL):
    col = 0
    while(col != WIDTH / CELL):
        canvas.create_image(col * CELL, row * CELL , anchor=Tkinter.NW, image = imgList[row][col])
        col += 1
    row += 1

root.mainloop()

그림사이즈 400*300

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:34
Processing time 0.0116 sec