-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.jsx
executable file
·135 lines (115 loc) · 4.72 KB
/
app.jsx
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
var React = require('react');
import CheckBox from './ChessBox.jsx'
import Soldier from './Soldier.jsx'
import Elephant from './Elephent.jsx'
import Camel from './Camel.jsx'
import Horse from './Horse.jsx'
import King from './King.jsx'
import Queen from './Queen.jsx'
import ElementAction from './ElementActionCreator.jsx'
import ChessStore from './ChessStore.jsx'
import ChessBoxAction from './ChessBoxActionCreator.jsx'
import MaskElement from './MaskElement.jsx'
var ChessBoard = React.createClass({
render: function() {
var checkBoxArray=[];
var soldierArray=[];
var divStyle={
height:'640px',
width:'640px',
border:'1px solid black',
position:'relative'
}
var color,x,y;
var soldierFilter=this.state.ChessState.filter(function(element){
return element.name=='soldier'
})
var optionListItems=soldierFilter.map(function(obj){
return(<Soldier color={obj.color} x={obj.x} y={obj.y} identifier={obj.identifier} onElementClick={this.ElementClick} {...this.state}/>)
}.bind(this));
var elephentFilter=this.state.ChessState.filter(function(element){
return element.name=='elephant'
})
var elephantListItem=elephentFilter.map(function(obj){
return(<Elephant color={obj.color} x={obj.x} y={obj.y} identifier={obj.identifier} onElementClick={this.ElementClick} {...this.state}/>)
}.bind(this));
var camelListFilter=this.state.ChessState.filter(function(element){
return element.name=='camel'
})
var camelListItem=camelListFilter.map(function(obj){
return(<Camel color={obj.color} x={obj.x} y={obj.y} identifier={obj.identifier} onElementClick={this.ElementClick} {...this.state}/>)
}.bind(this));
var horseListFilter=this.state.ChessState.filter(function(element){
return element.name=='horse'
})
var horseListItem=horseListFilter.map(function(obj){
return(<Horse color={obj.color} x={obj.x} y={obj.y} identifier={obj.identifier} onElementClick={this.ElementClick} {...this.state}/>)
}.bind(this));
var kingListFilter=this.state.ChessState.filter(function(element){
return element.name=='king'
})
var kingListItem=kingListFilter.map(function(obj){
return(<King color={obj.color} x={obj.x} y={obj.y} identifier={obj.identifier} onElementClick={this.ElementClick} {...this.state}/>)
}.bind(this));
var queenListFilter=this.state.ChessState.filter(function(element){
return element.name=='queen'
})
var queenListItem=queenListFilter.map(function(obj){
return(<Queen color={obj.color} x={obj.x} y={obj.y} identifier={obj.identifier} onElementClick={this.ElementClick} {...this.state}/>)
}.bind(this));
for(var i=0;i<8;i++){
for(var j=0;j<8;j++){
if (i % 2 == 0) {
if (j % 2 == 0) {
checkBoxArray.push(<CheckBox color='white' y={j} x={i} onChessBoxClick={this.chessBoxClick}/>)
}
else {
checkBoxArray.push(<CheckBox color='#0D9154' y={j} x={i} onChessBoxClick={this.chessBoxClick}></CheckBox>)
}
}
else {
if (j % 2 == 0) {
checkBoxArray.push(<CheckBox color='#0D9154' y={j} x={i} onChessBoxClick={this.chessBoxClick}/>)
}
else {
checkBoxArray.push(<CheckBox color='white' y={j} x={i} onChessBoxClick={this.chessBoxClick}/>)
}
}
}
}
return (
<div style={divStyle}><div>
{checkBoxArray
}</div>
<div>
<MaskElement x={this.state.MaskState.x} y={this.state.MaskState.y} isDisplayed={this.state.MaskState.isDisplayed}></MaskElement>
</div>
{optionListItems}
{elephantListItem}
{camelListItem}
{horseListItem}
{kingListItem}
{queenListItem}
</div>
)
},
getInitialState:function(){
return {ChessState:ChessStore.getChessState(),MaskState:ChessStore.getMaskElementState()}
},
componentDidMount: function() {
ChessStore.addChangeListener(this._onChange);
},
componentWillUnmount: function() {
ChessStore.removeChangeListener(this._onChange);
},
ElementClick: function ( args ){
ElementAction.updateElementAction( args );
},
chessBoxClick:function(args){
ChessBoxAction.updateChessBoxCoordinates(args);
},
_onChange:function(){
this.setState({ChessState:ChessStore.getChessState(),MaskState:ChessStore.getMaskElementState()})
}
});
React.render(<ChessBoard/>, document.getElementById('example'));