Advertisement
makispaiktis

Streaming - App.java

Nov 11th, 2019 (edited)
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 24.69 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Random;
  3. import java.util.Scanner;
  4. import java.io.*;
  5.  
  6. public class App {
  7.    
  8.     // Auxiliary Functions
  9.     void convertTime(int seconds) {
  10.         if(seconds >= 0 && seconds < 60) {
  11.             System.out.println("Streaming for " + seconds + " seconds.");
  12.         }
  13.         else if(seconds >= 60 && seconds < 3600) {
  14.             int minutes = (int)(seconds / 60);
  15.             int secondsRemaining = seconds % 60;
  16.             System.out.println("Streaming for " + minutes + " minutes and " + secondsRemaining + " seconds.");
  17.         }
  18.         else if(seconds >= 3600) {
  19.             int hours = (int)(seconds / 3600);
  20.             int minutesRemaining = (int)( (seconds - hours * 3600) / 60);
  21.             int secondsRemaining = (seconds - hours * 3600) % 60;
  22.             System.out.println("Streaming for " + hours + " hours, " + minutesRemaining + " minutes and " + secondsRemaining + " seconds.");
  23.         }
  24.     }   // END OF FUNCTION CONVERTTIME
  25.    
  26.     void createLandscapeAsImage(Stream streamOfSomeone) {
  27.         // System.out.println("********************************************************************************");
  28.         // I will make it like real one dimensions (16:9) <----> Width = columns = 80 and Height = rows = 45
  29.         // I will make 22 rows = int(45/2), because vertical distance of "|"s is bigger than horizontial space between "-"s
  30.  
  31.         for(int rows=1; rows<=22; rows++) {
  32.             for(int columns=1; columns<=80; columns++) {
  33.                
  34.                 // Rule for first row
  35.                 if(rows == 1) {
  36.                     // This code will be executed 80 times = range of columns
  37.                     System.out.print("-");
  38.                     if(columns == 80) {
  39.                         System.out.println();
  40.                     }
  41.                 }
  42.                
  43.                 // Rule of 2nd row
  44.                 else if(rows == 2) {
  45.                     if(columns == 1) {
  46.                         System.out.print("|");
  47.                     }
  48.                    
  49.                     else if(columns == 2) {
  50.                         System.out.print(streamOfSomeone.streamer.nameOfChannel + ": " + streamOfSomeone.title);
  51.                     }
  52.                    
  53.                     else if(columns >= 3 && columns <= 80 - (streamOfSomeone.streamer.nameOfChannel + ": " + streamOfSomeone.title).length() ) {
  54.                         System.out.print(" ");
  55.                     }
  56.                     else if(columns == 80) {
  57.                         System.out.print("|");
  58.                         System.out.println();
  59.                     }
  60.                 }
  61.                
  62.                 // Rule of medium rows
  63.                 else if(rows >= 3 && rows <= 20) {
  64.                     if(columns == 1) {
  65.                         System.out.print("|");
  66.                     }
  67.                     else if(columns >=2 && columns <= 79) {
  68.                         System.out.print(" ");
  69.                     }
  70.                     else if(columns == 80) {
  71.                         System.out.print("|");
  72.                         System.out.println();
  73.                     }
  74.                 }
  75.                
  76.                 // Rule for row 21
  77.                 else if(rows == 21) {
  78.                     if(columns == 1) {
  79.                         System.out.print("|");
  80.                     }
  81.                     else if(columns >=2 && columns < 80 - ("Viewers: " + (streamOfSomeone.viewers + 1)).length()) {
  82.                         System.out.print(" ");
  83.                     }
  84.                     else if(columns == 80 - ("Viewers: " + streamOfSomeone.viewers).length()) {
  85.                         System.out.print("Viewers: " + streamOfSomeone.viewers);
  86.                     }
  87.                     else if(columns == 80) {
  88.                         System.out.print("|");
  89.                         System.out.println();
  90.                     }
  91.                 }
  92.            
  93.                 // Rule for last row (22)
  94.                 else if(rows == 22) {
  95.                     System.out.print("-");
  96.                     if(columns == 80) {
  97.                         System.out.println();
  98.                     }
  99.                 }
  100.                
  101.             }   // END OF SECOND FOR-LOOP
  102.         }   // END OF FIRST FOR-LOOP
  103.        
  104.         // ************************************************************************************************************************************
  105.         // ************************************************************************************************************************************
  106.         // ************************************************************************************************************************************
  107.         // ************************************************************************************************************************************
  108.        
  109.         // I have ended with "screen-size"
  110.         for(int times=1; times<=3; times++) {
  111.             // Now, I will draw the shape of "screen-base"
  112.             // 38 blank-spaces
  113.             for(int i=1; i<39; i++) {
  114.                 System.out.print(" ");
  115.             }
  116.             // 4 symbols = "|" in positions 39,40,41 and 42 (4 spaces after the 38 blank spaces)
  117.             for(int j=1; j<=4; j++) {
  118.                 System.out.print("|");
  119.             }
  120.             System.out.println();
  121.         }
  122.        
  123.         // THE FINAL BASE OF SCREEN
  124.         for(int numOfBaseLevels=1; numOfBaseLevels<=2; numOfBaseLevels++) {
  125.             for(int columns=1; columns<=80; columns++) {
  126.                 System.out.print("-");
  127.             }
  128.             System.out.println();
  129.         }
  130.        
  131.         // ************************************************************************************************************************************
  132.         // ************************************************************************************************************************************
  133.         // ************************************************************************************************************************************
  134.         // ************************************************************************************************************************************
  135.        
  136.     }   // END OF FUNCTION CREATELANSCAPEASIMAGE
  137.    
  138.    
  139.     String selectRandomTalk(Stream streamOfSomeone) {
  140.         ArrayList <String> talks = new ArrayList <String> ();
  141.         talks.add("Hello guys? What's up?");
  142.         talks.add("Hi " + streamOfSomeone.streamer.nameOfChannel + "! How you doing?");
  143.         talks.add("I am so happy that my favorite streamer is back. Let's go " + streamOfSomeone.streamer.nameOfChannel);
  144.         talks.add("Anyone knows why is he so happy today?");
  145.         talks.add(streamOfSomeone.streamer.nameOfChannel + ", my day was pretty busy and difficult today. I like watching your channel");
  146.         talks.add("Keep on going. You are the best!");
  147.         talks.add("Wow! You have already " + streamOfSomeone.viewers + " viewers!");
  148.         talks.add("Such a nice guy in this wholesome streaming community!");
  149.         talks.add("How can I improve myself in aim?");
  150.         talks.add("I am sure he will be the best one day!");
  151.         Random randomObject = new Random();
  152.         // Create a random number ---> select a random talk
  153.         int randomTalkIndex = randomObject.nextInt(talks.size());
  154.         int randomUserIndex = randomObject.nextInt(1000) + 1;
  155.         return ( "User " + randomUserIndex + ": " + talks.get(randomTalkIndex) );
  156.     }
  157.    
  158.    
  159.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  160.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  161.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  162.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  163.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  164.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  165.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  166.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  167.    
  168.    
  169.     public static void main(String[] args) {
  170.        
  171.         // CREATE A VARIABLE THAT WILL COUNT THE DURATION OF USER'S CONNECTION IN THE STREAMING COMMUNITY
  172.         long startTime = System.currentTimeMillis();
  173.        
  174.         // First create the streamers
  175.        
  176.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  177.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ STREAMER 1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  178.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  179.         ArrayList <String> socialsThomas = new ArrayList <String> ();
  180.         socialsThomas.add("Facebook: Θωμάς Μπουφίκος");
  181.         socialsThomas.add("Instagram: thomas_boufikos");
  182.         socialsThomas.add("Twitter: Thomas Boufikos");
  183.         Streamer Thomas = new Streamer("Thomas Boufikos", "Tommino", "Greek",  20, socialsThomas);
  184.         // Create the bots of this channel
  185.         NightBot nb = new NightBot("Nb", Thomas);
  186.         Thomas.botsList.add(nb);
  187.         PlayBot pb = new PlayBot("Pb", Thomas);
  188.         Thomas.botsList.add(pb);
  189.        
  190.        
  191.         ArrayList <String> categoriesThomas = new ArrayList <String> ();
  192.         categoriesThomas.add("Shooters Games");
  193.         categoriesThomas.add("Family Friendly");
  194.         categoriesThomas.add("Greek and English Language spoken");
  195.         categoriesThomas.add("Multiplayer");
  196.         Stream streamOfThomas = new Stream(Thomas, "Fortnite", "My very first Stream in this streaming community", categoriesThomas);
  197.         StreamBot sb = new StreamBot("Sb", Thomas, streamOfThomas);
  198.         Thomas.botsList.add(sb);
  199.        
  200.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  201.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ STREAMER 2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  202.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  203.         ArrayList <String> socialsNinja = new ArrayList <String> ();
  204.         socialsNinja.add("Facebook: Tyler Blevins Official");
  205.         socialsNinja.add("Instagram: ninja");
  206.         socialsNinja.add("Twitter: ninja_official");
  207.         Streamer Ninja = new Streamer("Tyler Blevins", "Ninja", "American",  27, socialsNinja);
  208.         // Create the bots of this channel
  209.         NightBot nb2 = new NightBot("Nb2", Ninja);
  210.         Ninja.botsList.add(nb2);
  211.         PlayBot pb2 = new PlayBot("Pb2", Ninja);
  212.         Ninja.botsList.add(pb2);
  213.        
  214.         ArrayList <String> categoriesNinja = new ArrayList <String> ();
  215.         categoriesNinja.add("Shooters Games");
  216.         categoriesNinja.add("Up to 18");
  217.         categoriesNinja.add("Battle Royale Game");
  218.         categoriesNinja.add("Multiplayer");
  219.         Stream streamOfNinja = new Stream(Ninja, "Fortnite", "Chilling with the squad", categoriesNinja);
  220.         StreamBot sb2 = new StreamBot("Sb2", Ninja, streamOfNinja);
  221.         Ninja.botsList.add(sb2);
  222.        
  223.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  224.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ STREAMER 3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  225.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  226.         ArrayList <String> socialsShroud = new ArrayList <String> ();
  227.         socialsShroud.add("Facebook: Michael Grzesiek Official");
  228.         socialsShroud.add("Instagram: shroud_official");
  229.         socialsShroud.add("Twitter: shroud");
  230.         Streamer Shroud = new Streamer("Michael Grzesiek", "Shroud", "American/Canadian",  25, socialsShroud);
  231.         // Create the bots of this channel
  232.         NightBot nb3 = new NightBot("Nb3", Shroud);
  233.         Shroud.botsList.add(nb3);
  234.         PlayBot pb3 = new PlayBot("Pb3", Shroud);
  235.         Shroud.botsList.add(pb3);
  236.        
  237.         ArrayList <String> categoriesShroud = new ArrayList <String> ();
  238.         categoriesShroud.add("Shooters Games");
  239.         categoriesShroud.add("Teen-rated Stream");
  240.         categoriesShroud.add("First Person Shooters");
  241.         categoriesShroud.add("Multiplayer");
  242.         Stream streamOfShroud = new Stream(Shroud, "Call Of Duty: Modern Warframe", "I'm trying the new golden AK47 in COD MW", categoriesShroud);
  243.         StreamBot sb3 = new StreamBot("Sb3", Shroud, streamOfShroud);
  244.         Shroud.botsList.add(sb3);
  245.        
  246.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  247.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ STREAMER 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  248.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  249.         ArrayList <String> socialsTfue = new ArrayList <String> ();
  250.         socialsTfue.add("Facebook: Turner Ellis Tenney");
  251.         socialsTfue.add("Instagram: Tfue");
  252.         socialsTfue.add("Twitter: Official_Tfue");
  253.         Streamer Tfue = new Streamer("Turner Ellis Tenney", "Tfue", "American",  21, socialsTfue);
  254.         // Create the bots of this channel
  255.         NightBot nb4 = new NightBot("Nb4", Tfue);
  256.         Tfue.botsList.add(nb4);
  257.         PlayBot pb4 = new PlayBot("Pb4", Tfue);
  258.         Tfue.botsList.add(pb4);
  259.        
  260.         ArrayList <String> categoriesTfue = new ArrayList <String> ();
  261.         categoriesTfue.add("Shooters Games");
  262.         categoriesTfue.add("Teen-rated Stream");
  263.         categoriesTfue.add("English");
  264.         categoriesTfue.add("Multiplayer");
  265.         Stream streamOfTfue = new Stream(Tfue, "Fortnite", "Fortnite Pro Scrims: Friday Nite Squad Cash Cup", categoriesTfue);
  266.         StreamBot sb4 = new StreamBot("Sb4", Tfue, streamOfTfue);
  267.         Tfue.botsList.add(sb4);
  268.        
  269.        
  270.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  271.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  272.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  273.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  274.        
  275.        
  276.         // *************************************************************************************************************************
  277.         // *************************************************************************************************************************
  278.         // *************************************************************************************************************************
  279.         // *************************************************************************************************************************
  280.        
  281.         Scanner scanner2 = new Scanner(System.in);
  282.        
  283.         // First ask the username
  284.         System.out.println("Hello user! Please type down 0 or 1 to select: ");
  285.         System.out.println("0. Free use of our streaming community without the need of logging in.");
  286.         System.out.println("1. You will have to enter username and password to create an account and use our streaming services.");
  287.         System.out.println();
  288.         System.out.println("In both cases, you will the ability to communicate with streamer and chat and write some commands to their bots");
  289.         System.out.println("in order to play games or learn some info for them.");
  290.         System.out.println();
  291.         // Create the 3 basic variables for our purpose (log in)
  292.         String username;
  293.         String password;
  294.         String passwordForConfirmation;
  295.         // Read the user's input
  296.         System.out.print("Select (0 or 1): ");
  297.         int firstChoice = scanner2.nextInt();
  298.         while(firstChoice != 0 && firstChoice != 1) {
  299.             System.out.print("Select (0 or 1): ");
  300.             firstChoice = scanner2.nextInt();
  301.         }
  302.         // At the end of the while-loop, the variable "firstChoice" has the value 0 or the value 1!
  303.         if(firstChoice == 0) {
  304.             System.out.println();
  305.             System.out.println();
  306.             System.out.println();
  307.             System.out.println("So, you chose " + firstChoice + " and that means you will use our streaming services anonymously.");
  308.             System.out.println("Your username is 'User 0' and you have no password for logging in.");
  309.             username = "User 0";
  310.             password = "";
  311.             passwordForConfirmation = "";
  312.         }   // END OF IF-CASE <----> FOR GUEST USERS
  313.        
  314.         else {
  315.             System.out.println();
  316.             System.out.println();
  317.             System.out.println();
  318.             System.out.println("So, you chose " + firstChoice + " and that means that you are going to enter a username and a password.");
  319.             System.out.print("Please type down your username: ");
  320.             // Den diavazei tin prwti eisodo o scanner, opote apodidw tin prwti kai adiavasti eisodo se mia asxeti metavliti
  321.             String toKanwGtDENDiavazeiTinPrwtiEisodo = scanner2.nextLine();
  322.             username = scanner2.nextLine();
  323.             System.out.print("Now, enter your password: ");
  324.             password = scanner2.nextLine();
  325.            
  326.             // Now, I want the password to be confirmed by the user
  327.             int mistakes = 0;
  328.             while(mistakes < 3) {
  329.                 System.out.print("Confirm password: ");
  330.                 passwordForConfirmation = scanner2.nextLine();
  331.                 if(password.equals(passwordForConfirmation)) {
  332.                     System.out.println("Brilliant. Welcome to our streaming community Mr " + username);
  333.                     break;
  334.                 }
  335.                 else {
  336.                     mistakes++;
  337.                 }
  338.             }   // END OF WHILE-LOOP
  339.            
  340.             if(mistakes == 3) {
  341.                 username = "User 0";
  342.                 System.out.println("You have entered the wrong password 3 times. So, you will continue as 'User 0' and will have no password");
  343.             }  
  344.    
  345.         }   // END OF ELSE-STATEMENT <----> FOR PASSWORD USERS
  346.        
  347.         System.out.println();
  348.         System.out.println();
  349.         Scanner scanner = new Scanner(System.in);
  350.        
  351.        
  352.         // Ask the user to select which stream he wants to watch
  353.         System.out.println("Hello " + username + "! Please type down 1,2,3 or 4 to select which stream you want to watch:");
  354.         System.out.println("1. " + Thomas.nameOfChannel + ": " + streamOfThomas.title);
  355.         System.out.println("2. " + Ninja.nameOfChannel + ": " + streamOfNinja.title);
  356.         System.out.println("3. " + Shroud.nameOfChannel + ": " + streamOfShroud.title);
  357.         System.out.println("4. " + Tfue.nameOfChannel + ": " + streamOfTfue.title);
  358.         System.out.println();
  359.        
  360.         System.out.print("Select (1,2,3 or 4): ");
  361.         int streamChoice = scanner.nextInt();
  362.         Streamer streamerChoice;
  363.         Stream streamOfStreamer;
  364.         while(streamChoice != 1 && streamChoice != 2 && streamChoice != 3 && streamChoice != 4) {
  365.             System.out.print("Select (1,2,3 or 4): ");
  366.             streamChoice = scanner.nextInt();
  367.         }
  368.         switch(streamChoice) {
  369.             case 1:
  370.                 streamerChoice = Thomas;
  371.                 streamOfStreamer = streamOfThomas;
  372.                 streamOfStreamer.viewers += 1;          // Because user just started watching the stream
  373.                 break;
  374.             case 2:
  375.                 streamerChoice = Ninja;
  376.                 streamOfStreamer = streamOfNinja;
  377.                 streamOfStreamer.viewers += 1;          // Because user just started watching the stream
  378.                 break;
  379.             case 3:
  380.                 streamerChoice = Shroud;
  381.                 streamOfStreamer = streamOfShroud;
  382.                 streamOfStreamer.viewers += 1;          // Because user just started watching the stream
  383.                 break;
  384.             case 4:
  385.                 streamerChoice = Tfue;
  386.                 streamOfStreamer = streamOfTfue;
  387.                 streamOfStreamer.viewers += 1;          // Because user just started watching the stream
  388.                 break;
  389.             default:
  390.                 streamerChoice = new Streamer();
  391.                 streamOfStreamer = new Stream();
  392.                 streamOfStreamer.viewers += 1;          // Because user just started watching the stream
  393.                 break;
  394.         }
  395.        
  396.        
  397.         // **********************************************************************************************
  398.         // *************** An unused variable in order to solve the problem *****************************
  399.         String paliDiavazeiMiaTzampaEisodo = scanner.nextLine();
  400.         // **********************************************************************************************
  401.         // **********************************************************************************************
  402.        
  403.         // Some declarations after entering in a stream
  404.         System.out.println();
  405.         System.out.println();
  406.         System.out.println();
  407.         System.out.println();
  408.         System.out.println();
  409.         System.out.println();
  410.         System.out.println();
  411.         App app2 = new App();
  412.         app2.createLandscapeAsImage(streamOfStreamer);
  413.         System.out.println();
  414.         System.out.println();
  415.         System.out.println();
  416.         System.out.println();
  417.         System.out.println();
  418.         System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  419.         System.out.println("                    CHANNEL " + streamOfStreamer.streamer.nameOfChannel);
  420.         System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  421.        
  422.         // Create the contact between the user and the streamers' bots
  423.         String userInput = "";
  424.        
  425.         while(userInput.equals("stop") == false && userInput.equals("logout") == false && userInput.equals("!stop") == false && userInput.equals("!logout") == false) {
  426.            
  427.             System.out.println(app2.selectRandomTalk(streamOfStreamer));
  428.            
  429.             // System.out.println("Write a command: ");
  430.             System.out.print(username + ": ");
  431.             userInput = scanner.nextLine();
  432.            
  433.             // Now, I have some input/command from the user
  434.             // I want to check if this is a valid command or not
  435.             // First, I have to remember that botsList can contain 4 different types of variables
  436.             // 1. NightBot, 2. PlayBot or 3. StreamBot and 4. Bot (the first class and superclass of the other bots)
  437.             boolean isValidCommand = false;
  438.             for(int i=0; i<streamerChoice.botsList.size(); i++){
  439.                 // For every bot in botsList of the streamer
  440.                 Bot bot = streamerChoice.botsList.get(i);
  441.                 // Variable "bot" can also be --OR-- NightBot --OR-- PlayBot --OR-- simple Bot
  442.                 if(bot instanceof PlayBot){
  443.                     ArrayList <String> commands = ((PlayBot) bot).commands;
  444.                     for(int j=0; j<commands.size(); j++){
  445.                         // System.out.println(commands.get(j));
  446.                         if(userInput.equals(commands.get(j))){
  447.                             // That means this is a valid command for NightBot
  448.                             // So, we have to call the function "select...." with argument = commands.get(j). With this argument
  449.                             // the correct function will be called
  450.                             isValidCommand = true;
  451.                             System.out.print("    PlayBot answers: ");
  452.                             ((PlayBot) bot).selectMethodByCommand(commands.get(j));
  453.                             break;
  454.                         }
  455.                     }
  456.                 }   // END OF IF-CASE FOR PLAYBOT CLASS
  457.                
  458.                 else if(bot instanceof NightBot){
  459.                     ArrayList <String> commands = ((NightBot) bot).commands;
  460.                     for(int j=0; j<commands.size(); j++){
  461.                         // System.out.println(commands.get(j));
  462.                         if(userInput.equals(commands.get(j))){
  463.                             // That means this is a valid command for NightBot
  464.                             // So, we have to call the function "select...." with argument = commands.get(j). With this argument
  465.                             // the correct function will be called
  466.                             isValidCommand = true;
  467.                             System.out.print("    NightBot answers: ");
  468.                             ((NightBot) bot).selectMethodByCommand(commands.get(j));
  469.                             break;
  470.                         }
  471.                     }
  472.                 }   // END OF ELSE-IF-CASE FOR NIGHTBOT CLASS
  473.                
  474.                
  475.                 else if(bot instanceof StreamBot){
  476.                     ArrayList <String> commands = ((StreamBot) bot).commands;
  477.                     for(int j=0; j<commands.size(); j++){
  478.                         // System.out.println(commands.get(j));
  479.                         if(userInput.equals(commands.get(j))){
  480.                             // That means this is a valid command for NightBot
  481.                             // So, we have to call the function "select...." with argument = commands.get(j). With this argument
  482.                             // the correct function will be called
  483.                             isValidCommand = true;
  484.                             System.out.print("    StreamBot answers: ");
  485.                             ((StreamBot) bot).selectMethodByCommand(commands.get(j));
  486.                             break;
  487.                         }
  488.                     }
  489.                    
  490.                     // IF USERINPUT = UPTIME
  491.                     if(userInput.equals("!uptime")) {
  492.                         int secondsInitially = ((StreamBot) bot).uptime();
  493.                         long secondsOfRunningApp = System.currentTimeMillis();
  494.                         long elapsedTimeApp = secondsOfRunningApp - startTime;
  495.                         int uptimeSeconds = (int)(elapsedTimeApp / 1000F) + secondsInitially;
  496.                         App app = new App();
  497.                         app.convertTime(uptimeSeconds);
  498.                     }
  499.                        
  500.                 }   // END OF ELSE-IF-CASE FOR STREAMBOT CLASS
  501.                
  502.                
  503.             }   // END OF FOR-LOOP      SCANS THE BOTSLIST OF THE STREAMER
  504.            
  505.            
  506.             // Scanning for bots' commands has just ended
  507.             // There is a possibility for the given command to be invalid
  508.             boolean iHaveToStop = (userInput.equals("stop") == true) || (userInput.equals("logout") == true) || (userInput.equals("!stop") == true) ||(userInput.equals("!logout") == true);
  509.             // The above variable becomes true, when userInput = "!stop" OR "stop" OR "!logout" OR "logout"
  510.             // Then, I have to display some kind of message
  511.             if(isValidCommand == false && iHaveToStop == true) {
  512.                 System.out.println("You have successfully logged out! You cannot watch streams or communicate with others until you log in again!");
  513.                 // Time to stop the programme
  514.                 // First, I will close the Scanner instance named "scanner"
  515.                 scanner.close();
  516.                 long endTime = System.currentTimeMillis();
  517.                 long elapsedTimeInMillis = endTime - startTime;
  518.                 int elapsedTimeInSeconds = (int) (elapsedTimeInMillis / 1000F);
  519.                 if(elapsedTimeInSeconds < 60) {
  520.                     System.out.println("(You had been connected for " + elapsedTimeInSeconds + " seconds)");
  521.                 }
  522.                 else {
  523.                     int minutesLoggedIn = (int) (elapsedTimeInSeconds / 60);
  524.                     int secondsLoggedIn = elapsedTimeInSeconds % 60;
  525.                     System.out.println("(You had been connected for " + minutesLoggedIn + " minutes and " + secondsLoggedIn + " seconds).");
  526.                 }
  527.                
  528.             }   //  END OF IF-CASE      WHEN I TYPE "STOP" OR "LOGOUT" IN CONSOLE
  529.            
  530.             else if(isValidCommand == false && iHaveToStop == false) {
  531.                 // System.out.println("Invalid command (" + userInput + "). Try another command and notice that a common mistake is that some forget to write '!' first!");
  532.             }
  533.             System.out.println();
  534.             // System.out.println();
  535.            
  536.         }   // END OF WHILE-LOOP <-------------------> TAKES ALWAYS NEW COMMANDS
  537.            
  538.         System.exit(0);
  539.        
  540. }   // END OF MAIN FUNCTION
  541.  
  542.    
  543.    
  544. }   // END OF CLASS APP = MAIN FUNCTION OF THE PROJECT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement