package com.hotmail.kalebmarc.textfighter.casino;

import com.hotmail.kalebmarc.textfighter.main.Casino;
import com.hotmail.kalebmarc.textfighter.main.Ui;
import com.hotmail.kalebmarc.textfighter.player.Coins;
import com.hotmail.kalebmarc.textfighter.player.Stats;

public abstract class BasicCasinoGame {
    private final String header;
    private final String description;
    private final String options; //Options are the menu options presented to the player
    protected final GameType gameType;

    protected BasicCasinoGame(String header, String description, String options, GameType gameType) {
        this.header = header;
        this.description = description;
        this.options = options;
        this.gameType = gameType;
    }

    /**
     * Subclasses implement this function to create the respective gameplay
     *
     * @param selection The selection made by the user during the menu screen (typically 1)
     * @return The amount of coins added to the player's inventory. Negative values result in doing nothing. This also includes not increasing the play count etc
     */
    public abstract int play(int selection);

    /**
     * Starts the game loop. Ui pauses automatically after each playthrough
     */
    public void start(){
        while (true) {
            Ui.cls();
            Ui.println(header);
            Ui.println("     Coins: " + Coins.get());
            Ui.println("------------------------------------------------------------------");
            Ui.println("                           How to play                            ");
            Ui.println();
            Ui.println(description);
            Ui.println("------------------------------------------------------------------");
            Ui.println(options);
            Ui.println("------------------------------------------------------------------");

            int menuChoice = Ui.getValidInt();

            switch (menuChoice) {
                case 1:
                    int coinsWon = play(menuChoice); // Determines what to do after a played game
                    if(coinsWon >= 0){
                        Coins.set(coinsWon, true);
                        Casino.totalCoinsWon += coinsWon;
                        Casino.gamesPlayed++;

                        switch (gameType){ // Determines which stat to increase
                            case DICE:
                                Stats.diceGamesPlayed++;
                                break;
                            case SLOTS:
                                Stats.slotGamesPlayed++;
                                break;
                            case BLACKJACK:
                                Stats.blackjackGamesPlayed++;
                            case LOTTO:
                                Stats.lotteryTicketsBought++;
                        }

                        Ui.pause();
                    }
                    break;
                case 2:
                    return;
                default:
                    break;
            }
        }
    }

    public String getDescription() {
        return description;
    }

    public String getHeader() {
        return header;
    }

    public String getOptions() {
        return options;
    }
}

@@ -1230,39 +1230,182 @@
 ough
-%0A     */%0A    public void start(
+. The exit option is determined by the getExitEntry() method%0A     */%0A    public void start()%7B%0A        this.start(getExitEntry());%0A    %7D%0A%0A    private void start(int exitOption
 )%7B%0A 
@@ -2067,22 +2067,18 @@
         
-switch
+if
  (menuCh
@@ -2085,40 +2085,43 @@
 oice
-) %7B%0A                case 1:%0A    
+ %3C exitOption && menuChoice %3E 0) %7B%0A
     
@@ -2226,22 +2226,19 @@
         
-    
 if
+ 
 (coinsWo
@@ -2244,16 +2244,17 @@
 on %3E= 0)
+ 
 %7B%0A      
@@ -2267,20 +2267,16 @@
         
-   
- 
 Coins.se
@@ -2294,20 +2294,16 @@
  true);%0A
-    
         
@@ -2372,39 +2372,135 @@
     
-    Casino.gamesPlayed++;%0A%0A    
+if (!gameType.equals(GameType.LOTTO))%0A                        Casino.gamesPlayed++; // Only increases stat for playable games%0A%0A
     
@@ -2532,16 +2532,17 @@
 ameType)
+ 
 %7B // Det
@@ -2592,28 +2592,24 @@
             
-    
 case DICE:%0A 
@@ -2631,28 +2631,24 @@
             
-  
-  
 Stats.diceGa
@@ -2680,36 +2680,32 @@
                 
-    
 break;%0A         
@@ -2715,28 +2715,24 @@
             
-  
-  
 case SLOTS:%0A
@@ -2731,20 +2731,16 @@
  SLOTS:%0A
-    
         
@@ -2808,39 +2808,31 @@
             
-  
-  
 break;%0A
-    
             
@@ -2859,20 +2859,16 @@
 CKJACK:%0A
-    
         
@@ -2937,28 +2937,24 @@
             
-    
 case LOTTO:%0A
@@ -2977,28 +2977,24 @@
             
-  
-  
 Stats.lotter
@@ -3031,20 +3031,16 @@
         
-    
 %7D%0A%0A     
@@ -3050,28 +3050,24 @@
             
-  
-  
 Ui.pause();%0A
@@ -3074,32 +3074,38 @@
             
+    %7D%0A
         
 %7D%0A          
@@ -3088,30 +3088,67 @@
   %7D%0A        
-%7D%0A
     
+%7D else if (menuChoice == exitOption) %7B%0A
             
@@ -3143,37 +3143,38 @@
                 
-b
 re
-ak
+turn
 ;%0A              
@@ -3175,129 +3175,310 @@
     
+%7D%0A
     
-case 2:%0A
+ 
    
+%7D%0A
     
+%7D%0A%0A
     
+/**%0A
      
+*
   
-  return;%0A                default:
+Used to determine the exit entry of the game menu. All options numerically below this one are
 %0A     
+*
   
-             break;%0A            %7D%0A        %7D%0A    %7D
+given to the play function.%0A     * @return int The option the user has to pick in order to exit to the casino menu%0A     */%0A    protected abstract int getExitEntry();
 %0A%0A  

add support for custom exit option in BasicCasinoGame