나머지 왼쫀, 위, 아래 이동 하는 코드는 기존의 오른쪽으로 이동하는 코드에서 조금만 바꾸면 나머지 이동하는 코드를 완성할 수 있습니다.
Sub left()
'변수 불러오기
hx = Cells(4, 27)
hy = Cells(5, 27)
score = Cells(2, 26)
Cells(hx, hy) = "L"
If Cells(hx, hy - 1).Interior.Color = RGB(255, 0, 0) Then '사과 먹음
' 오른쪽을 뱀 색으로 바꾸기
Cells(hx, hy - 1).Interior.Color = RGB(84, 130, 53)
' 점수 1점 올리기
score = score + 1
' 점수 기록
Cells(2, 26) = score
' apple 함수 불러오기
apple
ElseIf Cells(hx, hy - 1).Interior.Color = RGB(146, 208, 80) Then ' 오른쪽이 게임판 색일때
Cells(hx, hy - 1).Interior.Color = RGB(84, 130, 53)
' 꼬리 이동하는 함수 불러오기
tail
Else
gameover
End If
Cells(5, 27) = hy - 1
End Sub
Sub up()
'변수 불러오기
hx = Cells(4, 27)
hy = Cells(5, 27)
score = Cells(2, 26)
Cells(hx, hy) = "U"
If Cells(hx - 1, hy).Interior.Color = RGB(255, 0, 0) Then '사과 먹음
' 오른쪽을 뱀 색으로 바꾸기
Cells(hx - 1, hy).Interior.Color = RGB(84, 130, 53)
' 점수 1점 올리기
score = score + 1
' 점수 기록
Cells(2, 26) = score
' apple 함수 불러오기
apple
ElseIf Cells(hx - 1, hy).Interior.Color = RGB(146, 208, 80) Then ' 오른쪽이 게임판 색일때
Cells(hx - 1, hy).Interior.Color = RGB(84, 130, 53)
' 꼬리 이동하는 함수 불러오기
tail
Else
gameover
End If
Cells(4, 27) = hx - 1
End Sub
Sub down()
'변수 불러오기
hx = Cells(4, 27)
hy = Cells(5, 27)
score = Cells(2, 26)
Cells(hx, hy) = "D"
If Cells(hx + 1, hy).Interior.Color = RGB(255, 0, 0) Then '사과 먹음
' 오른쪽을 뱀 색으로 바꾸기
Cells(hx + 1, hy).Interior.Color = RGB(84, 130, 53)
' 점수 1점 올리기
score = score + 1
' 점수 기록
Cells(2, 26) = score
' apple 함수 불러오기
apple
ElseIf Cells(hx + 1, hy).Interior.Color = RGB(146, 208, 80) Then ' 오른쪽이 게임판 색일때
Cells(hx + 1, hy).Interior.Color = RGB(84, 130, 53)
' 꼬리 이동하는 함수 불러오기
tail
Else
gameover
End If
Cells(4, 27) = hx + 1
End Sub
'엑셀 & VBA' 카테고리의 다른 글
2-5. Snake 이동하는 코드 만들기 (0) | 2021.08.22 |
---|---|
2-4. Snake 랜덤하게 사과 배치하기 (0) | 2021.08.21 |
2-3. Snake 게임판 초기화 VBA 코드 만들기 (0) | 2021.08.21 |
2-2. Snake 게임판 만들기 (0) | 2021.07.31 |
2-1. Snake 게임 만들기 (0) | 2021.07.31 |