Creating an Object Oriented Snake Game in LabVIEW

preview_player
Показать описание
Purchasing the course using this link is the best way to learn LabVIEW and support the channel.

In this video, I go through creating the classic Snake game in LabVIEW using object-oriented programming.

#LabVIEW #ObjectOrientedProgramming #OOP #SoftwareDesign
Рекомендации по теме
Комментарии
Автор

Thank you Tom! I am learning to code like a professional! Realy appreciate it.

MortezaVafadar
Автор

This has become my favorite channel. Thank you Tom!

panda
Автор

Tom, this is a really great tutorial. I learned a lot! Next I would love to learn more about class method Access Scope. All methods in this example are public. When and why would you use private and protected scope?

I made some notes while working through the example:

1. I noticed that the key down event as written will always indicate up (the default case) for any other key pressed. I changed this to have a default case for all other key presses, and only send the queue element (or set the global direction value) for the appropriate keys.

2. I appreciate the divide by two bit-shift trick for placing the snake on the board, but I feel like this obscures the basic math. To me this seems most appropriate for situations where performance must be optimized. I made the code a little cleaner by doing the divide (and other math steps) on the grid-size cluster before breaking out the x and y elements.

3. In the tail strike code you can also search the tail array for the new head position using Search 1-D array. This may make the logic easier to follow.

4. I didn't like the way "make tail longer" worked, as the length only increases once the tail passes all the way through where the fruit was. A more immediate approach is to reinstate the deleted portion of the tail when the fruit is captured. To do this I added a "Deleted Portion Coordinate" to the Snake class. When a fruit is caught, I append this to the tail array, and recolor the pixel. The other possibility is to detect the fruit capture before redrawing the snake, and then not removing the last element of the snake array.

5. To answer your challenge question, I made an adjustment to the Move Forward VI to allow the snake to cross from one edge of the board to the other. When moving right or down, you can use the quotient and remainder function to get the offset of the head coordinate from (grid size - 1). But when moving left or up, I found the easiest way to handle the math is to allow the head coordinate to become negative (requires changing the coordinate type definition to I32), in which case the corresponding negative value is replaced by (grid size -1). You have to handle the X coordinate when moving up and down, and the y coordinate when moving left and right. Is there an easier way?

The board failure routine remains unchanged.

It would be nice to include this as an option in the game setup. You could also color the edge of the board to indicate if it can be crossed or not.

6. I added a separate head color to the snake, which I think makes it easier to understand the snake's movements. The required a new head color class element and updating three pixels instead of two when moving the snake. Fun!

7. For the snake direction detection, I replaced your single element queue with the native global variable, which makes the code much cleaner, and is functionally identical. It occurred to me that the way we read the direction from the UI should not be a part of the class method, so I moved this out of the Read Direction VI and renamed this "Set Direction".

drwagner
Автор

Tom you were incredible 💯💯
Absolutely genius in LabVIEW❤️

santhoshkumar
Автор

a video on unit testing would be awesome.

aliasad
Автор

Thank you for this Tom, it is the first time for me to see the use of lossy enqueue and queue preview, they are quite useful to learn.

mlfbsbnmfirnbdml
Автор

Nice tutorial! I've implemented a snake game as an Easter egg in one of my programs. I will definitely replace it with this and expand the features. Thanks!

yvindmagnussen
Автор

Hi Tom, thanks for such an informative tutorial. As u mentioned I'm looking forward with unit test framework.

sankarmuthu
Автор

Hey Tom, I had a couple questions about editing the code you wrote to use a different form of input to move the snake. If you could reply with any help that would be much appreciated.

MichaelStiffler-dueb
Автор

You could sell your courses on Udemy. I was recommended your course by our Technical Director. Very good, please make more!

TheWildCamper
Автор

Really nice video. Do you have any videos of the same with manual creation of classes and methods(instead of using the oop tool)?

joejoe-qyhl
Автор

Recently stumbled across your channel . Great work :) . Wish I had the chance to make it to Munich this year to meet you.

shrinivasprabhurm
Автор

Thank you Tom for another great video! Could you do a tutorial on MAL in the context of AF for distributed systems?

gramsvn
Автор

Such a nice video, keep going with the great work!

osxdjr
Автор

what are the chances that the day I search for oop examples in labview our boy makes a dope ass video?

yayilovesquares
Автор

Thanks for the video! No matter what I try, I'm unable to get the UML modeller to generate the full code. The most luck I've had is when I remove the type def and the enum. Any suggestions you can give would be appreciated.

tonyspies
Автор

Great video! Very helpful in my efforts to learn OO LabView.

Why do you have two separate loops in Main? Why not put all the code of the top loop into the Timeout case of your Event Loop (with the appropriate check for elapsed time)? Then the current direction could go into a shift register and the Queue would not be necessary?

davidferster
Автор

how to control the snake? I can't

hahuyetannhien
Автор

You deserve a professional microphone for recording, please!

MortezaVafadar
Автор

27:24 Shouldn't it be "Add Fruit Object" instead of "Add Fruit Class"?

MortezaVafadar