我需要创建一个子手游戏。问题是我正在努力将猜测保留在那里并消除代表尚未选择字母的*字符。
有一个列表框,其中包含整个字母,供您在表单设计中选择;还有一个标签,代表要猜测的单词。
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
print('clicked');
},
child : Container(
padding: EdgeInsets.all(padding),
decoration: BoxDecoration(border: Border.all()),
child: Icon(
Icons.info_outline,
color: Colors.blue,
size: 20,
)
),
);
}
如果正确猜出,我需要通过列表框替换字母,其余的保持*字符直到被选中为止,例如,如果为当前单词bash选择了a和h。
public partial class Form1 : Form
{
string line;
public Form1()
{
InitializeComponent();
}
private void tabPage1_Click(object sender, EventArgs e)
{
}
private void lsbLetters_SelectedIndexChanged(object sender, EventArgs e)
{
string myString = "bash";
int d, counter;
char y, letter;
letter = Convert.ToChar(lsbLetters.SelectedItem.ToString());
for (counter = 1; counter < myString.Length; counter++)
{
line = "";
for (d = 0; d < myString.Length; d++)
{
y = myString[d];
if (letter == myString[d])
{
line += myString[d];
for (int j = 1; j <= myString.Length - d; j++)
{
line += "* ";
}
lblWord.Text = line;
}
}
}
}
}
答案 0 :(得分:0)
尝试一下:
private void lsbLetters_SelectedIndexChanged(object sender, EventArgs e)
{
string myString = "bash";
char letter = Convert.ToChar(lsbLetters.SelectedItem.ToString());
line = "";
for (int counter = 0; counter < myString.Length; counter++)
{
if (letter == myString[counter])
line += letter;
else
line += lblWord.Text[counter];
}
lblWord.Text = line;
}