0

I was trying to draw a scrabble game. You can refer to the attach image, it was my board design. My program will ask user to put the row and column and insert the words. Example : ROW =A Column =5. But i don know how to declare the variable for each. Kindly assist. Thanks.

http://img824.imageshack.us/img824/516/capturecba.jpg

Below is my code:

void displayBoard()

{ int a = 0; static string alpha[] = {"1 ","2 ","3 ","4 ","5 ","6 ","7 ","8 ","9 ","10","11","12","13","14","15"," "};

cout <<"   A B C D E F G H I J K L M N O P"<<endl;

for (int j=0; j<=14; j++)
{
    cout << alpha[a];
    for ( int i = 0; i <= 15; i++)
    {
        cout << "|_";
    }
    cout <<"|";
    cout <<endl;
    a++;
}

}


Thanks for help. I not so understand this.

for(i=0;i<word_length;i++)
{
board[word_i_offset][word_j_offset+i]=temporary_word_input[i];
}

Btw, i try re-do whole and halt on the insert.

void displayBoard()
{
 int i=15;
 int j=15;
 int a=0;
   static string alpha[] = {"1 ","2 ","3 ","4 ","5 ","6 ","7 ","8 ","9    ","10","11","12","13","14","15"," "};

  cout <<"   A B C D E F G H I J K L M N O"<<endl;


  char board[i][j];

for(int k=0; k<j; k++)
{
    cout<<alpha[a];
    for(int k=0; k<j; k++)
    {
       board[i][j]=' ';
       cout<<"|_";
    }
    cout<<"|";
    cout<<endl;
    a++;
}
cout<<endl;

 }

 int main()
  {
  int i=15;
  int j=15;
   int l=0;
  char board[i][j];
  int words,column;
  char answer,rows;

  displayBoard();

  cout<<endl;
  cout<<"Enter how many words : ";
  cin>>words;
  cout<<endl;
  cout<<"Insert on which rows : ";
  cin>>i;
  cout<<endl;
  cout<<"Insert on which column : ";
  cin>>j;
  cout<<endl;
  cout<<"Insert what words : ";
  cin>>answer;
  cout<<endl;

  for(l=0;l<words;l++)
  {
  board[i][j]=answer[];
   }

  return 0;
   }
4

1 に答える 1

0
  char board[imax][jmax]; //declaration

初期化:

for(int i=0;i<imax;i++)
{
    for(int j=0;j<jmax;j++)
    {
        board[imax][jmax]=' ';
    }

}

印刷:

 for(int i=0;i<imax;i++)
{
    for(int j=0;j<jmax;j++)
    {
        printf("%c",board[imax][jmax]);
    }
    printf("\n");//newline
}

言葉を入れる:

first check the bounds that word fits within the board's borders

check the horizontal borders and vertical borders, and check word length versus board length.

それから:

for(i=0;i<word_length;i++)
{
    board[word_i_offset][word_j_offset+i]=temporary_word_input[i];
}
于 2012-07-24T14:04:15.350 に答える