11import React , { Component } from "react" ;
2- import "./index.css"
2+ import "./index.css" ;
33
44export default class Dashboard extends Component {
5+ getRandomArbitrary ( min , max ) {
6+ return Math . random ( ) * ( max - min ) + min ;
7+ }
8+
9+ buttonStyle = { color : "white" , minWidth : "80px" } ;
10+
11+ directionDisabled = element => {
12+ if ( element === 0 ) {
13+ return true ;
14+ }
15+ } ;
16+
17+ directionHeader = ( ) => {
18+ if ( this . props . disableButton === true ) {
19+ return < h2 > You need gas money to travel!</ h2 > ;
20+ } else {
21+ return < h2 > Where to next?</ h2 > ;
22+ }
23+ } ;
24+
25+ canWork = ( ) => {
26+ const webJob = Math . floor ( this . getRandomArbitrary ( 90 , 500 ) ) ;
27+ if ( this . props . currentRoom . map ( e => e . can_make_money ) [ 0 ] === true ) {
28+ return (
29+ < div style = { { display : "flex" , justifyContent : "space-between" } } >
30+ < p > Someone needs a HTML website for ${ webJob } </ p >
31+ < button
32+ name = "job"
33+ value = { webJob }
34+ onClick = { this . props . moneyTransaction }
35+ className = "authButton build"
36+ style = { { color : "white" , minWidth : "80px" } }
37+ >
38+ Build
39+ </ button >
40+ </ div >
41+ ) ;
42+ } else {
43+ return "" ;
44+ }
45+ } ;
46+
547 render ( ) {
6- const players = [ this . props . players ] ;
48+ // const players = [this.props.players];
749 // console.log(players);
50+ const north = this . props . currentRoom . map ( e => e . n_to ) [ 0 ] ;
51+ const west = this . props . currentRoom . map ( e => e . w_to ) [ 0 ] ;
52+ const south = this . props . currentRoom . map ( e => e . s_to ) [ 0 ] ;
53+ const east = this . props . currentRoom . map ( e => e . e_to ) [ 0 ] ;
54+ const canmakemoney = this . props . currentRoom . map ( e => e . can_make_money ) [ 0 ] ;
55+ console . log ( "north" , north , this . directionDisabled ( north ) ) ;
56+ console . log ( "west" , west , this . directionDisabled ( west ) ) ;
57+ console . log ( "south" , south , this . directionDisabled ( south ) ) ;
58+ console . log ( "east" , east , this . directionDisabled ( east ) ) ;
59+
60+ // const webJob = Math.floor(this.getRandomArbitrary(90, 500));
61+
62+ console . log ( canmakemoney ) ;
863
964 return (
1065 < div >
11- { /* player info */ }
1266 < div >
67+ { /* {this.directionDisabled(this.props.currentRoom.map(e => e.w_to))} */ }
1368 < h3 > Player Info</ h3 >
69+
1470 < div
1571 style = { {
1672 display : "flex"
@@ -20,93 +76,125 @@ export default class Dashboard extends Component {
2076 < p > Welcome back { this . props . name } !</ p >
2177 < p style = { { paddingBottom : "30px" } } >
2278 { /* Current Location: <br /> */ }
23- < i class = "fas location fa-location-arrow" > </ i >
79+ < i class = "fas location fa-location-arrow" / >
2480 { this . props . title }
2581 </ p >
2682 </ div >
2783 < div className = "money" >
28- < i className = "fas fa-money-bill-wave" > </ i >
84+ < i className = "fas fa-money-bill-wave" / >
2985
3086 < h3 > { this . props . cash } </ h3 >
31-
87+ </ div >
3288 </ div >
33- </ div >
34- { /* Other players in this location */ }
35- < div >
36- < hr />
37- < h3 > Players in this State</ h3 >
38- { /* {this.players} */ }
89+ { /* Other players in this location */ }
3990 < div >
40- { this . props . players . length > 0 &&
41- this . props . players . map ( player => {
42- return < div > { player } </ div > ;
43- } ) }
91+ < hr />
92+ < h3 > Players in this State</ h3 >
93+ { /* {this.players} */ }
94+ < div style = { { display : "flex" , flexWrap : "wrap" } } >
95+ { this . props . players . length > 0 &&
96+ this . props . players . map ( player => {
97+ return < div style = { { margin : "0 3px" } } > { player } </ div > ;
98+ } ) }
99+ </ div >
44100 </ div >
45- </ div >
46- { /* actions */ }
47- < div >
101+ { /* actions */ }
48102 < div >
49- < h2 > Actions:</ h2 >
50- < div style = { { display : "flex" , justifyContent :"space-between" } } >
51- < p > Someone needs a HTML website for $400</ p >
52- < button
53- name = "job"
54- value = "400"
55- className = "build"
56- onClick = { this . props . moneyTransaction }
57- >
58- build
59- </ button >
60- </ div >
61- < div style = { { display : "flex" , justifyContent :"space-between" } } >
62- < p > 4 Star resturant -$100</ p >
63- < button
64- name = "job"
65- value = "-100"
66- className = "eat"
67- onClick = { this . props . moneyTransaction }
68- >
69- eat
70- </ button >
71- </ div >
72- < div style = { { display : "flex" , justifyContent :"space-between" } } >
73- < p > Pizza -$4</ p >
74- < button
75- name = "job"
76- value = "-4"
77- className = "eat"
78- onClick = { this . props . moneyTransaction }
79- >
80- eat
81- </ button >
103+ < div >
104+ < h2 > Actions:</ h2 >
105+ { this . canWork ( ) }
106+ < div style = { { display : "flex" , justifyContent : "space-between" } } >
107+ < p > 4 Star resturant -$100</ p >
108+ < button
109+ name = "job"
110+ value = "-100"
111+ onClick = { this . props . moneyTransaction }
112+ className = "authButton eat"
113+ style = { { color : "white" , minWidth : "80px" } }
114+ disabled = { this . props . disableButton }
115+ >
116+ Eat
117+ </ button >
118+ </ div >
119+ < div style = { { display : "flex" , justifyContent : "space-between" } } >
120+ < p > Pizza -$4</ p >
121+ < button
122+ name = "job"
123+ value = "-4"
124+ onClick = { this . props . moneyTransaction }
125+ className = "authButton eat"
126+ style = { { color : "white" , minWidth : "80px" } }
127+ disabled = { this . props . disableButton }
128+ >
129+ Eat
130+ </ button >
131+ </ div >
132+ { /* <div style={{ display: "flex", justifyContent: "space-between" }}>
133+ <p>Someone needs a HTML website for ${webJob}</p>
134+ <button
135+ name="job"
136+ value={webJob}
137+ onClick={this.props.moneyTransaction}
138+ className="authButton build"
139+ style={{ color: "white", minWidth: "80px" }}
140+ >
141+ Build
142+ </button>
143+ </div> */ }
82144 </ div >
83- { /* <p>stuff</p>
84- <p>stuff</p> */ }
85145 </ div >
86- { /* <div>
87- <input />
88- <button>Do</button>
89- </div> */ }
90- </ div >
91- { /* move direction buttons */ }
92- < h2 > Where to next?</ h2 >
93- < div className = "directionContainer" >
94- < button className = "direction ns" name = "n" value = "n" onClick = { this . props . sendRequest } >
95- N
96- </ button >
97- < br > </ br >
98- < button className = "direction" name = "w" value = "w" onClick = { this . props . sendRequest } >
99- W
100- </ button >
101- < button className = "direction" name = "e" value = "e" onClick = { this . props . sendRequest } >
102- E
103- </ button >
104- < br > </ br >
105- < button className = "direction ns" name = "s" value = "s" onClick = { this . props . sendRequest } >
106- S
107- </ button >
146+ { /* move direction buttons */ }
147+ { /* <h2>Where to next?</h2> */ }
148+ { this . directionHeader ( ) }
149+ < div className = "directionContainer" >
150+ < button
151+ className = "direction ns"
152+ name = "n"
153+ value = "n"
154+ onClick = { this . props . sendRequest }
155+ disabled = {
156+ this . directionDisabled ( north ) || this . props . disableButton
157+ }
158+ >
159+ N
160+ </ button >
161+ < br />
162+ < button
163+ className = "direction"
164+ name = "w"
165+ value = "w"
166+ onClick = { this . props . sendRequest }
167+ disabled = {
168+ this . directionDisabled ( west ) || this . props . disableButton
169+ }
170+ >
171+ W
172+ </ button >
173+ < button
174+ className = "direction"
175+ name = "e"
176+ value = "e"
177+ onClick = { this . props . sendRequest }
178+ disabled = {
179+ this . directionDisabled ( east ) || this . props . disableButton
180+ }
181+ >
182+ E
183+ </ button >
184+ < br />
185+ < button
186+ className = "direction ns"
187+ name = "s"
188+ value = "s"
189+ onClick = { this . props . sendRequest }
190+ disabled = {
191+ this . directionDisabled ( south ) || this . props . disableButton
192+ }
193+ >
194+ S
195+ </ button >
196+ </ div >
108197 </ div >
109- </ div >
110198 </ div >
111199 ) ;
112200 }
0 commit comments