Domanda

If I create a crossword puzzle, I'd want to store the words filled in on a 9 by 9 grid for example. I considered a 2d array but can only store the Across words and not the Down words. Even if each word is stored as an object(indicating direction), I won't know which words intersect which words. Can someone point me in the right direction?

È stato utile?

Soluzione 3

I'd save a start point and direction, then just store them in an object i.e.

{'starfish':{'direction':'horizontal','position':[0,4]}, 'ratchet':{'direction':'vertical', 'position':[0,8]}

Altri suggerimenti

Save direction (up/down/left/right) and start coordinates.

e.g.

 First
    e
    c
    o
    n
third

first would be placed left at 1,0; second would be down at 5,0; third at left 0,6.

You can also save characters into 2d array, this particular example would be:

[
  [null, 'f','i', 'r', 's', 't'],
  [null, null, null, null, 'e', null ],
  [null, null, null, null, 'c', null ],
  [null, null, null, null, 'o', null ],
  [null, null, null, null, 'n', null ],
  ['t', 'h', 'i', 'r', 'd', null ]
]

First way of saving give you advantages of having words and knowing their start points, but it doesn't enforce it to adhere to crossword format (e.g. it's hard to know which characters should be the same, etc). Second way enforces that, but it's harder to make out the words. Maybe combine the two?

Interesting problem. For fun, I'd start here:

class CrosswordItem
{
    int startX;
    int startY;
    string word;
}

Good luck with your problem!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top