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.)

Edited by evenmonkeys
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.