[[目次へもどる>PuyoPuyo]]
* Player [#t897373d]
#contents

入力を処理する機構はできたので,
いよいよFieldControllerを拡張する.

もともとFieldControllerはプレイヤーを表すクラスのスーパークラスとして定義していた.
ただし,CPUによる操作も考慮すると以下のような構造になると思われる.
- FieldController
-- Human
--- Player1
--- Player2
--- ...
-- CPU
--- ...(CPUの戦略アルゴリズムごとのクラス)

今回実行したのはHumanとそのサブクラスまで.CPUはとりあえず無視しておく.

#sh(ruby){{
class Human < FieldController
  def initialize(ipt_ctrl, x, y, row_s, line_s, block_s)
    super(x, y, row_s, line_s, block_s)
    @ipt_ctrl = ipt_ctrl
  end

  def human?; true; end
  def cpu?; false; end

  def update
    @ipt_ctrl.update
    super
  end

  def input_move_right?
    @ipt_ctrl.press?(:right)
  end
  def input_move_left?
    @ipt_ctrl.press?(:left)
  end
  def input_rotate_right?
    @ipt_ctrl.press?(:button1)
  end
  def input_rotate_left?
    @ipt_ctrl.trigger?(:button2)
  end
  def input_fastfall_right?
    @ipt_ctrl.press?(:down)
  end
end
}}
HumanクラスはFieldControllerにInputControllerを持たせただけである.
入力の情報をupdateメソッドで更新してコントロールブロックに対する操作をチェックできる.
#sh(ruby){{
class Player1 < Human
  def initialize(x, y, row_s, line_s, block_s)
    super(InputController.new(1), x, y, row_s, line_s, block_s)
  end
end
}}
Player1はInputControllerをプレイヤー番号1で生成する.


トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS