jeudi 19 novembre 2020

Java Slot machine college project

I'm making a slot machine for a college project. There are loads and loads of similar projects talked about online however the requirements for my project are slightly different. Here is my task:

  1. The player starts with £1 credit, with each go costing 20 p.
  2. If the Fruit Machine “rolls” two of the same symbol, the user wins 50 p.
  3. The player wins £1 for three of the same and £5 for 3 Bells.
  4. The player loses £1 if two skulls are rolled and all of his/her money if three skulls are rolled.
  5. The player can choose to quit with the winnings after each roll or keep playing until there is no money left.

What I've come up with so far is this:

for ( int runCount = 1; runCount <= 3; runCount ++ ) {

        int symIndex = r.nextInt(6);

        if (symIndex == 0) {
            symbol = "cherry";
        } else if (symIndex == 1){
            symbol = "orange";
        } else if (symIndex == 2){
            symbol = "lemon";
        } else if (symIndex == 3){
            symbol = "bell";
        } else if (symIndex == 4){
            symbol = "star";
        } else if (symIndex == 5){
            symbol = "skull";
        }

        if (runCount == 1){
            reel1 = symbol;
        } else if ( runCount == 2 ){
            reel2 = symbol;
        } else if ( runCount == 3 ){
            reel3 = symbol;
        }

    }
    System.out.println(reel1 + "  " + reel2 + "  " + reel3);

Which is great and spits out 3 random symbols but what is I need is a way is for it to somehow treat the bell and skull symbols differently. There must be an easier way than write out every possible combination in an if statement. In all the other projects I've seen the prize if statements have looked something like this

if (reel1 == reel2 && reel1 == reel3 && reel2 == reel3)
System.out.println("You have won!");

Or something about that etc etc. But if I do it this way it's not defining the actual symbol but just storing it in one of the reel variables so I can't make if statements for those specific outcomes.

Any help would be greatly, greatly appreciated. Even if you could just tell me how to phrase my question properly so I could search it would be helpful

Aucun commentaire:

Enregistrer un commentaire