0

我试图画一个拼字游戏。您可以参考附件图片,这是我的电路板设计。我的程序将要求用户放置行和列并插入单词。示例:ROW =A 列 =5。但我不知道如何为每个声明变量。请协助。谢谢。

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

下面是我的代码:

void displayBoard()

{ int a = 0; 静态字符串 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++;
}

}


感谢帮助。我不太明白这一点。

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

顺便说一句,我尝试重新做整个并停止插入。

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 回答