public class NCell
{
private var _player: NPlayer;
public function set player(value: NPlayer):void
{
this._player = value;
}
public function get player():NPlayer {return this._player}
}
public class NPlayer
{
private var _cell: NCell;
public function set cell(value: NCell):void
{
if (this._cell != null)
{
this._cell.player = null;
}
this._cell = value;
if (this._cell != null)
{
this._cell.player = this;
this.position = this.cell.position;
}
}
}
所以,我有一個NCells(大小20x15)和其上的幾個球員的領域。移動球員我寫我需要一個出路
player.cell = field[4][4];
當它的球員知道他的細胞(和位置)和細胞有一個鏈接到球員。因此我有一切來計算可用的移動。有時玩家有「單元格」,但單元格中的「玩家」== null。這不好。這是因爲當我計算移動時,我存儲玩家位置,然後移動玩家,然後繼續搜索,當遊戲點數變爲0時,恢復玩家位置並繼續搜索。例如。我有c1 ==字段[3] [4],c2 ==字段[4] [4],c3 ==字段[5] [4],p1.cell == c1,p2.cell == c2。 p2移動到c3,然後p1移動到c1。然後我恢復位置:
//c2.player == p1
p2.cell = c2;//now c2.player == c2 but p1.cell == c2
p1.cell = c1;//and here c2.player == null
並且它不依賴於恢復順序。如何避免鏈接擦除?
不能幫助你解決問題,但我喜歡標題:d – Blindy 2010-08-18 08:15:45