Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
02be145
branch change test 2
DeokyongKim Mar 29, 2022
8582e41
Update README.md
DeokyongKim Mar 31, 2022
d88220d
test
ssehyeon Apr 5, 2022
a34e625
주제 작성
DeokyongKim Apr 17, 2022
a8ca1de
Update README.md
DeokyongKim Apr 17, 2022
e1fd30d
some
DeokyongKim Apr 27, 2022
34c6368
Final change
DeokyongKim Apr 27, 2022
7188824
some more changes
DeokyongKim Apr 27, 2022
66fcd51
Update README.md
DeokyongKim Apr 27, 2022
67c0933
Update README.md
DeokyongKim Apr 27, 2022
eb48a0b
Add color, key, basic screen
DeokyongKim May 2, 2022
83c893f
add __name__ == __init__
DeokyongKim May 2, 2022
0461c80
basic display is ready
DeokyongKim May 2, 2022
e101f4e
description added
DeokyongKim May 2, 2022
580d9f6
added interaction class
DeokyongKim May 2, 2022
c84bd56
add exit condition and key pressed fuction
DeokyongKim May 2, 2022
350ec6c
added some interactions and Final Scene class
DeokyongKim May 2, 2022
51d8760
type annotation (type hint) added
DeokyongKim May 2, 2022
ee5e57f
test
DeokyongKim May 2, 2022
8e054e2
Merge remote-tracking branch 'origin/main'
DeokyongKim May 3, 2022
3270f4a
ㅁㄴㅇㄹㅁㄹㅇ
JunseoSong May 4, 2022
0fccc3e
Merge remote-tracking branch 'origin/main'
DeokyongKim May 10, 2022
a9bd061
Add decision page.
DeokyongKim May 10, 2022
79cc435
We need to get mouse input.
DeokyongKim May 10, 2022
0a302b1
interaction 파일을 분류했더니 sys.exit이 먹히지 않음 import가 문제인 것 같은데 모르겠고 나머지는 잘 …
DeokyongKim May 10, 2022
2107fff
입력이 잘 안됨
DeokyongKim May 24, 2022
230071e
everything GOOD
DeokyongKim May 31, 2022
a4e5211
example for 2 by 2
DeokyongKim May 31, 2022
4018cff
노가다 했습니다.
quartz0516 May 31, 2022
3645a5b
.
ssehyeon May 31, 2022
d89b1e6
update example
DeokyongKim May 31, 2022
60df460
Merge remote-tracking branch 'origin/main'
DeokyongKim May 31, 2022
a7c9877
REALLY done
DeokyongKim May 31, 2022
4f6ccc6
open source
DeokyongKim May 31, 2022
0b370d0
노가다 했습니다.
quartz0516 May 31, 2022
9af8dca
K_map_complete_2_3_4_var.py
JeongyunBAE May 31, 2022
046e64a
노가다 했습니다.
quartz0516 May 31, 2022
a981f47
노가다 했습니다.
quartz0516 May 31, 2022
ea879f6
Merge remote-tracking branch 'origin/main'
quartz0516 May 31, 2022
d52d642
노가다 했습니다.
quartz0516 May 31, 2022
1719741
노가다 했습니다.
quartz0516 May 31, 2022
94ddbc2
Almost end
DeokyongKim Jun 1, 2022
52cbff3
project almost end
DeokyongKim Jun 1, 2022
a81f240
ENDO
DeokyongKim Jun 1, 2022
fb88f67
really ended
DeokyongKim Jun 1, 2022
261f9f7
Update README.md
DeokyongKim Jun 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .idea/APTP2022.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions .idea/misc.xml

This file was deleted.

45 changes: 45 additions & 0 deletions 2by2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# t 라는 list가 입력되었다고 간주
# 2 * 2 list임

def get_2by2(t):
did = [['yet', 'yet'],
['yet', 'yet']]
ans = []

for i in range(2):
for j in range(2):
if t[i][j] == 1 and did[i][j] == 'yet':
did[i][j] = 'done'
small_ans = [[i, j]]

