Ich mache ein einfaches City Builder Spiel (in der Konsole). Ich habe ein Problem mit einer Methode (DrawMap). Ich kann die Listen nicht als Eingabeargumente für die Methode verwenden. Ich bekomme eine ganze Reihe von Fehlern, also hier ist der Code.Verwenden von Listen als Methodenargumente
EDIT: Es funktioniert jetzt, danke kmatyaszek.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace City
{
public class map
{
public int m { get; set; } //Map size
public List<int> info { get; set; }
public List<int> fire { get; set; }
public List<int> police { get; set; }
public List<int> education { get; set; }
public List<int> health { get; set; }
public List<int> cursor { get; set; }
}
class Program
{
static void Main(string[] args)
{
map map1 = new map();
map1.m = 256;
map1.info = new List<int>();
for (int i = 0; i < map1.m; i++)
{
map1.info.Add(0);
}
map1.fire = new List<int>();
for (int i = 0; i < map1.m; i++)
{
map1.fire.Add(0);
}
map1.police = new List<int>();
for (int i = 0; i < map1.m; i++)
{
map1.police.Add(0);
}
map1.education = new List<int>();
for (int i = 0; i < map1.m; i++)
{
map1.education.Add(0);
}
map1.health = new List<int>();
for (int i = 0; i < map1.m; i++)
{
map1.health.Add(0);
}
map1.cursor = new List<int>() { 0, 0 };
DrawMap(map1.info, map1.cursor);
}
static void DrawMap(List<int> map1.info, List<int> map1.cursor)
{
int j = 0;
int k = 0;
for (int k = 0; k < Math.Sqrt(map1.m); k++)
{
Console.SetCursorPosition(map1.cursor[j], map1.cursor[k]);
for (int j = 0; j < Math.Sqrt(map1.m); j++)
{
Console.SetCursorPosition(map1.cursor[j], map1.cursor[k]);
Console.Write("A");
}
}
}
}
}
Würde es Ihnen etwas ausmachen, diesen Haufen von Fehlern zu teilen? Hat es etwas mit den Parametern der 'DrawMaps' Methode zu tun? –
Warum haben Sie variable Namen wie map1.info ?? Es ist ein ungültiger Variablenname in C# –
@DanHunex Er ist Teil des Objekts map1. Und es scheint jetzt gut zu funktionieren. – pippu