最近、Java の知識を Objective C に移し始め、xcode を使ったアプリの作成も始めました。とはいえ、私が混乱していることがいくつかあります。まず第一に、私がトップダウンゲームを作っていて発射物を撃つ必要があるとき、私はそれを次のようにします:
public class Bullet{
int x,y;
public bullet(double x, double y){
this.x = x;
this.y = y;
}
public void tick(){
//logic goes in here to move bullet
}
}
次に、配列リストを持つクラスを作成します。
public class MainClass{
ArrayList<Bullet> bulletlist;
public main(){
//create an arraylist that takes Bullet objects
bulletlist = new ArrayList<Bullet>();
//add a new bullet at the coordinate (100,100)
bulletlist.add(new Bullet(100,100));
}
//gameloop(we'll pretend that this gets called every millisecond or so)
public void gameloop(){
//loop through list
for(int i = 0; i < bulletlist.size(); i++){
//run the method tick() at the current index
bulletlist.get(i).tick();
}
}
}
だから...私の質問は、このコードを目的のcにどのように変換するかです。または、言い換えると、 class のオブジェクトを作成する例のような arraylist を作成し、最後にこれをループしてループメソッドまたは内部で作成したメソッドを呼び出すにはどうすればよいですか。