私は、単語の検索パズルゲームを作成しようとしていると思う単語を入力するようにユーザーには、配列の中にあり、その単語が見つかった場合は、ユーザーにポイントを与える(合計10ポイントの後それはお祝いのメッセージが印刷されます)。単語検索パズル:単語の検索のために文字の配列を検索するにはどうすればよいですか?
このコードでは、私は規則的な配列を持っていますが、いくつかの研究に基づいて、私は2D配列が良いかもしれないと思います。あなたの考えは?具体的に私はあなたが簡単に検索を行うためにいくつかの追加の変数を追加提案
#include <iostream>
using namespace std;
int main() {
// your code goes here
cout<<"=================================================================================="<<endl;
cout<<"|| ||"<<endl;
cout<<"|| Welcome to the ECE 114 Game Design! ||"<<endl;
cout<<"|| ||"<<endl;
cout<<"=================================================================================="<<endl;
cout<<"This is a sample output"<<endl;
//We want to ask the user to enter a word that they think the cross-word puzzle contains
//if the puzzle contains that word, we tell the user they are correct and update their points
//score by 1. Total of 10 points to gain, when the points score reaches 10 the user gets congratulatory message
string myArray[] = { "A B C D E F G H
S P A D E T R Y
T I G O A L E A
T R A I N E A W
O A P B E A T N "};
//The first array above will just be a visual for the player to see
//This second array is the one that I will use to search for words
char wordBank[5][8] = [[ 'A', 'B ','C', 'D', 'E', 'F', 'G', 'H'],
['S','P', 'A', 'D', 'E', 'T', 'R', 'Y'],
['T', 'I', 'G', 'O', 'A', 'L', 'L', 'E', 'A'],
['T', 'R','A', 'I', 'N', 'E', 'A', 'W'],
['O', 'A', 'P', 'B', 'E', 'A', 'T', 'N']];
cout<<myArray<<endl;
return 0;
}
これは、文字の配列(または2次元)配列が、文字列が1つの文字列の1つの配列よりも優れている場所です。 –
おそらく[宿題に関する助けを求める方法](http://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions)に注意してください。 – wally
このコードはコンパイルされていますか?私は、配列宣言に文字 "H"の後に警告またはエラーがあると思われます。 –