I'm building a game. It is going well at the moment, but I'm not quite happy with my code because is not working the way I want to, due my low knowledge of C#. I was wondering if you guys could help me out to improve it by giving me some ideas and tips.
This is how I'm checking if the user has completed the levels.
public partial class MainMenu : PhoneApplicationPage
{
public MainMenu()
{
InitializeComponent();
ReadStar1();
ReadStar2();
}
private void btnbatland_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/1star/MainPage.xaml", UriKind.Relative));
}
private async Task ReadStar1()
{
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
if (local != null)
{
var dataFolder = await local.GetFolderAsync("level");
var file = await dataFolder.OpenStreamForReadAsync("star1.txt");
string readtxt;
using (StreamReader streamReader = new StreamReader(file))
{
readtxt = streamReader.ReadToEnd();
}
if (readtxt == "star1")
star2_lock.Visibility = Visibility.Collapsed;
star1_1.Visibility = Visibility.Collapsed;
}
}
private async Task ReadStar2()
{
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
if (local != null)
{
var dataFolder = await local.GetFolderAsync("level");
var file = await dataFolder.OpenStreamForReadAsync("star2.txt");
string readtxt;
using (StreamReader streamReader = new StreamReader(file))
{
readtxt = streamReader.ReadToEnd();
}
if (readtxt == "star2")
star3_lock.Visibility = Visibility.Collapsed;
}
}
Sometimes it takes 1-4 seconds to load the MainMenu
, then after 1-3 to load the function ReadStar1()
and ReadStar2()
. What could I do to improve its speed, so that the users don't even notice it has changed?