Optimize performance for silverlight minesweeper style game

I design a model for a model for playing silverlight. I have currently used the square user control in a Canvas control. There are properties for this. I also want to add functionality at a later stage. We are talking about bending using Bezier curves and plotting these squares on a curve with x, y coordinates instead of scrolling. Then I want to send the square x, y to the XML file.

My question is: how should I use this, it will be the optimal optimized combination in terms of the least memory consumption, fast and efficient operation, as well as simple implementation. If you have any other ideas, please let me know. Thanks in advance.!

+6
source share
2 answers

Well, in those days I figured out the answer myself. I continued to use the Square user control and used it in the layout.

On building x / y positions, I used this:

 Point point = myElement.TransformToVisual(App.Current.RootVisual as FrameworkElement)).Transform(new Point(0, 0)); 

There was a failure in saving the XML file because silverlight 4 does not provide elevated privileges for the application in the browser. But then I used this on my save button click event:

  SaveFileDialog dlgSave = new SaveFileDialog(); dlgSave.DefaultExt = "xml"; dlgSave.Filter = "XML Files (XML)|*.xml;"; dlgSave.FilterIndex = 1; strXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + myXML.ToString();//myXML is the XDocument I created globally and saved data in it try { bool check = (bool)dlgSave.ShowDialog(); if (check) { using (Stream stream = dlgSave.OpenFile()) { StreamWriter sw = new StreamWriter(stream, System.Text.Encoding.UTF8); sw.Write(strXML); sw.Close(); stream.Close(); } MessageBox.Show("XML Saved successfully"); } catch (SecurityException) { MessageBox.Show("There seems to be an issue with saving XML file on the disk, please try again...", "Something not right", MessageBoxButton.OK); } catch (UnauthorizedAccessException) { MessageBox.Show("Saving here requires authorised permissions", "Access Denied", MessageBoxButton.OK); } 
+2
source

If you can draw everything as shapes and images (for example, vector graphics), and you can use hardware acceleration for graphic elements. In addition, you will get better performance if you do not define your squares as UserControls, you should dynamically create them in the code as shapes containing other shapes, and then have an object model associated with the shapes based on their position (for example, Dictionary squares , dictionary squares).

In terms of memory consumption and file access, you should store the square x, y position in memory as a Point strucutre and serialize the file (XML is OK) only when you need it (i.e. when the player leaves the game).

+2
source

Source: https://habr.com/ru/post/916647/


All Articles