gpt4 book ai didi

c# - 单词搜索益智游戏

转载 作者:太空宇宙 更新时间:2023-11-03 22:24:08 25 4
gpt4 key购买 nike

我正在尝试创建一个单词搜索游戏。问题是我无法将单词插入 TableLayoutPanel。当我写这篇文章时,我收到一个编译错误,提示“方法‘placewords’没有重载需要‘5’个参数。

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
Random r = new Random();
for (int a = 0; a < tableLayoutPanel1.ColumnCount; a++)
{
for (int b = 0; b < tableLayoutPanel1.RowCount; b++)
{
Label nl = new Label();
int x = r.Next(65, 90);
char c = (char)x;
nl.Text = c.ToString();
tableLayoutPanel1.Controls.Add(nl, a, b);
}
}

}

private void newGameToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Restart();
}



private void PlaceWords()
{


string[] words = { "byte", "char" };
Random rn = new Random();
foreach (string p in words)
{
String s = p.Trim();
bool placed = false;// continue trying to place the word in // the matrix until it fits
while (placed == false)// generate a new random row and column
{
int nRow = rn.Next(30);// generate a new random x & y direction vector
int nCol = rn.Next(30);// x direction: -1, 0, or 1
int nDirX = 0; // y direction -1, 0, or 1
int nDirY = 0; // (although direction can never be 0, 0, this is null)
while (nDirX == 0 && nDirY == 0)
{
nDirX = rn.Next(3) - 1;
nDirY = rn.Next(3) - 1;
}

placed =PlaceWords(s.ToUpper(),nRow,nCol,nDirX,nDirY);
}

}
}

最佳答案

您的 PlaceWords 方法不接受那么多参数,事实上,它不接受任何参数。

此外,从外观上看,您的 PlaceWords 是一个不会退出的递归函数,会导致堆栈溢出。

要解决此问题,您需要创建第二个 PlaceWords 函数,它接受所有 5 个参数,执行 PlaceWords 执行的任何操作,并返回一个 bool 值。

关于c# - 单词搜索益智游戏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2015456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com