|
19700 | 19700 | var gameData = sdm.getGameData('random');
|
19701 | 19701 | _this.state = {
|
19702 | 19702 | gameData: gameData,
|
19703 |
| - userData: cloneObject(gameData.data) |
| 19703 | + userData: cloneObject(gameData.data), |
| 19704 | + failCells: [] |
19704 | 19705 | };
|
19705 | 19706 | return _this;
|
19706 | 19707 | }
|
|
19713 | 19714 |
|
19714 | 19715 | for (var i = 0; i < 9; i++) {
|
19715 | 19716 | boxes.push(_react2.default.createElement(_box2.default, {
|
| 19717 | + ref: i, |
19716 | 19718 | key: i,
|
19717 | 19719 | position: i,
|
19718 | 19720 | data: this.state.gameData.data[i],
|
|
19738 | 19740 | var _k = _cell$props._k;
|
19739 | 19741 |
|
19740 | 19742 | this.state.userData[_i][_j][_k] = value;
|
| 19743 | + |
| 19744 | + var check_data = sdm.gameDataCheck(this.state.userData); |
| 19745 | + |
| 19746 | + this.state.failCells.forEach(function (cell) { |
| 19747 | + cell.setState({ |
| 19748 | + isFail: false |
| 19749 | + }); |
| 19750 | + }); |
| 19751 | + |
| 19752 | + if (check_data.state === 'fail') { |
| 19753 | + for (var key in check_data.box) { |
| 19754 | + var coord = check_data.box[key]; |
| 19755 | + var cell = this.refs[coord._i].refs['' + coord._j + coord._k]; |
| 19756 | + cell.setState({ |
| 19757 | + isFail: true |
| 19758 | + }); |
| 19759 | + this.state.failCells.push(cell); |
| 19760 | + } |
| 19761 | + for (var key in check_data.rows) { |
| 19762 | + var coord = check_data.rows[key]; |
| 19763 | + var cell = this.refs[coord._i].refs['' + coord._j + coord._k]; |
| 19764 | + cell.setState({ |
| 19765 | + isFail: true |
| 19766 | + }); |
| 19767 | + this.state.failCells.push(cell); |
| 19768 | + } |
| 19769 | + for (var key in check_data.cols) { |
| 19770 | + var coord = check_data.cols[key]; |
| 19771 | + var cell = this.refs[coord._i].refs['' + coord._j + coord._k]; |
| 19772 | + cell.setState({ |
| 19773 | + isFail: true |
| 19774 | + }); |
| 19775 | + this.state.failCells.push(cell); |
| 19776 | + } |
| 19777 | + } else if (check_data.state === 'complete') { |
| 19778 | + alert('게임완료'); |
| 19779 | + } |
19741 | 19780 | }
|
19742 | 19781 | }
|
19743 | 19782 | }, {
|
|
19804 | 19843 | Cells.push(_react2.default.createElement(
|
19805 | 19844 | _cell2.default,
|
19806 | 19845 | {
|
| 19846 | + ref: '' + i + j, |
19807 | 19847 | key: '' + i + j,
|
19808 | 19848 | _i: this.props.position,
|
19809 | 19849 | _j: i,
|
@@ -19868,11 +19908,24 @@
|
19868 | 19908 |
|
19869 | 19909 | var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Cell).call(this, props));
|
19870 | 19910 |
|
19871 |
| - _this.state = { value: props.value }; |
| 19911 | + _this.state = { |
| 19912 | + value: props.value, |
| 19913 | + isFail: false |
| 19914 | + }; |
19872 | 19915 | return _this;
|
19873 | 19916 | }
|
19874 | 19917 |
|
19875 | 19918 | _createClass(Cell, [{
|
| 19919 | + key: 'getClassName', |
| 19920 | + value: function getClassName() { |
| 19921 | + var class_name = 'cell'; |
| 19922 | + if (this.state.isFail && !this.props.value) { |
| 19923 | + class_name += ' fail'; |
| 19924 | + } |
| 19925 | + |
| 19926 | + return class_name; |
| 19927 | + } |
| 19928 | + }, { |
19876 | 19929 | key: 'clickItem',
|
19877 | 19930 | value: function clickItem() {
|
19878 | 19931 | if (!this.props.value) {
|
|
19890 | 19943 | value: function render() {
|
19891 | 19944 | return _react2.default.createElement(
|
19892 | 19945 | 'div',
|
19893 |
| - { className: 'cell', onClick: this.clickItem.bind(this) }, |
| 19946 | + { className: this.getClassName(), onClick: this.clickItem.bind(this) }, |
19894 | 19947 | this.state.value
|
19895 | 19948 | );
|
19896 | 19949 | }
|
|
19936 | 19989 |
|
19937 | 19990 |
|
19938 | 19991 | // module
|
19939 |
| - exports.push([module.id, "/* prefix 영역 */\n.flex-box {\n display: -webkit-box;\n display: -moz-box;\n display: -ms-flexbox;\n display: -webkit-flex;\n display: flex;\n -webkit-flex-flow: row wrap;\n justify-content: space-around;\n}\n/* prefix 영역 */\n* {\n -webkit-user-select: none;\n /* Chrome all / Safari all */\n -moz-user-select: none;\n /* Firefox all */\n -ms-user-select: none;\n /* IE 10+ */\n user-select: none;\n /* Likely future */\n}\nhtml,\nbody {\n width: 100%;\n height: 100%;\n margin: 0;\n padding: 0;\n display: -webkit-box;\n display: -moz-box;\n display: -ms-flexbox;\n display: -webkit-flex;\n display: flex;\n -webkit-flex-flow: row wrap;\n justify-content: space-around;\n justify-content: center;\n align-items: center;\n}\n.game {\n display: -webkit-box;\n display: -moz-box;\n display: -ms-flexbox;\n display: -webkit-flex;\n display: flex;\n -webkit-flex-flow: row wrap;\n justify-content: space-around;\n width: 450px;\n}\n.box {\n display: -webkit-box;\n display: -moz-box;\n display: -ms-flexbox;\n display: -webkit-flex;\n display: flex;\n -webkit-flex-flow: row wrap;\n justify-content: space-around;\n width: 150px;\n -moz-box-shadow: inset 0 0 1px #ccc;\n -webkit-box-shadow: inset 0 0 1px #ccc;\n box-shadow: inset 0 0 1px #ccc;\n}\n.cell {\n cursor: pointer;\n width: 50px;\n height: 50px;\n align-items: center;\n display: flex;\n justify-content: center;\n}\n.box:nth-child(even) {\n background: #ccc;\n}\n.cell:nth-child(odd) {\n background: rgba(1, 1, 1, 0.1);\n}\n", ""]); |
| 19992 | + exports.push([module.id, "/* prefix 영역 */\n.flex-box {\n display: -webkit-box;\n display: -moz-box;\n display: -ms-flexbox;\n display: -webkit-flex;\n display: flex;\n -webkit-flex-flow: row wrap;\n justify-content: space-around;\n}\n/* prefix 영역 */\n* {\n -webkit-user-select: none;\n /* Chrome all / Safari all */\n -moz-user-select: none;\n /* Firefox all */\n -ms-user-select: none;\n /* IE 10+ */\n user-select: none;\n /* Likely future */\n}\nhtml,\nbody {\n width: 100%;\n height: 100%;\n margin: 0;\n padding: 0;\n display: -webkit-box;\n display: -moz-box;\n display: -ms-flexbox;\n display: -webkit-flex;\n display: flex;\n -webkit-flex-flow: row wrap;\n justify-content: space-around;\n justify-content: center;\n align-items: center;\n}\n.game {\n display: -webkit-box;\n display: -moz-box;\n display: -ms-flexbox;\n display: -webkit-flex;\n display: flex;\n -webkit-flex-flow: row wrap;\n justify-content: space-around;\n width: 450px;\n}\n.box {\n display: -webkit-box;\n display: -moz-box;\n display: -ms-flexbox;\n display: -webkit-flex;\n display: flex;\n -webkit-flex-flow: row wrap;\n justify-content: space-around;\n width: 150px;\n -moz-box-shadow: inset 0 0 1px #ccc;\n -webkit-box-shadow: inset 0 0 1px #ccc;\n box-shadow: inset 0 0 1px #ccc;\n}\n.cell {\n cursor: pointer;\n width: 50px;\n height: 50px;\n align-items: center;\n display: flex;\n justify-content: center;\n}\n.cell.fail {\n box-shadow: inset 0 0 7px #f00;\n}\n.box:nth-child(even) {\n background: #ccc;\n}\n.cell:nth-child(odd) {\n background: rgba(1, 1, 1, 0.1);\n}\n", ""]); |
19940 | 19993 |
|
19941 | 19994 | // exports
|
19942 | 19995 |
|
|
0 commit comments