Minecraft PC IP: play.cubecraft.net

Shamel

Forum Expert
Dec 24, 2016
769
2,497
384
24
yes
hey i have an assignment in my programing class but i got stuck with something. my assignment is to make a "game" where the game will generate a random number between 1-10 or 1-20 and you have to guess it. i also need to make the program say how many tries it took you to guess a number, so i need to make it count how many times the "guess" button is clicked. is it possible to do so? if yes please help me, thanks
 
  • Like
Reactions: Elenahh

Max ♠

Forum Expert
Feb 20, 2016
1,420
2,939
344
26
North pole
Might be a good idea to include what languages / engines / whatever you're using (Edit: didnt read title smh)

Anyway, best I can do without knowing what you're using to make this game:
Code:
var Number;
var Guesses;
var min = 1;
var max = 20;
var running = false;

ON ButtonClick
{
    if(running == false) {
        Number = random(min, max);
        running = true;
    }
   
    if(GuessedNumberByUser == Number) {
        alert("Congrats you guessed the number in " + Guesses + " tries!");
        running = false;
    } else {
        Guesses += 1;
        alert("Nope, not this number, try again");
    }
}
(just some semi-code, this will not work in any language)
 
  • Like
Reactions: Elenahh

Sulphate

Novice Member
Oct 20, 2017
201
157
58
England
In Java, you can create random numbers using the Random utility class. I suggest looking at the #nextInt(int bound) method on the Javadoc (follow the link in this comment).

No idea what library (if any) you're using for GUI creation since you said you need to click a button, but I would suggest Googling "library name button click listener", and you should get some promising results :)

Good luck!
 
Members Online

Team online

Latest profile posts

🇪🇸 SPAIN SPAM 🇪🇸 SPAIN SPAM 🇪🇸 SPAIN SPAM 🇪🇸 SPAIN SPAM 🇪🇸 SPAIN SPAM 🇪🇸 SPAIN SPAM 🇪🇸 SPAIN SPAM 🇪🇸 SPAIN SPAM 🇪🇸 SPAIN SPAM 🇪🇸 SPAIN SPAM 🇪🇸

Absolute footballing heritage. SPAIN JUST TOOK THE CROWN! 🏆🔥

🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴
🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡🟡
🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴

SPAIN OWNS THIS TOURNAMENT. DEBATE A WALL. 🇪🇸👑
itzT123O wrote on ebro's profile.
Ty for following me
itzqlial0 wrote on ebro's profile.
Thank you for following
Nathie wrote on Thijs's profile.
Sawubona Thijs! 😍
3415.jpg
A year has passed for this photo..
Top Bottom