Jump to content

Simon Says Game written in State Machine Architecture


Recommended Posts

Don,

Attached is the Simple Simon game I showed at the LAVA User Group at NI Week. It employs 'Large Code Architecture' features to demonstrate how even a small application can be written with this structure.

I use what I call a "Mono-Cluster State Machine" where there is only one data shift register which passes a Type Def 'Mono-Cluster'. This allows all cases on the State Machine to have access to all the parameters. It also allows you to write very 'pretty' code in that you can resolve each case into one VI - passing the cluster in & out.

The code is pretty efficient:

1. The sound is generated in only state and is triggered via Queue communication between Simon and the User Console.

2. There is very little usage of local and NO Global variable usage.

Another great strenght of this architecture is you break funtions into logical blocks - making it easier to code (smaller tasks to work on).

>Easier to test - you can pass parameters into it's input cluster.

>Less likely to break other parts of the code when implementing changes- because you be working on a single peice of code not a VI buried in a huge loop.

I simply love the Queue-Driven State Machine. I had a 1 year software development project that near the end the client wanted to control in Visual Basic. We decided to link the code using TCP/IP. It took me about 2+ hours to modify the code to accepts commands and allow full control of the software via TCP/IP - because my architecture was already built on a String based command;argument structure. I dropped an addtional TCP/IP link & poll state in the code and handed him my command manual and voila!

PS: the Simple Simon game was written at the request of a potential client who wanted to see a sample of coding style. It took me about 3+ hours to write and I think it is a marvelous way to assess coding style.

Download File:post-12-1073108130.zip

Link to comment

Hi Jack:

The architecture looks very elegant and by virtue of the fact that you require action every 50 msec, you have shown a nice way to use the event structure while still polling as well as using the event structure just to handle user interface events.

With the event structure in LV7 and user events, a number of other possibilties for architectures become available. I was able to add my NI_week slides by zipping up the file rather than sending as .llb in case anyone wants to see how I used the event structure with user events to create a nested tab control example using only the event structure and with no polling.

Also, FYI, your .llb did not contain the .wav files so actually playing the game was a little difficult (kept asking to find the sounds directory).

Sincerely,

Don

Link to comment
  • 3 months later...
  • 4 weeks later...
With the event structure in LV7 and user events, a number of other possibilties for architectures become available.  I was able to add my NI_week slides by zipping up the file rather than sending as .llb in case anyone wants to see how I used the event structure with user events to create a nested tab control example using only the event structure and with no polling.

Don,

Could you re-post the attachment called "NI week interface slides lv7.zip"?

While upgrading the forums I discovered that this file was not uploaded properly and was in fact blank! :(

Link to comment

Will do but I am out on leave and will get to this at the end of the week....

I remember having problems posting it and had to do it several times; I thought the last time it showed up properly. If I can't get it to post properly, I will just email it to you and let you do it.

Sincerely,

Don

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.