why is MrSystem.Windows.Forms.TextBox, Text: dsadasd keep apearring? - c#

case 2:
if (jk.SelectedIndex == 0)
{
if (stat.SelectedIndex == 0)
{
result = "Mr" + name;
}
else
{
result = "Mr" + name;
}
}
else
{
if (stat.SelectedIndex == 0)
{
result = "Mrs" + name;
}
else
{
result = "Ms" + name;
}
}
txbx1.Text = result;
break;
this is the code i use here, but
whenever click the button this keep appearing
System.Windows.Forms.TextBox, Text: dsndaslkdna.
i have try change it with txbx1 without .Text but i only become error can any one help with this?

private void button1_Click(object sender, EventArgs e)
{
string result;
//combobox : lg,Sex,stat
//textbox : name,show
//button : button1
switch (lg.SelectedIndex)
{
case 0:
if (Sex.SelectedIndex == 0)
{
if (stat.SelectedIndex == 0)
{
result = "Bapak" + name;
}
else
{
result = "Mas" + name;
}
}
else
{
if (stat.SelectedIndex == 0)
{
result = "Ibu" + name;
}
else
{
result = "Mbak" + name;
}
}
show.Text = result;
break;
case 1:
if (Sex.SelectedIndex == 0)
{
if (stat.SelectedIndex == 0)
{
result = "Xiansheng" + name;
}
else
{
result = "Xiansheng" + name;
}
}
else
{
if (stat.SelectedIndex == 0)
{
result = "Taitai" + name;
}
else
{
result = "Xiaojie" + name;
}
}
show.Text = result;
break;
case 2:
if (Sex.SelectedIndex == 0)
{
if (stat.SelectedIndex == 0)
{
result = "Mr" + name;
}
else
{
result = "Mr" + name;
}
}
else
{
if (stat.SelectedIndex == 0)
{
result = "Mrs" + name;
}
else
{
result = "Ms" + name;
}
}
show.Text = result;
break;
case 3:
if (Sex.SelectedIndex == 0)
{
if (stat.SelectedIndex == 0)
{
result = "San" + name;
}
else
{
result = "Kun" + name;
}
}
else
{
if (stat.SelectedIndex == 0)
{
result = "San" + name;
}
else
{
result = "Chan" + name;
}
}
show.Text = result;
break;
case 4:
if (Sex.SelectedIndex == 0)
{
if (stat.SelectedIndex == 0)
{
result = "Ssi" + name;
}
else
{
result = "Hyung" + name;
}
}
else
{
if (stat.SelectedIndex == 0)
{
result = "Ssi" + name;
}
else
{
result = "Noona" + name;
}
}
show.Text = result;
break;
case 5:
if (Sex.SelectedIndex == 0)
{
if (stat.SelectedIndex == 0)
{
result = "Monsieur" + name;
}
else
{
result = "Monsieur" + name;
}
}
else
{
if (stat.SelectedIndex == 0)
{
result = "Madame" + name;
}
else
{
result = "Mademoiselle" + name;
}
}
show.Text = result;
break;
}
here the full one

Related

ViewModel Method Not Reloading View

I have a problem with Xamarin.Forms whereby the View is not refreshing as I would expect it to.
I have bound a View to a ViewModel, and I have a series of methods to perform various functions.
On the successful completion of a function, I want it to execute my LoadResults() method.
The LoadResults() method works fine when I load the view initially. However, when I execute any other method (DeleteScan(id) method shown below) it should re-fire the LoadResults() method and reload the page.
I know it is entering the LoadResults() method as I've put a break point in there and stepped through it. But by the end of it, it doesn't reload the view.
I also know the view can refresh, as I have other simple methods which are simply updating properties in the VM and those changes are reflecting in the UI.
So for whatever reason, LoadResults() is not reloading the page.
Any ideas what I've done wrong here?
View Model Constructor and Properties
public class ResultsProcessViewModel : INotifyPropertyChanged
{
public ICommand AddTimingCommand { get; set; }
public ICommand AddScanCommand { get; set; }
public ICommand InsertTimingCommand { get; set; }
public ICommand InsertScanCommand { get; set; }
public ICommand DeleteTimingCommand { get; set; }
public ICommand DeleteScanCommand { get; set; }
public ICommand PublishCommand { get; set; }
public ICommand LoadResultsCommand { get; set; }
public ICommand CancelMissingFinisherCommand { get; set; }
public ICommand CancelMissingTimingCommand { get; set; }
public int RaceId { get; set; }
public DateTime RaceDate { get; set; }
//public ResultsViewModel(Race race)
public ResultsProcessViewModel(Race race)
{
AddTimingCommand = new Command<string>(AddTiming);
InsertTimingCommand = new Command(InsertTiming);
AddScanCommand = new Command<string>(AddScan);
InsertScanCommand = new Command(InsertScan);
DeleteTimingCommand = new Command<int>(DeleteTiming);
DeleteScanCommand = new Command<int>(DeleteScan);
PublishCommand = new Command(Publish);
LoadResultsCommand = new Command<int>(LoadResults);
CancelMissingFinisherCommand = new Command(CancelMissingFinisher);
CancelMissingTimingCommand = new Command(CancelMissingTiming);
Invalid = false;
PublishStatus = race.ResultStatus;
Published = false;
PublishVisibility = false;
AddTimingVisibility = false;
AddScanVisibility = false;
AddVisibility = true;
IsBusy = false;
RaceId = race.Id;
RaceDate = race.RaceDate;
RaceStartTime = Convert.ToDateTime(race.RaceStartTime);
Scans = ScansAPI.GetScans(RaceId);
Timings = TimingsAPI.GetTimings(RaceId);
Entries = EntriesAPI.GetEntries(RaceId);
LoadResults(RaceId);
}
ObservableCollection<GroupedResultModel> _grouped;
public ObservableCollection<GroupedResultModel> grouped
{
get { return _grouped; }
set
{
if (_grouped == value)
return;
_grouped = value;
OnPropertyChanged("Grouped");
}
}
DateTime _raceStartTime;
public DateTime RaceStartTime
{
get { return _raceStartTime; }
set
{
if (_raceStartTime == value)
return;
_raceStartTime = value;
OnPropertyChanged("RaceStartTime");
}
}
int _timingPosition;
public int TimingPosition
{
get { return _timingPosition; }
set
{
if (_timingPosition == value)
return;
_timingPosition = value;
OnPropertyChanged("TimingPosition");
}
}
int _addScanTimingId;
public int AddScanTimingId
{
get { return _addScanTimingId; }
set
{
if (_addScanTimingId == value)
return;
_addScanTimingId = value;
OnPropertyChanged("AddScanTimingId");
}
}
int _addTimingScanId;
public int AddTimingScanId
{
get { return _addTimingScanId; }
set
{
if (_addTimingScanId == value)
return;
_addTimingScanId = value;
OnPropertyChanged("AddTimingScanId");
}
}
int _scanPosition;
public int ScanPosition
{
get { return _scanPosition; }
set
{
if (_scanPosition == value)
return;
_scanPosition = value;
OnPropertyChanged("ScanPosition");
}
}
bool _isBusy;
public bool IsBusy
{
get { return _isBusy; }
set
{
if (_isBusy == value)
return;
_isBusy = value;
OnPropertyChanged("IsBusy");
}
}
bool _published;
public bool Published
{
get { return _published; }
set
{
if (_published == value)
return;
_published = value;
OnPropertyChanged("Published");
}
}
bool _publishVisibility;
public bool PublishVisibility
{
get { return _publishVisibility; }
set
{
if (_publishVisibility == value)
return;
_publishVisibility = value;
OnPropertyChanged("PublishVisibility");
}
}
bool _error;
public bool Error
{
get { return _error; }
set
{
if (_error == value)
return;
_error = value;
OnPropertyChanged("Error");
}
}
bool _addVisibility;
public bool AddVisibility
{
get { return _addVisibility; }
set
{
if (_addVisibility == value)
return;
_addVisibility = value;
OnPropertyChanged("AddVisibility");
}
}
bool _addTimingVisibility;
public bool AddTimingVisibility
{
get { return _addTimingVisibility; }
set
{
if (_addTimingVisibility == value)
return;
_addTimingVisibility = value;
OnPropertyChanged("AddTimingVisibility");
}
}
bool _addScanVisibility;
public bool AddScanVisibility
{
get { return _addScanVisibility; }
set
{
if (_addScanVisibility == value)
return;
_addScanVisibility = value;
OnPropertyChanged("AddScanVisibility");
}
}
ObservableCollection<Result> _results;
public ObservableCollection<Result> Results
{
get
{
return _results;
}
set
{
if (_results != value)
{
_results = value;
OnPropertyChanged("Results");
}
}
}
ObservableCollection<Scan> _scans;
public ObservableCollection<Scan> Scans
{
get
{
return _scans;
}
set
{
if (_scans != value)
{
_scans = value;
OnPropertyChanged("Scans");
}
}
}
ObservableCollection<Timing> _timings;
public ObservableCollection<Timing> Timings
{
get
{
return _timings;
}
set
{
if (_timings != value)
{
_timings = value;
OnPropertyChanged("Timings");
}
}
}
ObservableCollection<RaceEntry> _entries;
public ObservableCollection<RaceEntry> Entries
{
get
{
return _entries;
}
set
{
if (_entries != value)
{
_entries = value;
OnPropertyChanged("Entries");
}
}
}
bool _invalid;
public bool Invalid
{
get { return _invalid; }
set
{
if (_invalid == value)
return;
_invalid = value;
OnPropertyChanged("Invalid");
}
}
bool _resultsInvalid;
public bool ResultsInvalid
{
get { return _resultsInvalid; }
set
{
if (_resultsInvalid == value)
return;
_resultsInvalid = value;
OnPropertyChanged("ResultsInvalid");
}
}
bool _insertScanVisibility;
public bool InsertScanVisibility
{
get { return _insertScanVisibility; }
set
{
if (_insertScanVisibility == value)
return;
_insertScanVisibility = value;
OnPropertyChanged("InsertScanVisibility");
}
}
string _validationError;
public string ValidationError
{
get { return _validationError; }
set
{
if (_validationError == value)
return;
_validationError = value;
OnPropertyChanged("ValidationError");
}
}
string _resultsValidationError;
public string ResultsValidationError
{
get { return _resultsValidationError; }
set
{
if (_resultsValidationError == value)
return;
_resultsValidationError = value;
OnPropertyChanged("ResultsValidationError");
}
}
string _missingBib;
public string MissingBib
{
get { return _missingBib; }
set
{
if (_missingBib == value)
return;
_missingBib = value;
OnPropertyChanged("MissingBib");
}
}
string _errorMessage;
public string ErrorMessage
{
get { return _errorMessage; }
set
{
if (_errorMessage == value)
return;
_errorMessage = value;
OnPropertyChanged("ErrorMessage");
}
}
public Race SelectedRace { get; set; }
private bool _raceCountZero;
public bool RaceCountZero
{
get { return _raceCountZero; }
set
{
if (_raceCountZero == value)
return;
_raceCountZero = value;
OnPropertyChanged("RaceCountZero");
}
}
string _aboveBelow;
public string AboveBelow
{
get { return _aboveBelow; }
set
{
if (_aboveBelow == value)
return;
_aboveBelow = value;
OnPropertyChanged("AboveBelow");
}
}
string _aboveBelowPosition;
public string AboveBelowPosition
{
get { return _aboveBelowPosition; }
set
{
if (_aboveBelowPosition == value)
return;
_aboveBelowPosition = value;
OnPropertyChanged("AboveBelowPosition");
}
}
string _publishStatus;
public string PublishStatus
{
get { return _publishStatus; }
set
{
if (_publishStatus == value)
return;
_publishStatus = value;
OnPropertyChanged("PublishStatus");
}
}
string _newBatchCode;
public string NewBatchCode
{
get { return _newBatchCode; }
set
{
if (_newBatchCode == value)
return;
_newBatchCode = value;
OnPropertyChanged("NewBatchCode");
}
}
string _addHH;
public string AddHH
{
get { return _addHH; }
set
{
if (_addHH == value)
return;
_addHH = value;
OnPropertyChanged("AddHH");
}
}
string _addMM;
public string AddMM
{
get { return _addMM; }
set
{
if (_addMM == value)
return;
_addMM = value;
OnPropertyChanged("AddMM");
}
}
string _addSS;
public string AddSS
{
get { return _addSS; }
set
{
if (_addSS == value)
return;
_addSS = value;
OnPropertyChanged("AddSS");
}
}
string _scanBatchCode;
public string ScanBatchCode
{
get { return _scanBatchCode; }
set
{
if (_scanBatchCode == value)
return;
_scanBatchCode = value;
OnPropertyChanged("ScanBatchCode");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var changed = PropertyChanged;
if (changed != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
DeleteScan method
void DeleteScan(int scanid)
{
//Do stuff when deleting a scan. It needs to do all this in the observable collection. Then when we submit, we'll update all scans, timings etc with whats in the collection
Task.Run(() =>
{
try
{
Device.BeginInvokeOnMainThread(() => IsBusy = true);
var IsThereConnection = GlobalFunctions.CheckForInternetConnection();
if (IsThereConnection == false)
throw new Exception("You cannot delete a scan whilst you are offline");
//We are good to go
else
{
var deletescan = ScansAPI.DeleteScan(scanid);
if (deletescan.Code != "NoContent")
throw new Exception("Error deleting scan");
}
}
catch (Exception ex)
{
Device.BeginInvokeOnMainThread(() =>
{
ValidationError = ex.Message;
Invalid = true;
});
return;
}
finally
{
var newscans = ScansAPI.GetScans(RaceId);
var sortednewscans = new ObservableCollection<Scan>(newscans.OrderBy(c => c.Position));
Scans = sortednewscans;
Device.BeginInvokeOnMainThread(() => Published = false);
Device.BeginInvokeOnMainThread(() => LoadResults(RaceId));
Device.BeginInvokeOnMainThread(() => AddScanVisibility = false);
Device.BeginInvokeOnMainThread(() => IsBusy = false);
}
});
}
LoadResults Method
void LoadResults(int raceid)
{
var results = new ObservableCollection<Result>();
//Start with the timings
foreach (Timing timing in Timings)
{
var result = new Result();
//Basic details
result.RaceId = RaceId;
result.RaceDate = RaceDate;
result.Status = "Processing";
result.BackgroundColour = "White";
result.ScanTrashVisibility = true;
result.TimingTrashVisibility = true;
//Timing Data
result.TimingId = timing.Id;
result.TimingPosition = timing.Position;
result.TimingStatus = timing.Status;
result.StartTime = timing.StartTime;
result.EndTime = timing.EndTime;
result.TimingBatchCode = timing.BatchCode;
result.TimingBatchPosition = timing.BatchCode + timing.Position.ToString();
var elapsed = result.EndTime - result.StartTime;
string elapsedhours = elapsed.Hours.ToString();
string elapsedminutes = elapsed.Minutes.ToString();
string elapsedseconds = elapsed.Seconds.ToString();
string elapsedmillis;
if (elapsed.Milliseconds.ToString().Length > 2)
{
elapsedmillis = elapsed.Milliseconds.ToString().Substring(0, 2);
}
else
{
elapsedmillis = elapsed.Milliseconds.ToString();
}
if (elapsedhours.Length == 1) { elapsedhours = "0" + elapsedhours; }
if (elapsedminutes.Length == 1) { elapsedminutes = "0" + elapsedminutes; }
if (elapsedseconds.Length == 1) { elapsedseconds = "0" + elapsedseconds; }
if (elapsedmillis.Length == 1) { elapsedmillis = "0" + elapsedmillis; }
if((elapsedhours == "00"))
{
result.Elapsed = elapsedminutes + ":" + elapsedseconds + "." + elapsedmillis;
}
else
{
result.Elapsed = elapsedhours + ":" + elapsedminutes + ":" + elapsedseconds + "." + elapsedmillis;
}
results.Add(result);
}
//Add in the scans
foreach (Result result1 in results)
{
var scan = Scans.Where(p => p.BatchCode == result1.TimingBatchCode)
.FirstOrDefault(p => p.Position == result1.TimingPosition);
if (scan != null)
{
result1.ScanId = scan.Id;
result1.ScanPosition = scan.Position;
result1.ScanStatus = scan.Status;
result1.ScanBibNumber = scan.BibNumber;
result1.ScanBatchCode = scan.BatchCode;
result1.ScanBatchPosition = scan.BatchCode + scan.Position.ToString();
}
else
{
result1.ScanId = 0;
result1.ScanPosition = 0;
result1.ScanStatus = 99;
result1.ScanBibNumber = "UNKNOWN";
result1.AddScanButtonVisibility = true;
result1.ScanBatchCode = result1.TimingBatchCode;
}
}
//Add any scans which there are no times for
var notimescans = new ObservableCollection<Scan>();
foreach (Scan scan in Scans)
{
var checkscan = results.FirstOrDefault(s => s.ScanId == scan.Id);
if (checkscan == null)
{
var newresult = new Result();
newresult.RaceId = RaceId;
newresult.RaceDate = RaceDate;
newresult.Status = "Processing";
newresult.ScanId = scan.Id;
newresult.ScanPosition = scan.Position;
newresult.ScanStatus = scan.Status;
newresult.ScanBibNumber = scan.BibNumber;
newresult.ScanBatchCode = scan.BatchCode;
newresult.ScanBatchPosition = scan.BatchCode + scan.Position.ToString();
newresult.ScanTrashVisibility = true;
newresult.AddTimingButtonVisibility = true;
newresult.TimingId = 0;
newresult.TimingPosition = 99999;
newresult.TimingStatus = 99;
newresult.Elapsed = "N/A";
results.Add(newresult);
}
}
//Then add in the entries
foreach (Result result2 in results)
{
var entry = Entries.FirstOrDefault(p => p.BibNumber == result2.ScanBibNumber);
if (entry != null)
{
result2.EntryId = entry.Id;
result2.FirstName = entry.FirstName;
result2.LastName = entry.LastName;
result2.FormattedName = entry.FirstName + " " + entry.LastName.ToUpper();
result2.Gender = entry.Gender;
result2.DateOfBirth = entry.DateOfBirth;
result2.Club = entry.Club;
result2.Team = entry.Team;
result2.EntryBibNumber = entry.BibNumber;
if (result2.Club == null)
{
result2.FormattedClub = "";
}
else
{
result2.FormattedClub = entry.Club.ToUpper();
}
}
else
{
result2.EntryId = 0;
result2.FirstName = "Unknown";
result2.LastName = "ATHLETE";
result2.FormattedName = entry.FirstName + " " + entry.LastName.ToUpper();
result2.Gender = "Unknown";
result2.DateOfBirth = DateTime.Now;
result2.Club = "";
result2.Team = "";
result2.EntryBibNumber = result2.ScanBibNumber + " (Unrecognised)";
}
if(result2.ScanBatchCode == "NULLBATCH")
{
result2.ScanBatchCode = "Default";
}
if (result2.TimingBatchCode == "NULLBATCH")
{
result2.TimingBatchCode = "Default";
}
}
if(Scans.Count() != Timings.Count())
{
ResultsInvalid = true;
ResultsValidationError = "Your scan count and timing count's don't match. Please continue processing your results until these match and you will then be able to publish.";
}
else
{
Invalid = false;
PublishVisibility = true;
}
var sortedresults = new ObservableCollection<Result>(results.OrderBy(c => c.Elapsed));
int newposition = 1;
foreach (Result sortedresult in sortedresults)
{
sortedresult.OverallPosition = newposition;
newposition = newposition + 1;
}
//Create batches
grouped = new ObservableCollection<GroupedResultModel>();
foreach (Result result in results)
{
GroupedResultModel resultGroup = new GroupedResultModel();
var groupcheck = grouped.FirstOrDefault(b => b.BatchCode == result.ScanBatchCode);
if (groupcheck == null)
{
resultGroup.BatchCode = result.ScanBatchCode;
var BatchOfResults = results.Where(r => r.ScanBatchCode == resultGroup.BatchCode).OrderBy(r => r.Elapsed);
int batchposition = 1;
foreach (Result batchedresult in BatchOfResults)
{
batchedresult.OverallPosition = batchposition;
resultGroup.Add(batchedresult);
batchposition = batchposition + 1;
}
grouped.Add(resultGroup);
}
}
Results = sortedresults;
OnPropertyChanged("Invalid");
}

Xamarin View Not Refreshing

I am having some problems with my Xamarin XAML page and its viewmodel.
I have written the code with a bunch of methods which are executed via commands from the XAML.
Functionally its all working as desired. However, the view is not refreshing when the methods have finished executing. So despite inserting things and removing things from my observable collections (via an API call update), and having a notifypropertychanged event, the page doesn't reload.
Any ideas?
ViewModel (Some properties omitted to fit the character limit for a post)
namespace TechsportiseApp.ViewModels
{
public class ResultsProcessViewModel : INotifyPropertyChanged
{
public ICommand AddTimingCommand { get; set; }
public ICommand AddScanCommand { get; set; }
public ICommand DeleteTimingCommand { get; set; }
public ICommand DeleteScanCommand { get; set; }
public ICommand PublishCommand { get; set; }
public ICommand LoadResultsCommand { get; set; }
public ICommand MissingFinisherCommand { get; set; }
public ICommand MissingTimingCommand { get; set; }
public int RaceId { get; set; }
public DateTime RaceDate { get; set; }
//public ResultsViewModel(Race race)
public ResultsProcessViewModel(Race race)
{
AddTimingCommand = new Command(AddTiming);
AddScanCommand = new Command(AddScan);
DeleteTimingCommand = new Command<int>(DeleteTiming);
DeleteScanCommand = new Command<int>(DeleteScan);
PublishCommand = new Command<string>(Publish);
LoadResultsCommand = new Command<int>(LoadResults);
MissingFinisherCommand = new Command(MissingFinisher);
MissingTimingCommand = new Command(MissingTiming);
Invalid = false;
AddTimingVisibility = false;
AddScanVisibility = false;
AddVisibility = true;
PublishProvisionalVisibility = false;
PublishFinalVisibility = false;
IsBusy = false;
RaceId = race.Id;
RaceDate = race.RaceDate;
RaceStartTime = Convert.ToDateTime(race.RaceStartTime);
Scans = ScansAPI.GetScans(RaceId);
Timings = TimingsAPI.GetTimings(RaceId);
Entries = EntriesAPI.GetEntries(RaceId);
LoadResults(RaceId);
}
ObservableCollection<Result> _results;
public ObservableCollection<Result> Results
{
get
{
return _results;
}
set
{
if (_results != value)
{
_results = value;
OnPropertyChanged("Results");
}
}
}
ObservableCollection<Scan> _scans;
public ObservableCollection<Scan> Scans
{
get
{
return _scans;
}
set
{
if (_scans != value)
{
_scans = value;
OnPropertyChanged("Scans");
}
}
}
ObservableCollection<Timing> _timings;
public ObservableCollection<Timing> Timings
{
get
{
return _timings;
}
set
{
if (_timings != value)
{
_timings = value;
OnPropertyChanged("Timings");
}
}
}
ObservableCollection<RaceEntry> _entries;
public ObservableCollection<RaceEntry> Entries
{
get
{
return _entries;
}
set
{
if (_entries != value)
{
_entries = value;
OnPropertyChanged("Entries");
}
}
}
ObservableCollection<Race> _races;
public ObservableCollection<Race> Races
{
get
{
try
{
var racelist = RacesAPI.GetRaces();
var sortedracelist = new ObservableCollection<Race>(racelist.OrderBy(c => c.Name));
var racecount = racelist.Count();
if (racecount == 0)
{
RaceCountZero = true;
}
else
{
RaceCountZero = false;
}
return racelist;
}
catch
{
Invalid = true;
ValidationError = "Error getting Race List. No internet connection available.";
}
return _races;
}
set
{
if (_races != value)
{
_races = value;
OnPropertyChanged("Races");
}
}
}
string _aboveBelow;
public string AboveBelow
{
get { return _aboveBelow; }
set
{
if (_aboveBelow == value)
return;
_aboveBelow = value;
OnPropertyChanged("AboveBelow");
}
}
string _aboveBelowPosition;
public string AboveBelowPosition
{
get { return _aboveBelowPosition; }
set
{
if (_aboveBelowPosition == value)
return;
_aboveBelowPosition = value;
OnPropertyChanged("AboveBelowPosition");
}
}
string _addHH;
public string AddHH
{
get { return _addHH; }
set
{
if (_addHH == value)
return;
_addHH = value;
OnPropertyChanged("AddHH");
}
}
string _addMM;
public string AddMM
{
get { return _addMM; }
set
{
if (_addMM == value)
return;
_addMM = value;
OnPropertyChanged("AddMM");
}
}
string _addSS;
public string AddSS
{
get { return _addSS; }
set
{
if (_addSS == value)
return;
_addSS = value;
OnPropertyChanged("AddSS");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var changed = PropertyChanged;
if (changed != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
void AddTiming()
{
AddScanVisibility = false;
AddTimingVisibility = !AddTimingVisibility;
}
void AddScan()
{
AddScanVisibility = !AddScanVisibility;
AddTimingVisibility = false;
}
void MissingFinisher()
{
//Do stuff when deleting a scan. It needs to do all this in the observable collection. Then when we submit, we'll update all scans, timings etc with whats in the collection
Task.Run(() =>
{
try
{
var scancount = Scans.Count();
Device.BeginInvokeOnMainThread(() => IsBusy = true);
var IsThereConnection = GlobalFunctions.CheckForInternetConnection();
if (IsThereConnection == false)
throw new Exception("You cannot add a scan whilst you are offline");
else if (string.IsNullOrEmpty(MissingBib))
throw new Exception("You must enter a bib number");
else if (string.IsNullOrEmpty(AboveBelow))
throw new Exception("You must choose if you are adding the bib above or below");
else if (string.IsNullOrEmpty(AboveBelowPosition))
throw new Exception("You must enter the position you are inserting " + AboveBelow);
else if (Convert.ToInt32(AboveBelowPosition) > scancount)
throw new Exception("The position you have chosen to insert above or below does not exist. Please enter a valid value");
else if (Convert.ToInt32(AboveBelowPosition) < 1)
throw new Exception("The position you have chosen to insert above or below does not exist. Please enter a valid value");
//We are good to go
else
{
var InsertedSequence = new int();
var abovebelow = Scans.SingleOrDefault(i => i.Position == Convert.ToInt32(AboveBelowPosition));
var abposition = Convert.ToInt32(AboveBelowPosition);
if (AboveBelow == "Above")
{
InsertedSequence = abovebelow.Sequence + 5;
}
else if (AboveBelow == "Below")
{
InsertedSequence = abovebelow.Sequence - 5;
}
else
{
return;
}
//Need to add resequencing and reallocation of position numbers
var scan = new ScanPost
{
RaceId = RaceId,
BibNumber = MissingBib,
Sequence = InsertedSequence,
Position = abposition,
Reorder = true,
Status = 0
};
var createscan = ScansAPI.CreateScan(scan);
if (createscan.Code != "Created")
throw new Exception("Error creating scan");
}
}
catch (Exception ex)
{
Device.BeginInvokeOnMainThread(() =>
{
ValidationError = ex.Message;
Invalid = true;
});
return;
}
finally
{
Device.BeginInvokeOnMainThread(() => IsBusy = false);
LoadResults(RaceId);
OnPropertyChanged("Results");
}
});
}
void MissingTiming()
{
Task.Run(() =>
{
try
{
var timingcount = Timings.Count();
Device.BeginInvokeOnMainThread(() => IsBusy = true);
var IsThereConnection = GlobalFunctions.CheckForInternetConnection();
if (IsThereConnection == false)
throw new Exception("You cannot add a timing whilst you are offline");
//We are good to go
else
{
if (AddHH == "") { AddHH = "0"; }
if (AddMM == "") { AddMM = "0"; }
if (AddSS == "") { AddSS = "0"; }
var ManualEndTime = RaceStartTime.AddHours(Convert.ToDouble(AddHH))
.AddMinutes(Convert.ToDouble(AddMM))
.AddSeconds(Convert.ToDouble(AddSS));
var timing = new TimingPost
{
RaceId = RaceId,
StartTime = RaceStartTime,
EndTime = ManualEndTime,
Reorder = true,
Position = 0,
Status = 0
};
var createtiming = TimingsAPI.CreateTiming(timing);
if (createtiming.Code != "Created")
throw new Exception("Error creating timing");
}
}
catch (Exception ex)
{
Device.BeginInvokeOnMainThread(() =>
{
ValidationError = ex.Message;
Invalid = true;
});
return;
}
finally
{
Device.BeginInvokeOnMainThread(() => IsBusy = false);
Device.BeginInvokeOnMainThread(() => LoadResults(RaceId));
Device.BeginInvokeOnMainThread(() => OnPropertyChanged("Results"));
}
});
}
void DeleteTiming(int timingid)
{
//Do stuff when deleting a timing. It needs to do all this in the observable collection. Then when we submit, we'll update all scans, timings etc with whats in the collection
Task.Run(() =>
{
try
{
Device.BeginInvokeOnMainThread(() => IsBusy = true);
var IsThereConnection = GlobalFunctions.CheckForInternetConnection();
if (IsThereConnection == false)
throw new Exception("You cannot delete a timing whilst you are offline");
//We are good to go
else
{
var deletetiming = TimingsAPI.DeleteTiming(timingid);
if (deletetiming.Code != "NoContent")
throw new Exception("Error deleting timing");
}
}
catch (Exception ex)
{
Device.BeginInvokeOnMainThread(() =>
{
ValidationError = ex.Message;
Invalid = true;
});
return;
}
finally
{
Device.BeginInvokeOnMainThread(() => IsBusy = false);
LoadResults(RaceId);
OnPropertyChanged("Timings");
Device.BeginInvokeOnMainThread(() => LoadResults(RaceId));
Device.BeginInvokeOnMainThread(() => OnPropertyChanged("Timings"));
}
});
}
void DeleteScan(int scanid)
{
//Do stuff when deleting a scan. It needs to do all this in the observable collection. Then when we submit, we'll update all scans, timings etc with whats in the collection
Task.Run(() =>
{
try
{
Device.BeginInvokeOnMainThread(() => IsBusy = true);
var IsThereConnection = GlobalFunctions.CheckForInternetConnection();
if (IsThereConnection == false)
throw new Exception("You cannot delete a scan whilst you are offline");
//We are good to go
else
{
var deletetiming = TimingsAPI.DeleteTiming(scanid);
if (deletetiming.Code != "NoContent")
throw new Exception("Error deleting scan");
}
}
catch (Exception ex)
{
Device.BeginInvokeOnMainThread(() =>
{
ValidationError = ex.Message;
Invalid = true;
});
return;
}
finally
{
Device.BeginInvokeOnMainThread(() => IsBusy = false);
LoadResults(RaceId);
OnPropertyChanged("Results");
}
});
}
void Publish(string status)
{
Task.Run(() =>
{
try
{
var publish = new Publish();
publish.RaceId = RaceId;
publish.ResultStatus = status;
Device.BeginInvokeOnMainThread(() => IsBusy = true);
var IsThereConnection = GlobalFunctions.CheckForInternetConnection();
if (IsThereConnection == false)
throw new Exception("You cannot publish results whilst you are offline");
//We are good to go
else
{
var publishrace = RacesAPI.PublishRace(publish);
if (publishrace.Code != "NoContent")
throw new Exception("Error publishing race");
}
}
catch (Exception ex)
{
Device.BeginInvokeOnMainThread(() =>
{
ValidationError = ex.Message;
Invalid = true;
});
return;
}
finally
{
Device.BeginInvokeOnMainThread(() => IsBusy = false);
LoadResults(RaceId);
OnPropertyChanged("Results");
}
});
}
void LoadResults(int raceid)
{
var results = new ObservableCollection<Result>();
//Start with the timings
foreach (Timing timing in Timings)
{
var result = new Result();
//Basic details
result.RaceId = RaceId;
result.RaceDate = RaceDate;
result.Status = "Processing";
//Timing Data
result.TimingId = timing.Id;
result.TimingPosition = timing.Position;
result.TimingStatus = timing.Status;
result.StartTime = timing.StartTime;
result.EndTime = timing.EndTime;
var elapsed = result.EndTime - result.StartTime;
string elapsedhours = elapsed.Hours.ToString();
string elapsedminutes = elapsed.Minutes.ToString();
string elapsedseconds = elapsed.Seconds.ToString();
string elapsedmillis;
if (elapsed.Milliseconds.ToString().Length > 2)
{
elapsedmillis = elapsed.Milliseconds.ToString().Substring(0, 2);
}
else
{
elapsedmillis = elapsed.Milliseconds.ToString();
}
if (elapsedhours.Length == 1) { elapsedhours = "0" + elapsedhours; }
if (elapsedminutes.Length == 1) { elapsedminutes = "0" + elapsedminutes; }
if (elapsedseconds.Length == 1) { elapsedseconds = "0" + elapsedseconds; }
if (elapsedmillis.Length == 1) { elapsedmillis = "0" + elapsedmillis; }
if((elapsedhours == "00"))
{
result.Elapsed = elapsedminutes + ":" + elapsedseconds + "." + elapsedmillis;
}
else
{
result.Elapsed = elapsedhours + ":" + elapsedminutes + ":" + elapsedseconds + "." + elapsedmillis;
}
results.Add(result);
}
//Add in the scans
foreach (Result result1 in results)
{
var scan = Scans.FirstOrDefault(p => p.Position == result1.TimingPosition);
if (scan != null)
{
result1.ScanId = scan.Id;
result1.ScanPosition = scan.Position;
result1.ScanStatus = scan.Status;
result1.ScanBibNumber = scan.BibNumber;
}
else
{
result1.ScanId = 0;
result1.ScanPosition = 0;
result1.ScanStatus = 99;
result1.ScanBibNumber = "UNKNOWN";
}
}
//Add any scans which there are no times for (Higher than count)
var timingscount = Timings.Count();
var notimescans = new ObservableCollection<Scan>();
foreach (Scan scan in Scans)
{
if (scan.Position > timingscount)
{
var newresult = new Result();
newresult.RaceId = RaceId;
newresult.RaceDate = RaceDate;
newresult.Status = "Processing";
newresult.ScanId = scan.Id;
newresult.ScanPosition = scan.Position;
newresult.ScanStatus = scan.Status;
newresult.ScanBibNumber = scan.BibNumber;
newresult.TimingId = 0;
newresult.TimingPosition = 99999;
newresult.TimingStatus = 99;
newresult.StartTime = RaceStartTime;
newresult.EndTime = RaceStartTime;
var elapsed = newresult.EndTime - newresult.StartTime;
string elapsedhours = elapsed.Hours.ToString();
string elapsedminutes = elapsed.Minutes.ToString();
string elapsedseconds = elapsed.Seconds.ToString();
string elapsedmillis = elapsed.Milliseconds.ToString();
if (elapsedhours.Length == 1) { elapsedhours = "0" + elapsedhours; }
if (elapsedminutes.Length == 1) { elapsedminutes = "0" + elapsedminutes; }
if (elapsedseconds.Length == 1) { elapsedseconds = "0" + elapsedseconds; }
if (elapsedmillis.Length == 1) { elapsedmillis = "0" + elapsedmillis; }
if ((elapsedhours == "00"))
{
newresult.Elapsed = elapsedminutes + ":" + elapsedseconds + "." + elapsedmillis;
}
else
{
newresult.Elapsed = elapsedhours + ":" + elapsedminutes + ":" + elapsedseconds + "." + elapsedmillis;
}
results.Add(newresult);
}
}
//Then add in the entries
foreach (Result result2 in results)
{
var entry = Entries.FirstOrDefault(p => p.BibNumber == result2.ScanBibNumber);
if (entry != null)
{
result2.EntryId = entry.Id;
result2.FirstName = entry.FirstName;
result2.LastName = entry.LastName;
result2.FormattedName = entry.FirstName + " " + entry.LastName.ToUpper();
result2.Gender = entry.Gender;
result2.DateOfBirth = entry.DateOfBirth;
result2.Club = entry.Club;
result2.Team = entry.Team;
result2.EntryBibNumber = entry.BibNumber;
}
else
{
result2.EntryId = 0;
result2.FirstName = "Unknown";
result2.LastName = "ATHLETE";
result2.Gender = "Unknown";
result2.DateOfBirth = DateTime.Now;
result2.Club = "";
result2.Team = "";
result2.EntryBibNumber = "Unknown";
}
}
var sortedresults = new ObservableCollection<Result>(results.OrderBy(c => c.TimingPosition));
Results = sortedresults;
OnPropertyChanged("Results");
}
}
}

Kruskal's Maze Algorithm - Only Working up to dimension 11x11

I am using https://courses.cs.washington.edu/courses/cse326/07su/prj2/kruskal.html psuedocode as reference when writing my code.
Code is in C#, and my code can only generate mazes up to 11x11, anything more than than it will run, seemingly, forever (e.g. 12x11 or 12x12 won't work)
Grid Properties are just storing the dimension of the size of the maze
public class GridProperties
{
private int xLength;
private int yLength;
public GridProperties(int xlength, int ylength)
{
xLength = xlength;
yLength = ylength;
}
public int getXLength()
{
return this.xLength;
}
public int getYLength()
{
return this.yLength;
}
}
Cell Properties generates the grid
public class CellProperties
{
private GridProperties Grid;
private bool topWall, bottomWall, rightWall, leftWall;
private int? xCoord, yCoord;
private CellProperties topCell, bottomCell, rightCell, leftCell;
private CellProperties topParentCell, bottomParentCell, rightParentCell, leftParentCell;
private HashSet<String> passageID = new HashSet<String>();
public CellProperties(GridProperties grid = null, int? targetXCoord = null, int? targetYCoord = null,
CellProperties tpCell = null, CellProperties bpCell = null,
CellProperties rpCell = null, CellProperties lpCell = null)
{
this.Grid = grid;
this.xCoord = targetXCoord;
this.yCoord = targetYCoord;
this.updatePassageID(this.xCoord.ToString() + this.yCoord.ToString());
this.topWall = true;
this.bottomWall = true;
this.rightWall = true;
this.leftWall = true;
this.topParentCell = tpCell;
this.bottomParentCell = bpCell;
this.rightParentCell = rpCell;
this.leftParentCell = lpCell;
this.topCell = this.setTopCell();
this.bottomCell = this.setBottomCell();
if (this.yCoord == 0)
{
this.rightCell = this.setRightCell();
}
this.leftCell = this.setLeftCell();
}
public CellProperties setTopCell()
{
if (this.Grid == null)
{
return null;
}
if (this.yCoord == this.Grid.getYLength() - 1)
{
return new CellProperties();
}
else
{
return new CellProperties(this.Grid, this.xCoord, this.yCoord + 1, null, this, null, null);
}
}
public CellProperties setBottomCell()
{
if (this.yCoord == 0)
{
return new CellProperties();
}
else
{
return this.bottomParentCell;
}
}
public CellProperties setRightCell()
{
if (this.Grid == null)
{
return null;
}
if (this.xCoord == this.Grid.getXLength() - 1)
{
return new CellProperties();
}
else
{
return new CellProperties(this.Grid, this.xCoord + 1, this.yCoord, null, null, null, this);
}
}
public CellProperties setLeftCell( )
{
if (this.xCoord == 0)
{
return new CellProperties();
}
else
{
if (this.Grid == null)
{
return null;
}
if (this.yCoord == 0)
{
return this.leftParentCell;
}
else
{
CellProperties buffer = this.bottomCell;
for (int depth = 0; depth < this.yCoord - 1; depth++)
{
buffer = buffer.bottomParentCell;
}
buffer = buffer.leftParentCell.topCell;
for (int depth = 0; depth < this.yCoord - 1; depth++)
{
buffer = buffer.topCell;
}
buffer.rightCell = this;
return buffer;
}
}
}
public GridProperties getGrid()
{
return this.Grid;
}
public CellProperties getBottomCell()
{
return this.bottomCell;
}
public CellProperties getTopCell()
{
return this.topCell;
}
public CellProperties getLeftCell()
{
return this.leftCell;
}
public CellProperties getRightCell()
{
return this.rightCell;
}
public void setBottomWall(Boolean newBottomWall)
{
this.bottomWall = newBottomWall;
}
public void setTopWall(Boolean newTopWall)
{
this.topWall = newTopWall;
}
public void setLeftWall(Boolean newLeftWall)
{
this.leftWall = newLeftWall;
}
public void setRightWall(Boolean newRightWall)
{
this.rightWall = newRightWall;
}
public Boolean getBottomWall()
{
return this.bottomWall;
}
public Boolean getTopWall()
{
return this.topWall;
}
public Boolean getLeftWall()
{
return this.leftWall;
}
public Boolean getRightWall()
{
return this.rightWall;
}
public void updatePassageID(String newPassageID)
{
this.passageID.Add(newPassageID);
}
public void setPassageID(HashSet<String> newPassageID)
{
this.passageID = new HashSet<string>(newPassageID);
}
public HashSet<String> getPassageID()
{
return this.passageID;
}
}
This class is where the magic happens ... or suppose to happen.
public class KruskalMazeGenerator
{
private CellProperties Cell0x0;
private CellProperties CurrentCell;
private CellProperties NeighbourCell;
private int WallsDown;
private int TotalNumberOfCells;
private Random rnd = new Random();
private int rndXCoord, rndYCoord;
private String rndSide;
public KruskalMazeGenerator(CellProperties cell0x0)
{
Cell0x0 = cell0x0;
WallsDown = 0;
TotalNumberOfCells = Cell0x0.getGrid().getXLength() * Cell0x0.getGrid().getYLength();
}
public void selectRandomCellCoords()
{
this.rndXCoord = rnd.Next(0, this.Cell0x0.getGrid().getXLength());
this.rndYCoord = rnd.Next(0, this.Cell0x0.getGrid().getYLength());
}
public void selectRandomSide(String[] possibleSides)
{
if (possibleSides.Length != 0)
{
this.rndSide = possibleSides[rnd.Next(0, possibleSides.Length)];
}
}
public void selectRandomCurrentCell()
{
this.selectRandomCellCoords();
this.CurrentCell = this.Cell0x0;
for (int xWalk = 0; xWalk < this.rndXCoord; xWalk++)
{
this.CurrentCell = this.CurrentCell.getRightCell();
}
for (int xWalk = 0; xWalk < this.rndYCoord; xWalk++)
{
this.CurrentCell = this.CurrentCell.getTopCell();
}
}
public CellProperties checkWallBetweenCurrentAndNeighbour(List<String> possibleSides)
{
if (this.rndSide == "top")
{
if (this.CurrentCell.getTopCell() == null || this.CurrentCell.getTopCell().getGrid() == null)
{
possibleSides.Remove("top");
this.selectRandomSide(possibleSides.ToArray());
return this.checkWallBetweenCurrentAndNeighbour(possibleSides);
}
return this.CurrentCell.getTopCell();
}
else if (this.rndSide == "bottom")
{
if (this.CurrentCell.getBottomCell() == null || this.CurrentCell.getBottomCell().getGrid() == null)
{
possibleSides.Remove("bottom");
this.selectRandomSide(possibleSides.ToArray());
return this.checkWallBetweenCurrentAndNeighbour(possibleSides);
}
return this.CurrentCell.getBottomCell();
}
else if (this.rndSide == "left")
{
if (this.CurrentCell.getLeftCell() == null || this.CurrentCell.getLeftCell().getGrid() == null)
{
possibleSides.Remove("left");
this.selectRandomSide(possibleSides.ToArray());
return this.checkWallBetweenCurrentAndNeighbour(possibleSides);
}
return this.CurrentCell.getLeftCell();
}
else if (this.rndSide == "right")
{
if (this.CurrentCell.getRightCell() == null || this.CurrentCell.getRightCell().getGrid() == null)
{
possibleSides.Remove("right");
this.selectRandomSide(possibleSides.ToArray());
return this.checkWallBetweenCurrentAndNeighbour(possibleSides);
}
return this.CurrentCell.getRightCell();
}
return null;
}
public void selectRandomNeigbhourCell()
{
this.selectRandomSide(new String[4] { "top", "bottom", "left", "right" });
this.NeighbourCell = this.checkWallBetweenCurrentAndNeighbour(new List<String>(new String[4] { "top", "bottom", "left", "right" }));
}
public void checkForDifferentPassageID()
{
if (!this.CurrentCell.getPassageID().SetEquals(this.NeighbourCell.getPassageID()))
{
if (this.rndSide == "top")
{
this.CurrentCell.setTopWall(false);
this.NeighbourCell.setBottomWall(false);
this.unionAndResetPassageID();
this.WallsDown += 1;
}
else if (this.rndSide == "bottom")
{
this.CurrentCell.setBottomWall(false);
this.NeighbourCell.setTopWall(false);
this.unionAndResetPassageID();
this.WallsDown += 1;
}
else if (this.rndSide == "left")
{
this.CurrentCell.setLeftWall(false);
this.NeighbourCell.setRightWall(false);
this.unionAndResetPassageID();
this.WallsDown += 1;
}
else if (this.rndSide == "right")
{
this.CurrentCell.setRightWall(false);
this.NeighbourCell.setLeftWall(false);
this.unionAndResetPassageID();
this.WallsDown += 1;
}
}
}
public void unionAndResetPassageID()
{
HashSet<String> oldCurrentPassageID = new HashSet<String>(this.CurrentCell.getPassageID());
HashSet<String> oldNeighbourPassageID = new HashSet<String>(this.NeighbourCell.getPassageID());
HashSet <String> newPassageID = new HashSet<String>();
newPassageID = this.CurrentCell.getPassageID();
newPassageID.UnionWith(this.NeighbourCell.getPassageID());
CellProperties xwalkCell = new CellProperties();
CellProperties ywalkCell = new CellProperties();
for (int xWalk = 0; xWalk < this.Cell0x0.getGrid().getXLength(); xWalk++)
{
xwalkCell = xWalk == 0 ? this.Cell0x0 : xwalkCell.getRightCell();
for (int yWalk = 0; yWalk < this.Cell0x0.getGrid().getYLength(); yWalk++)
{
xwalkCell.setBottomWall(xWalk == 0 && yWalk == 0 ? false : xwalkCell.getBottomWall());
xwalkCell.setBottomWall(xWalk == this.Cell0x0.getGrid().getXLength() - 1 && yWalk == this.Cell0x0.getGrid().getYLength() - 1 ? false : xwalkCell.getBottomWall());
ywalkCell = yWalk == 0 ? xwalkCell : ywalkCell.getTopCell();
if (ywalkCell.getPassageID().SetEquals(oldCurrentPassageID) ||
ywalkCell.getPassageID().SetEquals(oldNeighbourPassageID))
{
ywalkCell.setPassageID(newPassageID);
}
}
}
}
public CellProperties createMaze()
{
while (this.WallsDown < this.TotalNumberOfCells - 1)
{
this.selectRandomCurrentCell();
this.selectRandomNeigbhourCell();
if (this.NeighbourCell != null)
{
this.checkForDifferentPassageID();
}
}
return this.Cell0x0;
}
}
then this is my visual representation class
public class drawGrid : CellProperties
{
private CellProperties Cell0x0 = new CellProperties();
private CellProperties yWalkBuffer = new CellProperties();
private CellProperties xWalkBuffer = new CellProperties();
private String bottomWall = "";
private String topWall = "";
private String leftAndrightWalls = "";
public drawGrid(CellProperties cell0x0)
{
Cell0x0 = cell0x0;
}
private void WallDrawingReset()
{
this.bottomWall = "\n";
this.topWall = "\n";
this.leftAndrightWalls = "\n";
}
private void Draw()
{
// draw bottom wall
{
if (this.bottomWall == "\n")
{
Console.Write("");
}
else
{
Console.Write(this.bottomWall);
}
}
Console.Write(this.leftAndrightWalls);
// draw top wall
{
if (topWall == "\n")
{
Console.Write("");
}
else
{
Console.Write(this.topWall);
}
}
}
public void yWalk()
{
for (int yWalk = 0; yWalk < this.Cell0x0.getGrid().getYLength(); yWalk++)
{
this.yWalkBuffer = yWalk == 0 ? this.Cell0x0 : this.yWalkBuffer.getTopCell();
this.WallDrawingReset();
this.xWalk(yWalk);
this.Draw();
}
}
private void xWalk(int yWalk)
{
for (int xWalk = 0; xWalk < this.Cell0x0.getGrid().getXLength(); xWalk++)
{
this.xWalkBuffer = xWalk == 0 ? this.yWalkBuffer : this.xWalkBuffer.getRightCell();
if (yWalk == 0)
{
this.bottomWall = xWalkBuffer.getBottomWall() ? this.bottomWall + "----" : this.bottomWall + " ";
this.topWall = xWalkBuffer.getTopWall() ? this.topWall + "----" : this.topWall + " ";
}
else
{
this.topWall = this.xWalkBuffer.getTopWall() ? this.topWall + "----" : this.topWall + " ";
}
if (xWalk == 0)
{
leftAndrightWalls = this.xWalkBuffer.getLeftWall() ? this.leftAndrightWalls + "| " : this.leftAndrightWalls + " ";
leftAndrightWalls = this.xWalkBuffer.getRightWall() ? this.leftAndrightWalls + "| " : this.leftAndrightWalls + " ";
}
else
{
leftAndrightWalls = this.xWalkBuffer.getRightWall() ? this.leftAndrightWalls + "| " : this.leftAndrightWalls + " ";
}
}
}
}
this is how i call them
class Program
{
static void Main(string[] args)
{
{
CellProperties cell = new CellProperties(new GridProperties(12, 11), 0, 0, null, null, null, null);
drawGrid draw = new drawGrid(cell);
draw.yWalk();
KruskalMazeGenerator kmaze = new KruskalMazeGenerator(cell);
cell = kmaze.createMaze();
Console.WriteLine("Final");
draw = new drawGrid(cell);
draw.yWalk();
}
Console.ReadKey();
}
}
Since I got you guys here, please don't mind pitching in what I can improve on as in coding style and other things that you are displeased with.
Thanks in advance.
Error seems to be here:
this.updatePassageID(this.xCoord.ToString() + this.yCoord.ToString());
Image those two scenarios:
xCoord = 1 and yCoord = 11.
xCoord = 11 and yCoord = 1.
both those result in newPassageID of 111.
So simply change the line to
this.updatePassageID(this.xCoord.ToString() + "|" + this.yCoord.ToString());
or written more sexy:
this.updatePassageID($"{xCoord}|{yCoord}");
With this you will receive
1|11 for the first scenario and 11|1 for the second which differs.
Edit based on comments:
I saw that your code is looping endlessly in the method createMaze. This method calls a method called checkForDifferentPassageID in there you check if two collections are equal or not. Once I saw that those collections are of type HashSet<string>, I thought that maybe your strings you put into the HashSet arent as unique as you think they are and there we go. So overall it took me like 10 minutes.

How can i enumerate methods inside this class?

When i check via debug, i can see the methods and variables but no matter what solution i have tried posted on stackoverflow failed
Here how i can see the methods with debug
Here the class
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public sealed partial class PlayerStats : pb::IMessage<PlayerStats>
{
/// <summary>Field number for the "level" field.</summary>
public const int LevelFieldNumber = 1;
/// <summary>Field number for the "experience" field.</summary>
public const int ExperienceFieldNumber = 2;
/// <summary>Field number for the "prev_level_xp" field.</summary>
public const int PrevLevelXpFieldNumber = 3;
/// <summary>Field number for the "next_level_xp" field.</summary>
public const int NextLevelXpFieldNumber = 4;
/// <summary>Field number for the "km_walked" field.</summary>
public const int KmWalkedFieldNumber = 5;
/// <summary>Field number for the "pokemons_encountered" field.</summary>
public const int PokemonsEncounteredFieldNumber = 6;
/// <summary>Field number for the "unique_pokedex_entries" field.</summary>
public const int UniquePokedexEntriesFieldNumber = 7;
/// <summary>Field number for the "pokemons_captured" field.</summary>
public const int PokemonsCapturedFieldNumber = 8;
/// <summary>Field number for the "evolutions" field.</summary>
public const int EvolutionsFieldNumber = 9;
/// <summary>Field number for the "poke_stop_visits" field.</summary>
public const int PokeStopVisitsFieldNumber = 10;
/// <summary>Field number for the "pokeballs_thrown" field.</summary>
public const int PokeballsThrownFieldNumber = 11;
/// <summary>Field number for the "eggs_hatched" field.</summary>
public const int EggsHatchedFieldNumber = 12;
/// <summary>Field number for the "big_magikarp_caught" field.</summary>
public const int BigMagikarpCaughtFieldNumber = 13;
/// <summary>Field number for the "battle_attack_won" field.</summary>
public const int BattleAttackWonFieldNumber = 14;
/// <summary>Field number for the "battle_attack_total" field.</summary>
public const int BattleAttackTotalFieldNumber = 15;
/// <summary>Field number for the "battle_defended_won" field.</summary>
public const int BattleDefendedWonFieldNumber = 16;
/// <summary>Field number for the "battle_training_won" field.</summary>
public const int BattleTrainingWonFieldNumber = 17;
/// <summary>Field number for the "battle_training_total" field.</summary>
public const int BattleTrainingTotalFieldNumber = 18;
/// <summary>Field number for the "prestige_raised_total" field.</summary>
public const int PrestigeRaisedTotalFieldNumber = 19;
/// <summary>Field number for the "prestige_dropped_total" field.</summary>
public const int PrestigeDroppedTotalFieldNumber = 20;
/// <summary>Field number for the "pokemon_deployed" field.</summary>
public const int PokemonDeployedFieldNumber = 21;
/// <summary>Field number for the "pokemon_caught_by_type" field.</summary>
public const int PokemonCaughtByTypeFieldNumber = 22;
/// <summary>Field number for the "small_rattata_caught" field.</summary>
public const int SmallRattataCaughtFieldNumber = 23;
private static readonly pb::MessageParser<PlayerStats> _parser =
new pb::MessageParser<PlayerStats>(() => new PlayerStats());
private int battleAttackTotal_;
private int battleAttackWon_;
private int battleDefendedWon_;
private int battleTrainingTotal_;
private int battleTrainingWon_;
private int bigMagikarpCaught_;
private int eggsHatched_;
private int evolutions_;
private long experience_;
private float kmWalked_;
private int level_;
private long nextLevelXp_;
private int pokeballsThrown_;
private pb::ByteString pokemonCaughtByType_ = pb::ByteString.Empty;
private int pokemonDeployed_;
private int pokemonsCaptured_;
private int pokemonsEncountered_;
private int pokeStopVisits_;
private int prestigeDroppedTotal_;
private int prestigeRaisedTotal_;
private long prevLevelXp_;
private int smallRattataCaught_;
private int uniquePokedexEntries_;
public PlayerStats()
{
OnConstruction();
}
public PlayerStats(PlayerStats other) : this()
{
level_ = other.level_;
experience_ = other.experience_;
prevLevelXp_ = other.prevLevelXp_;
nextLevelXp_ = other.nextLevelXp_;
kmWalked_ = other.kmWalked_;
pokemonsEncountered_ = other.pokemonsEncountered_;
uniquePokedexEntries_ = other.uniquePokedexEntries_;
pokemonsCaptured_ = other.pokemonsCaptured_;
evolutions_ = other.evolutions_;
pokeStopVisits_ = other.pokeStopVisits_;
pokeballsThrown_ = other.pokeballsThrown_;
eggsHatched_ = other.eggsHatched_;
bigMagikarpCaught_ = other.bigMagikarpCaught_;
battleAttackWon_ = other.battleAttackWon_;
battleAttackTotal_ = other.battleAttackTotal_;
battleDefendedWon_ = other.battleDefendedWon_;
battleTrainingWon_ = other.battleTrainingWon_;
battleTrainingTotal_ = other.battleTrainingTotal_;
prestigeRaisedTotal_ = other.prestigeRaisedTotal_;
prestigeDroppedTotal_ = other.prestigeDroppedTotal_;
pokemonDeployed_ = other.pokemonDeployed_;
pokemonCaughtByType_ = other.pokemonCaughtByType_;
smallRattataCaught_ = other.smallRattataCaught_;
}
public static pb::MessageParser<PlayerStats> Parser
{
get { return _parser; }
}
public static pbr::MessageDescriptor Descriptor
{
get { return global::PokemonGo.RocketAPI.GeneratedCode.PayloadsReflection.Descriptor.MessageTypes[14]; }
}
public int Level
{
get { return level_; }
set { level_ = value; }
}
public long Experience
{
get { return experience_; }
set { experience_ = value; }
}
public long PrevLevelXp
{
get { return prevLevelXp_; }
set { prevLevelXp_ = value; }
}
public long NextLevelXp
{
get { return nextLevelXp_; }
set { nextLevelXp_ = value; }
}
public float KmWalked
{
get { return kmWalked_; }
set { kmWalked_ = value; }
}
public int PokemonsEncountered
{
get { return pokemonsEncountered_; }
set { pokemonsEncountered_ = value; }
}
public int UniquePokedexEntries
{
get { return uniquePokedexEntries_; }
set { uniquePokedexEntries_ = value; }
}
public int PokemonsCaptured
{
get { return pokemonsCaptured_; }
set { pokemonsCaptured_ = value; }
}
public int Evolutions
{
get { return evolutions_; }
set { evolutions_ = value; }
}
public int PokeStopVisits
{
get { return pokeStopVisits_; }
set { pokeStopVisits_ = value; }
}
public int PokeballsThrown
{
get { return pokeballsThrown_; }
set { pokeballsThrown_ = value; }
}
public int EggsHatched
{
get { return eggsHatched_; }
set { eggsHatched_ = value; }
}
public int BigMagikarpCaught
{
get { return bigMagikarpCaught_; }
set { bigMagikarpCaught_ = value; }
}
public int BattleAttackWon
{
get { return battleAttackWon_; }
set { battleAttackWon_ = value; }
}
public int BattleAttackTotal
{
get { return battleAttackTotal_; }
set { battleAttackTotal_ = value; }
}
public int BattleDefendedWon
{
get { return battleDefendedWon_; }
set { battleDefendedWon_ = value; }
}
public int BattleTrainingWon
{
get { return battleTrainingWon_; }
set { battleTrainingWon_ = value; }
}
public int BattleTrainingTotal
{
get { return battleTrainingTotal_; }
set { battleTrainingTotal_ = value; }
}
public int PrestigeRaisedTotal
{
get { return prestigeRaisedTotal_; }
set { prestigeRaisedTotal_ = value; }
}
public int PrestigeDroppedTotal
{
get { return prestigeDroppedTotal_; }
set { prestigeDroppedTotal_ = value; }
}
public int PokemonDeployed
{
get { return pokemonDeployed_; }
set { pokemonDeployed_ = value; }
}
/// <summary>
/// TODO: repeated PokemonType ??
/// </summary>
public pb::ByteString PokemonCaughtByType
{
get { return pokemonCaughtByType_; }
set { pokemonCaughtByType_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); }
}
public int SmallRattataCaught
{
get { return smallRattataCaught_; }
set { smallRattataCaught_ = value; }
}
pbr::MessageDescriptor pb::IMessage.Descriptor
{
get { return Descriptor; }
}
public PlayerStats Clone()
{
return new PlayerStats(this);
}
public bool Equals(PlayerStats other)
{
if (ReferenceEquals(other, null))
{
return false;
}
if (ReferenceEquals(other, this))
{
return true;
}
if (Level != other.Level) return false;
if (Experience != other.Experience) return false;
if (PrevLevelXp != other.PrevLevelXp) return false;
if (NextLevelXp != other.NextLevelXp) return false;
if (KmWalked != other.KmWalked) return false;
if (PokemonsEncountered != other.PokemonsEncountered) return false;
if (UniquePokedexEntries != other.UniquePokedexEntries) return false;
if (PokemonsCaptured != other.PokemonsCaptured) return false;
if (Evolutions != other.Evolutions) return false;
if (PokeStopVisits != other.PokeStopVisits) return false;
if (PokeballsThrown != other.PokeballsThrown) return false;
if (EggsHatched != other.EggsHatched) return false;
if (BigMagikarpCaught != other.BigMagikarpCaught) return false;
if (BattleAttackWon != other.BattleAttackWon) return false;
if (BattleAttackTotal != other.BattleAttackTotal) return false;
if (BattleDefendedWon != other.BattleDefendedWon) return false;
if (BattleTrainingWon != other.BattleTrainingWon) return false;
if (BattleTrainingTotal != other.BattleTrainingTotal) return false;
if (PrestigeRaisedTotal != other.PrestigeRaisedTotal) return false;
if (PrestigeDroppedTotal != other.PrestigeDroppedTotal) return false;
if (PokemonDeployed != other.PokemonDeployed) return false;
if (PokemonCaughtByType != other.PokemonCaughtByType) return false;
if (SmallRattataCaught != other.SmallRattataCaught) return false;
return true;
}
public void WriteTo(pb::CodedOutputStream output)
{
if (Level != 0)
{
output.WriteRawTag(8);
output.WriteInt32(Level);
}
if (Experience != 0L)
{
output.WriteRawTag(16);
output.WriteInt64(Experience);
}
if (PrevLevelXp != 0L)
{
output.WriteRawTag(24);
output.WriteInt64(PrevLevelXp);
}
if (NextLevelXp != 0L)
{
output.WriteRawTag(32);
output.WriteInt64(NextLevelXp);
}
if (KmWalked != 0F)
{
output.WriteRawTag(45);
output.WriteFloat(KmWalked);
}
if (PokemonsEncountered != 0)
{
output.WriteRawTag(48);
output.WriteInt32(PokemonsEncountered);
}
if (UniquePokedexEntries != 0)
{
output.WriteRawTag(56);
output.WriteInt32(UniquePokedexEntries);
}
if (PokemonsCaptured != 0)
{
output.WriteRawTag(64);
output.WriteInt32(PokemonsCaptured);
}
if (Evolutions != 0)
{
output.WriteRawTag(72);
output.WriteInt32(Evolutions);
}
if (PokeStopVisits != 0)
{
output.WriteRawTag(80);
output.WriteInt32(PokeStopVisits);
}
if (PokeballsThrown != 0)
{
output.WriteRawTag(88);
output.WriteInt32(PokeballsThrown);
}
if (EggsHatched != 0)
{
output.WriteRawTag(96);
output.WriteInt32(EggsHatched);
}
if (BigMagikarpCaught != 0)
{
output.WriteRawTag(104);
output.WriteInt32(BigMagikarpCaught);
}
if (BattleAttackWon != 0)
{
output.WriteRawTag(112);
output.WriteInt32(BattleAttackWon);
}
if (BattleAttackTotal != 0)
{
output.WriteRawTag(120);
output.WriteInt32(BattleAttackTotal);
}
if (BattleDefendedWon != 0)
{
output.WriteRawTag(128, 1);
output.WriteInt32(BattleDefendedWon);
}
if (BattleTrainingWon != 0)
{
output.WriteRawTag(136, 1);
output.WriteInt32(BattleTrainingWon);
}
if (BattleTrainingTotal != 0)
{
output.WriteRawTag(144, 1);
output.WriteInt32(BattleTrainingTotal);
}
if (PrestigeRaisedTotal != 0)
{
output.WriteRawTag(152, 1);
output.WriteInt32(PrestigeRaisedTotal);
}
if (PrestigeDroppedTotal != 0)
{
output.WriteRawTag(160, 1);
output.WriteInt32(PrestigeDroppedTotal);
}
if (PokemonDeployed != 0)
{
output.WriteRawTag(168, 1);
output.WriteInt32(PokemonDeployed);
}
if (PokemonCaughtByType.Length != 0)
{
output.WriteRawTag(178, 1);
output.WriteBytes(PokemonCaughtByType);
}
if (SmallRattataCaught != 0)
{
output.WriteRawTag(184, 1);
output.WriteInt32(SmallRattataCaught);
}
}
public int CalculateSize()
{
var size = 0;
if (Level != 0)
{
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Level);
}
if (Experience != 0L)
{
size += 1 + pb::CodedOutputStream.ComputeInt64Size(Experience);
}
if (PrevLevelXp != 0L)
{
size += 1 + pb::CodedOutputStream.ComputeInt64Size(PrevLevelXp);
}
if (NextLevelXp != 0L)
{
size += 1 + pb::CodedOutputStream.ComputeInt64Size(NextLevelXp);
}
if (KmWalked != 0F)
{
size += 1 + 4;
}
if (PokemonsEncountered != 0)
{
size += 1 + pb::CodedOutputStream.ComputeInt32Size(PokemonsEncountered);
}
if (UniquePokedexEntries != 0)
{
size += 1 + pb::CodedOutputStream.ComputeInt32Size(UniquePokedexEntries);
}
if (PokemonsCaptured != 0)
{
size += 1 + pb::CodedOutputStream.ComputeInt32Size(PokemonsCaptured);
}
if (Evolutions != 0)
{
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Evolutions);
}
if (PokeStopVisits != 0)
{
size += 1 + pb::CodedOutputStream.ComputeInt32Size(PokeStopVisits);
}
if (PokeballsThrown != 0)
{
size += 1 + pb::CodedOutputStream.ComputeInt32Size(PokeballsThrown);
}
if (EggsHatched != 0)
{
size += 1 + pb::CodedOutputStream.ComputeInt32Size(EggsHatched);
}
if (BigMagikarpCaught != 0)
{
size += 1 + pb::CodedOutputStream.ComputeInt32Size(BigMagikarpCaught);
}
if (BattleAttackWon != 0)
{
size += 1 + pb::CodedOutputStream.ComputeInt32Size(BattleAttackWon);
}
if (BattleAttackTotal != 0)
{
size += 1 + pb::CodedOutputStream.ComputeInt32Size(BattleAttackTotal);
}
if (BattleDefendedWon != 0)
{
size += 2 + pb::CodedOutputStream.ComputeInt32Size(BattleDefendedWon);
}
if (BattleTrainingWon != 0)
{
size += 2 + pb::CodedOutputStream.ComputeInt32Size(BattleTrainingWon);
}
if (BattleTrainingTotal != 0)
{
size += 2 + pb::CodedOutputStream.ComputeInt32Size(BattleTrainingTotal);
}
if (PrestigeRaisedTotal != 0)
{
size += 2 + pb::CodedOutputStream.ComputeInt32Size(PrestigeRaisedTotal);
}
if (PrestigeDroppedTotal != 0)
{
size += 2 + pb::CodedOutputStream.ComputeInt32Size(PrestigeDroppedTotal);
}
if (PokemonDeployed != 0)
{
size += 2 + pb::CodedOutputStream.ComputeInt32Size(PokemonDeployed);
}
if (PokemonCaughtByType.Length != 0)
{
size += 2 + pb::CodedOutputStream.ComputeBytesSize(PokemonCaughtByType);
}
if (SmallRattataCaught != 0)
{
size += 2 + pb::CodedOutputStream.ComputeInt32Size(SmallRattataCaught);
}
return size;
}
public void MergeFrom(PlayerStats other)
{
if (other == null)
{
return;
}
if (other.Level != 0)
{
Level = other.Level;
}
if (other.Experience != 0L)
{
Experience = other.Experience;
}
if (other.PrevLevelXp != 0L)
{
PrevLevelXp = other.PrevLevelXp;
}
if (other.NextLevelXp != 0L)
{
NextLevelXp = other.NextLevelXp;
}
if (other.KmWalked != 0F)
{
KmWalked = other.KmWalked;
}
if (other.PokemonsEncountered != 0)
{
PokemonsEncountered = other.PokemonsEncountered;
}
if (other.UniquePokedexEntries != 0)
{
UniquePokedexEntries = other.UniquePokedexEntries;
}
if (other.PokemonsCaptured != 0)
{
PokemonsCaptured = other.PokemonsCaptured;
}
if (other.Evolutions != 0)
{
Evolutions = other.Evolutions;
}
if (other.PokeStopVisits != 0)
{
PokeStopVisits = other.PokeStopVisits;
}
if (other.PokeballsThrown != 0)
{
PokeballsThrown = other.PokeballsThrown;
}
if (other.EggsHatched != 0)
{
EggsHatched = other.EggsHatched;
}
if (other.BigMagikarpCaught != 0)
{
BigMagikarpCaught = other.BigMagikarpCaught;
}
if (other.BattleAttackWon != 0)
{
BattleAttackWon = other.BattleAttackWon;
}
if (other.BattleAttackTotal != 0)
{
BattleAttackTotal = other.BattleAttackTotal;
}
if (other.BattleDefendedWon != 0)
{
BattleDefendedWon = other.BattleDefendedWon;
}
if (other.BattleTrainingWon != 0)
{
BattleTrainingWon = other.BattleTrainingWon;
}
if (other.BattleTrainingTotal != 0)
{
BattleTrainingTotal = other.BattleTrainingTotal;
}
if (other.PrestigeRaisedTotal != 0)
{
PrestigeRaisedTotal = other.PrestigeRaisedTotal;
}
if (other.PrestigeDroppedTotal != 0)
{
PrestigeDroppedTotal = other.PrestigeDroppedTotal;
}
if (other.PokemonDeployed != 0)
{
PokemonDeployed = other.PokemonDeployed;
}
if (other.PokemonCaughtByType.Length != 0)
{
PokemonCaughtByType = other.PokemonCaughtByType;
}
if (other.SmallRattataCaught != 0)
{
SmallRattataCaught = other.SmallRattataCaught;
}
}
public void MergeFrom(pb::CodedInputStream input)
{
uint tag;
while ((tag = input.ReadTag()) != 0)
{
switch (tag)
{
default:
input.SkipLastField();
break;
case 8:
{
Level = input.ReadInt32();
break;
}
case 16:
{
Experience = input.ReadInt64();
break;
}
case 24:
{
PrevLevelXp = input.ReadInt64();
break;
}
case 32:
{
NextLevelXp = input.ReadInt64();
break;
}
case 45:
{
KmWalked = input.ReadFloat();
break;
}
case 48:
{
PokemonsEncountered = input.ReadInt32();
break;
}
case 56:
{
UniquePokedexEntries = input.ReadInt32();
break;
}
case 64:
{
PokemonsCaptured = input.ReadInt32();
break;
}
case 72:
{
Evolutions = input.ReadInt32();
break;
}
case 80:
{
PokeStopVisits = input.ReadInt32();
break;
}
case 88:
{
PokeballsThrown = input.ReadInt32();
break;
}
case 96:
{
EggsHatched = input.ReadInt32();
break;
}
case 104:
{
BigMagikarpCaught = input.ReadInt32();
break;
}
case 112:
{
BattleAttackWon = input.ReadInt32();
break;
}
case 120:
{
BattleAttackTotal = input.ReadInt32();
break;
}
case 128:
{
BattleDefendedWon = input.ReadInt32();
break;
}
case 136:
{
BattleTrainingWon = input.ReadInt32();
break;
}
case 144:
{
BattleTrainingTotal = input.ReadInt32();
break;
}
case 152:
{
PrestigeRaisedTotal = input.ReadInt32();
break;
}
case 160:
{
PrestigeDroppedTotal = input.ReadInt32();
break;
}
case 168:
{
PokemonDeployed = input.ReadInt32();
break;
}
case 178:
{
PokemonCaughtByType = input.ReadBytes();
break;
}
case 184:
{
SmallRattataCaught = input.ReadInt32();
break;
}
}
}
}
public override bool Equals(object other)
{
return Equals(other as PlayerStats);
}
public override int GetHashCode()
{
var hash = 1;
if (Level != 0) hash ^= Level.GetHashCode();
if (Experience != 0L) hash ^= Experience.GetHashCode();
if (PrevLevelXp != 0L) hash ^= PrevLevelXp.GetHashCode();
if (NextLevelXp != 0L) hash ^= NextLevelXp.GetHashCode();
if (KmWalked != 0F) hash ^= KmWalked.GetHashCode();
if (PokemonsEncountered != 0) hash ^= PokemonsEncountered.GetHashCode();
if (UniquePokedexEntries != 0) hash ^= UniquePokedexEntries.GetHashCode();
if (PokemonsCaptured != 0) hash ^= PokemonsCaptured.GetHashCode();
if (Evolutions != 0) hash ^= Evolutions.GetHashCode();
if (PokeStopVisits != 0) hash ^= PokeStopVisits.GetHashCode();
if (PokeballsThrown != 0) hash ^= PokeballsThrown.GetHashCode();
if (EggsHatched != 0) hash ^= EggsHatched.GetHashCode();
if (BigMagikarpCaught != 0) hash ^= BigMagikarpCaught.GetHashCode();
if (BattleAttackWon != 0) hash ^= BattleAttackWon.GetHashCode();
if (BattleAttackTotal != 0) hash ^= BattleAttackTotal.GetHashCode();
if (BattleDefendedWon != 0) hash ^= BattleDefendedWon.GetHashCode();
if (BattleTrainingWon != 0) hash ^= BattleTrainingWon.GetHashCode();
if (BattleTrainingTotal != 0) hash ^= BattleTrainingTotal.GetHashCode();
if (PrestigeRaisedTotal != 0) hash ^= PrestigeRaisedTotal.GetHashCode();
if (PrestigeDroppedTotal != 0) hash ^= PrestigeDroppedTotal.GetHashCode();
if (PokemonDeployed != 0) hash ^= PokemonDeployed.GetHashCode();
if (PokemonCaughtByType.Length != 0) hash ^= PokemonCaughtByType.GetHashCode();
if (SmallRattataCaught != 0) hash ^= SmallRattataCaught.GetHashCode();
return hash;
}
partial void OnConstruction();
public override string ToString()
{
return pb::JsonFormatter.ToDiagnosticString(this);
}
}
You can't see methods in the Auto and Locals View. Methods can have side effects when they get evaluated (properties are ought to have no side effects), so to prevent your application to end up corrupted it doesn't show them.
Only properties and fields are shown. You can call methods yourself in the Watch View.

How to only run methods when called?

I have a bunch of code below. However, I am hitting some bugs because the methods Move() and Genius() are running logic too much. I only want to two methods to run if they are being called by the submit click method. How can I do this?
namespace ShotgunApp
{
public partial class SingleGame : PhoneApplicationPage
{
public static class AmmoCount
{
public static int userAmmo = startVars.startAmmo;
public static int geniusAmmo = startVars.startAmmo;
}
public static class Global
{
public static int lives = 1;
public static string GeniusMove;
public static string UserMove;
}
public SingleGame()
{
InitializeComponent();
GeniusAmmo.Text = "ammo: " + AmmoCount.geniusAmmo;
UserAmmo.Text = "ammo: " + AmmoCount.userAmmo;
}
private void submit_Click(object sender, RoutedEventArgs e)
{
if (((String)submit.Content) == "Submit")
{
Move();
submit.Content = "Wait for Genius...";
uReload.IsEnabled = false;
uFire.IsEnabled = false;
uShield.IsEnabled = false;
Genius();
}
else if (((String)submit.Content) == "Go!")
{
GeniusSpeak.Text = "";
OutcomeDesc.Text = "You have " + Move() + " and Genius has " + Genius();
Outcome.Text = "ANOTHER ROUND...";
submit.Content = "Continue";
}
else if (((String)submit.Content) == "Continue")
{
uReload.IsEnabled = true;
uFire.IsEnabled = true;
uShield.IsEnabled = true;
OutcomeDesc.Text = "";
Outcome.Text = "";
submit.Content = "Submit";
}
}
public string Move()
{
if (uReload.IsChecked.HasValue && uReload.IsChecked.Value == true)
{
UserAmmo.Text = "ammo: " + ++AmmoCount.userAmmo;
Global.UserMove = "reloaded";
}
else if (uShield.IsChecked.HasValue && uShield.IsChecked.Value == true)
{
Global.UserMove = "shielded";
}
else if (uFire.IsChecked.HasValue && uFire.IsChecked.Value == true)
{
UserAmmo.Text = "ammo: " + --AmmoCount.userAmmo;
Global.UserMove = "fired";
}
else
{
submit.Content = "Enter a move!";
}
return Global.UserMove;
}
public string Genius()
{
GeniusSpeak.Text = "Genius has moved";
submit.Content = "Go!";
Random RandomNumber = new Random();
int x = RandomNumber.Next(0, 3);
if (x == 0)
{
Global.GeniusMove = "reloaded";
GeniusAmmo.Text = "ammo: " + ++AmmoCount.geniusAmmo;
}
else if (x == 1)
{
Global.GeniusMove = "shielded";
}
else if (x == 2)
{
Global.GeniusMove = "fired";
GeniusAmmo.Text = "ammo: " + ++AmmoCount.geniusAmmo;
}
return Global.GeniusMove;
}
}
}
Store the last results in data members:
private string lastMoveResult = string.Empty;
private string lastGeniusResult = string.Empty;
private void submit_Click(object sender, RoutedEventArgs e)
{
if (((String)submit.Content) == "Submit")
{
lastMoveResult = Move();
submit.Content = "Wait for Genius...";
uReload.IsEnabled = false;
uFire.IsEnabled = false;
uShield.IsEnabled = false;
lastGeniusResult = Genius();
}
else if (((String)submit.Content) == "Go!")
{
GeniusSpeak.Text = "";
OutcomeDesc.Text = "You have " + lastMoveResult + " and Genius has " + lastGeniusResult ;
Outcome.Text = "ANOTHER ROUND...";
submit.Content = "Continue";
}

Categories