タイマー機能を実装。
Reversiにタイマー機能を実装。自分のターンになった後、一定時間石を置かないと反則負けになります。あと、不具合もいくつか直しました。
- 処理フローが複雑になってきたので一旦リファクタしたい。
- コンテナのバインドメソッドを使ってイベント通知をしているけど、その設定が既にメンドイ。何とかして減らせないかな。
// コンテナ var c = new container.Container( function( binder ) { binder.ns( "ui", function( uiBinder ) { uiBinder.bind( "board" ).to( reversi.ui.Board ).inject( { id: document.getElementById( "board" ) } ); uiBinder.bind( "result").to( reversi.ui.ResultView ); uiBinder.bind( "currentPlayer" ).to( reversi.ui.CurrentPlayerView ).inject( { id: document.getElementById( "current-player" ) } ); uiBinder.bind( "timer" ).to( reversi.ui.TimerView ).inject( { id: document.getElementById( "current-time" ) } ); }); // ★この辺からバンドメソッドの登録箇所。 //「onXXX」を何回も書いているのを何とかしたい。 binder.bind( "onNext" ).toFunction( "ui.board", "onNext" ); binder.bind( "onNext" ).toFunction( "ui.currentPlayer", "onNext" ); binder.bind( "onEnd" ).toFunction( "ui.result", "onEnd" ); binder.bind( "onFoul" ).toFunction( "ui.result", "onFoul" ); binder.bind( "onTimerStart" ).toFunction( "ui.timer", "onTimerStart" ); binder.bind( "onTimerNext" ).toFunction( "ui.timer", "onTimerNext" ); binder.bind( "onTimerEnd" ).toFunction( "ui.timer", "onTimerEnd" ); });
- というか、こんなの作ってる場合じゃねぇ。
ここまでの成果
「一番最初に見つかった、おける場所に置く」プレーヤーと対戦できます。
→サンプル