ワールド生成コードに少し問題があります。以下のコードを投稿します:
#region generate world
private void genworld()
{
string world = tb_value1.Text;
int worldID = 9999;
int size = 0;
int col = 0;
int row = 0;
string sql = "SELECT * FROM " + variables.tbl_worlds + " WHERE worlds_name='" + world + "'";
MySqlCommand cmd = new MySqlCommand(sql, connection);
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
worldID = int.Parse(reader["worlds_ID"].ToString());
size = int.Parse(reader["worlds_x"].ToString());
}
reader.Dispose();
if (worldID != 9999)
{
addtolog("server", "World " + world + " exists!");
while (row < size)
{
while (col < size)
{
int above = row - 1;
int nextto = col - 1;
int tileabove = 9999;
int tilenextto = 9999;
int tile = 9999;
if (above >= 0)
{
string sql2 = "SELECT * FROM " + variables.tbl_tiles + "WHERE tiles_col='" + col + "' AND tiles_row='" + above + "' AND tiles_world='" + worldID + "'";
MySqlCommand cmd2 = new MySqlCommand(sql2,connection2);
MySqlDataReader reader2 = cmd.ExecuteReader();
while (reader2.Read())
{
if (reader2.IsDBNull(1))
{
tileabove = int.Parse(reader["tiles_type"].ToString());
}
}
reader2.Dispose();
}
if (nextto >= 0)
{
string sql2 = "SELECT * FROM " + variables.tbl_tiles + "WHERE tiles_col='" + nextto + "' AND tiles_row='" + row + "' AND tiles_world='" + worldID + "'";
MySqlCommand cmd2 = new MySqlCommand(sql2, connection2);
MySqlDataReader reader2 = cmd.ExecuteReader();
while (reader2.Read())
{
if (reader2.IsDBNull(1))
{
tilenextto = int.Parse(reader["tiles_type"].ToString());
}
}
reader2.Dispose();
}
if (tile == 9999 && (tileabove == 9999 || tilenextto == 9999))
{
tile = gentile(10, 10);
}
if (tile == 9999 && tileabove == 0 && tilenextto == 0)
{
tile = gentile(200, 10);
}
if (tile == 9999 && tileabove == 1 && tilenextto == 1)
{
tile = gentile(10, 200);
}
if (tile == 9999 && tileabove == 1)
{
tile = gentile(10, 10000);
}
if (tile == 9999 && (tileabove == 1 || tilenextto == 1))
{
tile = gentile(20,80);
}
string sql4 = "INSERT INTO " + variables.tbl_tiles + " (tiles_ID,tiles_row,tiles_column,tiles_world,tiles_type) VALUES ('','" + row + "','" + col + "','" + worldID + "','" + tile + "')";
MySqlCommand cmd3 = new MySqlCommand(sql4, connection2);
cmd3.ExecuteNonQuery();
col++;
}
row++;
col = 0;
}
}
else
{
addtolog("server","World " + world + " does not exist!");
}
}
#endregion
そして異邦人の方法
#region generate tile
private int gentile(int grass, int desert)
{
int totalchance = grass + desert;
//addtolog("server","TEST");
Random random = new Random();
int number = random.Next(1,totalchance);
if (number <= grass)
{
return 0;
}
else if (number <= grass + desert)
{
return 1;
}
else
{
return 0;
}
}
#endregion
#endregion
これに関する私の問題は、それがすべきではないのに次の行に続くように見えることです。この例:
画像をよく見ると、緑(タイルタイプとして0)と黄色(タイルタイプとして1)が次の行に続いていることがわかりますが、私はそれが上の最後のタイルをチェックしていません前の行...
誰かが私が間違っていることを教えてもらえますか?