Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Random;
- import java.util.Scanner;
- public class PlayBot extends Bot {
- // Extra Variables
- ArrayList <String> commands;
- // Constructor
- PlayBot(){
- super();
- commands = new ArrayList <String> ();
- }
- PlayBot(String name, Streamer owner){
- super(name, owner);
- commands = new ArrayList <String> ();
- commands.add("!help");
- commands.add("!roll");
- commands.add("!8ball");
- commands.add("!joker");
- commands.add("!yes or no");
- }
- PlayBot(String name, Streamer owner, ArrayList <String> commands){
- super(name, owner);
- this.commands = commands;
- }
- // Methods
- void showStatus(){
- super.showStatus();
- System.out.println();
- System.out.println("Commands of " + name + ": ");
- if(commands.size() == 0){
- System.out.println("Bot " + name + " has no commands yet.");
- }
- else{
- for(int i=0; i<commands.size(); i++){
- System.out.println("Command " + (i+1) + ": " + commands.get(i));
- }
- }
- System.out.println("*********************************");
- }
- // Commands / Methods
- void help() {
- System.out.println("PlayBot's commands: ");
- for(int i=0; i<commands.size(); i++) {
- System.out.println("Command " + i + ": " + commands.get(i));
- }
- System.out.println();
- } // END OF FUNCTION HELP
- void roll(){
- Random randomObject = new Random();
- int random = randomObject.nextInt(6);
- System.out.println("You rolled the dice. Your number is " + (random+1));
- }
- void eightBall(){
- System.out.println("Write a question to me and I will reply to you giving the right answer.");
- // Take the user input = question
- Scanner scanner = new Scanner(System.in);
- String question = scanner.nextLine();
- // Create the answer
- Random randomObject = new Random();
- int random = randomObject.nextInt(8);
- switch(random){
- case 0:
- System.out.println("My sources say no!");
- break;
- case 1:
- System.out.println("I'm so sorry! This is not true...");
- break;
- case 2:
- System.out.println("I want you to keep calm. Answer is no...");
- break;
- case 3:
- System.out.println("I'm afraid that this is not true...");
- break;
- case 4:
- System.out.println("Hmmmm..... There are some possibilities to be true!");
- break;
- case 5:
- System.out.println("You know well that the answer is yes!");
- break;
- case 6:
- System.out.println("Of course! Have you ever thought the opposite?");
- break;
- case 7:
- System.out.println("I'm not sure... Maybe yes, maybe no, that's a difficult question");
- break;
- } // END OF SWITCH - STATEMENT
- } // END OF FUNCTION 8BALL
- void joker(){
- Random randomObject = new Random();
- int r1, r2, r3, r4, r5, jokerNumber;
- r1 = randomObject.nextInt(45) + 1;
- r2 = randomObject.nextInt(45) + 1;
- while(r2 == r1){
- r2 = randomObject.nextInt(45) + 1;
- }
- r3 = randomObject.nextInt(45) + 1;
- while(r3 == r2 || r3 == r1){
- r3 = randomObject.nextInt(45) + 1;
- }
- r4 = randomObject.nextInt(45) + 1;
- while(r4 == r3 || r4 == r2 || r4 == r1){
- r4 = randomObject.nextInt(45) + 1;
- }
- r5 = randomObject.nextInt(45) + 1;
- while(r5 == r4 || r5 == r3 || r5 == r2 || r5 == r1){
- r5 = randomObject.nextInt(45) + 1;
- }
- jokerNumber = randomObject.nextInt(20) + 1;
- System.out.println("Your lucky numbers for joker today are:");
- System.out.println("Numbers: " + r1);
- System.out.println(" " + r2);
- System.out.println(" " + r3);
- System.out.println(" " + r4);
- System.out.println(" " + r5);
- System.out.println("Joker: " + jokerNumber);
- } // END OF FUNCTION JOKER
- void yesOrNo(){
- System.out.println("Give me a question, so I can answer with a 'yes' or 'no'.");
- Scanner scanner = new Scanner(System.in);
- String question = scanner.nextLine();
- Random randomObject = new Random();
- int random = randomObject.nextInt(2);
- if(random == 1){
- System.out.println("Yes!");
- }
- else{
- System.out.println("No!");
- }
- } // END OF FUNCTION YESORNO
- // METHOD FOR SELECTING FUNCTION
- void selectMethodByCommand(String command) {
- if(command.equals(commands.get(0))) {
- help();
- }
- else if(command.equals(commands.get(1))) {
- roll();
- }
- else if(command.equals(commands.get(2))) {
- eightBall();
- }
- else if(command.equals(commands.get(3))) {
- joker();
- }
- else if(command.equals(commands.get(4))) {
- yesOrNo();
- }
- }
- } // END OF CLASS PLAYBOT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement