-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_container.js
148 lines (134 loc) · 4.6 KB
/
game_container.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
'use strict';
const e = React.createElement;
class Container extends React.Component {
constructor(props) {
super(props);
this.state = {
verb: null,
item: null,
displayMessage: null,
inventory: [],
interactStates: {
buttonRevealed: false,
buttonPressed: false,
keyBoxOpen: false,
toolCrateOpen: false,
carDoorOpen: false,
garageGateOpen: false
},
room: "start"
};
this.interactions = {
pickUp: (newItem) => {
let newInventory = this.state.inventory;
newInventory.push(newItem);
this.setState({ inventory: newInventory });
},
dropItem: (droppedItem) => {
let newInventory = this.state.inventory;
let index = newInventory.indexOf(droppedItem);
newInventory.splice(index, 1);
this.setState({ inventory: newInventory });
},
buttonReveal: () => {
this.setState({ interactStates: { ...this.state.interactStates, buttonRevealed: true } });
},
buttonPress: () => {
this.setState({ interactStates: { ...this.state.interactStates, buttonPressed: true } });
},
keyBoxOpen: () => {
this.setState({ interactStates: { ...this.state.interactStates, keyBoxOpen: true } });
},
toolCrateOpen: () => {
this.setState({ interactStates: { ...this.state.interactStates, toolCrateOpen: true } });
},
carDoorOpen: () => {
this.setState({ interactStates: { ...this.state.interactStates, carDoorOpen: true } });
},
garageGateOpen: () => {
this.setState({ interactStates: { ...this.state.interactStates, garageGateOpen: true } });
},
};
this.changeVerb = this.changeVerb.bind(this);
this.changeItem = this.changeItem.bind(this);
this.changeDisplayMessage = this.changeDisplayMessage.bind(this);
this.interactions.buttonReveal = this.interactions.buttonReveal.bind(this);
this.interactions.buttonPress = this.interactions.buttonPress.bind(this);
this.interactions.keyBoxOpen = this.interactions.keyBoxOpen.bind(this);
this.interactions.toolCrateOpen = this.interactions.toolCrateOpen.bind(this);
this.interactions.carDoorOpen = this.interactions.carDoorOpen.bind(this);
this.interactions.garageGateOpen = this.interactions.garageGateOpen.bind(this);
this.changeRoom = this.changeRoom.bind(this);
this.reset = this.reset.bind(this);
}
changeVerb(newVerb) {
this.setState({ verb: newVerb });
}
changeItem(newItem) {
this.setState({ item: newItem });
}
changeDisplayMessage(newMessage) {
this.setState({ displayMessage: newMessage });
}
changeRoom(newRoom) {
this.setState({ room: newRoom });
}
reset() {
this.setState({
verb: null,
item: null,
displayMessage: null,
interactStates: {
buttonRevealed: false,
buttonPressed: false,
keyBoxOpen: false,
toolCrateOpen: false,
carDoorOpen: false,
garageGateOpen: false
},
room: "start",
inventory: []
})
}
render() {
return (
<div>
<div className="row" style={{margin: "auto"}}>
<div className="col my-auto rounded game-window">
<Window
verb={this.state.verb}
item={this.state.item}
room={this.state.room}
changeMessage={this.changeDisplayMessage}
changeRoom={this.changeRoom}
reset={this.reset}
inventory={this.state.inventory}
interactions={this.interactions}
interactStates={this.state.interactStates}
/>
</div>
</div>
<div className="row" style={{margin: "auto"}}>
<div className="col rounded display-box">
<Display message={this.state.displayMessage} />
</div>
</div>
<div className="row" style={{margin: "auto"}}>
<div className="col rounded verbs-box">
<Buttons verb={this.state.verb} onClick={this.changeVerb} />
</div>
<div className="col rounded inv-box">
<Inventory
inventory={this.state.inventory}
verb={this.state.verb}
changeItem={this.changeItem}
changeMessage={this.changeDisplayMessage}
/>
</div>
</div>
</div>
);
}
}
const domContainer = document.querySelector('#container');
ReactDOM.render(e(Container), domContainer);