Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Controlled Random Integer?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
klutzedufus




PostPosted: 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.



box game.t
 Description:

Download
 Filename:  box game.t
 Filesize:  13.79 KB
 Downloaded:  129 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon May 16, 2011 5:24 pm   Post subject: RE:Controlled Random Integer?

Would "average rounded to the closest integer" work?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Raknarg




PostPosted: Mon May 16, 2011 5:34 pm   Post subject: RE:Controlled Random Integer?

You can use div 2 instead
klutzedufus




PostPosted: 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




PostPosted: 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.


box game.t
 Description:

Download
 Filename:  box game.t
 Filesize:  17.63 KB
 Downloaded:  134 Time(s)

Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: