Skip to content

Commit

Permalink
Major refactor. Separate module into files
Browse files Browse the repository at this point in the history
  • Loading branch information
fikriauliya committed Oct 2, 2017
1 parent 4146290 commit b9eca47
Show file tree
Hide file tree
Showing 20 changed files with 606 additions and 601 deletions.
2 changes: 1 addition & 1 deletion bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"sources": [
{
"dir": "src",
"subdirs": ["retris"]
"subdirs": ["retris", "retris/components", "retris/engine"]
}
],
"namespace": true,
Expand Down
1 change: 1 addition & 0 deletions src/retris/RootComp.re
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ReactDOMRe.renderToElementWithId <GameComp /> "index";
4 changes: 2 additions & 2 deletions src/retris/board.re → src/retris/components/BoardComp.re
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ let basic_colors = [|"#C0C0C0", "#808080", "#000000", "#FF0000", "#800000", "#FF
let make ::board _children => {
...component,
render: fun _self => {
let m = Engine.Board.matrix board;
let m' = Engine.Matrix.transpose m;
let m = Board.matrix board;
let m' = Matrix.transpose m;

<table style=(
ReactDOMRe.Style.make border::"2px solid black" ())>
Expand Down
24 changes: 12 additions & 12 deletions src/retris/game.re → src/retris/components/GameComp.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type state = {
game: option Engine.Game.t,
game: option Engine.t,
timer_id: ref (option Js.Global.intervalId)
};
type action = | Tick | ClickLeft | ClickRight | ClickRotate | Restart | PressKey string;
Expand All @@ -14,23 +14,23 @@ let make _children => {
},
reducer: fun action state => {
let new_game = switch (state.game) {
| None => Some (Engine.Game.create (10, 15))
| None => Some (Engine.create (10, 15))
| Some g => {
switch action {
| Tick => Some (Engine.Game.tick g)
| ClickLeft => Some (Engine.Game.move g Left)
| ClickRight => Some (Engine.Game.move g Right)
| ClickRotate => Some (Engine.Game.rotate g)
| Tick => Some (Engine.tick g)
| ClickLeft => Some (Engine.move g Left)
| ClickRight => Some (Engine.move g Right)
| ClickRotate => Some (Engine.rotate g)
| PressKey key => {
switch (key) {
| "h" | "H" => Some (Engine.Game.move g Left)
| "l" | "L" => Some (Engine.Game.move g Right)
| "j" | "J" => Some (Engine.Game.tick g)
| "k" | "K" => Some (Engine.Game.rotate g)
| "h" | "H" => Some (Engine.move g Left)
| "l" | "L" => Some (Engine.move g Right)
| "j" | "J" => Some (Engine.tick g)
| "k" | "K" => Some (Engine.rotate g)
| _ => None
};
}
| Restart => Some (Engine.Game.create (10, 15))
| Restart => Some (Engine.create (10, 15))
}
}
};
Expand All @@ -53,7 +53,7 @@ let make _children => {
<div> (ReasonReact.stringToElement "Gameover") </div>
| Playing => {
<div>
<Board board=g.board/>
<BoardComp board=g.board/>
<button onClick=(self.reduce (fun _event => ClickLeft))> (ReasonReact.stringToElement "<") </button>
<button onClick=(self.reduce (fun _event => ClickRotate))> (ReasonReact.stringToElement "o") </button>
<button onClick=(self.reduce (fun _event => ClickRight))> (ReasonReact.stringToElement ">") </button>
Expand Down
Loading

0 comments on commit b9eca47

Please sign in to comment.