Advertisement
DevNeon

윷놀이 프로그램 소스코드

Dec 12th, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 28.70 KB | None | 0 0
  1. # coding=utf-8
  2. from tkinter import *
  3. from threading import Timer
  4. from datetime import datetime
  5. import time
  6. import random
  7.  
  8. class PlayerUnit :
  9.     hAmount = 0         # 말 갯수
  10.     selObject = None    # 움직이기로 선택한 말 (None=선택안함, "I"=보관함, 그외 고유 좌표)
  11.     def __init__(self) :
  12.         self.hAmount = 3
  13.         self.selObject = None
  14.  
  15. class Horse :
  16.     C = [[0]*2 for i in range(20)]
  17.     R = [[0] * 2 for i in range(7)]
  18.     L = [[0] * 2 for i in range(7)]
  19.     Location = ""
  20.     master = None
  21.     hButton = None
  22.     Amount = 1
  23.  
  24.     def __init__(self, loc, Turn, window) :
  25.         self.defLoc()
  26.         if (loc >= 5) :
  27.             self.Location = "R0"
  28.         else :
  29.             self.Location = f"C{loc}"
  30.         self.master = window
  31.         self.hButton = Button(
  32.             self.master,
  33.             relief='solid',
  34.             width=4,
  35.             height=2,
  36.             command=self.selectMe,
  37.             text=f"{self.Amount}"
  38.         )
  39.  
  40.         if(Turn == 0) :
  41.             self.hButton.configure(bg='dodgerblue')
  42.         elif (Turn == 1):
  43.             self.hButton.configure(bg='red', fg='snow')
  44.         elif (Turn == 2):
  45.             self.hButton.configure(bg='gold')
  46.         elif (Turn == 3):
  47.             self.hButton.configure(bg='green2')
  48.         self.hButton.place(x = self.C[loc][0], y = self.C[loc][1])
  49.  
  50.     def selectMe(self) :
  51.         all.selObject = self.Location
  52.         print(f"  └ 말 선택됨 : {self.Location}")
  53.         all.MovingHorse()
  54.         all.SelectAble(False)
  55.  
  56.     def Replace(self) :
  57.         idx = int(self.Location[1:])
  58.         if (self.Location[:1] == "C") :
  59.             self.hButton.place(x=self.C[idx][0], y=self.C[idx][1])
  60.         elif (self.Location[:1] == "L") :
  61.             self.hButton.place(x=self.L[idx][0], y=self.L[idx][1])
  62.         elif (self.Location[:1] == "R") :
  63.             self.hButton.place(x=self.R[idx][0], y=self.R[idx][1])
  64.  
  65.     def defLoc(self):
  66.         '''좌표지정'''
  67.         x = 0
  68.         y = 1
  69.         count = 0
  70.         self.C[count][x] = self.L[6][x] = 421
  71.         self.C[count][y] = self.L[6][y] = 421
  72.         count = 5
  73.         self.C[count][x] = self.R[0][x] = 421
  74.         self.C[count][y] = self.R[0][y] = 23
  75.         count = 10
  76.         self.C[count][x] = self.L[0][x] = 23
  77.         self.C[count][y] = self.L[0][y] = 23
  78.         count = 15
  79.         self.C[count][x] = self.R[6][x] = 23
  80.         self.C[count][y] = self.R[6][y] = 421
  81.         t_x = 421
  82.         t_y = 340
  83.         for count in range(1, 5) :
  84.             self.C[count][x] = t_x
  85.             self.C[count][y] = t_y
  86.             t_y -= 75
  87.         t_x = 340
  88.         t_y = 23
  89.         for count in range(6, 11) :
  90.             self.C[count][x] = t_x
  91.             self.C[count][y] = t_y
  92.             t_x -= 75
  93.         t_x = 23
  94.         t_y = 115
  95.         for count in range(11, 16) :
  96.             self.C[count][x] = t_x
  97.             self.C[count][y] = t_y
  98.             t_y += 75
  99.         t_x = 111
  100.         t_y = 421
  101.         for count in range(16, 20):
  102.             self.C[count][x] = t_x
  103.             self.C[count][y] = t_y
  104.             t_x += 75
  105.         self.R[1][x] = 340
  106.         self.R[1][y] = 100
  107.         self.R[2][x] = 285
  108.         self.R[2][y] = 155
  109.         self.R[3][x] = self.L[3][x] = 223
  110.         self.R[3][y] = self.L[3][y] = 220
  111.         self.R[4][x] = 160
  112.         self.R[4][y] = 285
  113.         self.R[5][x] = 102
  114.         self.R[5][y] = 340
  115.  
  116.         self.L[1][x] = 102
  117.         self.L[1][y] = 100
  118.         self.L[2][x] = 160
  119.         self.L[2][y] = 155
  120.         self.L[4][x] = 285
  121.         self.L[4][y] = 285
  122.         self.L[5][x] = 345
  123.         self.L[5][y] = 340
  124.  
  125. class Yut :
  126.     Board_C = [[None]*3 for i in range(20)]
  127.     Board_R = [[None]*3 for i in range(7)]
  128.     Board_L = [[None]*3 for i in range(7)]
  129.     Score = [0] * 4
  130.     MaxPlayer = 0                   # 플레이중인 플레이어 수
  131.     TurnCount = 0                   # 몇번째 플레이어
  132.     selObject = None
  133.    
  134.     PlayAble = True                 # 굴리기 가능여부
  135.     Horse_img = [None] * 4          # 말 이미지 집합
  136.     Yut_img = [None] * 4            # 윷 이미지 집합
  137.     Dis_horse_but = [None] * 4      # 말 버튼 집합
  138.     Dis_horse_count = [None] * 4    # 말 갯수 레이블 집합
  139.    
  140.     Yut_Front = None                # 윷 앞 이미지
  141.     Yut_Back = None                 # 윷 뒤 이미지
  142.     Yut_BackB = None                # 윷 백도 위 이미지
  143.     Player = None
  144.     Horse_Area = None
  145.     Board_Area = None
  146.     NowRolled = False
  147.     Roll = 0                        # 윷 값
  148.    
  149.     def __init__(self, master) : # GUI 생성 및 게임 초기화
  150.         global Board_img
  151.         global Horse_img
  152.         global Yut_img
  153.         global Yut_Front
  154.         global Yut_Back
  155.         global Yut_BackB
  156.        
  157.         ###### 게임에 필요한 이미지 로드 ######
  158.         for i in range(0,4) :
  159.             self.Horse_img[i] = PhotoImage(file=f"resource/Horse{i+1}.png")
  160.         self.Yut_Front = PhotoImage(file="resource/Yut_Front.png")
  161.         self.Yut_Back = PhotoImage(file="resource/Yut_Back.png")
  162.         self.Yut_BackB = PhotoImage(file="resource/Yut_BackB.png")
  163.         Board_img = PhotoImage(file="resource/Board.png")
  164.  
  165.        
  166.         ###### 게임 판 GUI ######
  167.        
  168.         # 게임 판 레이블 프레임
  169.         self.Board_Area = LabelFrame(master, text="윷놀이 판", padx=10, pady=10)
  170.         self.Board_Area.place(x=10, y=10)
  171.  
  172.         # 게임 판 레이블
  173.         boardImg = Label(self.Board_Area, image=Board_img)
  174.         boardImg.pack()
  175.        
  176.  
  177.         ###### 윷 롤링 구역 GUI ######
  178.  
  179.         # 윷 롤링 구역 레이블 프레임
  180.         Play_Area = LabelFrame(master, text="윷", padx=6, pady=10)
  181.         Play_Area.place(x=10, y=539)
  182.  
  183.         # 윷 롤링 구역 (검정색 사각형)
  184.         rollArea = Label(Play_Area, width=55, height=13, background='black')
  185.         rollArea.pack(side='left', padx=5)
  186.  
  187.         # 윷 배치
  188.         x_loc = 80
  189.         x_gap = 80
  190.         for i in range(0, 4) :
  191.             self.Yut_img[i] = Label(master, image=self.Yut_Front, width=30, height=164,)
  192.             self.Yut_img[i].place(x=x_loc, y=585)
  193.             x_loc += x_gap
  194.        
  195.  
  196.         ###### 윷 롤링 버튼 GUI ######
  197.         button = Button(
  198.             Play_Area,
  199.             text='윷 던지기',
  200.             relief='solid',
  201.             width=10,
  202.             height=13,
  203.             command=self.Rolling
  204.         )
  205.         button.pack(side='right', padx=5)
  206.  
  207.         ###### 로그 박스 GUI ######
  208.         Log_Area = LabelFrame(master, text="로그", padx=10, pady=9)
  209.         Log_Area.place(x=530, y=10)
  210.        
  211.         frame = Frame(Log_Area, width=320, height=730, bd=1)
  212.         frame.pack()
  213.  
  214.         self.listbox_log = Listbox(frame, height=30, width=45, activestyle='none')
  215.         self.listbox_log.bindtags((self.listbox_log, master, "all"))
  216.        
  217.         self.scrollbar_log = Scrollbar(frame)
  218.  
  219.         self.scrollbar_log.pack(side='right', fill='y')
  220.         self.listbox_log.pack(side='left',fill='y')
  221.  
  222.         self.listbox_log.configure(yscrollcommand = self.scrollbar_log.set)
  223.         self.scrollbar_log.configure(command = self.listbox_log.yview)
  224.         self.item_num = 0
  225.  
  226.         ###### 말 GUI ######
  227.         self.Horse_Area = LabelFrame(master, text="말 보관", padx=10, pady=10)
  228.         self.Horse_Area.place(x=530, y=539)
  229.        
  230.         hFrame = Frame(self.Horse_Area, width=339, height=205, bd=1)
  231.         hFrame.pack()
  232.  
  233.         # 말 이미지
  234.         x_loc = 45
  235.         x_gap = 70
  236.         Dis_horse_img = [None] * 4
  237.         for i in range(0, 4) :
  238.             Dis_horse_img[i] = Label(self.Horse_Area, image=self.Horse_img[i])
  239.             Dis_horse_img[i].place(x=x_loc, y=50)
  240.             x_loc += x_gap
  241.  
  242.         # 말 갯수
  243.         x_loc = 47
  244.         x_gap = 70
  245.         for i in range(0, 4) :
  246.             self.Dis_horse_count[i] = Label(self.Horse_Area, text="없음")
  247.             self.Dis_horse_count[i].place(x=x_loc, y=30)
  248.             x_loc += x_gap
  249.    
  250.         # 말 버튼
  251.         for i in range(0, 4) :
  252.             self.Dis_horse_but[i] = Button(
  253.                 self.Horse_Area,
  254.                 text='선택',
  255.                 width=5,
  256.                 height=1,
  257.                 relief='solid',
  258.                 command=self.Select_Home,
  259.                 bg='snow'
  260.             )
  261.             x_loc += x_gap
  262.  
  263.     def iniGame(self, Max) : # # # # # # # # # # # # # # # # # # # # # 게임 초기화
  264.         self.MaxPlayer = Max
  265.         self.Player = [None] * Max
  266.         self.OnBoard_Horse = [None] * (3 * Max)
  267.         for i in range(0, self.MaxPlayer) :
  268.             self.Player[i] = PlayerUnit()
  269.         self.ReHorseAmount()
  270.  
  271.     def addLog(self, text) : # # # # # # # # # # # # # # # # # # # # # 로그 추가 메소드
  272.         now = datetime.now()
  273.         self.listbox_log.insert(END,"[%02d:%02d:%02d]  " %(now.hour, now.minute, now.second) + str(text))
  274.         self.listbox_log.select_clear(self.listbox_log.size() - 2)
  275.         self.listbox_log.select_set(END)
  276.         self.listbox_log.yview(END)
  277.         self.item_num += 1
  278.  
  279.     def ReHorseAmount(self) : # # # # # # # # # # # # # # # # # # # # # 말 갯수  GUI 갱신
  280.         for i in range(0, self.MaxPlayer) :
  281.             self.Dis_horse_count[i].configure(text=f"{self.Player[i].hAmount}개")
  282.        
  283.     def Rolling(self) : # 윷 롤링 메소드
  284.         if (self.PlayAble) and (self.NowRolled == False) :
  285.             result = 0
  286.  
  287.             # 윷 롤링
  288.             print(f" {self.TurnCount +1}번 플레이어 턴")
  289.             print(f"  └ 윷 던짐")
  290.             RandYut = [0] * 4
  291.             for i in range(0, 4) :
  292.                 RandYut[i] = random.randrange(0, 2)
  293.                 if(RandYut[i] == 1) :
  294.                     if(i == 0) :
  295.                         self.Yut_img[i].configure(image = self.Yut_BackB)
  296.                     else :
  297.                         self.Yut_img[i].configure(image = self.Yut_Back)
  298.                 else :
  299.                     self.Yut_img[i].configure(image = self.Yut_Front)
  300.                 result += RandYut[i]
  301.                
  302.             # 도, 1번째가 뒤집어졌을때 result를 -1로 (백도)
  303.             if(result == 1) and (RandYut[0] == 1) :
  304.                 result = -1
  305.             # 출력
  306.             if(result < 0) :
  307.                 self.addLog(f"백도가 나왔습니다!")
  308.             elif(result == 0) :
  309.                 self.addLog(f"모가 나왔습니다!")
  310.                 result = 5
  311.             elif(result == 1) :
  312.                 self.addLog(f"도가 나왔습니다!")
  313.             elif(result == 2) :
  314.                 self.addLog(f"개가 나왔습니다!")
  315.             elif(result == 3) :
  316.                 self.addLog(f"걸이 나왔습니다!")
  317.             elif(result == 4) :
  318.                 self.addLog(f"윷이 나왔습니다!")
  319.             print(f"  └ 윷 결과 : {result}")
  320.             self.addLog("움직일 말을 선택해주세요.")
  321.             self.Roll = result
  322.             self.SelectAble(True)
  323.             self.NowRolled = True
  324.         else :
  325.             self.addLog("아직 윷을 굴릴 수 없습니다.")
  326.  
  327.     def Select_Home(self) : # # # # # # # # # # # # # # # # # # # # # 말 선택 (보관함)
  328.         self.selObject = "I"
  329.         print(f"  └ 말 선택됨 : {self.selObject}")
  330.         if (self.Roll < 0) :
  331.             self.addLog("백도가 나와 말을 세울수 없습니다.")
  332.         self.MovingHorse()
  333.         self.SelectAble(False)
  334.  
  335.     def MovingHorse(self) :
  336.         amount = self.Roll
  337.         returnValue = False
  338.         field = ""
  339.         Move_Loc = ""
  340.         if (self.selObject == "I") and (amount > 0):
  341.             self.Player[self.TurnCount].hAmount -= 1
  342.             self.ReHorseAmount()
  343.  
  344.             # 0 = 객체
  345.             # 1 = 플레이어
  346.             # 2 = 갯수
  347.             if (amount != 5) :
  348.                 print(f"  └ 말 이동함 : {self.selObject} → C{amount}")
  349.                 if (self.Board_C[amount][0] == None) :
  350.                     # 전진 칸에 아무것도 없다면
  351.                     self.Board_C[amount][0] = Horse(amount, self.TurnCount, self.Board_Area)
  352.                     self.Board_C[amount][1] = self.TurnCount
  353.                     self.Board_C[amount][2] = 1
  354.                 else :
  355.                     # 전진 칸에 무언가가 있다면
  356.                     if (self.Board_C[amount][1] == self.TurnCount) :
  357.                         # 그 무언가가 자신의 말이라면
  358.                         self.Board_C[amount][2] += 1
  359.                         self.addLog(f"{self.Board_C[amount][1] + 1}번 플레이어의 말이 업혔습니다.")
  360.                         print(f"  └ 말 업힘 : C{amount}")
  361.                         returnValue = False
  362.                     else :
  363.                         # 그 무언가가 타인의 말이라면
  364.                         self.addLog(f"{self.Board_C[amount][1] +1}번 플레이어의 말이 잡혔습니다.")
  365.                         print(f"  └ {self.Board_C[amount][1] + 1}번 말 잡음 : C{amount}")
  366.                         self.Board_C[amount][0].hButton.place_forget()
  367.                         self.Player[self.Board_C[amount][1]].hAmount += self.Board_C[amount][2]
  368.                         self.Board_C[amount] = [None] * 3
  369.                         self.Board_C[amount][0] = Horse(amount, self.TurnCount, self.Board_Area)
  370.                         self.Board_C[amount][1] = self.TurnCount
  371.                         self.Board_C[amount][2] = 1
  372.                         returnValue = True
  373.             else :
  374.                 print(f"  └ 말 이동함 : {self.selObject} → R0")
  375.                 if (self.Board_R[0][0] == None) :
  376.                     # 전진 칸에 아무것도 없다면
  377.                     self.Board_R[0][0] = Horse(amount, self.TurnCount, self.Board_Area)
  378.                     self.Board_R[0][1] = self.TurnCount
  379.                     self.Board_R[0][2] = 1
  380.                 else :
  381.                     # 전진 칸에 무언가가 있다면
  382.                     if (self.Board_R[0][1] == self.TurnCount) :
  383.                         # 그 무언가가 자신의 말이라면
  384.                         self.Board_R[0][2] += 1
  385.                         self.addLog(f"{self.Board_R[0][1] + 1}번 플레이어의 말이 업혔습니다.")
  386.                         print(f"  └ 말 업힘 : R0")
  387.                         returnValue = False
  388.                     else :
  389.                         # 그 무언가가 타인의 말이라면
  390.                         self.addLog(f"{self.Board_R[0][1] +1}번 플레이어의 말이 잡혔습니다.")
  391.                         print(f"  └ {self.Board_R[0][1] + 1}번 말 잡음 : R0")
  392.                         self.Board_R[0][0].hButton.place_forget()
  393.                         self.Player[self.Board_R[0][1]].hAmount += self.Board_R[0][2]
  394.                         self.Board_R[0] = [None] * 3
  395.                         self.Board_R[0][0] = Horse(amount, self.TurnCount, self.Board_Area)
  396.                         self.Board_R[0][1] = self.TurnCount
  397.                         self.Board_R[0][2] = 1
  398.                         returnValue = True
  399.  
  400.         elif (self.selObject != "I") :
  401.  
  402.             if (amount > 0) :
  403.                 field = self.selObject[:1]
  404.                 Cur_idx = int(self.selObject[1:])
  405.                 Move_Loc = ""
  406.                 if (field == "R") and (Cur_idx == 3):
  407.                     field = "L"
  408.                 Next_idx = Cur_idx + amount
  409.                
  410.                 if (field == "C") :
  411.                     if (Next_idx > 20) :
  412.                         field = "END"
  413.                     else :
  414.                         if (Next_idx == 5) :
  415.                             Move_Loc = "R0"
  416.                         elif (Next_idx == 10) :
  417.                             Move_Loc = "L0"
  418.                         elif (Next_idx == 20) :
  419.                             Move_Loc = "L6"
  420.                         else :
  421.                             Move_Loc = f"C{Next_idx}"
  422.  
  423.                 elif (field == "L") :
  424.                     if (Next_idx > 6) :
  425.                         field = "END"
  426.                     else :
  427.                         Move_Loc = f"L{Next_idx}"
  428.  
  429.                 elif (field == "R") :
  430.                     if (Next_idx > 6) :
  431.                         Move_Loc = f"C{amount + 14}"
  432.                     else :
  433.                         Move_Loc = f"R{Next_idx}"
  434.                        
  435.             else :
  436.                 # 백도
  437.                 field = self.selObject[:1]
  438.                 Next_idx = int(self.selObject[1:]) - 1
  439.                 Move_Loc = ""
  440.  
  441.                 if (field == "C"):
  442.                     if (Next_idx < 0):
  443.                         field = "END"
  444.                     else:
  445.                         if (Next_idx == 0):
  446.                             Move_Loc = "L0"
  447.                         elif (Next_idx == 5):
  448.                             Move_Loc = "R0"
  449.                         elif (Next_idx == 10):
  450.                             Move_Loc = "L0"
  451.                         else:
  452.                             Move_Loc = f"C{Next_idx}"
  453.  
  454.                 elif (field == "L"):
  455.                     if (Next_idx > 6):
  456.                         field = "END"
  457.                     elif (Next_idx < 0):
  458.                         Move_Loc = "C9"
  459.                     else:
  460.                         Move_Loc = f"L{Next_idx}"
  461.  
  462.                 elif (field == "R"):
  463.                     if (Next_idx > 6):
  464.                         amount = Next_idx - amount
  465.                         Move_Loc = f"C{amount + 15}"
  466.                     elif (Next_idx < 0):
  467.                         Move_Loc = "C4"
  468.                     else:
  469.                         if (Next_idx == 3):
  470.                             Move_Loc = "L3"
  471.                         else:
  472.                             Move_Loc = f"R{Next_idx}"
  473.  
  474.             print(f"  └ 말 이동함 : {self.selObject} → {Move_Loc}")
  475.             # 통과 조건
  476.             if (field == "END"):
  477.                 num = int(self.selObject[1:])
  478.                 score = 0
  479.                 if (self.selObject[:1] == "C") :
  480.                     self.Board_C[num][0].hButton.place_forget()
  481.                     self.Score[self.TurnCount] += self.Board_C[num][2]
  482.                     score = self.Board_C[num][2]
  483.                 elif (self.selObject[:1] == "L") :
  484.                     self.Board_L[num][0].hButton.place_forget()
  485.                     self.Score[self.TurnCount] += self.Board_L[num][2]
  486.                     score = self.Board_L[num][2]
  487.                 self.DeleteLoc(self.selObject)
  488.                 self.addLog(f"{self.TurnCount + 1} 플레이어의 {score}개 득점!")
  489.                 print(f"  └ {score}점 득점")
  490.                 for i in range(0, len(self.Score)) :
  491.                     if (self.Score[i] >= 3) :
  492.                         self.addLog(f"{self.TurnCount + 1} 플레이어가 승리했습니다!")
  493.                         print(f"  └ 승리")
  494.                         print("게임 끝")
  495.                         return
  496.                        
  497.             else:
  498.                 # 말 이동
  499.                 num = int(Move_Loc[1:])
  500.                 if (Move_Loc[:1] == "C"):
  501.                     if (self.Board_C[num][0] != None):
  502.                         if (self.Board_C[num][1] == self.TurnCount):
  503.                             self.ForgetLoc(self.selObject)
  504.                             self.Board_C[num][2] += self.callNum(self.selObject)
  505.                             self.addLog(f"{self.Board_C[num][1] + 1}번 플레이어의 말이 업혔습니다.")
  506.                             print(f"  └ 말 업힘 : C{num}")
  507.                             returnValue = False
  508.                         else:
  509.                             self.Board_C[num][0].hButton.place_forget()
  510.                             self.addLog(f"{self.Board_C[num][1] + 1}번 플레이어의 말이 잡혔습니다.")
  511.                             print(f"  └ {self.Board_C[num][1]+1}번 말 잡음 : C{num}")
  512.                             self.Player[self.Board_C[num][1]].hAmount += self.Board_C[num][2]
  513.                             self.Board_C[num] = self.ChangeLoc(self.selObject)
  514.                             self.DeleteLoc(self.selObject)
  515.                             returnValue = True
  516.                         self.DeleteLoc(self.selObject)
  517.                     else:
  518.                         self.Board_C[num] = self.ChangeLoc(self.selObject)
  519.                         self.DeleteLoc(self.selObject)
  520.                     self.Board_C[num][0].Location = Move_Loc
  521.                     self.Board_C[num][0].Replace()
  522.  
  523.                 elif (Move_Loc[:1] == "L"):
  524.                     if (self.Board_L[num][0] != None):
  525.                         if (self.Board_L[num][1] == self.TurnCount):
  526.                             self.ForgetLoc(self.selObject)
  527.                             self.Board_L[num][2] += self.callNum(self.selObject)
  528.                             self.addLog(f"{self.Board_L[num][1] + 1}번 플레이어의 말이 업혔습니다.")
  529.                             print(f"  └ 말 업힘 : L{num}")
  530.                             returnValue = False
  531.                         else:
  532.                             self.Board_L[num][0].hButton.place_forget()
  533.                             self.addLog(f"{self.Board_L[num][1] + 1}번 플레이어의 말이 잡혔습니다.")
  534.                             print(f"  └ {self.Board_L[num][1] + 1}번 말 잡음 : L{num}")
  535.                             self.Player[self.Board_L[num][1]].hAmount += self.Board_L[num][2]
  536.                             self.Board_L[num] = self.ChangeLoc(self.selObject)
  537.                             self.DeleteLoc(self.selObject)
  538.                             returnValue = True
  539.                         self.DeleteLoc(self.selObject)
  540.                     else:
  541.                         self.Board_L[num] = self.ChangeLoc(self.selObject)
  542.                         self.DeleteLoc(self.selObject)
  543.                     self.Board_L[num][0].Location = Move_Loc
  544.                     self.Board_L[num][0].Replace()
  545.  
  546.                 elif (Move_Loc[:1] == "R"):
  547.                     if (self.Board_R[num][0] != None):
  548.                         if (self.Board_R[num][1] == self.TurnCount):
  549.                             self.ForgetLoc(self.selObject)
  550.                             self.Board_R[num][2] += self.callNum(self.selObject)
  551.                             self.addLog(f"{self.Board_R[num][1] + 1}번 플레이어의 말이 업혔습니다.")
  552.                             print(f"  └ 말 업힘 : R{num}")
  553.                             returnValue = False
  554.                         else:
  555.                             self.Board_R[num][0].hButton.place_forget()
  556.                             self.addLog(f"{self.Board_R[num][1] + 1}번 플레이어의 말이 잡혔습니다.")
  557.                             print(f"  └ {self.Board_R[num][1] + 1}번 말 잡음 : R{num}")
  558.                             self.Player[self.Board_R[num][1]].hAmount += self.Board_R[num][2]
  559.                             self.Board_R[num] = self.ChangeLoc(self.selObject)
  560.                             self.DeleteLoc(self.selObject)
  561.                             returnValue = True
  562.                         self.DeleteLoc(self.selObject)
  563.                     else:
  564.                         self.Board_R[num] = self.ChangeLoc(self.selObject)
  565.                         self.DeleteLoc(self.selObject)
  566.                     self.Board_R[num][0].Location = Move_Loc
  567.                     self.Board_R[num][0].Replace()
  568.         self.NowRolled = False
  569.         if (returnValue) or (self.Roll >= 4):
  570.             self.TryTurn()
  571.         else :
  572.             self.NextTurn()
  573.  
  574.     def SelectAble(self, value) :
  575.         if (value == True) :
  576.             x_loc = 39
  577.             x_gap = 70
  578.             for i in range(0, 4):
  579.                 self.Dis_horse_but[i].place_forget()
  580.                 if (i == self.TurnCount):
  581.                     if (self.Player[i].hAmount < 1):
  582.                         continue
  583.                     self.Dis_horse_but[i].place(x=x_loc, y=110)
  584.                 x_loc += x_gap
  585.             for i in range(0, len(self.Board_C)):
  586.                 if (self.Board_C[i][0] != None):
  587.                     if (self.Board_C[i][1] == self.TurnCount):
  588.                         self.Board_C[i][0].hButton.configure(state='normal', text=f"{self.Board_C[i][2]}")
  589.                     else:
  590.                         self.Board_C[i][0].hButton.configure(text=f"{self.Board_C[i][2]}")
  591.                         self.Board_C[i][0].hButton.configure(state='disable')
  592.             for i in range(0, len(self.Board_L)):
  593.                 if (self.Board_L[i][0] != None):
  594.                     if (self.Board_L[i][1] == self.TurnCount):
  595.                         self.Board_L[i][0].hButton.configure(state='normal', text=f"{self.Board_L[i][2]}")
  596.                     else:
  597.                         self.Board_L[i][0].hButton.configure(text=f"{self.Board_L[i][2]}")
  598.                         self.Board_L[i][0].hButton.configure(state='disable')
  599.             for i in range(0, len(self.Board_R)):
  600.                 if (self.Board_R[i][0] != None):
  601.                     if (self.Board_R[i][1] == self.TurnCount):
  602.                         self.Board_R[i][0].hButton.configure(state='normal', text=f"{self.Board_R[i][2]}")
  603.                     else:
  604.                         self.Board_R[i][0].hButton.configure(text=f"{self.Board_R[i][2]}")
  605.                         self.Board_R[i][0].hButton.configure(state='disable')
  606.         else :
  607.             for i in range(0, 4):
  608.                 self.Dis_horse_but[i].place_forget()
  609.  
  610.             for i in range(0, len(self.Board_C)) :
  611.                 if (self.Board_C[i][0] != None) :
  612.                     self.Board_C[i][0].hButton.configure(text=f"{self.Board_C[i][2]}")
  613.                     self.Board_C[i][0].hButton.configure(state='disable')
  614.             for i in range(0, len(self.Board_L)) :
  615.                 if (self.Board_L[i][0] != None) :
  616.                     self.Board_L[i][0].hButton.configure(text=f"{self.Board_L[i][2]}")
  617.                     self.Board_L[i][0].hButton.configure(state='disable')
  618.             for i in range(0, len(self.Board_R)) :
  619.                 if (self.Board_R[i][0] != None) :
  620.                     self.Board_R[i][0].hButton.configure(text=f"{self.Board_R[i][2]}")
  621.                     self.Board_R[i][0].hButton.configure(state='disable')
  622.         self.ReHorseAmount()
  623.  
  624.     def callNum(self, select) :
  625.         num = int(select[1:])
  626.         if (select[:1] == "C") :
  627.             return self.Board_C[num][2]
  628.         elif (select[:1] == "L") :
  629.             return self.Board_L[num][2]
  630.         elif (select[:1] == "R") :
  631.             return self.Board_R[num][2]
  632.  
  633.     def ForgetLoc(self, select) :
  634.         num = int(select[1:])
  635.         if (select[:1] == "C") :
  636.             self.Board_C[num][0].hButton.place_forget()
  637.         elif (select[:1] == "L") :
  638.             self.Board_L[num][0].hButton.place_forget()
  639.         elif (select[:1] == "R") :
  640.             self.Board_R[num][0].hButton.place_forget()
  641.  
  642.     def ChangeLoc(self, select) :
  643.         num = int(select[1:])
  644.         if (select[:1] == "C") :
  645.             return self.Board_C[num]
  646.         elif (select[:1] == "L") :
  647.             return self.Board_L[num]
  648.         elif (select[:1] == "R") :
  649.             return self.Board_R[num]
  650.  
  651.     def DeleteLoc(self, select) :
  652.         num = int(select[1:])
  653.         if (select[:1] == "C") :
  654.             self.Board_C[num] = [None] * 3
  655.         elif (select[:1] == "L") :
  656.             self.Board_L[num] = [None] * 3
  657.         elif (select[:1] == "R") :
  658.             self.Board_R[num] = [None] * 3
  659.  
  660.     def TryTurn(self) :
  661.         self.selObject = None
  662.         self.SelectAble(False)
  663.         self.addLog(f"한번더 기회가 주어집니다.")
  664.         print(f"  └ 턴 다시 진행")
  665.  
  666.     def NextTurn(self) :
  667.         self.TurnCount += 1
  668.         if (self.TurnCount >= self.MaxPlayer) :
  669.             self.TurnCount = 0
  670.         self.selObject = None
  671.         self.SelectAble(False)
  672.         self.addLog(f"{all.TurnCount + 1}번 플레이어의 차례입니다. 윷을 던져주세요")
  673.         print(f"  └ 턴 넘어감")
  674.  
  675. # Main
  676. root = Tk()
  677. root.iconbitmap(default = 'resource/icon.ico')
  678. root.title("윷놀이")
  679. root.geometry("900x795")
  680. root.resizable(False, False)
  681. global all
  682. while True :
  683.     try :
  684.         Max = int(input("몇 인용으로 게임하시겠습니까? : "))
  685.         if (Max >= 2) and (Max <= 4) :
  686.             break
  687.         print("\n2인 이상 4인 이하의 게임입니다.")
  688.     except ValueError :
  689.         print("\n올바르지 않은 문자가 포함됬습니다.")
  690. print("────────────────────────")
  691. all = Yut(root)
  692. all.addLog(f"게임이 {Max}인용으로 시작됩니다.")
  693. all.addLog(f"{all.TurnCount + 1}번 플레이어의 차례입니다. 윷을 던져주세요")
  694. all.iniGame(Max)
  695. root.lift()
  696. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement