EDIT: Ich bearbeite diese Frage, weil es meine einzige nach unten abgestimmte Frage ist und ich versuche, eine Frage Verbot aufgehoben zu bekommen.Verwenden von XML-Dateien zum Erstellen von Objekten in C#
Ich verwende derzeit eine XML-Datei für ein textbasiertes Spiel. Ich habe die Datei bereits geschrieben und ich weiß, wie man aus der Datei liest, aber ich bin verwirrt, wie man tatsächliche Objekte aus der Datei erstellt. Meine Frage ist, wie übertrage ich von der XML-Datei zu einem tatsächlichen C# -Objekt. Ich suche entweder direkten Code oder ein gutes Tutorial (von denen ich ausgiebig gesucht habe und nicht finden konnte.) Unten ist ein Beispiel meiner XML-Datei und meines C# -Codes.
<?xml version="1.0" encoding="utf-8" ?>
<rooms>
<room>
<entrance>
<Description>
<Entry1>
You walk up and try the door bell. No answer...You force your way into the large, heavy, oak door. In the main foyer, you take
a quick look around. You see a baseball bat by the door and a Super Snack on a nearby dresser. Carved into one of the walls are the
words "First is 0." There is a door to the west and a door to the north.
</Entry1>
<Entry2>
You are back in the main foyer. Carved into one of the walls are the words "First is 0." There are doors to the west, north, or east.
</Entry2>
<Entry3>
You are back in the main foyer. You see a baseball bat by the door. Carved into one of the walls are the words "First is 0."
There are doors to the west, north, and east.
</Entry3>
<Entry4>
You are back in the main foyer. You see a Super Snack on a nearby dresser. Carved into one of the walls are the words "First is 0." There
are doors to the west, north, and east.
</Entry4>
</Description>
<Items>
<Item name ="Baseball Bat" type ="weapon" attribute="player.attack + 2"></Item>
<Item name ="Super Snack" type ="consumable" attribute ="player.health = 100"></Item>
</Items>
<border>
<direction>north</direction>
<name>room2</name>
</border>
<border>
<direction>west</direction>
<name>room3</name>
</border>
</entrance>
</room>
<room>
<room2>
<Description>
<Locked>You walk forward and try the door. Locked...maybe find a key?</Locked>
<Unlocked>
You use the key you found on the door in front of you. It fits! In the next room you find two doors: one to the west, one to the east.
There is a picture on the wall of the professor receiving a watch from a colleague, looks like maybe a work anniversary gift.
</Unlocked>
</Description>
<border>
<direction>west</direction>
<name>room4</name>
</border>
<border>
<direction>east</direction>
<name>room9</name>
</border>
</room2>
</room>
Dies ist meine Rooms-Datei C# -Code. Da ist nicht viel, denn ich bin mir nicht sicher, was ich hier brauche.
mit System.Xml; Namespace FirstTextBasedGame { Klasse Räume { Zeichenfolge Beschreibung; Saitengrenze; öffentlichen Räume() { // unsicher, wo von hier aus zu ... } } }
Nur klar zu sein, die Elemente und die Zimmer sind zwei verschiedene Entitäten Sie die Frage zu bewerben? – Mfusiki