Crossword Puzzle Game code in asp.net with c#...

Posted by Punitha2013 under ASP.NET on 9/28/2013 | Points: 10 | Views : 10323 | Status : [Member] | Replies : 2
Hi,


I need code for crossword puzzle in asp.net with c#.


Thanks in advance,
Punitha R.




Responses

Posted by: Bandi on: 9/28/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
refer
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=6082&lngWId=10
http://www.david-sherman.com/projects/crosswordplugin/
http://www.sourcecodeonline.com/list?q=crossword_puzzle_code_in_c


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Punitha2013, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jennyhannb on: 10/5/2017 [Member] Starter | Points: 25

Up
0
Down
The Code
The demo source code was created using c# and Visual Studio 2010.

There are several building blocks:

First, per each word about to be placed, we check if this place is valid :

Hide Copy Code
bool IsValidPosition(int x , int y)
{
return x >= 0 && y >= 0 && x < _n && y < _m;
}
Even if the position is valid, we also check if there is no other word crossing the word we are about to place, and if there is, the crossing point must have the same letter, both for the word placed horizontally and the word placed vertically.

Hide Shrink Copy Code
int CanBePlaced(string word, int x, int y, int dir)
{
var result = 0;
if (dir == 0)
{
for (var j = 0; j < word.Length; j++)
{
int x1 = x, y1 = y + j;
if (!(IsValidPosition(x1, y1) && (_board[x1, y1] == ' ' || _board[x1, y1] = = word[j])))
return -1;
if (IsValidPosition(x1 - 1, y1))
if (_hWords[x1 - 1, y1] > 0)
return -1;
if (IsValidPosition(x1 + 1, y1))
if (_hWords[x1 + 1, y1] > 0)
return -1;
if (_board[x1, y1] == word[j])
result++;
}
}
else
{
for (var j = 0; j < word.Length; j++)
{
int x1 = x + j, y1 = y;
if (!(IsValidPosition(x1, y1) && (_board[x1, y1] == ' ' || _board[x1, y1] = = word[j])))
return -1;
if (IsValidPosition(x1, y1 - 1))
if (_vWords[x1, y1 - 1] > 0)
return -1;
if (IsValidPosition(x1, y1 + 1))
if (_vWords[x1, y1 + 1] > 0)
return -1;
if (_board[x1, y1] == word[j])
result++;
}
}
int xStar = x - _dirX[dir], yStar = y - _dirY[dir];
if (IsValidPosition(xStar, yStar))
if (!(_board[xStar, yStar] == ' ' || _board[xStar, yStar] == '*'))
return -1;
xStar = x + _dirX[dir]*word.Length;
yStar = y + _dirY[dir]*word.Length;
if (IsValidPosition(xStar, yStar))
if (!(_board[xStar, yStar] == ' ' || _board[xStar, yStar] == '*'))
return -1;
return result == word.Length ? -1 : result;
}
Then, when we actually place the word, we call:

Hide Copy Code
void PutWord(string word , int x , int y , int dir, int value)
{
var mat = dir==0 ? _hWords :_vWords;
for (var i = 0; i < word.Length; i++)
{
int x1 = x + _dirX[dir]*i, y1 = y + _dirY[dir]*i;
_board[x1, y1] = word[i];
mat[x1, y1] = value;
}
int xStar = x - _dirX[dir], yStar = y - _dirY[dir];
if (IsValidPosition(xStar, yStar)) _board[xStar, yStar] = '*';
xStar = x + _dirX[dir]*word.Length;
yStar = y + _dirY[dir]*word.Length;
if (IsValidPosition(xStar, yStar)) _board[xStar, yStar] = '*';
}
This application is meant only for demonstration purposes. It creates a matrix of 13 X 17. The "Optimize" button, tries to place the list of given words randomly while seeking for the optimal result for up to 1 minute. Obviously, this is not optimizing, and there can be many improvements, which will be more than welcomed.
Socure:
http://geometrydashfree.com/
http://happywheels247.com/



Punitha2013, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response