Click here to Skip to main content
6,595,444 members and growing! (16,538 online)
Email Password   helpLost your password?
Languages » C# » Applications License: The Code Project Open License (CPOL)

Stopwatch and Rubik's Cube Shuffle Algorithm Generator

By pHysiX

A simple program that features a straight forward stopwatch, history and a Rubik's Cube Shuffle Algorithm Generator
C# (C# 1.0, C# 2.0, C# 3.0)
Posted:15 Feb 2008
Updated:15 Feb 2008
Views:15,542
Bookmarked:10 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
1 vote for this article.
Popularity: 0.00 Rating: 1.00 out of 5
1 vote, 100.0%
1

2

3

4

5

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

pHysiX


Member

Company: PHYSIX Coding Corp
Location: Australia Australia

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
Generalcode Pinmemberjskapur7:57 30 May '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 15 Feb 2008
Editor:
Copyright 2008 by pHysiX
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project