Advertisement
makispaiktis

Streaming - PlayBot.java

Nov 11th, 2019 (edited)
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.49 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Random;
  3. import java.util.Scanner;
  4.  
  5. public class PlayBot extends Bot {
  6.    
  7.     // Extra Variables
  8.     ArrayList <String> commands;
  9.    
  10.     // Constructor
  11.     PlayBot(){
  12.         super();
  13.         commands = new ArrayList <String> ();
  14.     }
  15.    
  16.     PlayBot(String name, Streamer owner){
  17.         super(name, owner);
  18.         commands = new ArrayList <String> ();
  19.         commands.add("!help");
  20.         commands.add("!roll");
  21.         commands.add("!8ball");
  22.         commands.add("!joker");
  23.         commands.add("!yes or no");
  24.  
  25.     }
  26.    
  27.     PlayBot(String name, Streamer owner, ArrayList <String> commands){
  28.         super(name, owner);
  29.         this.commands = commands;
  30.     }
  31.    
  32.        
  33.    
  34.     // Methods
  35.     void showStatus(){
  36.         super.showStatus();
  37.         System.out.println();
  38.         System.out.println("Commands of " + name + ": ");
  39.         if(commands.size() == 0){
  40.             System.out.println("Bot " + name + " has no commands yet.");
  41.         }
  42.         else{
  43.             for(int i=0; i<commands.size(); i++){
  44.                 System.out.println("Command " + (i+1) + ": " + commands.get(i));
  45.             }
  46.         }
  47.        
  48.         System.out.println("*********************************");
  49.     }
  50.    
  51.    
  52.    
  53.     // Commands / Methods
  54.     void help() {
  55.         System.out.println("PlayBot's commands: ");
  56.         for(int i=0; i<commands.size(); i++) {
  57.             System.out.println("Command " + i + ": " + commands.get(i));
  58.         }
  59.         System.out.println();
  60.     }   // END OF FUNCTION HELP
  61.    
  62.    
  63.     void roll(){
  64.         Random randomObject = new Random();
  65.         int random = randomObject.nextInt(6);
  66.         System.out.println("You rolled the dice. Your number is " + (random+1));
  67.     }
  68.    
  69.    
  70.     void eightBall(){
  71.         System.out.println("Write a question to me and I will reply to you giving the right answer.");
  72.         // Take the user input = question
  73.         Scanner scanner = new Scanner(System.in);
  74.         String question = scanner.nextLine();
  75.         // Create the answer
  76.         Random randomObject = new Random();
  77.         int random = randomObject.nextInt(8);
  78.         switch(random){
  79.             case 0:
  80.                 System.out.println("My sources say no!");
  81.                 break;
  82.             case 1:
  83.                 System.out.println("I'm so sorry! This is not true...");
  84.                 break;
  85.             case 2:
  86.                 System.out.println("I want you to keep calm. Answer is no...");
  87.                 break;
  88.             case 3:
  89.                 System.out.println("I'm afraid that this is not true...");
  90.                 break;
  91.             case 4:
  92.                 System.out.println("Hmmmm..... There are some possibilities to be true!");
  93.                 break;
  94.             case 5:
  95.                 System.out.println("You know well that the answer is yes!");
  96.                 break;
  97.             case 6:
  98.                 System.out.println("Of course! Have you ever thought the opposite?");
  99.                 break;
  100.             case 7:
  101.                 System.out.println("I'm not sure... Maybe yes, maybe no, that's a difficult question");
  102.                 break;
  103.         }   //  END OF SWITCH - STATEMENT
  104.        
  105.        
  106.     }   // END OF FUNCTION 8BALL
  107.    
  108.    
  109.     void joker(){
  110.         Random randomObject = new Random();
  111.         int r1, r2, r3, r4, r5, jokerNumber;
  112.         r1 = randomObject.nextInt(45) + 1;
  113.         r2 = randomObject.nextInt(45) + 1;
  114.         while(r2 == r1){
  115.             r2 = randomObject.nextInt(45) + 1;
  116.         }
  117.         r3 = randomObject.nextInt(45) + 1;
  118.         while(r3 == r2 || r3 == r1){
  119.             r3 = randomObject.nextInt(45) + 1;
  120.         }
  121.         r4 = randomObject.nextInt(45) + 1;
  122.         while(r4 == r3 || r4 == r2 || r4 == r1){
  123.             r4 = randomObject.nextInt(45) + 1;
  124.         }
  125.         r5 = randomObject.nextInt(45) + 1;
  126.         while(r5 == r4 || r5 == r3 || r5 == r2 || r5 == r1){
  127.             r5 = randomObject.nextInt(45) + 1;
  128.         }
  129.         jokerNumber = randomObject.nextInt(20) + 1;
  130.         System.out.println("Your lucky numbers for joker today are:");
  131.         System.out.println("Numbers: " + r1);
  132.         System.out.println("         " + r2);
  133.         System.out.println("         " + r3);
  134.         System.out.println("         " + r4);
  135.         System.out.println("         " + r5);
  136.         System.out.println("Joker:   " + jokerNumber);
  137.        
  138.     }   //  END OF FUNCTION JOKER
  139.    
  140.    
  141.     void yesOrNo(){
  142.         System.out.println("Give me a question, so I can answer with a 'yes' or 'no'.");
  143.         Scanner scanner = new Scanner(System.in);
  144.         String question = scanner.nextLine();
  145.         Random randomObject = new Random();
  146.         int random = randomObject.nextInt(2);
  147.         if(random == 1){
  148.             System.out.println("Yes!");
  149.         }
  150.         else{
  151.             System.out.println("No!");
  152.         }
  153.        
  154.     }   // END OF FUNCTION YESORNO
  155.    
  156.    
  157.  
  158.     // METHOD FOR SELECTING FUNCTION
  159.     void selectMethodByCommand(String command) {
  160.         if(command.equals(commands.get(0))) {
  161.             help();
  162.         }
  163.         else if(command.equals(commands.get(1))) {
  164.             roll();
  165.         }
  166.         else if(command.equals(commands.get(2))) {
  167.             eightBall();
  168.         }
  169.         else if(command.equals(commands.get(3))) {
  170.             joker();
  171.         }
  172.         else if(command.equals(commands.get(4))) {
  173.             yesOrNo();
  174.         }
  175.     }
  176.    
  177.    
  178.    
  179. }   // END OF CLASS PLAYBOT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement