2010-10-16 44 views
9

我必須創建一個模型來存儲多個平臺上的遊戲遊戲控件。我很難找到正確的方法。如何爲複雜數據建模

  1. 控制按鈕在不同的系統不同(的Wii,微軟Xbox 360,PS3都有自己特定的控制器按鈕。)
  2. 有些遊戲實際上是幾款遊戲打包成一個;這意味着根據正在玩的遊戲,單個產品可以有多個控件。
  3. 許多遊戲的遊戲控制取決於您的遊戲活動(駕駛/步行/飛行等等)而改變
  4. 僅存儲按鈕功能是不夠的,因爲大多數遊戲都有幾個需要組合的特殊動作的按鈕。

你會如何解決這個問題?老實說,我不知道從哪裏開始!

更新:非常感謝大家的周到和非常有幫助的意見。我還沒有選擇和回答,因爲最終決定這個功能是不值得的。非常感謝。

+1

這是一個非常酷的設計問題。 :)無論如何,優雅地做它! – Matt 2010-10-16 02:34:50

+1

偉大的問題! – 2010-10-16 04:01:57

回答

1

你可以試試這個對於初學者(編輯:第二次嘗試)

Game 
---------- 
(PK) GameID integer 
GameTitle varchar(100) 

Controller 
---------- 
(PK) ControllerID integer 
ControllerDescription varchar(100) 
(FK) GameID integer 

Effect 
---------- 
(PK) EffectID integer 
EffectDescription varchar(100) 
(FK) ControllerID integer 

Buttons 
---------- 
(PK) ButtonID integer 
ButtonKey varchar(25) 
(FK) EffectID integer 

例如:

GameID GameTitle 
---------------------------------------------- 
1  Super Mario Bros. 

ControllerID ControllerDescription GameID 
---------------------------------------------- 
1   Main Controller  1 

EffectID EffectDescription ControllerID 
---------------------------------------------- 
1  Run    1 
2  Jump    1 
3  Pause    1 
4  Move Left   1 
5  Move Right  1 

ButtonID ButtonKey  EffectID 
---------------------------------------------- 
1  B    1 
2  Direction Pad 1 
3  A    2 
4  Start   3 
5  Left Pad  4 
6  Right Pad  5 
+0

不確定模型的關鍵組合是否合適... – 2010-10-16 02:30:38

+0

Hrm,有效點 - 沒有考慮到這一點。我已經採取了第二次刺戳,不知道我是否滿意。 – LittleBobbyTables 2010-10-16 02:40:31

+0

爲了允許複雜的按鈕組合,添加一個名爲「延遲」的假按鈕,指示玩家應該在組合按鈕之間暫停。也許可以在Button表中添加一個「時間」列,以允許「一個按鈕必須保持一段時間」的要求。將一個OrderNumber列添加到Button表中以允許按下指定按鈕。如果要同時按下按鈕,請爲它們指定相同的訂單號。 – ulty4life 2010-10-19 02:51:47

1

我給這個一掄:)


controller [table] 
// list of controllers - Wii Mote etc. 
    controller_id (int, PK) | title (varchar) 

    game_buttons [table] 
// list of buttons on a controller A/B/X/Y/... 
    button_id (int, PK) | title (varchar) | controller_id (int, FK) 

    game [table] 
// game details - you could, if you want, differentiate the games by console here as well as they may have different titles even though they are similar in nature 
    game_id (int, PK) | title (varchar) 

    controls [table] 
// this is the main table that will combine the buttons with the games. combo_id is a foreign key to the control_combo table. So if you have a sequence of keys that calls for buttons A and then B, you would call in the same number for combo_id and ord table will tell us in what order they should be placed. If they're not part of a combo, you can leave the default combo_id to 0. 

    game_id (int, PK) | button_id (int, FK) | title (varchar) | description (text) | combo_id (int) | ord 

    control_combo [table] 
// control_combo - the master table for button combos 
    combo_id (int, PK) | title (varchar) | ord (tinyint) 
1

這個怎麼樣:

/* PRODUCTS: Each product has one title and runs on one gamesystem */ 
(PK) ProductID int 
ProductTitle varchar(100) 
(FK) GameSystemID int 

/* GAMES: Each game has one title and belongs to one product */ 
(PK) GameID int 
GameTitle varchar(100) 
(FK) ProductID int 

/* GAMESYSTEMS: Each gamesystem has one name */ 
(PK) GameSystemID int 
GameSystemName varchar(100) 

