Sign in to follow this  

Storing battleship data in a table

This topic is 2162 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
You need to use more than one table. Simple example:

[CODE]
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)

[/CODE]
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
[CODE]
-- 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>
[/CODE]

Share this post


Link to post
Share on other sites

This topic is 2162 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this