728x90
반응형

class 5

[ Python ] pass

# pass # 일반 유닛 class Unit: def __init__(self, name, hp, speed): self.name = name self.hp = hp self.speed = speed def move(self, location): print("[지상 유닛 이동]") print("{0} : {1} 방향으로 이동합니다. [속도 {2}]".format(self.name, location, self.speed)) # 공격 유닛 class AttackUnit(Unit): def __init__(self, name, hp, damage, speed=0): Unit.__init__(self, name, hp, speed) # 부모에게 값을 넘겨주어 초기화하는 작업. self.damage = dama..

Python 2021.03.07

[ Python ] 클래스 만들기

# 클래스 만들기 # ------------ 클래스 생성 시작 -------------- class Unit: def __init__(self, name, hp, damage): self.name = name self.hp = hp self.damage = damage print("{0} 유닛이 생성 되었습니다.".format(self.name)) print("체력 {0}, 공격력 {1}".format(self.hp, self.damage)) # ------------ 클래스 생성 끝 -------------- marine1 = Unit("마린", 40, 5) marine2 = Unit("마린", 40, 5) tank = Unit("탱크", 150, 35)

Python 2021.03.07

[ Python ] 클래스 시작하기.

# 클래스 # 스타크래프트 게임 예시 # 마린 : 공격 유닛, 군인. 총을 쏠 수 있음 name = "마린" # 유닛의 이름 hp = 40 # 유닛의 체력 damage = 5 # 유닛의 공격력 print("{0} 유닛이 생성되었습니다.".format(name)) print("체력 {0}, 공격력 {1}\n".format(hp, damage)) # 탱크 : 공격 유닛, 탱크. 포를 쏠 수 있는데, 일반 모드 / 시즈 모드 tank_name = "탱크" tank_hp = 150 tank_damage = 35 print("{0} 유닛이 생성되었습니다.".format(tank_name)) print("체력 {0}, 공격력 {1}\n".format(tank_hp, tank_damage)) tank2_name = ..

Python 2021.03.07

[ react-native ] 스타일링 방법 2가지, import, module, class 외

View, Text import React, { Component } from 'react'; react라는 module에서 Component class를 import하는 의미. 그 Component를 상속받는 App이라는 클래스를 생성하는 순서 App 클래스 화면을 렌더링하는 함수가 있고(render() 함수) 그 안에 return 되는 것들이 화면을 구성하게 된다. import { View, Text } from 'react-native'; 'react-native'라는 module에서 View, Text 클래스를 import하는 것이다. Button, Image 등 다양한 클래스를 가져와서 사용할 수 있다. Text, Button, Image 등 화면에 출..

IT 유용한 정보 2021.01.17
728x90
반응형
LIST