# 상하좌우
if t[(i-1+2) % 2][j] == 1:
if [(i-1+2) % 2, j] not in small_ans:
small_ans.append([(i-1+2) % 2, j])
did[(i-1+2) % 2][j] = 'done'
if t[(i+1) % 2][j] == 1:
if [(i+1) % 2, j] not in small_ans:
small_ans.append([(i+1) % 2, j])
did[(i+1) % 2][j] = 'done'
if t[i][(j-1+2) % 2] == 1:
if [i, (j-1+2) % 2] not in small_ans:
small_ans.append([i, (j-1+2) % 2])
did[i][(j-1+2) % 2] = 'done'
if t[i][(j+1) % 2] == 1:
if [i, (j+1) % 2] not in small_ans:
small_ans.append([i, (j+1) % 2])
did[i][(j+1) % 2] = 'done'

if len(small_ans) & (len(small_ans) - 1) == 0:
ans.append(small_ans)
else:
while len(small_ans) & (len(small_ans) - 1) != 0:
index = small_ans.pop()
did[index[0]][index[1]] = 'yet'
if small_ans is not []:
ans.append(small_ans)

return ans


print(get_2by2([[1, 1], [1, 1]]))
30 changes: 30 additions & 0 deletions 3개짜리.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
def get_3by3(t):
did = [['yet', 'yet'],
['yet', 'yet'],
['yet', 'yet'],
['yet', 'yet']]
ans = []

for i in range(4):
for j in range(2):
if t[i][j] == 1 and did[i][j] == 'yet':
did[i][j] = 'done'
small_ans = [[i, j]]

# 상하좌우
if t[i - 1][j] == 1:
small_ans.append([i - 1, j])
did[i-1][j] = 'done'
if t[i + 1][j] == 1:
small_ans.append([i + 1, j])
did[i+1][j] = 'done'
if t[i][j - 1] == 1:
small_ans.append([i, j-1])
did[i][j - 1] = 'done'
if t[i][j + 1] == 1:
small_ans.append([i, j+1])
did[i][j + 1] = 'done'

ans.append(small_ans)

return ans
129 changes: 129 additions & 0 deletions GUI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import pygame
import sys
import TABLE

color = {
'white': (255, 255, 255),
'black': (0, 0, 0),
'red': (255, 0, 0),
'green': (0, 255, 0),
'blue': (0, 0, 255)
}

alphabet = {pygame.K_a: 'a', pygame.K_b: 'b', pygame.K_c: 'c', pygame.K_d: 'd', pygame.K_e: 'e',
pygame.K_f: 'f', pygame.K_g: 'g', pygame.K_h: 'h', pygame.K_i: 'i', pygame.K_j: 'j',
pygame.K_k: 'k', pygame.K_l: 'l', pygame.K_m: 'm', pygame.K_n: 'n', pygame.K_o: 'o',
pygame.K_p: 'p', pygame.K_q: 'q', pygame.K_r: 'r', pygame.K_s: 's', pygame.K_t: 't',
pygame.K_u: 'u', pygame.K_v: 'v', pygame.K_w: 'w', pygame.K_x: 'x', pygame.K_y: 'y',
pygame.K_z: 'z'}

number = {pygame.K_0: '0', pygame.K_1: '1', pygame.K_2: '2', pygame.K_3: '3', pygame.K_4: '4',
pygame.K_5: '5', pygame.K_6: '6', pygame.K_7: '7', pygame.K_8: '8', pygame.K_9: '9'}

command = {pygame.K_BACKSPACE: 'backspace', pygame.K_RETURN: 'return', pygame.K_SPACE: ' '}

direction = {pygame.K_UP: 'up', pygame.K_DOWN: 'down', pygame.K_LEFT: 'left', pygame.K_RIGHT: 'right'}

key_l = [alphabet, number, command, direction]


class Screen(TABLE.Table):
"""
Responsibility on Displaying Screen
"""

def __init__(self, screen_size, table, table_size, cell_size, cell_border):
"""
Screen Information
:param screen_size: tuple[int, int]
:param table: list[list[int]]
:param table_size: tuple[int, int]
"""
super().__init__(table, table_size)
pygame.init()
self.screen_size = screen_size
self.screen = pygame.display.set_mode(screen_size)
self.cell_size = cell_size
self.cell_border = cell_border

