Example Code

Snake - Producer/Consumer Architecture

Code and Documents

Attachment

Download All


Summary:

I have recreated Snake in LabVIEW using event-based producer consumer architecture.  This is a fun example of the producer consumer architecture that uses user events to send messages from the consumer to the producer.  The consumer loop is structured using states and executes similar to how a state machine would.  I was able to take advantage of inlining sub VI’s, giving me the ability to really clean up my block diagram without taking a performance hit.  A custom menu was created to give the VI a nice finished feel while it’s running. This project also demonstrates the ability of a project to organize more than just your code.  I have included screenshots, project documentation, and VI Analyzer results all within the project file.

Function:

This VI recreates the classic Snake game as well as has a custom mode, Grow, to give the classic a new twist.  For instructions on game play simply go to Help -> Instructions while the main VI is running.

Steps to execute code:

1 Extract the zip file

2 Open the project file Snake.lvproj

3 Run Snake Main.vi

4 For game instructions see Help->Instructions while running Snake Main.vi

Screenshots:

Main Pause.jpgGrow Pause.jpgStart Level Menu.jpg

VI Snippet:

Snake Main.png

VI attached below

Herrlin

Just trying to spread the LabVIEW love.

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

Comments
jgcode
Active Participant
Active Participant
on

This is really cool - I used to love this game as a kid.

Certified LabVIEW Architect * LabVIEW Champion
Ben_Phillips
Member
Member
on

Really nice, I'm giving kudos.

Contributors