Jump to content

Tutorial simple dice game

- - - - -

  • Please log in to reply
26 replies to this topic

#1
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts
Yet again my own tutorial. This time its a dice game I made.(Of course text based :x, Improvment will later, java isn't my thing :P)

So lets begin...
import java.util.*;

public class mathrandom {

	protected static Scanner sc = new Scanner(System.in);//The scanner instead of keyboarder

	

	public static void main(String[] arg) {

	

		

	

		System.out.println("Would you like to throw the dice?" +//Input choice

				"\n1.Yes, please\n2.No thanks");

        int	dice = sc.nextInt();//Operation

Our choices of operation...
if(dice == 1) {//if the input was 1 then

	int nr;//Anything in the range of an integer

	nr = (int)(Math.random()*6+1);//The random selection of number range 1-6

	

	System.out.println("You got number "+nr);//Printout the dice number

	}

	

	else if(dice == 2){//else if your choice was 2 then

	

	System.out.println("What ever ");//Printout this message

	

		}

	else {//else if your choices were not 1 or 2 then it will close it self

		System.exit(0);

	}

	}

}


Now the whole code...
import java.util.*;

public class mathrandom {

	protected static Scanner sc = new Scanner(System.in);

	

	public static void main(String[] arg) {

	

		

	

		System.out.println("Would you like to throw the dice?" +

				"\n1.Yes, please\n2.No thanks");

	

	int	dice = sc.nextInt();


	if(dice == 1) {

	int nr;

	nr = (int)(Math.random()*6+1);

	

	System.out.println("You got number "+nr);

	}

	

	else if(dice == 2){

	

	System.out.println("What ever ");

	

		}

	else {

		System.exit(0);

	}

	}

}


Hope this simple dice game will entertain you guys when you are bored lol.
Posted Image

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Again, nice code. You should add a bit more description of what your functions do so that new users to Java can learn.

#3
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts

Jordan said:

Again, nice code. You should add a bit more description of what your functions do so that new users to Java can learn.

Thanks, I will try to give more description; But I am not normally good at it :)
Posted Image

#4
shoaibbi

shoaibbi

    Newbie

  • Members
  • PipPip
  • 15 posts
nice and perfect for beginners
VIvAcIoUs pAkIsTaNi

#5
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts

shoaibbi said:

nice and perfect for beginners

Thank you :)
Posted Image

#6
MathX

MathX

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,001 posts
+rock :D

Interested in participating in community events?
Want to harness your programming skill and turn it into absolute prowess?
Come join our programming events!


#7
kresh7

kresh7

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 661 posts
+rep
Posted Image

#8
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts

kresh7 said:

+rep

Thank you :)
Posted Image

#9
Egz0N

Egz0N

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,034 posts
nice one .. +rep :)

#10
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts
Thank you Egz0N :D
Posted Image

#11
MathX

MathX

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,001 posts
Why did u thank Egzon and Kresh and not me???

Interested in participating in community events?
Want to harness your programming skill and turn it into absolute prowess?
Come join our programming events!


#12
Turk4n

Turk4n

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,847 posts

MathXpert said:

Why did u thank Egzon and Kresh and not me???

Since I love you :)
Posted Image




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users