Landkarte mit c#

pamax

Erfahrenes Mitglied
Hi,

Aufgabe: Ich will eine Map mit C# bauen.

Vorgehensweise:
-Ich habe mir eine Tabelle erstellt.(7*7 Felder)
-ich habe eine Datenbank Tabelle erstellt mit 100*100 Koordinaten(Bsp. Koordinate: x=1 y=100, x=2 y=100) Felder:(ID|x|y|TYP)
-In der Code-Behind-Datei frage ich den Typ der jeweiligen Koordinate ab
-Koordinaten werden per Request eingelesen(x, y)
-eingegebene Koordinaten werden in der Mitte der Tabelle angezeigt


Frage: Kann ich das nicht auch mit einer While-Schleife machen? Denn ich will später nicht nur den Typ abfragen, sondern auch den Besitzer.

CODE:

So ermittele ich die Koordinaten:
Code:
            int x = Convert.ToInt32(Page.Request["x"]);
            int y = Convert.ToInt32(Page.Request["y"]);
            if (x >= 100)
            {
                x = 96;
            }
            if (x < 4)
            {
                x = 4;
            }
            if (y >= 100)
            {
                x = 96;
            }
            if (y < 4)
            {
                y = 4;
            }
            int x1_start = x - 3;
            x1 = x1_start;
            int x2_start = x - 2;
            x2 = x2_start;
            int x3_start = x - 1;
            x3 = x3_start;
            int x4_start = x - 0;
            x4 = x4_start;
            int x5_start = x + 1;
            x5 = x5_start;
            int x6_start = x + 2;
            x6 = x6_start;
            int x7_start = x + 3;
            x7 = x7_start;
            int y1_start = y - 3;
            y1 = y1_start;
            int y2_start = y - 2;
            y2 = y2_start;
            int y3_start = y - 1;
            y3 = y3_start;
            int y4_start = y - 0;
            y4 = y4_start;
            int y5_start = y + 1;
            y5 = y5_start;
            int y6_start = y + 2;
            y6 = y6_start;
            int y7_start = y + 3;
            y7 = y7_start;
So die Abfrage(in diesem Beispiel die Koordinate x1 und y1):
Code:
            string SQL_1 = "SELECT TYP FROM LAND WHERE x = '" + x1_start + "' AND y = '" + y1_start + "'";
            SqlCommand cmd_1 = new SqlCommand(SQL_1, conn);
            typ_x1_y1 = cmd_1.ExecuteScalar().ToString();
So übergebe ich die Daten von der Code-Behind-Datei:
Code:
    string _typ_x1_y1;
    public string typ_x1_y1
    {
        get
        {
            return _typ_x1_y1;
        }
        set
        {
            _typ_x1_y1 = value;
        }
    }
Ausgabe in Tabelle;
Code:
<table width="532" height="406" border="1" style="z-index: 110; left: 51px; position: absolute; top: 31px">
              <tr>
                <td style="width: 74px" onmouseover="sndReq(<% Response.Write(x1.ToString()); %>, <% Response.Write(y1.ToString()); %>, '<% Response.Write(x1y1); %>'); return false;"><% Response.Write(typ_x1_y1); %></td>
                <td onmouseover="sndReq(<% Response.Write(x1.ToString()); %>,<% Response.Write(y2.ToString()); %>; return false;" ><% Response.Write(typ_x1_y2); %></td>
                <td onmouseover="sndReq(<% Response.Write(x1.ToString()); %>,<% Response.Write(y3.ToString()); %>; return false;" ><% Response.Write(typ_x1_y3); %></td>
                <td onmouseover="sndReq(<% Response.Write(x1.ToString()); %>,<% Response.Write(y4.ToString()); %>; return false;" ><% Response.Write(typ_x1_y4); %></td>
                <td onmouseover="sndReq(<% Response.Write(x1.ToString()); %>,<% Response.Write(y5.ToString()); %>; return false;" ><% Response.Write(typ_x1_y5); %></td>
                <td onmouseover="sndReq(<% Response.Write(x1.ToString()); %>,<% Response.Write(y6.ToString()); %>; return false;" ><% Response.Write(typ_x1_y6); %></td>
                <td onmouseover="sndReq(<% Response.Write(x1.ToString()); %>,<% Response.Write(y7.ToString()); %>; return false;" ><% Response.Write(typ_x1_y7); %></td>
              </tr>
[...]
</table>

Viele Dank für Euere Hilfe

pMx
 

Neue Beiträge

Zurück