2015年1月23日金曜日

開発環境

  • OS X Yosemite - Apple (OS)
  • Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
  • Java (プログラミング言語)
  • javac (コンパイラ)
  • java (application launcher)

Head First Object-Oriented Analysis and Design: A Brain Friendly Guide to OOA&D (Brett McLaughlin (著)、 Gary Pollice (著)、 David West (著) 、 O'Reilly Media)のChapter 7. Architecture: Bringing Order to Chaos、ARCHITECTURE PUZZLE(No. 4260)を解いてみる。

その他参考書籍

ARCHITECTURE PUZZLE(No. 4260)

コード(BBEdit, Emacs)

Board.java

import java.util.List;

public class Board {
    private int width;
    private int height;
    private List<List<Tile>> tiles;
    
    public Board(int width, int height){
        this.width = width;
        this.height = height;
        for(List<Tile> tile_rows: tiles){
           for (Tile tile:tile_rows){
               tile = new Tile();
           }
        }
    }

    public Tile getTile(int x, int y){
        return tiles.get(x - 1).get(y -1 );
    }

    public void addUnits(List<Unit> units, int x, int y){
        Tile tile = getTile(x - 1, y - 1);
        tile.addUnits(units);
    }

    public List<Unit> getAllUnits(int x, int y){
        return getTile(x - 1, y - 1).getUnits();
    }
}

Tile.java

import java.util.List;

public class Tile {
    private List<Unit> units;
    
    public Tile(){}

    public void addUnits(List<Unit> units){
        for(Unit unit:units){
            units.add(unit);
        }
    }

    public List<Unit> getUnits(){
        return units;
    }
}

Unit.java

public class Unit {
    public Unit(){}
}

入出力結果(Terminal)

$ javac Board.java
$

0 コメント:

コメントを投稿