I am writing a small battleship clone in flash with multiplayer functionality and while designing I came across the fact of having to store the whole board for each game.
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
Storing battleship data in a table
You need to use more than one table. Simple example:
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
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>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement