/************************************************ * from http://home.att.net/~gobruen/ * * *Slots.java * * Called by GameDriver.java, needs LoopLL.java to run * * * Methods: * * slots() main driver for game * pullHandle() "pulls" the handle by generating a random * number of spins for the wheels * loadFirstWheel() load the first "wheel" circular linked list * loadOtherWheels() load the other two based on the first * calculateWin() calculate winings * isNum() boolean to see if entry is a number * introduction() intro script * slotStart() ascii art * help() general help * *************************************************/ import java.io.*; import java.util.*; import java.lang.Math.*; public class Slots { public static int slots(int bank, String player)throws IOException{ //setup for command line reading BufferedReader clin = new BufferedReader(new InputStreamReader(System.in)); /* * Setup values for slot wheels and the outcomes */ LoopLL wheel1 = new LoopLL(); wheel1 = loadFirstWheel(wheel1); LoopLL wheel2 = new LoopLL(); LoopLL wheel3 = new LoopLL(); wheel2 = loadOtherWheels(wheel2, wheel1, 2); wheel3 = loadOtherWheels(wheel3, wheel1, 7); String w1, w2, w3; int bet = 0; int totalBet = 0; String action = "start"; boolean money = false; System.out.println("\n\n\n"); introduction(); while(!action.equals("leave")){ System.out.print("["+player+", "+bank+"]Action: "); action = clin.readLine(); action = action.toLowerCase(); if(action.length()>0){ if(action.equals("pull")){ if(money == true){ w1 = pullHandle(wheel1); w2 = pullHandle(wheel2); w3 = pullHandle(wheel3); System.out.println(); System.out.println(w1+w2+w3); System.out.println(); bank = bank + calculateWin(w1, w2, w3, totalBet); money = false; totalBet = 0; }else{ System.out.println("The handle doesn't move"); } }else{ if(action.equals("kick")){System.out.println("You'll get thrown out if you kick the machine.");} if(action.equals("cheat")){System.out.println("You have no magnets or other devices.");} if(action.equals("bank")){System.out.println("You have: "+bank);} if(action.equals("exit")){action="leave";} if(action.equals("bye")){action="leave";} if(action.equals("help")){help();} if(isNum(action)){ bet = Integer.parseInt(action.trim()); if(bet <= bank){ totalBet = totalBet + bet; money = true; bank = bank - bet; }else{ System.out.println("You've got "+bank+" and you're trying to bet "+bet+"."); } } } } }//end main while loop return bank; }//end slots main driver method /*************methods**********************/ public static String pullHandle(LoopLL wheel){ return wheel.spin((int)(Math.random() * 40)); //use random number generate spins } /**************************************************************/ /********** These methods load the slot wheels with values*****/ /**************************************************************/ public static LoopLL loadFirstWheel(LoopLL wheel1){ wheel1.addTo("| BAR BAR |"); wheel1.addTo("| Lemon |"); wheel1.addTo("| Joker |"); wheel1.addTo("| BAR |"); wheel1.addTo("| Cherry |"); wheel1.addTo("| Lemon |"); wheel1.addTo("| Diamonds |"); wheel1.addTo("| Smile |"); wheel1.addTo("| Coins |"); wheel1.addTo("| $$$$$$ |"); wheel1.addTo("| Smile |"); wheel1.addTo("| BAR BAR BAR |"); wheel1.addTo("| Coins |"); wheel1.addTo("| Lemon |"); wheel1.loopList(); return wheel1; }//end loadFirstWheel public static LoopLL loadOtherWheels(LoopLL newWheel, LoopLL wheel1, int newStPt){ newWheel = wheel1.loadFromFirst(newStPt, newWheel); return newWheel; }//end loadOtherWheels /***************************************************************/ public static int calculateWin(String w1, String w2, String w3, int totalBet){ int win = 0; if((w1.equals(w2))&&(w1.equals(w3))){ win = totalBet * 50; }else{ if(w1.equals(w2)){ win = totalBet * 5; } if(w2.equals(w3)){ win = totalBet * 5; } if(w3.equals(w1)){ win = totalBet * 5; } } if(w1.equals("| Joker |")){ win = win + (totalBet * 10); } if(w2.equals("| Joker |")){ win = win + (totalBet * 10); } if(w3.equals("| Joker |")){ win = win + (totalBet * 10); } if(win > 0){ System.out.println("You win $"+win); } return win; }//end calculate win /*************************/ public static boolean isNum(String s) { int count=0; for(int j=0; j