/* GAMEACTIVITIES: Each game has one or more activities (flying, running, ..) */ 
(PK) GameActivityID int 
(FK) GameID int 
GameActivityDescription VARCHAR(100) 

/* BUTTONS: Each gamesystem has certain buttons with names */ 
(PK) ButtonID int 
(FK) GameSystemID int 
ButtonName VARCHAR(100) 

/* GAMEACTIONS: Each game activity provides certain game actions (fly left, fly right, ..) */ 
(PK) ActionID int 
(FK) GameActivityID int 
ActionDescription VARCHAR(100) 

/* BUTTONCOMBINATIONS: Each game action is associated with a certain button or combination of buttons */ 
(FK) ActionID int 
(FK) ButtonID int 
1

Console 
    int id 
    string name 

Controller 
    int id 
    string name 
    int console_id fk 

Button 
    int id 
    string name 
    int controller_id fk 

Game 
    int id 
    string name 
    int parent_id fk -- game within a game 

-- context within a game (default, driving, swimming) 
Context 
    int id 
    string name 
    int game_id fk 

-- applicable actions within a context of a game 
Action 
    int id 
    string name 
    id context_id int 

-- a set of buttons that map to an action, whether it is one button or multiple 
Combination 
    int id 
    int action_id fk 
    int button_id fk 

使用上述結構的一個例子:

控制檯:PS3遊戲 :MAG ...

當前遊戲狀態:
語境:駕駛
允許的操作:方向(前進,左側等),制動,吸菸
允許的組合:每個動作的每個組合列表

當按下一系列按鈕時,例如:L1 + DirectionRight,在允許的組合中查找該組合,查找相關動作並執行該動作。

2

一些控制器共享公共佈局但具有不同的面,即360和PS3(X是A,三角形是Y等)。有了戰鬥棒,飛行棒,吉他等額外的外圍設備 - 它們只是映射到控制檯期望的不同面孔。由於按鈕通常是在任何控制器均勻成型之前定義的,因此您也可以這樣做。

每個映射並不都適用於每個控制器,因此它可能不是理想的 - 考慮到現代控制檯控制器,它應該沒問題。如果您添加Intellivision控制器和鍵盤/鼠標,事情可能會變得很奇怪。

// using CHAR(8) for absolutely no good reason. change at will. 
CREATE TABLE button_maps (
id tinyint unsigned not null auto_increment, 
map_id char(8) not null, 
primary key (id), 
unique key map_id (map_id) 
); 

INSERT INTO button_maps (map_id) 
VALUES 
// dual analog, any direction 
('ANA_LFT'), ('ANA_RT'), 
// 4-button compass face 
('BT_N'), ('BT_S'), ('BT_E'), ('BT_W'), 
// shoulder buttons 
('BT_LT1'), ('BT_LT2'), ('BT_RT1'), ('BT_RT2'), 
// system buttons 
('BT_START'), ('BT_SEL'), ('BT_MENU'), 
// analog stick click-in, usually called "L/R 3" 
('ANA_L3'), ('ANA_R3'), 
// 8-direction d-pad - add clockface points for both analogs too 
('DPAD_N'), ('DPAD_S'), ('DPAD_E'), ('DPAD_W'), 
('DPAD_NW'), ('DPAD_NE'), ('DPAD_SW'), ('DPAD_SE'), 
// and DS stylus so it's not obvious what I'm looking at right now 
('STL_TAP'), ('STL_DTAP'), ('STL_DRAG'), 
// and so on 

注:我不知道如何將這些全身運動控制事物內部處理,祝你好運如果你有對付他們。 LFOOT_HOKEYPOKEY什麼的。

注意2:嚴重的是,不要在那裏使用char(8)。獲取詳細信息,但保持一般,足以應用於通用控制器風格而不是品牌。

現在每每個品牌控制器的按鈕,與他們的名字(假定爲「控制器」表):

CREATE TABLE buttons (
id tinyint unsigned not null auto_increment, 
controller_id tinyint unsigned not null references controllers.id, 
map_id tinyint unsigned not null references button_maps.id, 
button_name varchar(32) not null, 
primary key (id), 
unique key controller_map (controller_id, map_id) 
); 

INSERT INTO buttons (controller_id, map_id, button_name) 
VALUES 
(2, 1, 'Left Analog'), (2, 2, 'Right Analog'), 
(2, 3, 'Y'), (2, 4, 'A'), (2, 5, 'B'), (2, 6, 'X'), 
(2, 7, 'Left Trigger (LT)'), (2, 8, 'Right Trigger (RT)'), 
(2, 9, 'Left Bumper (LB)'), (2, 10, 'Right Bumper (RB)') 
// and so on. PS3 with button shapes and R1/2, L1/2 instead of trigger/bumper 

現在,對於操作按鈕按壓(或多個按鈕,或者序列)表示到遊戲。這沒有考慮上下文(原始問題的2 & 3),例如遊戲模式或替代按鈕配置,但Josh Smeaton和littlegreen已經涵蓋了這一點。

這定義了每個單獨遊戲的動作,這不是非常有效。通過添加一個通用的遊戲「類型」層,您可能會顯着地壓縮事物。許多在某種流派/視角內的遊戲都有共同的控制,並且它只是變得越來越普遍(控制檯FPS添加了預定義的Halo和CoD風格的按鈕配置,因爲玩家知道它們等等)。因此,如果您可以根據每種流派定義一組常用操作,並且僅根據需要使用這些操作來覆蓋/擴展這些默認設置,那麼您可能可以獲得更乾淨的解決方案。

首先,定義每一個動作:

CREATE TABLE game_actions (
id int unsigned not null auto_increment, 
game_id int unsigned not null references games.id, 
action varchar(32) not null, 
primary key (id) 
); 

INSERT INTO game_actions (game_id, action) 
VALUES (1, 'Shoot'), (1, 'Reload'), (1, 'Turn Left'), (1, 'Turn Right') 
// and so on 

最後,定義與每個動作相關的按鈕按下。 「序數」字段用於組合序列,如格鬥遊戲組合 - 單個動作是0次序,序列從1開始計數,只是爲了使它們易於區分。它沒有考慮時間,所以你可能需要一個「無」按鈕作爲一些更復雜的組合遊戲(Soul Caliber等)的休息。

CREATE TABLE game_action_buttons (
id int unsigned not null auto_increment, 
game_action_id int unsigned not null references game_actions.id, 
ordinal tinyint unsigned not null, 
button_map_id tinyint unsigned not null references button_maps.id, 
primary key (id) 
); 

INSERT INTO game_action_buttons (game_action_id, ordinal, button_map_id) 
VALUES 
(1, 0, 8), // right trigger to shoot 
(2, 0, 6), // west face button (X/square) to reload 
(3, 0, 7), (3, 0, 9) // combo: both bumpers for rear view look-back while driving 
// and a Street Fighter shoryuken on the d-pad to show a sequence: 
(4, 1, 21), // DPAD_E: right 
(4, 2, 20), // DPAD_S: down 
(4, 3, 26), (4, 3, 4) // DPAD_SE + BT_S: down/right + fierce... i think. 

(免責聲明:。!我創建了一個遊戲工作室我在工作了類似的數據庫不完全一樣,但足以使我那種故意留下了很多了類似對不起我希望這足夠與Kickstart一些想法雖然,這是一個有趣的問題。)

1

我只給它一個簡短的想法,但我認爲你可以使用這樣的事情(我是懶惰地添加ER'叉',但頂部表引用底部表)):

data model

  • 按鈕 - 是一個控制器上的按鈕,我想你需要將這些也標識與類型,所以你能確定的事情等按壓,風向,氣壓等...
  • CONSLE - 商店Wii,Xbox,...
  • 遊戲玩法 - 是你的水平和每個級別有多個動作(或動作,如果你喜歡)這些行動應該執行一段代碼,最終做出一些事情發生在這個遊戲級別。
  • 控制檯移動 - 是在特定控制檯上執行特定移動的按鈕組合。如果您需要按在Wii遊戲機的按鍵組合,而不是在Xbox上,那麼應該可以

可選您可以鏈接按鈕來安慰

1

我給它一個嘗試:)

1)你將需要一個系統表

2)你將需要一個表(包含一個父對象的可空引用),一個包含遊戲的表和一個表來將遊戲與包關聯起來。這可以確保遊戲可以成爲不同軟件包的一部分。儘管如此,它不允許不同的軟件包擁有不同的「特殊版本」。但是,這不是必需的:)

3)我不知道這是否是同2),如果不是:一起遊戲的參考表,如果:見2)

4)你需要一個引用遊戲部分的動作表(「序列」),然後你需要一個表組合鍵和一個參考序列。最後,你將需要一個特定鍵的表格,並引用一個組合。

我認爲這將覆蓋它,但我有一些關於遊戲杆,鼠標等問題。您可能想將「關鍵」表分爲幾個表,以避免表中的許多列,但這是一個決定必須取決於你如何計劃訪問你的數據庫等。