Jump to content




Recent Status Updates

View All Updates

Binpress - Cut your development time and costs in half
Photo
- - - - -

Tutorial simple dice game


  • Please log in to reply
26 replies to this topic

#1 Turk4n

Turk4n

    ???

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,919 posts
  • Location:Sweden
  • Programming Language:C, Java, PHP, Python, Bash
  • Learning:C++, C#, JavaScript, Visual Basic .NET, Others

Posted 19 June 2008 - 06:29 AM

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.
  • 6

#2 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 20 June 2008 - 06:17 AM

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

#3 Turk4n

Turk4n

    ???

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,919 posts
  • Location:Sweden
  • Programming Language:C, Java, PHP, Python, Bash
  • Learning:C++, C#, JavaScript, Visual Basic .NET, Others

Posted 20 June 2008 - 07:48 AM

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 :)
  • 0

#4 shoaibbi

shoaibbi

    CC Lurker

  • Just Joined
  • Pip
  • 9 posts

Posted 15 January 2009 - 07:54 AM

nice and perfect for beginners
  • 0

#5 Turk4n

Turk4n

    ???

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,919 posts
  • Location:Sweden
  • Programming Language:C, Java, PHP, Python, Bash
  • Learning:C++, C#, JavaScript, Visual Basic .NET, Others

Posted 15 January 2009 - 08:17 AM

nice and perfect for beginners


Thank you :)
  • 0

#6 MathX

MathX

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,034 posts
  • Programming Language:Java
  • Learning:C, Java, C++, PHP, JavaScript, PL/SQL

Posted 16 January 2009 - 07:57 AM

+rock :D
  • 0

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

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 326 posts

Posted 16 January 2009 - 08:33 AM

+rep
  • 0
Posted Image

#8 Turk4n

Turk4n

    ???

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,919 posts
  • Location:Sweden
  • Programming Language:C, Java, PHP, Python, Bash
  • Learning:C++, C#, JavaScript, Visual Basic .NET, Others

Posted 16 January 2009 - 09:48 AM

+rep


Thank you :)
  • 0

#9 Egz0N

Egz0N

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,155 posts

Posted 16 January 2009 - 12:23 PM

nice one .. +rep :)
  • 0

#10 Turk4n

Turk4n

    ???

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,919 posts
  • Location:Sweden
  • Programming Language:C, Java, PHP, Python, Bash
  • Learning:C++, C#, JavaScript, Visual Basic .NET, Others

Posted 16 January 2009 - 12:38 PM

Thank you Egz0N :D
  • 0

#11 MathX

MathX

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,034 posts
  • Programming Language:Java
  • Learning:C, Java, C++, PHP, JavaScript, PL/SQL

Posted 19 January 2009 - 06:38 AM

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

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

    ???

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,919 posts
  • Location:Sweden
  • Programming Language:C, Java, PHP, Python, Bash
  • Learning:C++, C#, JavaScript, Visual Basic .NET, Others

Posted 19 January 2009 - 07:50 AM

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


Since I love you :)
  • 0




Powered by binpress