2/16 모각소 5주차 스터디 팀명: 데이터란 무엇인가

Jong.-.HANA·2023년 2월 23일

아주대학교 인공지능융합학과 학생들이 모여 진행하는 pygame

2/16 아주대학교 팔달관 317호
활동시간 : 15:00 ~ 19:20

<주제> 파이썬 pygame - snake 게임

실행 코드

import pygame # 1. pygame 선언
import random
from datetime import datetime
from datetime import timedelta
 
pygame.init() # 2. pygame 초기화
 
# 3. pygame에 사용되는 전역변수 선언
WHITE = (255,255,255)
RED = (255,0,0)
GREEN = (0,255,0)
size = [400,400]
screen = pygame.display.set_mode(size)
 
done= False
clock= pygame.time.Clock()
last_moved_time = datetime.now()
 
KEY_DIRECTION = {
    pygame.K_UP: 'N',
    pygame.K_DOWN: 'S',
    pygame.K_LEFT: 'W',
    pygame.K_RIGHT: 'E',
}
 
def draw_block(screen, color, position):
    block = pygame.Rect((position[1] * 20, position[0] * 20),
                        (20, 20))
    pygame.draw.rect(screen, color, block)
 
class Snake:
    def __init__(self):
        self.positions = [(0,2),(0,1),(0,0)]  # 뱀의 위치
        self.direction = ''
 
    def draw(self):
        for position in self.positions: 
            draw_block(screen, GREEN, position)
 
    def move(self):
        head_position = self.positions[0]
        y, x = head_position
        if self.direction == 'N':
            self.positions = [(y - 1, x)] + self.positions[:-1]
        elif self.direction == 'S':
            self.positions = [(y + 1, x)] + self.positions[:-1]
        elif self.direction == 'W':
            self.positions = [(y, x - 1)] + self.positions[:-1]
        elif self.direction == 'E':
            self.positions = [(y, x + 1)] + self.positions[:-1]
 
    def grow(self):
        tail_position = self.positions[-1]
        y, x = tail_position
        if self.direction == 'N':
            self.positions.append((y - 1, x))
        elif self.direction == 'S':
            self.positions.append((y + 1, x))
        elif self.direction == 'W':
            self.positions.append((y, x - 1))
        elif self.direction == 'C':
            self.positions.append((y, x + 1))    
 
 
class Apple:
    def __init__(self, position=(5, 5)):
        self.position = position
 
    def draw(self):
        draw_block(screen, RED, self.position)
 
# 4. pygame 무한루프
def runGame():
    global done, last_moved_time
    #게임 시작 시, 뱀과 사과를 초기화
    snake = Snake() 
    apple = Apple()
 
    while not done:
        clock.tick(10)
        screen.fill(WHITE)
 
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done=True
            if event.type == pygame.KEYDOWN:
                if event.key in KEY_DIRECTION:
                    snake.direction = KEY_DIRECTION[event.key]
 
        if timedelta(seconds=0.1) <= datetime.now() - last_moved_time:
            snake.move()
            last_moved_time = datetime.now()
 
        if snake.positions[0] == apple.position:
            snake.grow()    
            apple.position = (random.randint(0, 19), random.randint(0, 19))
        
        if snake.positions[0] in snake.positions[1:]:
            done = True
 
 
        snake.draw()
        apple.draw()
        pygame.display.update()
 
runGame()
pygame.quit()

동영상 링크

<팀원 github 주소>
< 깃허브 주소 >
박종일 :https://github.com/aosdbfc/every_software
김산 : https://github.com/3n952/every_soft.git
임재환 : https://github.com/Jxxhwan/mogakso
최강인 : https://github.com/ganggri
최웅환 : https://github.com/dnstjr4567

모각소 - 5주차를 마무리하며...

각자의 학과에서 인공지능융합학과를 복전하며, python 공부가 필요한 사람들끼리
같은 프로젝트와 각각의 개인 프로젝트를 마무리하며 한 주씩 마무리하고 다음 이런 자리가 있으면 또 개인적으로 모여, 더욱 발전한 개인의 실력으로 다른 목표를 향해 도전하자고 서로 다짐하였다.

이미지인식, 데이터 분석, 자료구조, 코딩테스트 등 개인이 공부하는 분야만큼은 달랐지만 모두 pygame을 진행하였을 땐 평균 연령 25.4세들이 모여서 어린 아이들 처럼 웃고 있는 모습과 개인 프로젝트로 힘들고, 공부가 힘들 때 약간의 스트레스를 푸는 요소로 보이게 되어 팀장인 저로 큰 뿌듯함을 느꼈다.

각자 데이터를 보며 하나하나 모두가 개인 프로젝트를 완성했을 때 결국 데이터가 왜 필요한지 근본적으로 생각해보았다.
남겨진 데이터들이 하나하나 남겨져 있는데, 그것을 기록으로 남기는 일이라 결국 생각하게 되었다.
이 분야에 계속 남고 공부하면서 이 기록들로 세상을 바꾸는 일.. 그것이 하고 싶어졌다. 5주 동안 공부하며 많은 것을 배웠다.
또한 우리 팀원들 모두 각자 하고자 하는 분야에 빛을 보길 기원한다.

데이터란... 무엇인가...

다음에도 또 하자^^

profile
존경하는 인물: 현 수원삼성블루윙즈 감독 이정효

0개의 댓글