473,461 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Random Game

Hi there
M developing an game in the form of an applet which has two buttons: Random and Clear
Random button has to generate random numbers in a textfield labelled start.
Generating random numbers is not a problem i have used the code below:
************************************************
Random rand = new Random();
int i = rand.nextInt();
int n = 10;
i = rand.nextInt(n+1);
tfld.setText("" + i);
*************************************************
but the assignment says that to start the game the player clicks on the random button to generate a random number in the tfld textfield.
AND when he clicks again the number should be generated in a different textfleld while the first number is retained.
ANY IDEAS OR HELP WILL BE HIGHLY APPRECIATED
THNKS
Yasin
Mar 26 '08 #1
3 1301
r035198x
13,262 8TB
Hi there
M developing an game in the form of an applet which has two buttons: Random and Clear
Random button has to generate random numbers in a textfield labelled start.
Generating random numbers is not a problem i have used the code below:
************************************************
Random rand = new Random();
int i = rand.nextInt();
int n = 10;
i = rand.nextInt(n+1);
tfld.setText("" + i);
*************************************************
but the assignment says that to start the game the player clicks on the random button to generate a random number in the tfld textfield.
AND when he clicks again the number should be generated in a different textfleld while the first number is retained.
ANY IDEAS OR HELP WILL BE HIGHLY APPRECIATED
THNKS
Yasin
Where's the applet with the textfields then?
Have a read at this and give it a try.
Mar 26 '08 #2
sukatoa
539 512MB
Hi there
M developing an game in the form of an applet which has two buttons: Random and Clear
Random button has to generate random numbers in a textfield labelled start.
Generating random numbers is not a problem i have used the code below:
************************************************
Random rand = new Random();
int i = rand.nextInt();
int n = 10;
i = rand.nextInt(n+1);
tfld.setText("" + i);
*************************************************
but the assignment says that to start the game the player clicks on the random button to generate a random number in the tfld textfield.
AND when he clicks again the number should be generated in a different textfleld while the first number is retained.
ANY IDEAS OR HELP WILL BE HIGHLY APPRECIATED
THNKS
Yasin
If the other textfield is already set.... i mean shown...
You can use any flags... to determine whether the first field has already occupied by a value......

tell me if it's to far from your point,
sukatoa
Mar 26 '08 #3
chaarmann
785 Expert 512MB
Hi there
M developing an game in the form of an applet which has two buttons: Random and Clear
Random button has to generate random numbers in a textfield labelled start.
Generating random numbers is not a problem i have used the code below:
************************************************
Random rand = new Random();
int i = rand.nextInt();
int n = 10;
i = rand.nextInt(n+1);
tfld.setText("" + i);
*************************************************
but the assignment says that to start the game the player clicks on the random button to generate a random number in the tfld textfield.
AND when he clicks again the number should be generated in a different textfleld while the first number is retained.
ANY IDEAS OR HELP WILL BE HIGHLY APPRECIATED
THNKS
Yasin
On first start of your game, don't create random number at all. When the user presses button,then call your code listed above to show up a number inside the text field.
When the user clicks the button again, you first check the first text field if it is empty or not. When it is not empty, you call your code listed above again, but with the difference that you write this number inside your second text field:
tfld2.setText(...)
Mar 26 '08 #4

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

Similar topics

2
by: M. Braun | last post by:
Hello, first I have to say, my english isn't very well so just try to understand it ;-). I've got a little problem with the PHP function rand(). I want to create a little programm which...
23
by: Thomas Mlynarczyk | last post by:
I remember there is a programming language where you can initialize the random number generator, so that it can - if you want - give you the exactly same sequence of random numbers every time you...
4
by: SoulSniper | last post by:
Hi, I have been stuck on this for a few days now and have given up trawling through pages and pages of google results.. I'm just putting the finishing touches to a small game I've written....
23
by: Alvin | last post by:
Well, I'm developing a Tetris game in SDL, but when it comes to deciding the next block, I'm stuck. It's random, but when I try something like seeding the randomizer with the time, it won't update...
15
by: felixnielsen | last post by:
This is something i have done before and i know its pretty simple, however i cant remember how it works exactly, and i need it i kinda hurry, so if someone would be so nice to drop a random number...
104
by: fieldfallow | last post by:
Hello all, Is there a function in the standard C library which returns a prime number which is also pseudo-random? Assuming there isn't, as it appears from the docs that I have, is there a...
6
by: skulkrinbait | last post by:
I asked for some advice a few months back about how to generate a "random" map for a game I was writing. I got sidetracked but here is the latest version of it in case anyone is interested: ...
24
by: pereges | last post by:
I need to generate two uniform random numbers between 0 and 1 in C ? How to do it ? I looked into rand function where you need to #define RAND_MAX as 1 but will this rand function give me ...
9
xpun
by: xpun | last post by:
hey all So I decided to be a little ambitious over the summer and create the game of clue in c. I figured it would give my self a GOOD refresher of the language and further understand functions...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.