Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Storing battleship data in a table


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Thanamos   Members   -  Reputation: 151

Like
0Likes
Like

Posted 14 February 2012 - 08:07 AM

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

Sponsor:

#2 Ashaman73   Crossbones+   -  Reputation: 8001

Like
0Likes
Like

Posted 15 February 2012 - 12:42 AM

You need to use more than one table. Simple example:

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>





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS