mercredi 16 octobre 2019

Game of Craps, issues with game counter and scoring

Basically this game of craps is nearly completely functioning. Running it in Java. I just have two issues at this point:

  1. If the player wins on the second roll, it doesn't register as a win and end the game. I haven't tried much to fix this because I just don't know how to stop it.
  2. I am having some trouble with a game, win, and loss counter. How can I add these in?

We're encouraged to make it as fun for our professor as possible because he's a goofy guy and doesn't like to run the same boring old program so I try to entertain him with my print statements and such sorry if it seems dumb but just want it to be fun for him and also give it some personality.

I've been comparing my code to a lot of craps games before, but not many things have been helpful and very few examples have a counter. Also the methods that I have taken in my code are mostly enforced by my instructor and followed to the best of my ability. If there are any heinous sins in my code it's my fault but a lot of the complicated stuff is required.

import java.util.Scanner; import java.util.Random;

//ISSUES: Roll 2 won't initiate a win if it equals the point. Win, loss, and game counters.

public class Craps_MCCH { public static void main(String[] args){

    Scanner keyboard = new Scanner(System.in);
    Random rand = new Random();

    System.out.println("Hey, over there. Yeah, you. What's your name?");
    String name = keyboard.nextLine();
    System.out.println("Are you serious? " + name + "? We don't use real names here.");
    System.out.println("This is a serious operation. Give me your codename.");
    String code = keyboard.nextLine();
    System.out.println("Oh. " + code +". Okay. Sure.");
    System.out.println();
    System.out.println("So, want to play Craps?");
    System.out.println("y/n");

    char letter = '0';
    letter = keyboard.nextLine().charAt(0);

    while(letter == 'y' || letter == 'Y'){
        System.out.println("Press Enter to roll.");
        keyboard.nextLine();

        int die1 = rand.nextInt(6)+1;
        int die2 = rand.nextInt(6)+1;




        System.out.println("For roll 1, you rolled a " + die1 + " and a " + die2);
        int outcome = die1 + die2;

        if(outcome == 7 || outcome ==11){
            System.out.println("Wow, won already! No prize for new gize.");
        }
        else if(outcome == 2){
            System.out.println("We call that snake-eyes. You lose. Do better");
        }
        else if(outcome == 12){
            System.out.println("Choo-choo it's the boxcar children! Also you lose.");
        }
        else {
            System.out.println(outcome + " is now your point. Roll it again to win.");

            int die3 = rand.nextInt(6)+1;
            int die4 = rand.nextInt(6)+1;
            int outcome2 = (die3+die4);


            System.out.println();
            System.out.println("Let's roll. Press Enter.");
            keyboard.nextLine();
            int rcount = 3;

            System.out.println("Roll 2: \n" + die1 + " and " + die2);
            while(outcome2 != 7 || outcome2 != 11){
                if(outcome == outcome2){
                    System.out.println("Huzzah! You've won!");
                    //win = win+1;
                    break;
                }
                else{
                    System.out.println("Point is " + outcome);
                    die3 = rand.nextInt(6)+1;
                    die4 = rand.nextInt(6)+1;
                    outcome2 = die3+die4;
                    System.out.println("Roll " + rcount++ + ":");
                    System.out.println("You rolled " + outcome2);
                    System.out.println("Press Enter.");
                    keyboard.nextLine();
                }

            }
            if(outcome2 == 7 || outcome2 == 11){
            System.out.println("After all that... no dice.");
            //loss = loss+1;
        }

        }


        //System.out.println("Current wins: " + win);
        //System.out.println("Current losses: " + loss);
        System.out.println();
        System.out.println("Wins: ");
        System.out.println("Losses: ");
        System.out.println("Games played: ");
        System.out.println();
        System.out.println("Would you like to play again?");
        System.out.println("y/n");

        letter = keyboard.nextLine().charAt(0);


    }


}

}

I want the game to end on the second roll of it ends up being a win but I don't know how to make that happen. Also it needs to count my wins, losses, and games played.




Aucun commentaire:

Enregistrer un commentaire