05-02-2015 03:53 PM
Hi!
I am programming the Frozen game (available for Android) which is pretty much like Candy Crush Saga.
The program should swap two elements of an array selected by the player clicking on them.
My problem is that the program keeps on swapping the elements.
And I don't know how to change the numbers of the array to pictures (i.e. number 1 is a blue stone, 2 is a red one,...).
Please somebody help me!
Thanks in advance 🙂
05-02-2015 04:03 PM
I don't see where you are doing anything with your array at the end of a long series of array operations. You never use the output of the last Replace Array function.
Since you are doing something iteratively, you will need a shift register to take the array at the end of one set of manipulations and return it to the front of the loop for the next operations.
A game should probably be based on an event structure so something only happens when the player manipulates the front panel.
A picture ring is a good way to have different pictures associated with different values.
05-02-2015 04:28 PM - edited 05-02-2015 05:49 PM
Start with a few simple LabVIEW tutorial before starting such a project. (For example you might learn that "index array" is resizable.)
Then sit down and think about the code layout and design template that would be most approriate.
After glancing at your code for a few milliseconds, here are some of the glaring mistakes I noticed (I am sure there are many more...):
Your random number generator is flawed, because it does not produce an fair and even distribution. Edge elements only occur with half the probability of the other elements.
Why are there so many stop buttons?
You have a loop that does a gigantic amount of data manipulation based on exactly two local variables as fast as the computer allows. Except for filling a few meaningless indicators, most of the code gets stripped out by the compiler because it produces no output. So why is it there?
You have another small while loop that operates on the array based on the value of four local variables, repeating the same operation over and over, again as fast as the computer allows. If this calculation is important, it only needs to be done if one ot the inputs changes, and not over and over, millions of times per second. This code belongs in the event loop to execute when a mouse-down occurs and the code is in the correct state. It seems to swap two elements of a 2D array, this is much more easily done using the "in place element structure" and "" (or simply cross the wires).
Now let's have a look at the loop with the event structure:
Delete the timeout case since you don't use it.
You don't need a stacked shift register. Get the current value after the event structure and use a feeback node for the immediately previous value.
In the "mouse down" event you do some exceedingly convoluted calcuation based on the coordinates. For some ideas on how to do it better, have a look at my old 4x4 tic tac toe game posted here long ago. Your game is much simpler and I truly believe that your game could be written with code fitting on a postcard. Try it!
05-03-2015 01:14 AM - edited 05-03-2015 11:51 AM
@sdfxb wrote:
And I don't know how to change the numbers of the array to pictures (i.e. number 1 is a blue stone, 2 is a red one,...).
Just use a picture ring for the array elements.
To give you some ideas, here's a very simple draft (LabVIEW 2014) using color boxes. It just shows hows to swap elements with consecutive clicks arguably using significantly less code than your version :D.
Maybe you could use it as a starting point.
(of course you could omit the "cluster to array" functions and replace the "index array" with "unbundle", and replace the "clicked element" indicator with a cluster. The rest would stay the same).
01-23-2019 10:29 AM
Hi, I am new to labview and was interesting in making a puzzle type game for a new job I am going into. So in regards to the attached array, will anyone know how to change the array so you can only move the square to a box next to it rather being able to move a square to any position on the grid.
01-23-2019 11:03 AM
Is this part of something akin to a job interview?
01-23-2019 11:12 AM
The game is not directly linked to the job, its advised to look at some games and try learn the basics as it may be required. Just trying to learn my way around labview.
01-23-2019 12:29 PM
So you need to determine if it is a valid move. Let's say if the new position is 1 column away OR 1 row away, BUT not both. So an XOR (exclusive OR) would help.
Some boolean logic that drives a case structure that either makes the move or discards it.
01-23-2019 12:52 PM
where and how would you apply that to the array? sorry Im very new to this.
01-23-2019 01:04 PM
I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours