Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Help with XML design.

Help with XML design.

Scheduled Pinned Locked Moved C#
questiondesigngame-devxmlhelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lord Kixdemp
    wrote on last edited by
    #1

    Hello everyone! Okay. I have a game, and it has weapons. I have code like this:

    abstract class Weapon
    {
        int power;
    }
    
    class W_Handgun : Weapon
    {
        public W_Handgun()
        {
            power = 40;
        }
    }
    

    Well, there will be many different types of weapons. So I'd like to save all of the different types in an XML file instead of hard-coding them. My question is, how do I do that? I know how to read XML files, but how do I convert something like <Handgun><Power>40</Power></Handgun> to the above mentioned class? I'm lost. (And excuse the smiley.) Thanks in advance!

    Windows Calculator told me I will die at 28. :(

    P 1 Reply Last reply
    0
    • L Lord Kixdemp

      Hello everyone! Okay. I have a game, and it has weapons. I have code like this:

      abstract class Weapon
      {
          int power;
      }
      
      class W_Handgun : Weapon
      {
          public W_Handgun()
          {
              power = 40;
          }
      }
      

      Well, there will be many different types of weapons. So I'd like to save all of the different types in an XML file instead of hard-coding them. My question is, how do I do that? I know how to read XML files, but how do I convert something like <Handgun><Power>40</Power></Handgun> to the above mentioned class? I'm lost. (And excuse the smiley.) Thanks in advance!

      Windows Calculator told me I will die at 28. :(

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Look into XML serialization.

      L 1 Reply Last reply
      0
      • P PIEBALDconsult

        Look into XML serialization.

        L Offline
        L Offline
        Lord Kixdemp
        wrote on last edited by
        #3

        Oh, so that's how it's done. I won't use this method because it's an online game, and it'll be easy for people to hack it. But thanks!

        Windows Calculator told me I will die at 28. :(

        M 1 Reply Last reply
        0
        • L Lord Kixdemp

          Oh, so that's how it's done. I won't use this method because it's an online game, and it'll be easy for people to hack it. But thanks!

          Windows Calculator told me I will die at 28. :(

          M Offline
          M Offline
          mikker_123
          wrote on last edited by
          #4

          At least I hope you won't die at 28 :)

          L 1 Reply Last reply
          0
          • M mikker_123

            At least I hope you won't die at 28 :)

            L Offline
            L Offline
            Lord Kixdemp
            wrote on last edited by
            #5

            Trust me, I do too.:laugh:

            Windows Calculator told me I will die at 28. :(

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups