Click here to Skip to main content
15,913,166 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to archive multiple inheritance in .net Pin
Abhinav S5-Dec-09 3:50
Abhinav S5-Dec-09 3:50 
AnswerRe: how to archive multiple inheritance in .net Pin
PIEBALDconsult5-Dec-09 4:20
mvePIEBALDconsult5-Dec-09 4:20 
Questioncapture window text in c# Pin
krinaljariwala5-Dec-09 0:38
krinaljariwala5-Dec-09 0:38 
AnswerRe: capture window text in c# Pin
Saksida Bojan5-Dec-09 0:53
Saksida Bojan5-Dec-09 0:53 
GeneralRe: capture window text in c# Pin
krinaljariwala5-Dec-09 1:02
krinaljariwala5-Dec-09 1:02 
GeneralRe: capture window text in c# [modified] Pin
Saksida Bojan5-Dec-09 1:21
Saksida Bojan5-Dec-09 1:21 
Questionword search puzzle Pin
choti74-Dec-09 22:58
choti74-Dec-09 22:58 
AnswerRe: word search puzzle [modified] Pin
DaveyM695-Dec-09 0:17
professionalDaveyM695-Dec-09 0:17 
You need to be able to restrict the characters available and generate them randomly, something like this will take care of that:
C#
public static class Letters
{
    private static readonly Random random = new Random((int)DateTime.Now.Ticks);
    public static readonly char[] AllowedLetters = new char[]{
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
        'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
    };

    public static Char GetRandomLetter()
    {
        return AllowedLetters[random.Next(0, AllowedLetters.Length - 1)];
    }
}
Each row is an array of char (one element for each column).
The grid is an array of rows, so a grid can be represented as char[][]. You can use indexers to get and set each character, so the grid will need to be something like this (untested!):
C#
public class LetterGrid
{
    public const int MinSize = 8;
    public const int MaxSize = 32;

    private int size;
    private char[][] letters;

    public LetterGrid(int size)
    {
        if (size < MinSize || size > MaxSize)
            throw new ArgumentOutOfRangeException(
                "Size",
                string.Format("Size must be between {0} and {1}",
                    MinSize, MaxSize));
        this.size = size;
        letters = new char[size][]; // create rows
        for (int row = 0; row < size; row++) // iterate over rows
        {
            letters[row] = new char[size]; // create columns
            for (int column = 0; column < size; column++)
                letters[row][column] = Letters.GetRandomLetter();
        }
    }

    public char this[int row, int column]
    {
        get { return letters[row][column]; }
        set
        {
            // ToDo: Check value is valid
            letters[row][column] = value;
        }
    }

    public int Size
    {
        get { return size; }
    }

    public bool AddWord(string word, int row, int column, Direction direction)
    {
        bool result = false;
        char[] letters = word.ToCharArray();

        // ToDo: Check word will fit inside grid and if so, change letters.

        return result;
    }
}
In the AddWord method I have a Direction type for the last parameter, this can just be an enum such as:
C#
public enum Direction
{
    Horizontal = 0,
    Vertical = 1,
    DiagonalPositive = 2,
    DiagonalNegative = 3,
    HorizontalReversed = 4,
    VerticalReversed = 5,
    DiagonalPositiveReversed = 6,
    DiagonalNegativeReversed = 7,
}
This should be enough to get you underway Smile | :)

Dave

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)

modified on Saturday, December 5, 2009 6:59 AM

QuestionSending packet to a specified IP address & predefined the contents of it... Pin
3bood.ghzawi4-Dec-09 22:07
3bood.ghzawi4-Dec-09 22:07 
AnswerMessage Closed Pin
4-Dec-09 22:46
stancrm4-Dec-09 22:46 
GeneralRe: Sending packet to a specified IP address & predefined the contents of it... Pin
3bood.ghzawi5-Dec-09 2:51
3bood.ghzawi5-Dec-09 2:51 
QuestionA Question About Class Properties Pin
Roger Wright4-Dec-09 17:15
professionalRoger Wright4-Dec-09 17:15 
AnswerRe: A Question About Class Properties Pin
PIEBALDconsult4-Dec-09 17:44
mvePIEBALDconsult4-Dec-09 17:44 
GeneralRe: A Question About Class Properties Pin
Roger Wright4-Dec-09 18:02
professionalRoger Wright4-Dec-09 18:02 
GeneralRe: A Question About Class Properties Pin
DaveyM694-Dec-09 21:06
professionalDaveyM694-Dec-09 21:06 
GeneralRe: A Question About Class Properties Pin
Roger Wright5-Dec-09 2:59
professionalRoger Wright5-Dec-09 2:59 
GeneralRe: A Question About Class Properties Pin
PIEBALDconsult5-Dec-09 4:17
mvePIEBALDconsult5-Dec-09 4:17 
AnswerRe: A Question About Class Properties Pin
Richard Blythe4-Dec-09 18:08
Richard Blythe4-Dec-09 18:08 
GeneralRe: A Question About Class Properties Pin
Roger Wright4-Dec-09 18:24
professionalRoger Wright4-Dec-09 18:24 
GeneralRe: A Question About Class Properties Pin
Richard Blythe4-Dec-09 18:39
Richard Blythe4-Dec-09 18:39 
GeneralRe: A Question About Class Properties Pin
Roger Wright4-Dec-09 18:58
professionalRoger Wright4-Dec-09 18:58 
AnswerRe: A Question About Class Properties Pin
Luc Pattyn5-Dec-09 3:06
sitebuilderLuc Pattyn5-Dec-09 3:06 
QuestionReading x64 registry keys from a x86 computer remotely Pin
Jacob Dixon4-Dec-09 14:53
Jacob Dixon4-Dec-09 14:53 
AnswerRe: Reading x64 registry keys from a x86 computer remotely Pin
Dave Kreskowiak4-Dec-09 17:05
mveDave Kreskowiak4-Dec-09 17:05 
GeneralRe: Reading x64 registry keys from a x86 computer remotely Pin
Jacob Dixon4-Dec-09 18:13
Jacob Dixon4-Dec-09 18:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.