Example Code

LabVIEW Solitaire (v1.0)

Code and Documents

Attachment

Dear NI Community,

I stumbled across the deck of cards picture ring in LabVIEW a bit ago, and have been developing a classic solitaire game application .  While I do want to stress that this is still a bit of a work in progress (version 1.0), I wish to share this with the community as there is a lot of content ideas here.  Furthermore in case anyone can suggest better ways to develop the code into a completely bug free application to show how much LabVIEW rocks I am all ears.  I attached a zipped up copy of all my source code and project for people to browse (LabVIEW 2012).

LabVIEW Solitaire.png

I began by using the example code "Dynamically Register for Events", which puts the mouse cursor co-ordinates into the object co-ordinates using a property node, referenced to the object that the mouse was clicked down on.  When the mouse is released, the reference is closed.  I developed this so that depending on which card was selected I would pass a control reference and depending on the user action a type def enum into a queue from an event driven producer loop into a consumer loop using de-queue element.  Based on the user actions a card can be revealed or dragged and dropped onto a new location to play the classic card game Solitaire.

I made the front panel as aesthetically pleasing as a regular solitaire game with a custom icon and run time menu containing "New Game", "Exit" and "About" options which are called in the Menu Selection event of the producer loop.  If the user selects Exit, a command is passed into the queue to stop the consumer and display loops, but what is quite cool is at the end I have it so that if you are in deployment mode it quits LabVIEW, but not if you are in development mode .

From the project window I was also able to make an executable and installer to make the finished application seem just like a professional piece of custom software.  The installer contains the LabVIEW run time engine so you can burn it onto a disc and pass it to a computer that has no NI software installed and it will still work.

So if anyone has any ideas for how to make this better then I am all ears.  For example; at the moment I am struggling to find a way to reorder front panel objects in run mode i.e. I would like a property node `Bring to Front' so that the card selected goes over every other card not behind sometimes as is the case now .  Also I would like to build up a history of the stacked turned cards so that you can actually play the game!

But for now...

Enjoy the block diagram and I hope you find some of the design ideas useful


Robert Ward

Robert Ward
Applications Engineer, NI

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Marshall_B
NI Employee (retired)
on

An absolute gem of a program!

Marshall B
Applications Engineer
National Instruments UK & Ireland
Eden_S
NI Employee (retired)
on

Good start - I like the idea! I look forward to seeing how this develops

Eden S
Applications Engineer
National Instruments UK & Ireland
hicksc
NI Employee (retired)
on

Incandescent example!

Chris | Applications Engineer NIUK
Contributors