Stopwatch and Rubik's Cube Shuffle Algorithm Generator
A simple program that features a straight forward stopwatch, history and a Rubik's Cube Shuffle Algorithm Generator
Cube AlgGen-Timer (approx 900kb) by pHysiX
Introduction
This is my first post @ CP and I hope many people will find this useful.
Background
I enjoy speedcubing and have repeatedly looked for a straight-forward stopwatch to no avail. Now, I hope to solve that problem with my own app.
Using the code
There are two main codes in this program; stopwatch and algorithm generator.
Below are the major bits of code:
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Diagnostics; using System.Drawing.Drawing2D; using System.Security.Cryptography; using System.IO; //Declare these things private AlgGenerator cgenAlg; private Stopwatch stopWatch; private Boolean captureLap; //These are functions for when you form is called public MainFrm() { stopWatch = new Stopwatch(); captureLap = false; InitializeComponent(); } private void timerMain_Tick(System.Object sender, System.EventArgs e) { // When the timer is running, update the displayed timer // value for each tick event. if (stopWatch.IsRunning) { // Get the elapsed time as a TimeSpan value. TimeSpan ts = stopWatch.Elapsed; // Format and display the TimeSpan value. labelTime.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); // If the user has just clicked the "Lap" button, // then capture the current time for the lap time. if (captureLap) { labelLap.Text = labelTime.Text; captureLap = false; } } } private void btnGenerate_Click(object sender, System.EventArgs e) { if (null != cgenAlg) { if ((null != this.exclude.Text) || (String.Empty != this.exclude.Text)) { cgenAlg.Exclusions = this.exclude.Text; } cgenAlg.Maximum = this.maxSize.Value; cgenAlg.ConsecutiveCharacters = this.consecutive.Checked; cgenAlg.RepeatCharacters = this.repeating.Checked; cgenAlg.ExcludeSymbols = this.excludeSymbols.Checked; genAlg.Text = cgenAlg.Generate(); } } //The history function can read the stopwatch time and record it to a text file private void buttonStartStop_Click(System.Object sender, System.EventArgs e) { if (stopWatch.IsRunning) using (StreamWriter sw = new StreamWriter("Cube History.txt", true)) { stopWatch.Stop(); buttonStartStop.Text = "Start"; buttonLapReset.Text = "Reset"; buttonLapReset.Visible = true; buttonStartStop.Enabled = false; sw.WriteLine(""); sw.WriteLine("==========================="); sw.WriteLine("PHYSIX Alg-Gen Cube Timer"); sw.WriteLine("Cubing Session:"); sw.WriteLine(DateTime.Now); sw.WriteLine(""); sw.WriteLine("Your recorded time:"); sw.WriteLine(labelTime.Text); sw.WriteLine(""); sw.WriteLine("Your shuffle algorithm:"); sw.WriteLine(genAlg.Text); sw.WriteLine("==========================="); } else { stopWatch.Start(); buttonStartStop.Text = "Stop"; buttonLapReset.Visible = false; button1.Enabled = false; button2.Enabled = false; button4.Enabled = false; labelLap.Visible = false; labelLapPrompt.Visible = false; groupBox1.Enabled = false; } }
Those are just some things that I believe that can help you with using file I/O, a stopwatch and random strings/character generation.
To do
I was more a HTML developer so my C/C# skills will be no where near the skill of those on CP. What I hope to do is add some better aesthetics and make a less buggy algorithm generator (people that understand the names of the Rubik's Cube faces will understand the bug). Feel free to post any suggestions and if you are interested, simply request the SRC code below and I will upload as soon as I am free.