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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Saving and loading a file

Saving and loading a file

Scheduled Pinned Locked Moved C#
game-dev
6 Posts 6 Posters 1 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.
  • B Offline
    B Offline
    bar3000
    wrote on last edited by
    #1

    Hi, I am building a checkers game and I would like to have an option of saving and loading the game. I need to save the game state meaning pictureboxes, arrays, stacks etc... I would be glad to be directed to some article that explains how this could be done. Thank you:)

    CPalliniC P L 3 Replies Last reply
    0
    • B bar3000

      Hi, I am building a checkers game and I would like to have an option of saving and loading the game. I need to save the game state meaning pictureboxes, arrays, stacks etc... I would be glad to be directed to some article that explains how this could be done. Thank you:)

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      See, for instance [^]. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • B bar3000

        Hi, I am building a checkers game and I would like to have an option of saving and loading the game. I need to save the game state meaning pictureboxes, arrays, stacks etc... I would be glad to be directed to some article that explains how this could be done. Thank you:)

        P Offline
        P Offline
        Paul Kettley
        wrote on last edited by
        #3

        Hi Bar3000, I would generally look down the route of Serialization and DeSerialization of a object(s), that will hold you Games details. These can be implemented using the ISerializable interface. Cheers, Paul

        J 1 Reply Last reply
        0
        • P Paul Kettley

          Hi Bar3000, I would generally look down the route of Serialization and DeSerialization of a object(s), that will hold you Games details. These can be implemented using the ISerializable interface. Cheers, Paul

          J Offline
          J Offline
          Jon Rista
          wrote on last edited by
          #4

          Perhapse better than implementing ISerializable, which is extra work that really is not neccesary...storing your game state in a separate serializable object that is utilized by your game engine would be a better approach. That way, you put all your game state (i.e. a matrix that maintains the state of each cell on the board, etc.) in a single class. That class can then be serialized without the worry of serializing other game state.

          1 Reply Last reply
          0
          • B bar3000

            Hi, I am building a checkers game and I would like to have an option of saving and loading the game. I need to save the game state meaning pictureboxes, arrays, stacks etc... I would be glad to be directed to some article that explains how this could be done. Thank you:)

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Hi, I reckon checkers state is rather limited: to me it is what you see on the board (50 squares being empty, or taken by white, black, white queen, black queen) plus ply (=half move) number. Internally I would be inclined to store the board state in bitmaps (not the GDI ones!_, being long integers where each bit represents one square. Possible variables might be: white, black, queen, and empty (which would be redundant but might speed up things). The advantage of bitmaps is they allow you to generate possible moves in parallel by: - performing shifts, e.g. (newState = oldState << 1) could be a forward move right - then mask or AND to discard moves to non-empty squares, etc. So what is keeping you from saving/restoring those few longs? BTW: I would NEVER use PictureBoxes to render the board of a board game. I'd rather use a single Panel and paint the squares and pieces myself in its Paint handler. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


            modified on Sunday, June 12, 2011 8:36 AM

            P 1 Reply Last reply
            0
            • L Luc Pattyn

              Hi, I reckon checkers state is rather limited: to me it is what you see on the board (50 squares being empty, or taken by white, black, white queen, black queen) plus ply (=half move) number. Internally I would be inclined to store the board state in bitmaps (not the GDI ones!_, being long integers where each bit represents one square. Possible variables might be: white, black, queen, and empty (which would be redundant but might speed up things). The advantage of bitmaps is they allow you to generate possible moves in parallel by: - performing shifts, e.g. (newState = oldState << 1) could be a forward move right - then mask or AND to discard moves to non-empty squares, etc. So what is keeping you from saving/restoring those few longs? BTW: I would NEVER use PictureBoxes to render the board of a board game. I'd rather use a single Panel and paint the squares and pieces myself in its Paint handler. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


              modified on Sunday, June 12, 2011 8:36 AM

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

              Luc Pattyn wrote:

              I'd rather use a single Panel

              I just use buttons, but I don't need to move anything around.

              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