+ Reply to Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 27
Like Tree1Likes

Thread: Tutorial simple dice game

  1. #1
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,851
    Blog Entries
    4
    Rep Power
    49

    Tutorial simple dice game

    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 )

    So lets begin...
    Code:
    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...
    Code:
    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...
    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.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: Tutorial simple dice game

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

  4. #3
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,851
    Blog Entries
    4
    Rep Power
    49

    Re: Tutorial simple dice game

    Quote Originally Posted by Jordan View Post
    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

  5. #4
    shoaibbi's Avatar
    shoaibbi is offline Newbie
    Join Date
    Jan 2009
    Posts
    15
    Rep Power
    0

    Re: Tutorial simple dice game

    nice and perfect for beginners
    VIvAcIoUs pAkIsTaNi

  6. #5
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,851
    Blog Entries
    4
    Rep Power
    49

    Re: Tutorial simple dice game

    Quote Originally Posted by shoaibbi View Post
    nice and perfect for beginners
    Thank you

  7. #6
    Join Date
    Oct 2008
    Location
    Istog, Kosova
    Posts
    4,001
    Blog Entries
    1
    Rep Power
    40

    Re: Tutorial simple dice game

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

  8. #7
    Join Date
    Jun 2007
    Location
    Kosovo
    Posts
    660
    Rep Power
    23

    Re: Tutorial simple dice game

    +rep

  9. #8
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,851
    Blog Entries
    4
    Rep Power
    49

    Re: Tutorial simple dice game

    Quote Originally Posted by kresh7 View Post
    +rep
    Thank you

  10. #9
    Join Date
    Sep 2008
    Location
    Kosovo
    Posts
    4,032
    Rep Power
    44

    Re: Tutorial simple dice game

    nice one .. +rep

  11. #10
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,851
    Blog Entries
    4
    Rep Power
    49

    Re: Tutorial simple dice game

    Thank you Egz0N

+ Reply to Thread
Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 10
    Last Post: 10-17-2011, 06:26 AM
  2. Creating a "dice" game using python
    By taabistan in forum Python
    Replies: 4
    Last Post: 12-01-2010, 02:31 AM
  3. Dice game error...
    By wiwbiz in forum C and C++
    Replies: 2
    Last Post: 12-16-2009, 12:46 AM
  4. JavaScript:Tutorial, Your First Game!
    By TcM in forum JavaScript Tutorials
    Replies: 35
    Last Post: 06-11-2009, 01:27 PM
  5. Tutorial - A Simple Stropwatch!
    By travy92 in forum Visual Basic Tutorials
    Replies: 19
    Last Post: 05-04-2009, 02:02 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts