Members - Reputation: 151
Posted 14 February 2012 - 08:07 AM
I need to store every 100 cells (10x10) for state (state includes x, y, ship, hit, miss), but ofc I don't want to have a table with 100 columns.
My first thought was to have a column with char(100), and then just write a long string with 100 values to that column.
That will work, but I wanted to run this issue here and see if there is a better, smarter way to do this...
Thanks in advance guys
Crossbones+ - Reputation: 13467
Posted 15 February 2012 - 12:42 AM
GAME_SESSION (table for a game session) - PID : int (primary key) - name : varchar - start_time : date - end_time : data BOARD_CELL (contains the cell state for one cell only) - PID : int (primary key) - x - y - ship - hit - miss - GAME_SESSION_ID : int (foreign key to connect a cell to a certain game session)In this case you have 100 cell entries in the BOARD_CELL table for each game session.
Here're some simple selects to retrieve your game state
-- get all cells for game session XX select * from BOARD_CELL where GAME_SESSION_ID = <XX> -- get cell at x,y for game sessino XX select * from BOARD_CELL where GAME_SESSION_ID = <XX> and x=<x> and y =<y>