我正在開發一款具有地圖的遊戲。在地圖上,有幾個不同的項目,如城堡(普通玩家),礦山,空白點等,由type
欄定義。這裏是世界的定義:根據列值加入
CREATE TABLE IF NOT EXISTS `world` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`type` tinyint(2) unsigned NOT NULL,
`x` int(11) NOT NULL,
`y` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `coors` (`x`,`y`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
我還有其他的表像castles
,mines
我選擇它們的基礎上,type
值:
foreach($spots as $spot){
if($spot['type'] == 1){
//it's normal castle
$db->get_castle($spot['id']);
}else if($spot['type'] == 2){
//it's a mine
$db->get_mine($spot['id']);
}else{
//empty spot, can be taken by anyone
}
}
現在我的問題:是否有加入不同的方式基於type
的價值?
編輯: mines
表的定義:
CREATE TABLE IF NOT EXISTS `mines` (
`wid` int(10) unsigned NOT NULL,
`type` tinyint(2) unsigned NOT NULL,
`castle` int(10) unsigned NOT NULL,
PRIMARY KEY (`wid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
「城堡」和「礦山」的構成是什麼?在'world'中我沒有看到明確的外鍵,它指向另一個表中的id。 –
@TommyCrush'礦山'被城堡俘虜。因爲'world'表可能引用兩個表,所以我無法創建一個外鍵! – undone