473,324 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Draw item to random x,y position

254 100+
i have to design a simple game.
I asked some question before in this forum.
Now the game version is the new version with more items in it.

now, i have a 11 items to draw, '$'.
and i have a function in a header file called utils.h, GetRandom() function.
code:
Expand|Select|Wrap|Line Numbers
  1. inline unsigned GetRandom(unsigned min, unsigned max) {
  2.         return rand() % (max - min + 1) + min;
  3.     }
  4.  
i have to draw that 11 items(which is the same character '$' ) randomly to the screen(specified width and height, which is 25wdth, 11 in height) using that function above.

What my examiner said :
suppose you have decided to have 11 powerups. Where are you
going to put them? So you'll neeed to use GetRandom at least 22 times to
get random x and y positions. The min and max will depend on the size of
the screen that you'll have.
I have no idea what it means by min & max argument in GetRandom() function will depend on the size of the screen.
So, what should i put in for the min & max argument? 11 and 25 (the height and width) ?

Please could someone show the example ? because i can't figure it out.
What i have tried (which is failed ) :
Expand|Select|Wrap|Line Numbers
  1.      unsigned xPos;
  2.      unsigned yPos;
  3.  
  4.      for(unsigned i = 0; i <= max; i++) {
  5.       xPos = GetRandom(1, 275);
  6.           yPos = GetRandom(1, 275);
  7.                 screen->Insert(xPos, yPos, '$');   // draw 11 of $ into screen
  8.      }
  9.  
Jan 2 '07 #1
1 4247
Banfa
9,065 Expert Mod 8TB
I have no idea what it means by min & max argument in GetRandom() function will depend on the size of the screen.
So, what should i put in for the min & max argument? 11 and 25 (the height and width) ?

Please could someone show the example ? because i can't figure it out.
What i have tried (which is failed )
When it says screeen size it is not talking about the physical dimensions of you monitor (19" for instance) but the resolution of you display. For instance at a resolution of 800x600 then the max x would be 800 but at 1024x768 the max x would be 1024. Also it is likely that yougame screen will be smaller then the actual available space and that there may be margins hence the need to a minimum too.


You example at the end is unlike to be correct because it is unlikely (but not impossible) that the game screen is square.
Jan 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Paul C-T | last post by:
Hi, Is there a way to repeat a set of code until a certain if statement is satisfied. If it is then to exit the loop and if not repeat the code? Say I want to write a card game application in...
7
by: Bob Smith | last post by:
Hi, I have a Python list. I can't figure out how to find an element's numeric value (0,1,2,3...) in the list. Here's an example of what I'm doing: for bar in bars: if 'str_1' in bar and...
2
by: Joachim Bauer | last post by:
I'm using the code below to display a menu that opens when the mouse goes over the main menu item (try it in your browser to understand the behaviour). It uses "position:absolute" and a switch...
13
by: quickcur | last post by:
Suppose I have a function rand() that can generate one integer random number between 0 and 100. Suppose also rand() is very expensive. What is the fastest way to generate 10 different random number...
7
by: Devron Blatchford | last post by:
Hi there, I have created an owner draw menu item using DrawItem and MeasureItem in VB.NET. This seems to work well. I was wondering how I can do mouse over effects in these menus. Basically the...
0
by: Filippo Bettinaglio | last post by:
Hi, I use VS2005 , C#, .net2.0 framework. I need to be able to position where I want the Items inside a listview. I tried the belowed code but the items are always align togheter i turn off...
2
by: Tartifola | last post by:
Hi, I have a list with probabilities as elements with of course p1+p2+p3=1. I'd like to draw a random element from this list, based on the probabilities contained in the list itself, and...
3
by: James Fang | last post by:
Hi all, I need to edit a random position of a file, for e.g, the 500th byte. To keep portability, I would like to use standard C++ instead of os apis. Could you help on this? Thanks
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.