게임판 상호작용 블럭을 드래그&드롭 할 때, 게임판 위에 위치하는지와 어느 칸에 삽입하는지를 알기 위해 게임판의 좌표를 가져와야할 필요가 있다. ObjectList.js ... useEffect(() => { const container = document.getElementById("top-gameboard-container") const boundary = container.getBoundingClientRect() return ( console.log(boundary) // 확인용 ) } ) ... useEffect를 사용하여 DOM이 렌더링되고 난 이후 게임판의 좌표를 getBoundingCilentRect() 통해서 가져오고자 했다. 결과는 에러였는데, 서로 다른 컴포넌트에서 렌더링되어 useEffect로 접근이 불가능한 듯하다. 이를 해결하기 위해서 context를 통한 전역변수로 사용하고자 했는데, 게임판의 좌표 외에 각 격자마다의 좌표, 삽입할 경우의 style 또는 state 변경 등을 생각하면 모두 context로 전달하기에는 너무 복잡해질 것 같았다. More

6077번 end = int(input()) result = 0 for i in range(0, end+1): if i%2 == 0: result+=i print(result) 6078번 while True: word = input() print(word) if word == 'q': break 6079번 limit = int(input()) value = 1 sum = 0 while True: sum += value if sum >= limit: print(value) break value += 1 6080번 a, b = map(int, input().split(" ")) for i in range(1, a+1): for j in range(1, b+1): print(i, end=" ") print(j) 6081번 value = int(input(), 16) for i in range(1, 16): print('%X'%value, '*%X'%i, '=%X'%(value * i), sep="") 6082번 end = int(input()) for i in range(1, end+1): if (i%10) in [3, 6, 9]: print('X', end=" ") else: print(i, end=" ") 6083번 r, g, b = map(int, input(). More

6063번 a, b = map(int, input().split(" ")) print(a if (a>b) else b) 6064번 a, b, c = map(int, input().split(' ')) num1 = a if (a < b) else b num2 = c if (c < b) else b print(num1 if (num1 < num2) else num2) 6065번 a, b, c = map(int, input().split(' ')) if not bool(a%2) : print(a) if not bool(b%2) : print(b) if not bool(c%2) : print(c) 6066번 a, b, c = map(int, input(). More

블럭 오브젝트 만들기 줄곧 빈 칸으로 있던 ObjectList.js를 먼저 채워주기로 했다. 하나의 파일 안에 코드를 몰아넣으면 복잡해질 것 같아 생성하는 함수는 따로 작성하여 import 해주기로 했다. ObjectUtil.js const blockShape = [ [[1]], [[0,1],[1,1]], [[1,1],[1,1]], [[1,0,0],[1,1,1]], [[0,1,0],[1,1,1]], [[0,0,1],[1,1,1]], [[0,0,1],[0,0,1],[1,1,1]], [[1,1,1],[1,1,1],[1,1,1]], ] // 블럭 모양 설정 const blockColor = [ 'black', 'gray', 'blue', 'red', 'purple', 'yellowgreen' ] // 블럭 색깔 설정 const rotate = [ 0, 90, 180, 270 ] // 블럭 회전 const randomNumber = () => { return ({ shape: Math. More

Context API 도입 (1)에서 만들었던 화면에서는 게임 모드를 선택해도 게임판의 격자가 바뀌지 않았다. Gamemode.js의 state가 Gameboard.js로 전달되지 않아서인데, state를 공통 상위 컴포넌트로 올려도 되지만 이후 게임판의 좌표를 통해서 드래그&드롭되는 위치를 확인할 계획이기 때문에 컴포넌트 간 여러 변수를 공유할 계획으로 전역변수를 위한 Context API를 사용해 보기로 했다. context/GameData.js const GameDataContext = createContext({ state: { gamemode : 7, }, actions : { setGamemode: () => {}, } }) const GameDataProvider = ({ children }) => { const [gamemode, setGamemode] = useState(7) const context = { state : { gamemode }, actions : { setGamemode } } return ( <GameDataContext. More

6046번 value = int(input()) print(value<<1) 6047번 a, b = map(int, input().split(' ')) print(a<<b) 6048번 a, b = map(int, input().split(' ')) print(a<b) 6049번 a, b = map(int, input().split(' ')) print(a==b) 6050번 a, b = map(int, input().split(' ')) print(a<=b) 6051번 a, b = map(int, input().split(' ')) print(a!=b) 6052번 print(bool(int(input()))) 6053번 print(not bool(int(input()))) 6054번 a, b = map(int, input().split()) print(bool(a) and bool(b)) 6055번 a, b = map(int, input().split()) print(bool(a) or bool(b)) 6056번 a, b = map(int, input(). More

6032번 value = int(input()) print(-value) 6033번 value = ord(input()) print(chr(value + 1)) 6034번 a, b = input().split(' ') print(int(a) - int(b)) 6035번 f1, f2 = input().split(' ') print(float(f1) * float(f2)) 6036번 word, repeatValue = input().split(' ') print(word * int(repeatValue)) 6037번 repeatValue = int(input()) sentence = input() print(sentence * repeatValue) 6038번 a, b = input().split(' ') print(int(a) ** int(b)) 6039번 f1, f2 = input().split(' ') print(float(f1) ** float(f2)) 6040번 a, b = input(). More

Page 4 / 5
Top