Skip to content

Commit

Permalink
Code clean-up and auto-properties
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurits committed Apr 3, 2022
1 parent f7c0374 commit 7f0c887
Show file tree
Hide file tree
Showing 17 changed files with 378 additions and 545 deletions.
4 changes: 2 additions & 2 deletions Simon says.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Global
{5C30595C-50CF-4F2E-8752-AED30F3ADD0C}.Debug|x64.Build.0 = Debug|Any CPU
{5C30595C-50CF-4F2E-8752-AED30F3ADD0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5C30595C-50CF-4F2E-8752-AED30F3ADD0C}.Release|Any CPU.Build.0 = Release|Any CPU
{5C30595C-50CF-4F2E-8752-AED30F3ADD0C}.Release|x64.ActiveCfg = Release|x64
{5C30595C-50CF-4F2E-8752-AED30F3ADD0C}.Release|x64.Build.0 = Release|x64
{5C30595C-50CF-4F2E-8752-AED30F3ADD0C}.Release|x64.ActiveCfg = Release|Any CPU
{5C30595C-50CF-4F2E-8752-AED30F3ADD0C}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 2 additions & 4 deletions Simon says/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ public static class ExtensionMethods
/// <param name="key">Key we are looking for</param>
/// <param name="defaultValue">Default value to return when the TKey is not found in the dictionary</param>
/// <returns></returns>
public static TValue GetOrDefault<TKey, TValue>(this System.Collections.Generic.Dictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue = default(TValue))
public static TValue GetOrDefault<TKey, TValue>(this System.Collections.Generic.Dictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue = default)
{

if(dictionary.TryGetValue(key, out var value))
{
return value;
}

return defaultValue;
/*
if (dictionary != null && dictionary.ContainsKey(key))
Expand Down
16 changes: 8 additions & 8 deletions Simon says/InitializationRoutines.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SimonSays;

partial class frmSimon
partial class FrmSimon
{
/// <summary>
/// Initialize the ToolStripPanel component: add the child components to it
Expand All @@ -27,13 +27,13 @@ private void InitializeToolStrip()

toolStripMain.Renderer = new customRenderer(Brushes.SteelBlue, Brushes.LightSkyBlue);

if (File.Exists(_path + @"\images\exit.ico")) this.toolStripMain_Exit.Image = new Icon(_path + @"\images\exit.ico", 48, 48).ToBitmap();
if (File.Exists(_path + @"\images\start.ico")) this.toolStripMain_Start.Image = new Icon(_path + @"\images\start.ico", 48, 48).ToBitmap();
if (File.Exists(_path + @"\images\stop.ico")) this.toolStripMain_Stop.Image = new Icon(_path + @"\images\stop.ico", 48, 48).ToBitmap();
if (File.Exists(_path + @"\images\soundoff.ico")) this.toolStripMain_Sound.Image = new Icon(_path + @"\images\soundoff.ico", 48, 48).ToBitmap();
if (File.Exists(_path + @"\images\graph.ico")) this.toolStripMain_Stats.Image = new Icon(_path + @"\images\graph.ico", 48, 48).ToBitmap();
if (File.Exists(_path + @"\images\settings.ico")) this.toolStripMain_Settings.Image = new Icon(_path + @"\images\settings.ico", 48, 48).ToBitmap();
if (File.Exists(_path + @"\images\about.ico")) this.toolStripMain_About.Image = new Icon(_path + @"\images\about.ico", 48, 48).ToBitmap();
if (File.Exists(_settings.AppPath + @"\images\exit.ico")) this.toolStripMain_Exit.Image = new Icon(_settings.AppPath + @"\images\exit.ico", 48, 48).ToBitmap();
if (File.Exists(_settings.AppPath + @"\images\start.ico")) this.toolStripMain_Start.Image = new Icon(_settings.AppPath + @"\images\start.ico", 48, 48).ToBitmap();
if (File.Exists(_settings.AppPath + @"\images\stop.ico")) this.toolStripMain_Stop.Image = new Icon(_settings.AppPath + @"\images\stop.ico", 48, 48).ToBitmap();
if (File.Exists(_settings.AppPath + @"\images\soundoff.ico")) this.toolStripMain_Sound.Image = new Icon(_settings.AppPath + @"\images\soundoff.ico", 48, 48).ToBitmap();
if (File.Exists(_settings.AppPath + @"\images\graph.ico")) this.toolStripMain_Stats.Image = new Icon(_settings.AppPath + @"\images\graph.ico", 48, 48).ToBitmap();
if (File.Exists(_settings.AppPath + @"\images\settings.ico")) this.toolStripMain_Settings.Image = new Icon(_settings.AppPath + @"\images\settings.ico", 48, 48).ToBitmap();
if (File.Exists(_settings.AppPath + @"\images\about.ico")) this.toolStripMain_About.Image = new Icon(_settings.AppPath + @"\images\about.ico", 48, 48).ToBitmap();

}

Expand Down
4 changes: 1 addition & 3 deletions Simon says/JsonSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace SimonSays;

partial class frmSimon
partial class FrmSimon
{
/// <summary>
/// Loads all settings from file _sett.FileName into class instance _settings
Expand All @@ -19,8 +19,6 @@ private void LoadProgramSettingsJSON()
{
var jsonString = File.ReadAllText(_settings.FileName);
_settings = JsonSerializer.Deserialize<ClassSettings>(jsonString) ?? _settings;

ApplySettingsJSON(_settings.WindowPosition);
}
catch (FileNotFoundException)
{
Expand Down
16 changes: 8 additions & 8 deletions Simon says/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 18 additions & 25 deletions Simon says/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

namespace SimonSays;

public partial class frmSimon : Form
public partial class FrmSimon : Form
{
private SimonGame _Game = new();
private readonly SimonGame _Game = new();
private ClassSettings _settings = new();

private readonly System.Resources.ResourceManager StringsRM = new("SimonSays.localization.strings", typeof(frmSimon).Assembly);
private readonly System.Resources.ResourceManager StringsRM = new("SimonSays.localization.strings", typeof(FrmSimon).Assembly);

public frmSimon()
public FrmSimon()
{
// Set form icon
if (System.IO.File.Exists(_settings.AppPath + @"\images\simon.ico")) this.Icon = new Icon(_settings.AppPath + @"\images\simon.ico");
Expand All @@ -33,10 +33,9 @@ public frmSimon()

// Load and apply the program settings
LoadProgramSettingsJSON();

ApplySettingsJSON(_settings.WindowPosition);
}

#region Events subscription
/// <summary>
/// Consumes the Tick event of the Game class
/// </summary>
Expand Down Expand Up @@ -79,11 +78,9 @@ private void OnCorrectSequence(object sender, CorrectEventArgs e)
//MessageBox.Show("Well done!\nTotal score: " + e.Score.ToString());
this.simonBoard.ScoreTotal = _Game.ScoreTotal;
this.simonBoard.ScoreHighest = _Game.ScoreHighest;

if ((this._Game.GameMode & SimonGame.PlayMode.SimonBounce)==SimonGame.PlayMode.SimonBounce)
{

if ((this._Game.GameMode & SimonGame.PlayMode.SimonBounce) == SimonGame.PlayMode.SimonBounce)
this.simonBoard.RandomizeButtons();
}

/*
foreach (ColorButton.SimonButton button in simonBoard.Controls.OfType<ColorButton.SimonButton>())
Expand All @@ -95,20 +92,19 @@ private void OnCorrectSequence(object sender, CorrectEventArgs e)

private void OnGameOver(object sender, OverEventArgs e)
{
MessageBox.Show("Your total score is: " + e.Score.ToString(),"Game over");
using (new CenterWinDialog(this))
{
MessageBox.Show(this, "Your total score is: " + e.Score.ToString(), "Game over");
}
this.simonBoard.ScoreTotal = 0;
}

#endregion Events subscription

#region Form events

private void frmSimon_Load(object sender, EventArgs e)
private void FrmSimon_Load(object sender, EventArgs e)
{
Win32.Win32API.AnimateWindow(this.Handle, 500, Win32.Win32API.AnimateWindowFlags.AW_BLEND);
}

private void frmSimon_FormClosing(object sender, FormClosingEventArgs e)
private void FrmSimon_FormClosing(object sender, FormClosingEventArgs e)
{
using (new CenterWinDialog(this))
{
Expand All @@ -130,14 +126,14 @@ private void frmSimon_FormClosing(object sender, FormClosingEventArgs e)
SaveProgramSettingsJSON();
}

private void frmSimon_Shown(object sender, EventArgs e)
private void FrmSimon_Shown(object sender, EventArgs e)
{
// Send Close event to the splash screen
using var closeSplashEvent = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset, "CloseSplashScreenEvent");
closeSplashEvent.Set();
}

private void frmSimon_Resize(object sender, EventArgs e)
private void FrmSimon_Resize(object sender, EventArgs e)
{
// Force the client area to be painted again
//Invalidate();
Expand All @@ -147,16 +143,13 @@ private void frmSimon_Resize(object sender, EventArgs e)
//this.btnGreen.Width = 400;
}

private void frmSimon_ResizeBegin(object sender, EventArgs e)
private void FrmSimon_ResizeBegin(object sender, EventArgs e)
{
this.SuspendLayout();
}

private void frmSimon_ResizeEnd(object sender, EventArgs e)
private void FrmSimon_ResizeEnd(object sender, EventArgs e)
{
this.ResumeLayout();
}

#endregion Form events

}
}
2 changes: 1 addition & 1 deletion Simon says/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmSimon());
Application.Run(new FrmSimon());
}
}
}
4 changes: 3 additions & 1 deletion Simon says/Simon says.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
<Content Include="images\settings.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="images\simon splash.png" />
<Content Include="images\simon splash.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="images\simon.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
Loading

0 comments on commit 7f0c887

Please sign in to comment.