0

I created a game in c #, the user must select the image interloper from those displayed on the buttons, the problem I am having is to export the exercise of other PCs, I'm forced to copy all the folders and all images ? I currently do it this way:

string [] files = Directory.GetFiles (".. \ \ .. \ \ img4");
image_target_path = ".. \ \ .. \ \ img4 \ \ hammer.png";
Random rnd = new Random ();
files.OrderBy files = (x => rnd.Next ()). ToArray ();

hammer is the image interloper, this works but when I run it on another PC I have to copy the folders, there is a solution?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364

1 Answers1

1

You could always embed the images as resources into your executable.

There are a number of different options detailed in this post: Load image from resources area of project in C#.

If you are referencing files by their path on disk, you will always need to copy the folders and files to wherever your code is being deployed.

Community
  • 1
  • 1
Sean Airey
  • 6,352
  • 1
  • 20
  • 38
  • Thank you for the response, all the images are resources, but i would to know if there is a method to eliminate the path ..\\.\\.., because ig i change the location of my .exe the project doesn't works – Andrea Caroppo Jul 08 '13 at 13:40
  • `Directory.GetFiles` will never load a compiled resource. Compiled resources are contained within the executable or DLL. You are loading these files from disk, not from the resources embedded in your application. In order to eliminate using the `..\\..\\` in your path, you must either install the application to one directory that will never change, or use embedded resources. Steven A Lowe's answer at http://stackoverflow.com/questions/278838/visual-studio-how-to-store-an-image-resource-as-an-embedded-resource tells you how to do this. – Sean Airey Jul 08 '13 at 13:59