Wednesday, January 31, 2018

Rubik cube game - 3- C Sharp

Rubik's cube game in C#
(Computer game for solving Rubik's cube puzzle)
(Written by me in c# 2010)
.
On last year's (2017) birthday of my niece,  one of my nephew,  gave her 2 gifts. One was a good looking Barbie doll and another was colorful Rubik's cube. While my niece preferred Barbie doll more, I started to analyze Rubik's cube to get some idea how to play with it, to make me able to teach my niece how to play with it. After making some un-successful tries I started searching Internet for tutorials about playing Rubik's cube.
And during searching and researching about Rubik's cube I got an usual idea. Idea was to make softwares for (1) playing Rubik's cube game (2) finding shortest solution for any given pattern of Rubik's cube. So I started making plans for these softwares and then started coding and in some days made them.
During coding of rotations of Rubik's cube I was getting disoriented again and again. So to solve that problem I made a small cube of hard paper. Made 3x3 boxes on it's each side with pencil and numbered them like 2d matrix. Then during coding I used it for reference. Before using this technique I was having difficult time in finding the bug in cube side/face rotation methods.
.
Salient features of Rubik's cube game:
All 6 sides of Rubik's cube are displayed side by side with their side name above them. Side rotating buttons are also above each side on left and right of side name. Game can be played in two modes: manual or auto. In manual human plays and in auto computer plays random moves.
.
Screen shots of game and their description:
Following are screen shots of Rubik's cube solving game at different stages with their description.
.
Game on Load:
Game looks like in the following image when it loads. Menus are on top line and status is at bottom line. Area in between them is divided in 3 columns.  In left column under 'Cube sides' heading are 6 colorful squares of 3x3 sub-squares. They are sides/faces of cube with their respective color. Each side's name is displayed above them. On left and right of each side name are buttons for rotating respective side. Left button for rotating  side clockwise and Right button for rotating side counter-clockwise. In center column Moves log and game controlling controls are displayed. In right column rotation buttons are explained.
.
.

.
Help menu expanded:
Game looks like in the following image when help menu is clicked. Showing it's 5 options: About, Purpose, User interface, How to use and Copyright. Each option of help menu is shown and explained in following.
.
.

.
Help/About:
Game looks like in the following image when 'About' in 'Help' menu is clicked. This menu-item displays basic information about game and it's author.
.
.

.
Help/Purpose:
Game looks like in the following image when 'Purpose' in 'Help' menu is clicked. This menu-item display text explaining purpose of the game.
.
.

.
Help/User interface:
Game looks like in the following image when 'User interface' in 'Help' menu is clicked. This menu option explains game's user interface as visible in following image.
.
.

.
Help/How to use:
Game looks like in the following image when 'How to use' in 'Help' menu is clicked. This menu option explains how to use this game application as visible in following image.
.
.

.
Help/Copyright:
Game looks like in the following image when 'Copyright' in 'Help' menu is clicked. This menu-item displays copyright text for this game application.
.
.

.
'New Game' button clicked
Game looks like in the following image when 'New Game' button in center column under 'Game' section is clicked. This button begins game starting process.
.
.

.
Play mode
Under 'New game' button are two radiobuttons called 'Manual' and 'Auto'. They are enabled only during after 'New game' button is clicked and before 'Start' button is clicked. They allow either human or computer to play the game. Select 'Manual' for human to play or select  'Auto' for computer to play. Computer only makes random moves so chances of computer solving the game is between in minimum moves possible to never.
.

.
'Shuffle colors' buttons
'Shuffle colors' button is also enabled only during after 'New game' button is clicked and before 'Start' button is clicked. Use this button for shuffling Rubik's cube.
.

.
'Start' button clicked (Manual mode):
Game looks like in the following image when 'Start' button in center column under 'Game' section is clicked in manual mode. Only Rubik's cube patterns may be different. I used Rubik's cube patterns in following image in an online Rubik's cube solver to test my game and my game worked correctly.
..
.

.
Some moves are made (Manual mode):
Game looks like in the following image when game is started in manual mode and some moves made.  This image is not sequence of above image. Only Rubik's cube patterns may be different.
.
.

.
'New Game' clicked during running game 'Manual':
Game looks like in the following image when 'New Game' button in center column under 'Game' section is clicked in 'Manual' mode while a game is already running. This option is useful for aborting an running game. This option gives options for actually aborting game or continue with the running game.
.
.

.
'Start' button clicked (Auto mode):
Game looks like in the following image when 'Start' button in center column under 'Game' section is clicked in 'Auto' mode and some moves are made.
.
.

.
'New Game' clicked during running game 'Auto':
Game looks like in the following image when 'New Game' button in center column under 'Game' section is clicked in 'Auto' mode while a game is already running. This option is useful for aborting an running game. This option gives options for actually aborting game or continue with the running game.
.
.

Game completed 'Manual':
Game looks like in the following image when it is completed/solved while game is in 'Manual' mode. Meaning all side/face square's are arranged in the same color as in the respective center square. When this happens game displays an alert message and a message in status bar to congratulate the player. This result was achieved by using generated moves from an online Rubik's cube solver site where I used starting patterns as mentioned above in "'Start' button clicked (Manual mode)"section. And felt happy on finding that my game was working correctly.
.
..

.
After a completed game:
Game looks like in the following image when it is completed/solved and 'Congratulating' alert message is also closed. Now game is ready for player to start New game.
.
.

.
I decided to display all 6 sides/faces of Rubik's cube side by side instead of displaying it as a rotate-able cube because 'side by side' way looks better and easy to understand to me.
.
Enjoy Complete Source code of application written and compiled in visual studio 2010 Ultimate by me. Download it. Extract it. Read 'ReadMeFirst.txt' file and do as is explained in it.



No comments:

Post a Comment