Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Change logics when make board #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Gagle637 wants to merge 1 commit into sople1:master
base: master
Choose a base branch
Loading
from Gagle637:feature/python_code
Open
Changes from all commits
Commits
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
49 changes: 22 additions & 27 deletions project_9/core.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
"""
from . import util, view

# 각기맞는 방향의값을 딕셔너리를 정의합니다.
move = {
'w': [-1, 0],
's': [1, 0],
'a': [0, -1],
'd': [0, 1],
}

class Project9:
_size = {
Expand Down Expand Up @@ -72,19 +79,10 @@ def make_board(self):

:return: string : board string
"""
rows = []

for i in range(self._size['x']):
row = []
for j in range(self._size['y']):
if i == self._pos['x'] and j == self._pos['y']:
row.append("9")
else:
row.append("0")

rows.append(" ".join(row))

return "\n".join(rows)
rows = [['0'] * self._size['x'] for _ in range(self._size['y'])]
rows[self._pos['x']][self._pos['y']] = "9"
return "\n".join([" ".join(row) for row in rows])

def set_size(self, size_x, size_y):
"""
Expand Down Expand Up @@ -119,21 +117,18 @@ def _parse_arg(self, arg):
if arg == 'n': # End program
return False

if arg == 'w': # move up
self._pos['x'] -= 1
if arg == 's': # move down
self._pos['x'] += 1
if arg == 'a': # move left
self._pos['y'] -= 1
if arg == 'd': # move right
self._pos['y'] += 1

for k in ['x', 'y']:
if self._pos[k] < 0:
self._pos[k] = 0
self._wall_touched = True
elif self._pos[k] >= self._size[k]:
self._pos[k] = self._size[k] - 1
# 각 키에맞는 값을 가져옵니다. 저장된 값 w,a,s,d 가 아니라면 target_move는 값이 없어 if문을 통과하지 못합니다.
target_move = move.get(arg)
if target_move: # move up
dx = self._pos['x'] + target_move[0]
dy = self._pos['y'] + target_move[1]

# target_move에서 통과하지 못햇을경우 움직이지 못하므로 기존값과 동일하여 실행될 이유가 없다고 생각합니다.
# 또한 해당값 움직여야할 값이 다음 비교식을 통과하지 못하면 다음 이동이 벽을 넘어가거나 혹은 현재 벽을 넘어가 있다는 가정이 있습니다.
if 0 <= dx < self._size['x'] and 0 <= dy < self._size['y']:
self._pos['x'] = dx
self._pos['y'] = dy
else:
self._wall_touched = True

return True
Expand Down

AltStyle によって変換されたページ (->オリジナル) /