def ShowText(self, word, text_size, font_color, text_position):
"""
Function to Show Text on Screen
:param word: str
:param text_size: int
:param font_color: str
:param text_position: tuple[int, int]
:return: none
"""
font = pygame.font.SysFont("notosanscjkk", text_size)
word = font.render(str(word), True, color[font_color])
self.screen.blit(word, text_position)

def ShowScreen(self, screen_color):
"""
Function to Show Screen
:param screen_color: str
:return: none
"""
self.screen.fill(color[screen_color])

def ShowTable(self, cell_color):
"""
Function to Show Table
:param cell_color: str
:return: none
"""
# print('table screen')
start_position = (self.screen_size[0]/2 - self.table_size[1]*self.cell_size/2.0,
self.screen_size[1]/2 - self.table_size[0]*self.cell_size/2.0)

for i in range(self.table_size[0]):
for j in range(self.table_size[1]):
adjust_position = (start_position[0] + j * self.cell_size - self.cell_border * j,
start_position[1] + i * self.cell_size - self.cell_border * i)
pygame.draw.rect(self.screen, color[cell_color],
(adjust_position[0],
adjust_position[1],
self.cell_size,
self.cell_size),
self.cell_border)
self.ShowText(self.table[i][j], self.cell_size, cell_color,
(adjust_position[0] + self.cell_size/3,
adjust_position[1] + self.cell_size/6))

def ShowDecisionPage(self, cell_color, start_position):
# print('decision page')
for i in range(1, 4):
adjust_position = (start_position[0] + i * self.cell_size - self.cell_border * i - 5*self.cell_size/2,
start_position[1] - self.cell_size)
pygame.draw.rect(self.screen, color[cell_color],
(adjust_position[0],
adjust_position[1],
self.cell_size,
self.cell_size),
self.cell_border)
self.ShowText(i + 1, self.cell_size, cell_color,
(adjust_position[0] + self.cell_size/3,
adjust_position[1] + self.cell_size/6))
self.ShowText('Choose number of inputs', int(self.cell_size/2), cell_color,
(start_position[0] / 3,
start_position[1]/3))


if __name__ == '__main__':
t = [[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]
a = Screen((1000, 1000), t, (4, 4), 150, 3)

while True:
# for event in pygame.event.get():
# if event.type == pygame.QUIT:
# sys.exit()
a.ShowScreen('white')
a.ShowDecisionPage('black', (a.screen_size[0] / 2, a.screen_size[1]/2))

# a.ShowTable(150, 'black', 3, (100, 100))
# a.ShowText("Hi There", 90, 'black', (20, 20))
pygame.display.flip()
168 changes: 168 additions & 0 deletions INTERACTION.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
from GUI import Screen, pygame, sys, color


class Interaction(Screen):
"""
Responsibility on Interaction with User
"""

def __init__(self, screen_size, table, table_size, cell_size, cell_border):
super().__init__(screen_size, table, table_size, cell_size, cell_border)

def MouseClick(self, table_position):
(mouseX, mouseY) = pygame.mouse.get_pos()
for i in self.table_size[0]:
for j in self.table_size[1]:
adjust_position = (table_position[0] + j * self.cell_size - j * self.cell_border,
table_position[1] + i * self.cell_size - i * self.cell_border)
if 0 < mouseX - adjust_position[0] < self.cell_size and \
0 < mouseY - adjust_position[1] < self.cell_size:
self.table[i][j] = 1

def GetDecision(self, start_position):
(mouseX, mouseY) = pygame.mouse.get_pos()
for i in range(1, 4):
adjust_position = (start_position[0] + i * self.cell_size - self.cell_border * i - 5 * self.cell_size / 2,
start_position[1] - self.cell_size)
if 0 < mouseX - adjust_position[0] < self.cell_size and 0 < mouseY - adjust_position[1] < self.cell_size:
return i + 1
return -1

def GetInput(self, start_position):
(mouseX, mouseY) = pygame.mouse.get_pos()
for i in range(self.table_size[0]):
for j in range(self.table_size[1]):
adjust_position = (start_position[0] + j * self.cell_size - self.cell_border * j,
start_position[1] + i * self.cell_size - self.cell_border * i + self.cell_size/2)
if 0 < mouseX - adjust_position[0] < self.cell_size and 0 < mouseY - adjust_position[1] < self.cell_size:
if self.table[i][j] == 1:
self.table[i][j] = 0
elif self.table[i][j] == 0:
self.table[i][j] = 1

def IsEvent(self, mode, start_position, event_list):
# print('get event')
for input_event in event_list:
if input_event.type == pygame.MOUSEBUTTONDOWN:
if mode == 'number':
return self.GetDecision(start_position)
if mode == 'table':
self.GetInput(start_position)
# return self.MouseClick(start_position)

def BackButton(self):
# print('show back button')
pygame.draw.rect(self.screen, color['black'],
(30,
30,
self.cell_size / 2,
self.cell_size / 2),
self.cell_border)
pygame.draw.polygon(self.screen, color['black'],
((30 + 10, 30 + self.cell_size / 4),
(30 + self.cell_size / 2 - 10, 30 + 10),
(30 + self.cell_size / 2 - 10, 30 + self.cell_size / 2 - 10)
))

def AnswerButton(self, event_list_ans):
pygame.draw.rect(self.screen, color['black'],
(self.screen_size[0] - 230,
self.screen_size[1] - 100,
190,
60),
self.cell_border)
self.ShowText("Answer", 60, 'black', (self.screen_size[0] - 230 + 10, self.screen_size[1] - 100 + 10))

for ans_event in event_list_ans:
if ans_event.type == pygame.MOUSEBUTTONDOWN:
(mouseX, mouseY) = pygame.mouse.get_pos()
if 0 < mouseX - (self.screen_size[0] - 230) < 190 and 0 < mouseY - (self.screen_size[1] - 100) < 60:
return True

return False


# if __name__ == '__main__':
# t = [
# [0, 0, 0, 0],
# [0, 0, 0, 0],
# [0, 0, 0, 0],
# [0, 0, 0, 0]
# ]
# a = Interaction((800, 800), t, (4, 4), 130, 3)
# screen_type = 'decide'
#
# while True:
# el = pygame.event.get()
#
# for end_event in el:
# if end_event.type == pygame.QUIT:
# print('program ended')
# sys.exit()
# a.ShowScreen('white')
#
# if screen_type == 'decide':
# a.ShowDecisionPage('black', (a.screen_size[0] / 2, a.screen_size[1] / 2))
# decision = a.IsEvent('number', (a.screen_size[0] / 2, a.screen_size[1] / 2), el)
# if decision is not None:
# print(decision)
# if decision != -1:
# if decision == 2:
# a.table = [
# [0, 0],
# [0, 0]
# ]
# a.table_size = (2, 2)
# if decision == 3:
# a.table = [
# [0, 0],
# [0, 0],
# [0, 0],
# [0, 0]
# ]
# a.table_size = (4, 2)
# if decision == 4:
# a.table = [
# [0, 0, 0, 0],
# [0, 0, 0, 0],
# [0, 0, 0, 0],
# [0, 0, 0, 0]
# ]
# a.table_size = (4, 4)
# if decision == 5:
# a.table = [
# [
# [0, 0, 0, 0],
# [0, 0, 0, 0],
# [0, 0, 0, 0],
# [0, 0, 0, 0]
# ],
# [
# [0, 0, 0, 0],
# [0, 0, 0, 0],
# [0, 0, 0, 0],
# [0, 0, 0, 0]
# ]
# ]
# a.table_size = (4, 4)
# screen_type = 'done'
# elif screen_type == 'done':
# a.BackButton()
# input_done = a.AnswerButton(el)
# if input_done:
# pass
#
# stp = (a.screen_size[0] / 2 - a.table_size[1] * a.cell_size / 2.0,
# a.screen_size[1] / 2 - a.table_size[0] * a.cell_size / 2.0 - a.cell_size / 2)
#
# for back_event in el:
# if back_event.type == pygame.MOUSEBUTTONDOWN:
# (mx, my) = pygame.mouse.get_pos()
# if 30 < mx < 30 + 150 / 2 and 30 < my < 30 + 150 / 2:
# screen_type = 'decide'
# decision = None
#
# a.IsEvent('table', stp, el)
# a.ShowTable('black')
#
# pygame.display.flip()
Loading