Jump to content

How to Validate 2 Columns do Not Match Over 20 Rows


evenmonkeys

Recommended Posts

Just to play around with what I'm learning.. I made a battleship game. I'm sure there are better ways to do what I did.. but this is what I have and I'd like to figure out a faster, cleaner way to make this work.

 

I have a table where each row is a square on the battleship board. If a ship has three squares to it, there are three rows for the ship, each corresponding to a column (x) and a row (y).

 

What I am trying to do.. is that when a player creates a board, how can I validate that when they click the "validate my board" button, it checks to see if any of the rows entered for that game have matching x and y entries.

 

For example, if Ship 1 has 1x1, 2x1, and 3x1.. and Ship 2 has 2x1, 2x2 and 2x3, then it's clear that the ships overlap at 2x1. Well, there are 20 rows (squares) that need to be validated all at once.

 

How can I do this without having 14 pages of <if> statements? Any help would be appreciated.

 

(This may be better in the PHP forums.. but I wasn't sure since it requires the database as well. Move if necessary.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.