Advertisement
svetlio_top

Wizard Poker

Feb 28th, 2020
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Poker(input){
  2.     let cards = input.shift();
  3.     let InputCards = cards.split(":");
  4.     let command = input.shift();
  5.     let OurDeck=[];
  6.  
  7.         while(command !== 'Ready'){
  8.                  
  9.                 if(command.includes('Add')){
  10.                     let arrCommand = command.split(" ");
  11.                     let CardNameNew = arrCommand[1];
  12.  
  13.                        if(InputCards.includes(CardNameNew)){
  14.  
  15.                           OurDeck.push(CardNameNew);
  16.                          
  17.                        }else{
  18.                            console.log('Card not found.');    
  19.                        }    
  20.                                                  
  21.                     command = input.shift();
  22.  
  23.                 }else if(command.includes('Insert')){
  24.  
  25.                     let arrCommand = command.split(" ");
  26.                     let CardNameNew = arrCommand[1];  
  27.                     let CardIndex = +arrCommand[2];        
  28.  
  29.                     if(InputCards.includes(CardNameNew)){
  30.  
  31.                        OurDeck.splice(CardIndex, 0, CardNameNew)
  32.                        
  33.                      }else{
  34.                          console.log('Error!');    
  35.                      }      
  36.                    
  37.                     command = input.shift();
  38.  
  39.                 }else if(command.includes('Remove')){
  40.                     let arrCommand = command.split(" ");
  41.                     let CardNameNew = arrCommand[1];
  42.  
  43.                     if(OurDeck.includes(CardNameNew)){
  44.  
  45.                         const isVal = (element) => element === CardNameNew;
  46.                         let indexRemove = OurDeck.findIndex(isVal);
  47.                        
  48.                         OurDeck.splice(indexRemove, 1);
  49.                          
  50.                       }else{
  51.                           console.log('Card not found.');    
  52.                       }        
  53.                                                    
  54.                     command = input.shift();
  55.                 }else if(command.includes('Swap')){
  56.  
  57.                     let arrCommand = command.split(" ");
  58.                     let CardName1 = arrCommand[1];  
  59.                     let CardName2 = arrCommand[2];    
  60.  
  61.                     const isCardName1 = (element) => element === CardName1;
  62.                     const isCardName2 = (element) => element === CardName2;
  63.                     let indexCardName1 = OurDeck.findIndex(isCardName1);
  64.                     let indexCardName2 = OurDeck.findIndex(isCardName2);
  65.  
  66.              
  67.                     OurDeck.splice(indexCardName1, 1, CardName2);
  68.                     OurDeck.splice(indexCardName2, 1, CardName1);
  69.                     command = input.shift();
  70.  
  71.                 }else if(command.includes('Shuffle')){
  72.                  
  73.                     OurDeck = OurDeck.reverse();
  74.                     command = input.shift();
  75.  
  76.                 }
  77.              
  78.     }
  79.    
  80.     console.log(OurDeck.join(' '));
  81. }
  82. Poker([
  83.     'Wrath:Pounce:Lifeweaver:Exodia:Aso:Pop',
  84.     'Add Pop',
  85.     'Add Exodia',
  86.     'Add Aso',
  87.     'Remove Wrath',
  88.     'Add SineokBqlDrakon',
  89.     'Shuffle deck',
  90.     'Insert Pesho 0',
  91.     'Ready'
  92.   ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement