def draw_card(dealer, player): bj_board.clear() dealer_score = Text("The dealer's Total : " + str(hand_value(dealer)), 20) player_score = Text("Your Total : " + str(hand_value(player)), 20) dealer_score.setFontColor("white") player_score.setFontColor("white") dealer_score.moveTo(450, 100) player_score.moveTo(450, 300) x0, y0 = 100, 100 # for dealer x1, y1 = 100, 300 # for player dx_dealer = 0 dx_player = 0 if dealer[0].hidden: # 게임 안 끝남(내 점수만 표시) for card in dealer: if card.hidden: back_img = Image(img_path + "Back.png") back_img.moveTo(x0 + dx_dealer, y0) bj_board.add(back_img) dx_dealer += 20 else: front_img = card.image front_img.moveTo(x0 + dx_dealer, y0) bj_board.add(front_img) dx_dealer += 20 for card in player: front_img = card.image front_img.moveTo(x1 + dx_player, y1) bj_board.add(front_img) dx_player += 20 bj_board.add(player_score) else: # 게임 끝남(두 사람 점수 모두 표시) for card in dealer: if card.hidden: back_img = Image(img_path + "Back.png") back_img.moveTo(x0 + dx_dealer, y0) bj_board.add(back_img) dx_dealer += 20 else: front_img = card.image front_img.moveTo(x0 + dx_dealer, y0) bj_board.add(front_img) dx_dealer += 20 for card in player: front_img = card.image front_img.moveTo(x1 + dx_player, y1) bj_board.add(front_img) dx_player += 20 bj_board.add(dealer_score) bj_board.add(player_score)
def view_scores(): # 점수 보기 __clear() paper.clear() bg = Image(resource_path("images/image/background.png")) bg.moveTo(400, 300) paper.add(bg) Prize = Layer() grade = Text(" Rank Name Tries", 25) grade.moveTo(400, 100) firstEmpty = Text("-----------------------------------------------------", 25) firstEmpty.moveTo(400, 130) Prize.add(grade) Prize.add(firstEmpty) paper.add(Prize) ThirdEmpty = Text("-----------------------------------------------------", 25) ThirdEmpty.moveTo(400, 550) paper.add(ThirdEmpty) tempDict = dict() with open(resource_path("best_user_score.txt"), "r", encoding='utf8') as f: while True: read = list(f.readline().split()) if not read: break user_name, tries = read[0], int(read[1]) if user_name not in tempDict: tempDict[user_name] = tries else: if tempDict[user_name] > tries: tempDict[user_name] = tries sorted_list = sorted(tempDict.items(), key=lambda x: x[1]) ranking = 1 ran = len(sorted_list) if len(sorted_list) <= 10 else 10 for i in range(ran): if sorted_list[i - 1][1] < sorted_list[i][1]: ranking += 1 data = "%2sth\t%10s\t\t%2d" % (ranking, sorted_list[i][0], sorted_list[i][1]) data_text = Text(data, 25) data_text.moveTo(400, 160 + 40 * i) paper.add(data_text) input("메인으로 가려면 아무키나 입력하세요")
def displayHowToPlay(): # 게임 방법을 알려주는 화면 global paper paper.clear() HowToPlay = Layer() HowToPlay_background = Image(resource_path("images/how_to_back.png")) HowToPlay_background.setDepth(100) HowToPlay_background.moveTo(400, 300) what_is = Text("숫자 야구란?", 20) FirstTxt = Text("감춰진 3개의 숫자가 무엇인지 맞추는 게임입니다.", 20) wayTxt = Text("게임 방법", 20) SecondTxt = Text("1. 숫자는 0~9까지 구성되어 있으며, 각 숫자는 한번씩만 사용 가능합니다", 20) ThirdTxt = Text("2. 숫자와 자리의 위치가 맞으면 스트라이크(S), 숫자만 맞으면 볼(B) 입니다.", 20) FourthTxt = Text("3. 숫자가 하나도 맞지 않을 경우 아웃(OUT)으로 표시됩니다.", 20) HowToPlay.add(what_is) HowToPlay.add(FirstTxt) HowToPlay.add(wayTxt) HowToPlay.add(SecondTxt) HowToPlay.add(ThirdTxt) HowToPlay.add(FourthTxt) HowToPlay.add(HowToPlay_background) what_is.moveTo(400, 80) FirstTxt.moveTo(400, 160) wayTxt.moveTo(400, 240) SecondTxt.moveTo(400, 320) ThirdTxt.moveTo(400, 390) FourthTxt.moveTo(400, 460) paper.add(HowToPlay) return
def __init__(self, state): Drawable.__init__(self) self._label = Text(state.abbrev(), 9, Point(*state.centroid().project())) self._bounds = None self._polys = [] for k in range(state.numBoundaries()): b = state.getBoundary(k) p = Polygon() for geo in b: x, y = geo.project() p.addPoint(Point(x, y)) if x > 0: # hack to deal with Alaska going past 180 date line self._bounds = _mergeBounds([x, x, y, y], self._bounds) self._polys.append(p)
def displayNameCheck(): #'이름 이(가) 맞습니까?' 화면 displayCheck("namecheck") global l_nameCheck l_nameCheck = Layer() nameBox = Rectangle(230, 50, Point(148, 255)) nameBox.setBorderWidth(3) nameCk = Text(str(userName), 40) nameCk.moveTo(148, 255) l_nameCheck.add(nameBox) l_nameCheck.add(nameCk) paper.add(l_nameCheck) return
def how_to_play(): os.system(console_clear) # 수정 필요 ############################################ HowToPlay = Layer() HowToPlay_background = Image("python/how_to_back.png") HowToPlay_background.setDepth(100) HowToPlay_background.moveTo(500, 300) what_is = Text("숫자 야구란?", 26) FirstTxt = Text("감춰진 3개의 숫자가 무엇인지 맞추는 게임입니다.", 26) wayTxt = Text("게임 방법", 26) SecondTxt = Text("1. 숫자는 0~9까지 구성되어 있으며, 각 숫자는 한번씩만 사용 가능합니다", 26) ThirdTxt = Text("2. 숫자와 자리의 위치가 맞으면 스트라이크(S), 숫자만 맞으면 볼(B) 입니다.", 26) FourthTxt = Text("3. 숫자가 하나도 맞지 않을 경우 아웃(OUT)으로 표시됩니다.", 26) HowToPlay.add(what_is) HowToPlay.add(FirstTxt) HowToPlay.add(wayTxt) HowToPlay.add(SecondTxt) HowToPlay.add(ThirdTxt) HowToPlay.add(FourthTxt) HowToPlay.add(HowToPlay_background) what_is.moveTo(500, 70) FirstTxt.moveTo(500, 150) wayTxt.moveTo(500, 230) SecondTxt.moveTo(500, 310) ThirdTxt.moveTo(500, 380) FourthTxt.moveTo(500, 450) paper.add(HowToPlay) ############################################ # 수정 범위 끝 print("메인으로 가려면 아무키나 입력하세요") try: go_main = sys.stdin.readline() except: pass print(go_main)
def execute(): global paper paper.clear() os.system(console_clear) ##################################################### Main = Layer() start = Rectangle(200, 100, Point(275, 450)) start.setFillColor('yellow') Main.add(start) way = Rectangle(200, 100, Point(525, 450)) way.setFillColor('yellow') Main.add(way) paper.add(Main) Man = Layer() man = Image("python/man.png") Man.setDepth(80) Man.add(man) Man.moveTo(390, 350) paper.add(Man) Txt = Layer() startTxt = Text("START", 30) startTxt.moveTo(275, 450) Txt.add(startTxt) howplayTxt = Text("HOW PLAY", 30) howplayTxt.moveTo(525, 450) Txt.add(howplayTxt) numberTxt = Text("NUMBER", 45) numberTxt.moveTo(140, 320) Txt.add(numberTxt) baseballTxt = Text("BASEBALL", 45) baseballTxt.moveTo(660, 350) Txt.add(baseballTxt) # 구름 Cloud = Layer() flcloud = Circle(30, Point(80, 70)) slcloud = Circle(30, Point(130, 70)) thlcloud = Circle(30, Point(180, 70)) flcloud.setFillColor('white') slcloud.setFillColor('white') thlcloud.setFillColor('white') flcloud.setBorderColor('white') slcloud.setBorderColor('white') thlcloud.setBorderColor('white') Cloud.add(flcloud) Cloud.add(slcloud) Cloud.add(thlcloud) Cloud.scale(5) Cloud.moveTo(-250, 0) Cloud.setDepth(100) paper.add(Cloud) # 대화상자 Input_a = Layer() input_bar = Rectangle(1000, 50, Point(500, 575)) input_bar.setFillColor('black') input_bar.setBorderWidth(0) Input_a.add(input_bar) paper.add(Input_a) #명령 입력 welcome = Text("☆☆☆ Welcome to Number Baseball Game!! ☆☆☆", 20) welcome.moveTo(390, 575) welcome.setFontColor("white") introduction1 = Text("게임을 시작하려면 '1'을 입력하세요", 20) introduction1.moveTo(390, 575) introduction1.setFontColor("white") introduction2 = Text("게임방법을 알고싶다면 '2'를 입력하세요", 20) introduction2.moveTo(390, 575) introduction2.setFontColor("white") introduction3 = Text("게임순위를 보고싶다면 '3'을 입력하세요", 20) introduction3.moveTo(390, 575) introduction3.setFontColor("white") introduction4 = Text("게임을 종료하려면 '4'를 입력하세요", 20) introduction4.moveTo(390, 575) introduction4.setFontColor("white") for _ in range(3): paper.add(Txt) sleep(0.5) paper.remove(Txt) sleep(0.5) paper.add(Txt) paper.add(welcome) sleep(2) paper.remove(welcome) paper.add(introduction1) sleep(2) paper.remove(introduction1) paper.add(introduction2) sleep(2) paper.remove(introduction2) paper.add(introduction3) sleep(2) paper.remove(introduction3) paper.add(introduction4) sleep(2) paper.remove(introduction4) ############################################################# while True: try: choose_option = input("\n옵션을 선택해주세요 : ") except: os.system(console_clear) continue if choose_option == '1': while True: gs = game_start() if gs == -1: execute() return elif choose_option == '2': how_to_play() execute() return elif choose_option == '3': view_scores() execute() return elif choose_option == '4': os.system(console_clear) return
def displayMainScreen(): # 게임 메인 화면(메뉴) global paper paper.clear() Main = Layer() start = Rectangle(150, 100, Point(115, 450)) start.setFillColor('yellow') Main.add(start) way = Rectangle(150, 100, Point(305, 450)) way.setFillColor('yellow') Main.add(way) score = Rectangle(150, 100, Point(495, 450)) score.setFillColor('yellow') Main.add(score) exit = Rectangle(150, 100, Point(685, 450)) exit.setFillColor('yellow') Main.add(exit) paper.add(Main) Man = Layer() man = Image(resource_path("images/man.png")) Man.setDepth(80) Man.add(man) Man.moveTo(390, 350) paper.add(Man) Txt = Layer() startTxt = Text("1. START", 25) startTxt.moveTo(115, 450) Txt.add(startTxt) howplayTxt = Text("2. HOW", 25) howplayTxt.moveTo(305, 450) Txt.add(howplayTxt) numberTxt = Text("NUMBER", 45) numberTxt.moveTo(140, 320) Txt.add(numberTxt) baseballTxt = Text("BASEBALL", 45) baseballTxt.moveTo(660, 350) Txt.add(baseballTxt) scoreTxt = Text("3. SCORE", 25) scoreTxt.moveTo(495, 450) Txt.add(scoreTxt) exitTxt = Text("4. EXIT", 25) exitTxt.moveTo(685, 450) Txt.add(exitTxt) # 구름 Cloud = Layer() flcloud = Circle(30, Point(80, 70)) slcloud = Circle(30, Point(130, 70)) thlcloud = Circle(30, Point(180, 70)) flcloud.setFillColor('white') slcloud.setFillColor('white') thlcloud.setFillColor('white') flcloud.setBorderColor('white') slcloud.setBorderColor('white') thlcloud.setBorderColor('white') Cloud.add(flcloud) Cloud.add(slcloud) Cloud.add(thlcloud) Cloud.scale(5) Cloud.moveTo(-250, 0) Cloud.setDepth(100) paper.add(Cloud) # 대화상자 Input_a = Layer() input_bar = Rectangle(1000, 50, Point(500, 575)) input_bar.setFillColor('black') input_bar.setBorderWidth(0) Input_a.add(input_bar) paper.add(Input_a) #명령 입력 welcome = Text("☆☆☆ Welcome to Number Baseball Game!! ☆☆☆", 20) welcome.moveTo(390, 575) welcome.setFontColor("white") introduction1 = Text("게임을 시작하려면 '1'을 입력하세요", 20) introduction1.moveTo(390, 575) introduction1.setFontColor("white") introduction2 = Text("게임방법을 알고싶다면 '2'를 입력하세요", 20) introduction2.moveTo(390, 575) introduction2.setFontColor("white") introduction3 = Text("게임순위를 보고싶다면 '3'을 입력하세요", 20) introduction3.moveTo(390, 575) introduction3.setFontColor("white") introduction4 = Text("게임을 종료하려면 '4'를 입력하세요", 20) introduction4.moveTo(390, 575) introduction4.setFontColor("white") introduction5 = Text("옵션을 선택해주세요!", 20) introduction5.moveTo(390, 575) introduction5.setFontColor("white") for _ in range(3): paper.add(Txt) sleep(0.5) paper.remove(Txt) sleep(0.5) paper.add(Txt) paper.add(welcome) sleep(1.5) paper.remove(welcome) paper.add(introduction1) sleep(1.5) paper.remove(introduction1) paper.add(introduction2) sleep(1.5) paper.remove(introduction2) paper.add(introduction3) sleep(1.5) paper.remove(introduction3) paper.add(introduction4) sleep(1.5) paper.remove(introduction4) sleep(1.5) paper.add(introduction5) return
def playGame(userGivesNumber=False): # 인게임 global strikes global balls global tries global givenNumber global predictedNumber ask = " " if userGivesNumber: displayFix("digit") while True: try: __clear() ask = input("자릿수를 입력해주세요 (3 또는 4) : ") except: continue if ask == '3' or ask == '4': break givenNumber = __getRandomNumber(int(ask)) paper.remove(fix) else: __clear() givenNumber = __getRandomNumber(rd.randint(3, 4)) displayStartSec() __clear() displayStartGame() while True: __clear() balls = strikes = 0 while True: __clear() displayFix("guess") t = "< " + str(len(givenNumber)) + "자리수 >" len_givenNumber = Text(t, 30) len_givenNumber.moveTo(400, 400) paper.add(len_givenNumber) predictedNumber = input("숫자를 추측하세요: ") paper.remove(fix) paper.remove(len_givenNumber) if not predictedNumber.isdigit(): continue if len(predictedNumber) != len(givenNumber): continue isDuplicate = False for i in range(len(predictedNumber)): if not isDuplicate: for j in range(len(predictedNumber)): if i != j and predictedNumber[i] == predictedNumber[j]: displayFix("dupl_input") sleep(1) paper.remove(fix) isDuplicate = not isDuplicate break if isDuplicate == False: tries += 1 break for i in range(len(givenNumber)): for j in range(len(predictedNumber)): if givenNumber[i] == predictedNumber[j]: if i == j: strikes += 1 else: balls += 1 if strikes == 0 and balls == 0: displayOutSituation() elif strikes == len(givenNumber): displayGameOverByWinning() return tries else: __clear() displayEvaluationResult() continue