import pygame, sys
from pygame.locals import *
import random, time
class InputField:
def __init__(self, size) -> None:
self.image = pygame.Surface(size, pygame.SRCALPHA)
self.image.fill((0, 0, 0, 255))
self.font = pygame.font.SysFont("malgungothic", size[1])
self.text = ""
self.edit_pos = 0
self.text_edit = False
self.text_editing = ""
def event(self, event):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_BACKSPACE:
self.text = self.text[:self.edit_pos - 1] + self.text[self.edit_pos:]
self.edit_pos = max(0, self.edit_pos - 1)
elif event.type == pygame.TEXTEDITING:
self.text_edit = True
self.text_editing = event.text
self.text_editing_pos = event.start
elif event.type == pygame.TEXTINPUT:
self.text_edit = False
self.text_editing = ""
self.text = self.text[:self.edit_pos] + event.text + self.text[self.edit_pos:]
self.edit_pos = min(self.edit_pos + len(event.text), len(self.text + self.text_editing))
def render(self, surface):
surface.blit(self.image, self.image.get_rect(topleft=(200, 500)))
string = self.font.render(self.text + self.text_editing, True, (255, 255, 255))
surface.blit(string, string.get_rect(topleft=(200, 500)))
pygame.init()
fps = 60
FramePerSec = pygame.time.Clock()
Surface = pygame.display.set_mode((700, 400))
# 색깔 설정
red = (255, 0, 0)
orange = (255, 153, 51)
yellow = (255, 255, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
white = (255, 255, 255)
black = (0, 0, 0)
font = pygame.font.SysFont('@System', 20)
small_font = pygame.font.SysFont('@System', 20)
game_over = font.render("GAME_OVER", True, black)
A=0
B=0
C=0
while True:
A=random.randint(0,9)
B=random.randint(0,9)
C=random.randint(0,9)
if A == B or A==C or B == C :
continue
else :
break
answer=[]
answer.append([A,B,C])
guess=[]
strike=0
ball=0
out=0
tried=0
def number() :
global strike
global ball
global out
global answer
# 변수를 리셋해버리자
ball = strike = out = 0
guess=[]
a,b,c=map(int, input().split())#화면모드로 고치기
guess.append([a,b,c])
for i in range(0,3) :
if answer[0][i] == guess[0][i] :
strike += 1
elif guess[0][i] == answer[0][i-1] or guess[0][i] == answer[0][i-2] :
ball += 1
elif guess[0][i] != answer[0][i-1] or guess[0][i] != answer[0][i-2] :
out += 1
if strike == 3 :
print(" HOMERUN!!!, ", tried,"회 도전만에 성공!")#화면모드로 고치기
elif out == 3 :
print("OUT!")#화면모드로 고치기
else :
print(ball ,"BALL, " ,strike ," STRIKE 입니다.")#화면모드로 고치기
# pygame.init()
# pygame.key.start_text_input()
# screen = pygame.display.set_mode((1000, 800))
#
# input_field = InputField((300, 50))
#
# while True:
# screen.fill((100, 0, 50))
#
# for event in pygame.event.get():
# if event.type == pygame.QUIT:
# pygame.quit()
# input_field.event(event)
#
# input_field.render(screen)
#
# pygame.display.update()
top of page

실제 작동 상태를 확인하려면 라이브 사이트로 이동하세요.
20250923
20250923
댓글 0개
좋아요
댓글(0)
더 이상 게시물에 대한 댓글 기능이 지원되지 않습니다. 자세한 사항은 사이트 소유자에게 문의하세요.
bottom of page


