Controlled Random Integer?
Author |
Message |
klutzedufus
|
Posted: Mon May 16, 2011 5:19 pm Post subject: Controlled Random Integer? |
|
|
I'm making a game just for fun where you control a small box and need to push a bigger box into the goal. I know I still need to make a menu, but that shouldn't be too hard.
The problem, however, is that the goal box spawns based on random integers, and sometimes spawns on top of the box that you need to get into the goal. So when you start the game, the score could already be 7 to 0.
I've tried taking the average of the two big boxes, but it needs to be an integer and can't be divided by 2.
I'm using Turing version 4.1.1.
Description: |
|
Download |
Filename: |
box game.t |
Filesize: |
13.79 KB |
Downloaded: |
129 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Mon May 16, 2011 5:24 pm Post subject: RE:Controlled Random Integer? |
|
|
Would "average rounded to the closest integer" work?
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Raknarg
|
Posted: Mon May 16, 2011 5:34 pm Post subject: RE:Controlled Random Integer? |
|
|
You can use div 2 instead
|
|
|
|
|
|
klutzedufus
|
Posted: Mon May 16, 2011 8:06 pm Post subject: RE:Controlled Random Integer? |
|
|
I found a way to make it work, but it may take a while to write in code.
I could use if statements to check the positions (in quadrants) of the boxes, and the goal will spawn in another spot. Visualize this by imagining the game board as divided into quadrants: if both the red and blue squares are in the top right quadrant, the goal can spawn in the top left, bottom left, or bottom right.
I'll finish it later, if it works I'll post the code so you can see how I worked it out. Otherwise, I'll post the code so you can help me.
|
|
|
|
|
|
klutzedufus
|
Posted: Tue May 17, 2011 4:19 pm Post subject: Re: Controlled Random Integer? |
|
|
It seems to have worked, but it took a long time to write out. There are a total of 16 possible positions of the two boxes in the four quadrants, so I had to type out 16 if statements.
Description: |
|
Download |
Filename: |
box game.t |
Filesize: |
17.63 KB |
Downloaded: |
134 Time(s) |
|
|
|
|
|
|
|
|