오락실 pang게임 직접 코딩해보기.py
·
python/python_pygame
##1 환경설정 & 프레임 ###################################################################### # 무조건 해야하는 부분 ###################################################################### import pygame import os pygame.init() screen_width = 640 screen_height = 480 screen = pygame.display.set_mode((screen_width, screen_height)) # 화면 타이틀 설정 pygame.display.set_caption("rusharp Pang") # 게임 이름 # 객체 생성 current_path = ..
오락실 pang게임.py
·
python/python_pygame
목표 : 오락실 pang게임 만들기. 캐릭터는 화면 아래에 위치, 좌우로만 이동 가능 스페이스를 누르면 무기를 쏘아 올림 큰 공 1개가 나타나서 바운스 무기에 닿으면 공은 작은 크기 2개로 분할, 가장 작은 크기의 공은 사라짐 모든 공을 없애면 게임종료(성공) 캐릭터가 공에 닿으면 게임 종료 (실패) 시간 제한 99초 초과 시 게임 종료 (실패) FPS는 30으로 고정 초기 설정 1. 환경설정 & 프레임 import pygame import os #1 초기화 (반드시 필요.) pygame.init() # 화면 크기 설정 screen_width = 640 # 가로 크기 screen_height = 480 # 세로 크기 screen = pygame.display.set_mode((screen_width, s..
pygame 기초
·
python/python_pygame
##1 환경설정 & 프레임 ###################################################################### # 무조건 해야하는 부분 ###################################################################### import pygame #1 초기화 (반드시 필요.) pygame.init() #1 화면 크기 설정 screen_width = 480 # 가로 크기 screen_height = 640 # 세로 크기 screen = pygame.display.set_mode((screen_width, screen_height)) #1 화면 타이틀 설정 pygame.display.set_caption("rusharp Ga..
모듈과 패키지.py
·
python
## 모듈 # 필요한 기능끼리 부품처럼 잘 만들어진 파일을 의미함. # 유지보수 및 코드의 재사용이 편리해짐. import theater_module # 3명이서 영화를 보러갔을 때 가격 theater_module.price(3) theater_module.price_morning(4) theater_module.price_soldier(5) # theater_module의 내용을 mv로 호출할 수 있음 import theater_module as mv mv.price(3) mv.price_morning(4) mv.price_soldier(5) # from random import * # theater_module을 작성할 필요없이 모든것을 import하겠다는 의미. from theater_module ..
예외처리.py
·
python
## 예외처리 # 에러가 발생했을 때 그에대해 처리해주는 것을 의미함. try: print("나누기 전용 계산기입니다.") nums = [] nums.append(int(input("첫번째 숫자를 입력하세요 : "))) nums.append(int(input("첫번째 숫자를 입력하세요 : "))) nums.append(int(nums[0]/nums[1])) print("{} / {} = {}".format(nums[0], nums[1], nums[2])) except ValueError: print("잘못된 값을 입력했습니다.") except ZeroDivisionError as err: print("0으로 나눌 수 없습니다.") # 에러문장을 그대로 출력할 수 있다. print(err) # ValueE..
클래스.py
·
python
## 클래스 # 공격 함수 def attack(name, location, damage): print("{}:{} 방향으로 적군을 공격합니다. [공격력{}]"\\ .format(name, location, damage)) # class : 붕어빵 기계로 많이 묘사된다. class unit: # __init__ : python 에서 쓰이는 생성자, 객채가 생성될때 자동으로 호출되는 부분 # __init__ 은 특정 초기상태로 커스터마이즈된 인스턴스 객체로 생각하면 된다. # class로부터 만들어지는 요소들을 객체라고 표현함. def __init__(self,name, hp, damage) : self.name = name self.hp = hp self.damage = damage print("{}유닛이..
표준입출력.py
·
python
## 표준입출력 # sep = , 에 뭐가들어갈지 정할 수 있음. # end = print문 끝에 원하는 텍스트를 넣을 수 있음. print("Python","Java", "C#",sep = " vs ", end = "?") print("무엇이 더 재밌을까요?") import sys # 표준출력으로 문장이 출력된다. print("Python","Java", "C#",file = sys.stdout) # 표준에러로 문장이 출력된다. 사용 에러가 난 부분을 쉽게 찾을 수 있음. print("Python","Java", "C#",file = sys.stderr) scores = {"수학":50, "영어":100, "코딩":80} # for문에 dictionary사용 시, 아이템을 2개씩 받아야 한다. for ..
함수.py
·
python
## 함수 def open_account(): print("새 계좌가 생성되었습니다.") # 함수호출해야지 작동함. # balance : 잔액 / money : 입금할 금액 def deposit(balance, money): balance = balance+money print("입금이 완료되었습니다. 잔액은 {}원 입니다.".format(balance)) plus = input("추가 입금하사겠습니까? : ") if plus == 'y': money = input("입금할 금액을 입력하세요 : ") balance = deposit(balance, int(money)) return balance # balance : 잔액 / money : 출금할 금액 def withdraw(balance, money):..