-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
117 lines (103 loc) · 3.94 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var player = 0;
class LifeCounter extends React.Component{
constructor(props) {
super(props);
this.state = {score: 8000, playerid: ('player'+props.player)};
}
render(){
return (
<div className="container">
<div className="box">
<img src={"./images/player_" + this.props.player + ".png"} width="100" height="100"></img>
<h2 className="title is-2">Player {this.props.player}</h2>
<h3 className="title is-3">Score: {this.state.score}</h3>
{/*Change Value Form*/}
<p className="control has-addons has-addons-centered">
<span className="select is-large">
<select id={'op' + this.state.playerid}>
<option>-</option>
<option>+</option>
</select>
</span>
<input className="input is-expanded is-large" type="text" id={this.state.playerid}/>
<a className="button is-large is-primary"
onClick={
() => {
var opt = $("#op" + this.state.playerid + " :selected").text();
var newScore = this.state.score;
{/*Calculate value*/}
if(opt == '-'){
newScore -= parseInt(document.getElementById(this.state.playerid).value)
}
else if(opt == '+'){
newScore += parseInt(document.getElementById(this.state.playerid).value)
}
{/*Change value*/}
if(isNaN(newScore)){
alert('Invalid value');
}
else{
alert(newScore);
this.setState({
score: newScore
})
}
{/*Clear textbox*/}
document.getElementById(this.state.playerid).value = "";
}}>
OK
</a>
</p>
</div>
</div>
)
}
}
const LifeCounterList = ({lcList}) => {
const eiei = lcList.map((lc) => {
return (<LifeCounter player={lc} />)
});
return (<div className="box">{eiei}</div>);
}
class App extends React.Component{
constructor(props) {
super(props);
this.state = {amount: 2, lcList: [1, 2, 3, 4, 5, 6, 7, 8], currentlist : [1, 2]};
}
render(){
return (
<div id="page">
<div>
<center>
<h1 className="title is-1">Life Counter</h1>
<h3 className="title is-3">Player Amount</h3>
<p className="control playerSelect">
<span className="select is-large">
<select id="amount"
onChange={
() => {
var newAmount = document.getElementById('amount').value;
this.setState({
amount: newAmount,
currentlist: this.state.lcList.slice(0, newAmount)
});
}
}>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
</select>
</span>
</p>
<LifeCounterList lcList={this.state.currentlist} />
</center>
</div>
</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('main'));