Craps Game

DiabloVodkaShot

LOMCN VIP
VIP
Feb 20, 2009
2,272
182
265
Hey Guys,
Been learning java for a while now never really attempted a game, but here is my Craps Game...
It runs in command prompt..

Code:
public class DiceDemo{

public static void main(String[] args){


	//First Roll Dice
	int dice1 = (int) (Math.random()*6 + 1);
	int dice2 = (int) (Math.random()*6 + 1);
	int sum = dice1 + dice2;
	int Marker = 0; // declare Marker here




	//First Roll Totals
	System.out.println("Dice 1 Rolled .... " + dice1);
	System.out.println("Dice 2 Rolled .... " + dice2);
	System.out.println("In Total you scored .. " + sum);


	//Determination time
	if(sum==2 || sum==3 || sum==12){
		System.out.println("You Loose");


	} else if(sum==7 || sum==11){
		System.out.println("WINNER!");
	} else {


		Marker = sum; // initialize marker here


		do{ // start do while here


			 //Marker = sum;
			System.out.println("-------------------------------------------");
			System.out.println("              ++NEW ROLL++");
			System.out.println("            Your Marker IS : " + Marker);


			//Variables
			int dice3 = (int) (Math.random()*6 + 1);
			int dice4 = (int) (Math.random()*6 + 1);


				//int total = dice3 + dice4;


				sum = dice3 + dice4; // reinialize sum


			//Second Roll Dice
		//DO Section


		//do { Remove start of do


		System.out.println("You Rolled a ... " + sum);


				if (sum == Marker){


				    System.out.println("You win!");
				} else if(sum == 7) {


					System.out.println("You lose!");
							}
			} while((sum != Marker) && (sum != 7));


        } // else


    }//main


}//class

Any coders out there tell me what you think.
 

Alecs

SPQR
VIP
Jan 10, 2009
3,309
3
1,191
380
Europa
What is it supposed to do? Sometimes I win, sometimes I lose but I don't get why.

I made a rock-paper-scissors game in a examen. If I find the code I'll post here.
 

DiabloVodkaShot

LOMCN VIP
VIP
Feb 20, 2009
2,272
182
265
Its just a game:

The rules are. Two dice are initially rolled. if the roll is a 7 or 11, you win. if the roll is a 2 or 3 or 12 you loose because this is craps. Otherwise the roll becomes your marker. The player then rolls the two dice untill they get either their marker, in which case they win, or a 7 in which case they lose.
 

Alecs

SPQR
VIP
Jan 10, 2009
3,309
3
1,191
380
Europa
Ok, I understand now. I found my rock-paper-scissors source code, I'll translate the text and I'll upload it.
 

Alecs

SPQR
VIP
Jan 10, 2009
3,309
3
1,191
380
Europa
Sorry for the bad translation. I want to remake the whole game. I'm more experienced now and I can improve it. I can do the same in less lines, I'd use the workds "rock", "paper" and "scissors" instead of numbers.

How it works. First of all you have to imput the any number between 1 and 3. 1 is rock, 2 is paper and 3 is scissors. You will be asked to input the numers 10 times because there will be 10 rounds. Then the game will randomly get a number between 1 and 3 for every round. And then...you now, rock wins over scissors, paper wins over rock, etc...

Code:
import java.util.*;
import javax.swing.JOptionPane;
public class gametest {
	
	public static void main(String[] args) {
		Random rnd = new Random();
		int valor1 = rnd.nextInt(3-1+1)+1;
		int valor2 = rnd.nextInt(3-1+1)+1;
		int valor3 = rnd.nextInt(3-1+1)+1;
		int valor4 = rnd.nextInt(3-1+1)+1;
		int valor5 = rnd.nextInt(3-1+1)+1;
		int valor6 = rnd.nextInt(3-1+1)+1;
		int valor7 = rnd.nextInt(3-1+1)+1;
		int valor8 = rnd.nextInt(3-1+1)+1;
		int valor9 = rnd.nextInt(3-1+1)+1;
		int valor10 = rnd.nextInt(3-1+1)+1;
		System.out.println(valor1); 
		
	    System.out.println("There will be 10 rounds. Input 1 for rock, 2 for paper and 3 for scissors."); 
	    System.out.println("Remember:");
	    System.out.println("Rock: 1");
	    System.out.println("Paper: 2");
	    System.out.println("Scissors: 3"); 
	    System.out.println("");
		
	    int a=Integer.parseInt(JOptionPane.showInputDialog("First round"));
	    int b=Integer.parseInt(JOptionPane.showInputDialog("Second round"));
	    int c=Integer.parseInt(JOptionPane.showInputDialog("Third round"));
	    int d=Integer.parseInt(JOptionPane.showInputDialog("Fourth round"));
	    int e=Integer.parseInt(JOptionPane.showInputDialog("Fifth round"));
	    int f=Integer.parseInt(JOptionPane.showInputDialog("Sixth round"));
	    int g=Integer.parseInt(JOptionPane.showInputDialog("Seventh round"));
	    int h=Integer.parseInt(JOptionPane.showInputDialog("Eighth round"));
	    int i=Integer.parseInt(JOptionPane.showInputDialog("Ninth round"));
	    int j=Integer.parseInt(JOptionPane.showInputDialog("Tenth round"));
		
		System.out.print("First round: " + a + " vs " + valor1); 
		
		if (a==valor1) {
			System.out.println("    Tie"); 
		}
		else if (a==1 && valor1==3) {
			System.out.println("    You win with rock vs scissors");
			
		}
		else if (a==1 && valor1==2) {
			System.out.println("    You lose with stone vs paper");
		}
		
		else if (a==2 && valor1==1) {
			System.out.println("    You win with paper vs stone"); 
		}
		
		else if (a==2 && valor1==3) {
			System.out.println("    You lose with paper vs scissors"); 
		}
		
		else if (a==3 && valor1==1) {
			System.out.println("    You lose with scissors vs rock");
		}
		else if (a==3 && valor1==2) {
			System.out.println("    You win with scissors vs paper"); 
		}
		
		
		
System.out.print("Second round: " + b + " vs " + valor2); 
		
		if (b==valor2) {
			System.out.println("    Tie"); 
		}
		else if (b==1 && valor2==3) {
			System.out.println("    You win with rock vs scissors");
			
		}
		else if (b==1 && valor2==2) {
			System.out.println("    You lose with stone vs paper");
		}
		
		else if (b==2 && valor2==1) {
			System.out.println("    You win with paper vs stone"); 
		}
		
		else if (b==2 && valor2==3) {
			System.out.println("    You lose with paper vs scissors"); 
		}
		
		else if (b==3 && valor2==1) {
			System.out.println("    You lose with scissors vs rock");
		}
		else if (b==3 && valor2==2) {
			System.out.println("    You win with scissors vs paper"); 
		}
		
		
		
System.out.print("Third round: " + c + " vs " + valor3); 
		
		if (c==valor3) {
			System.out.println("    Tie"); 
		}
		else if (c==1 && valor3==3) {
			System.out.println("    You win with rock vs scissors");
			
		}
		else if (c==1 && valor3==2) {
			System.out.println("    You lose with stone vs paper");
		}
		
		else if (c==2 && valor3==1) {
			System.out.println("    You win with paper vs stone"); 
		}
		
		else if (c==2 && valor3==3) {
			System.out.println("    You lose with paper vs scissors"); 
		}
		
		else if (c==3 && valor3==1) {
			System.out.println("    You lose with scissors vs rock");
		}
		else if (c==3 && valor3==2) {
			System.out.println("    You win with scissors vs paper"); 
		}
		
		
		
System.out.print("Fourth round: " + d + " vs " + valor4); 
		
		if (d==valor4) {
			System.out.println("    Tie"); 
		}
		else if (d==1 && valor4==3) {
			System.out.println("    You win with rock vs scissors");
			
		}
		else if (d==1 && valor4==2) {
			System.out.println("    You lose with stone vs paper");
		}
		
		else if (d==2 && valor4==1) {
			System.out.println("    You win with paper vs stone"); 
		}
		
		else if (d==2 && valor4==3) {
			System.out.println("    You lose with paper vs scissors"); 
		}
		
		else if (d==3 && valor4==1) {
			System.out.println("    You lose with scissors vs rock");
		}
		else if (d==3 && valor4==2) {
			System.out.println("    You win with scissors vs paper"); 
		}
		
		
		
System.out.print("Fifth round: " + e + " vs " + valor5); 
		
		if (e==valor5) {
			System.out.println("    Tie"); 
		}
		else if (e==1 && valor5==3) {
			System.out.println("    You win with rock vs scissors");
			
		}
		else if (e==1 && valor5==2) {
			System.out.println("    You lose with stone vs paper");
		}
		
		else if (e==2 && valor5==1) {
			System.out.println("    You win with paper vs stone"); 
		}
		
		else if (e==2 && valor5==3) {
			System.out.println("    You lose with paper vs scissors"); 
		}
		
		else if (e==3 && valor5==1) {
			System.out.println("    You lose with scissors vs rock");
		}
		else if (e==3 && valor5==2) {
			System.out.println("    You win with scissors vs paper"); 
		}
		
		
		
System.out.print("Sixth round: " + f + " vs " + valor6); 
		
		if (f==valor6) {
			System.out.println("    Tie"); 
		}
		else if (f==1 && valor6==3) {
			System.out.println("    You win with rock vs scissors");
			
		}
		else if (f==1 && valor6==2) {
			System.out.println("    You lose with stone vs paper");
		}
		
		else if (f==2 && valor6==1) {
			System.out.println("    You win with paper vs stone"); 
		}
		
		else if (f==2 && valor6==3) {
			System.out.println("    You lose with paper vs scissors"); 
		}
		
		else if (f==3 && valor6==1) {
			System.out.println("    You lose with scissors vs rock");
		}
		else if (f==3 && valor6==2) {
			System.out.println("    You win with scissors vs paper"); 
		}
		
		
		
System.out.print("Seventh round: " + g + " vs " + valor7); 
		
		if (g==valor7) {
			System.out.println("    Tie"); 
		}
		else if (g==1 && valor7==3) {
			System.out.println("    You win with rock vs scissors");
			
		}
		else if (g==1 && valor7==2) {
			System.out.println("    You lose with stone vs paper");
		}
		
		else if (g==2 && valor7==1) {
			System.out.println("    You win with paper vs stone"); 
		}
		
		else if (g==2 && valor7==3) {
			System.out.println("    You lose with paper vs scissors"); 
		}
		
		else if (g==3 && valor7==1) {
			System.out.println("    You lose with scissors vs rock");
		}
		else if (g==3 && valor7==2) {
			System.out.println("    You win with scissors vs paper"); 
		}
		
		
		
System.out.print("Eighth round: " + h + " vs " + valor8); 
		
		if (h==valor8) {
			System.out.println("    Tie"); 
		}
		else if (h==1 && valor8==3) {
			System.out.println("    You win with rock vs scissors");
			
		}
		else if (h==1 && valor8==2) {
			System.out.println("    You lose with stone vs paper");
		}
		
		else if (h==2 && valor8==1) {
			System.out.println("    You win with paper vs stone"); 
		}
		
		else if (h==2 && valor8==3) {
			System.out.println("    You lose with paper vs scissors"); 
		}
		
		else if (h==3 && valor8==1) {
			System.out.println("    You lose with scissors vs rock");
		}
		else if (h==3 && valor8==2) {
			System.out.println("    You win with scissors vs paper"); 
		}
		
		
		
System.out.print("Ninth round: " + i + " vs " + valor9); 
		
		if (i==valor9) {
			System.out.println("    Tie"); 
		}
		else if (i==1 && valor9==3) {
			System.out.println("    You win with rock vs scissors");
			
		}
		else if (i==1 && valor9==2) {
			System.out.println("    You lose with stone vs paper");
		}
		
		else if (i==2 && valor9==1) {
			System.out.println("    You win with paper vs stone"); 
		}
		
		else if (i==2 && valor9==3) {
			System.out.println("    You lose with paper vs scissors"); 
		}
		
		else if (i==3 && valor9==1) {
			System.out.println("    You lose with scissors vs rock");
		}
		else if (i==3 && valor9==2) {
			System.out.println("    You win with scissors vs paper"); 
		}
		
		
		
System.out.print("Tenth round: " + j + " vs " + valor10); 
		
		if (j==valor10) {
			System.out.println("    Tie"); 
		}
		else if (j==1 && valor10==3) {
			System.out.println("    You win with rock vs scissors");
			
		}
		else if (j==1 && valor10==2) {
			System.out.println("    You lose with stone vs paper");
		}
		
		else if (j==2 && valor10==1) {
			System.out.println("    You win with paper vs stone"); 
		}
		
		else if (j==2 && valor10==3) {
			System.out.println("    You lose with paper vs scissors"); 
		}
		
		else if (j==3 && valor10==1) {
			System.out.println("    You lose with scissors vs rock");
		}
		else if (j==3 && valor10==2) {
			System.out.println("    You win with scissors vs paper"); 
		}
		
	}
	
}
 
Last edited:

DiabloVodkaShot

LOMCN VIP
VIP
Feb 20, 2009
2,272
182
265
Very nice work :) Agreed could be done a lot easier now days :P ... What other things u coded using Java
 

Alecs

SPQR
VIP
Jan 10, 2009
3,309
3
1,191
380
Europa
Only stuff for school. But the last weeks I didn't code anything and I have my finals in a few days. I got about 2 days to learn java with relational database (MySQL). I don't think I'm gonna pass this test now. This is the price I've to pay for being lazy. :(

Study summer I guess. :(
 

Alecs

SPQR
VIP
Jan 10, 2009
3,309
3
1,191
380
Europa
I will but not now. I'm not ready for that test. I want to pass the school ones first.
 

Alecs

SPQR
VIP
Jan 10, 2009
3,309
3
1,191
380
Europa
As I said, I'm not enough experienced for that test. I don't think it's easy as it's an official certificate. But in a future I'll need it. I'm studyin web applications development and multi-platform applications development (apps for tables and smartphones). I'll use Java a lot.
 

DiabloVodkaShot

LOMCN VIP
VIP
Feb 20, 2009
2,272
182
265
Yerh, it is very hard but hopefully i will get there. I'm doing it having no other experience in java :P but we will see how it goes for me. i need to start building a extra curricular portfolio up, but its thinking what to create.
 

XxEvilDxX

Banned
Banned
Dedicated Member
Apr 10, 2010
158
15
85
USA
Hey Guys,
Been learning java for a while now never really attempted a game, but here is my Craps Game...
It runs in command prompt..

Code:
public class DiceDemo{

public static void main(String[] args){

    //First Roll Dice
    int dice1 = (int) (Math.random()*6 + 1);
    int dice2 = (int) (Math.random()*6 + 1);
    int sum = dice1 + dice2;
    int Marker = 0; // declare Marker here

    //First Roll Totals
    System.out.println("Dice 1 Rolled .... " + dice1);
    System.out.println("Dice 2 Rolled .... " + dice2);
    System.out.println("In Total you scored .. " + sum);

    //Determination time
    if(sum==2 || sum==3 || sum==12){
        System.out.println("You Loose");

    } else if(sum==7 || sum==11){
        System.out.println("WINNER!");
    } else {

        Marker = sum; // initialize marker here

        do{ // start do while here

             //Marker = sum;
            System.out.println("-------------------------------------------");
            System.out.println("              ++NEW ROLL++");
            System.out.println("            Your Marker IS : " + Marker);

            //Variables
            int dice3 = (int) (Math.random()*6 + 1);
            int dice4 = (int) (Math.random()*6 + 1);

                //int total = dice3 + dice4;

                sum = dice3 + dice4; // reinialize sum


            //Second Roll Dice
        //DO Section


        //do { Remove start of do


        System.out.println("You Rolled a ... " + sum);


                if (sum == Marker){


                    System.out.println("You win!");
                } else if(sum == 7) {


                    System.out.println("You lose!");
                            }
            } while((sum != Marker) && (sum != 7));


        } // else


    }//main


}//class

Any coders out there tell me what you think.


Nice games!
Here is your game translated to C++
Code:
#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

int main()
{
    //Declare the integer variables
    int dice1, dice2, dice3, dice4, sum, Marker;
    /* initialize random seed: */
    srand ( time(NULL) );

    /****************First Roll Dice****************/
    //Get a random number from 1 to 6
    dice1 = rand()%6 + 1;
    //Get a random number from 1 to 6
    dice2 = rand()%6 + 1;
    //Get the sum of the dice
    sum = dice1 + dice2;
    // initialize Marker here
    Marker = 0; 

    /****************First Roll Totals****************/
    //C output the data
    cout << "Dice 1 Rolled .... " << dice1 << endl;
    cout << "Dice 2 Rolled .... " << dice2 << endl;
    cout << "In Total you scored .. " << sum << endl;

    //Determination time
    if(sum==2 || sum==3 || sum==12)
    {
        cout << "You Loose" << endl;
    } 
    else if(sum==7 || sum==11)
    {
        cout << "WINNER!" << endl;
    } 
    else 
    {
        // initialize marker here
        Marker = sum; 

        // start do while here
        do
        { 
             //Marker = sum;
            cout << "-------------------------------------------" << endl;
            cout << "              ++NEW ROLL++" << endl;
            cout << "            Your Marker IS : " << Marker << endl;

            //Variables
            dice3 = rand()%6 + 1;
            dice4 = rand()%6 + 1;

            // reinialize sum
            sum = dice3 + dice4; 

            cout << "You Rolled a ... " << sum << endl;

            if (sum == Marker)
            {
                cout << "You win!" << endl;
            } 
            else if(sum == 7) 
            {
                cout << "You lose!"<< endl;
            }
        } 
        while((sum != Marker) && (sum != 7));

    }
    cin.get();
    return 0;
}
 
Last edited: