LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Frozen game

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 🙂

0 Kudos
Message 1 of 12
(5,000 Views)

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.

0 Kudos
Message 2 of 12
(4,991 Views)

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!

 

0 Kudos
Message 3 of 12
(4,982 Views)

@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).

Download All
0 Kudos
Message 4 of 12
(4,933 Views)

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. 

0 Kudos
Message 5 of 12
(3,858 Views)

Is this part of something akin to a job interview?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 12
(3,845 Views)

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.

0 Kudos
Message 7 of 12
(3,841 Views)

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.

0 Kudos
Message 8 of 12
(3,824 Views)

where and how would you apply that to the array? sorry Im very new to this.

0 Kudos
Message 9 of 12
(3,819 Views)

I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

0 Kudos
Message 10 of 12
(3,812 Views)