@@ -2,117 +2,133 @@ import { CSSTransition, TransitionGroup } from 'react-transition-group'
22import Ball from '../components/Ball'
33import Levels from '../components/Levels'
44
5- export default ( {
6- width,
7- colors,
8- score,
9- highScore,
10- gameover,
11- level,
12- balls
13- } ) => (
5+ const Score = ( { score, highScore } ) => (
146 < div
157 style = { {
16- display : 'flex' ,
17- alignItems : 'center' ,
18- justifyContent : 'center' ,
19- position : 'fixed' ,
20- background : '#f5f5f5' ,
21- margin : 0 ,
22- top : 0 ,
23- bottom : 0 ,
24- left : 0 ,
25- right : 0
8+ position : 'absolute' ,
9+ fontFamily : 'Open sans, sans-serif' ,
10+ color : '#aaa' ,
11+ fontWeight : 'bold' ,
12+ right : '105%' ,
13+ top : '5%' ,
14+ whiteSpace : 'nowrap'
2615 } }
2716 >
17+ < div > SCORE: { score } </ div >
18+ < div > HIGHSCORE: { highScore } </ div >
19+ </ div >
20+ )
21+
22+ const GameOverScreen = ( { gameover } ) => (
23+ < div
24+ style = { {
25+ display : gameover ? 'block' : 'none' ,
26+ position : 'absolute' ,
27+ left : '50%' ,
28+ top : '50%' ,
29+ transform : 'translate(-50%, -50%)' ,
30+ fontSize : '50px' ,
31+ fontFamily : 'Open sans, sans-serif' ,
32+ whiteSpace : 'nowrap' ,
33+ color : '#d50000' ,
34+ fontWeight : 'bold'
35+ } }
36+ >
37+ GAME OVER
38+ </ div >
39+ )
40+
41+ const GameBox = ( { width, children } ) => {
42+ console . log ( arguments )
43+ return (
2844 < div
2945 style = { {
30- position : 'relative' ,
31- border : '1px solid #ddd' ,
32- width : `${ width } px` ,
33- maxWidth : '100%' ,
34- background : '#fff'
46+ display : 'flex' ,
47+ alignItems : 'center' ,
48+ justifyContent : 'center' ,
49+ position : 'fixed' ,
50+ background : '#f5f5f5' ,
51+ margin : 0 ,
52+ top : 0 ,
53+ bottom : 0 ,
54+ left : 0 ,
55+ right : 0
3556 } }
3657 >
37- < style jsx global > { `
38- .ball-enter {
39- transform: scale(1.7);
40- border-radius: 0% !important;
41- opacity: 0.01;
42- z-index: 2;
43- }
44-
45- .ball-enter.ball-enter-active {
46- opacity: 1;
47- transform: scale(1);
48- border-radius: 50% !important;
49- transition: 0.3s !important;
50- z-index: 2;
51- }
52-
53- .ball-exit {
54- opacity: 1;
55- }
56-
57- .ball-exit.ball-exit-active {
58- opacity: 0.01;
59- border-radius: 0% !important;
60- transform: scale(0.7);
61- transition: 0.4s !important;
62- }
63- ` } </ style >
6458 < div
6559 style = { {
6660 position : 'relative' ,
67- width : '100%' ,
68- paddingBottom : '100%' ,
69- height : 0
70- } }
71- />
72- < div
73- style = { {
74- position : 'absolute' ,
75- fontFamily : 'Open sans, sans-serif' ,
76- color : '#aaa' ,
77- fontWeight : 'bold' ,
78- right : '105%' ,
79- top : '5%' ,
80- whiteSpace : 'nowrap'
61+ border : '1px solid #ddd' ,
62+ width : `${ width } px` ,
63+ maxWidth : '100%' ,
64+ background : '#fff'
8165 } }
8266 >
83- < div > SCORE: { score } </ div >
84- < div > HIGHSCORE: { highScore } </ div >
67+ < div
68+ style = { {
69+ position : 'relative' ,
70+ width : '100%' ,
71+ paddingBottom : '100%' ,
72+ height : 0
73+ } }
74+ />
75+ { children }
8576 </ div >
86- < div
87- style = { {
88- display : gameover ? 'block' : 'none' ,
89- position : 'absolute' ,
90- left : '50%' ,
91- top : '50%' ,
92- transform : 'translate(-50%, -50%)' ,
93- fontSize : '50px' ,
94- fontFamily : 'Open sans, sans-serif' ,
95- whiteSpace : 'nowrap' ,
96- color : '#d50000' ,
97- fontWeight : 'bold'
98- } }
99- >
100- GAME OVER
101- </ div >
102- < Levels colors = { colors } current = { level } />
103- < TransitionGroup >
104- { balls . map ( ( params , i ) => {
105- return (
106- < CSSTransition
107- key = { params . key }
108- classNames = 'ball'
109- timeout = { { enter : 300 , exit : 400 } }
110- >
111- < Ball colors = { colors } { ...params } />
112- </ CSSTransition >
113- )
114- } ) }
115- </ TransitionGroup >
11677 </ div >
117- </ div >
78+ )
79+ }
80+
81+ export default ( {
82+ width,
83+ colors,
84+ score,
85+ highScore,
86+ gameover,
87+ level,
88+ balls
89+ } ) => (
90+ < GameBox width = { width } >
91+ < Score score = { score } highScore = { highScore } />
92+ < GameOverScreen gameover = { gameover } />
93+ < Levels colors = { colors } current = { level } />
94+
95+ < style jsx global > { `
96+ .ball-enter {
97+ transform: scale(1.7);
98+ border-radius: 0% !important;
99+ opacity: 0.01;
100+ z-index: 2;
101+ }
102+
103+ .ball-enter.ball-enter-active {
104+ opacity: 1;
105+ transform: scale(1);
106+ border-radius: 50% !important;
107+ transition: 0.3s !important;
108+ z-index: 2;
109+ }
110+
111+ .ball-exit {
112+ opacity: 1;
113+ }
114+
115+ .ball-exit.ball-exit-active {
116+ opacity: 0.01;
117+ border-radius: 0% !important;
118+ transform: scale(0.7);
119+ transition: 0.4s !important;
120+ }
121+ ` } </ style >
122+ < TransitionGroup >
123+ { balls . map ( params => (
124+ < CSSTransition
125+ key = { params . key }
126+ classNames = 'ball'
127+ timeout = { { enter : 300 , exit : 400 } }
128+ >
129+ < Ball colors = { colors } { ...params } />
130+ </ CSSTransition >
131+ ) ) }
132+ </ TransitionGroup >
133+ </ GameBox >
118134)
0 commit comments