Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Card Game

Comments in 'Plugin Development' started by FlamingGenius, Oct 12, 2015.

  1. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    I was working on a card game for just because i was bored and thought this might actually be interesting for a plugin

    So heres a little snippet of the code(in web development form)

    Could this work in a plugin as is? With the exception of changing echo to sendMessage
    PHP:
    <?php

    class cardGame{

    public 
    $deck;
    public 
    $faces;
    public 
    $suits;

    public function 
    cards(){
      
    $suits = array(
       
    "spades","hearts","clovers","diamonds"
       
    );
      
    $faces = array(
       
    "ace","one","two","three","four","five","six",
       
    "seven","eight","nine","ten","jack","queen",
       
    "king"
       
    );
    }
    public function 
    Deck(){

      
    $deck = array();

      foreach(
    $suits as $suit){
       foreach(
    $faces as $face){
        
    $deck[] = array("face"=>$face"suit"=>$suit);
       }
      }
    }

    public function 
    Shuffle(){
      
    shuffle($deck);
    }

    public function 
    Draw(){
      
    $draw array_shift($deck);
      echo 
    $draw['face'] . "of" $draw['suit'];
    }

    }

    EDIT:

    So i went ahead and coded up what i believe would be the interpetation of this into OOP but in a lottery type of game instead of cards (bc obviously i cant have physical carda in mcpe)

    PHP:
    <?php

    namespace FlamingGenius\Lottery;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;

    class 
    Lottery extends PluginBase{

    public function 
    onEnable(){
      
    $this->saveDefaultConfig();
    }

    public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
      
    $cmd $this->command->getName();
      
    $winT $this->getConfig()->get("winning-number");
      if(
    strtolower($cmd) == "lottery"){
       
    $numbers = array(
       
    "4062","2332","1127","1975",
       
    "8458","9883","4762","3038",
       
    "8459","7111","3858","8814",
       );

     
       
    $draw array_rand($numbers);
     
       
    $ticket $numbers[$draw];
     
       
    $sender->sendMessage("Your ticket number is" " " $ticket);
       if(
    $ticket == $winT){
        
    $player $this->getServer()->getPlayer()->getName();
        
    $this->getServer()->broadcastMessage($player " " "Got a winning lottery ticket");
       }
       else{
        
    $sender->sendMessage("Sorry your ticket is not a winning number");
       }
      }
    }



    }





    ?>
    Last edited: Oct 12, 2015
  2. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    ???
    Learn PHP. He created his own function -_-
    Taha_The_Hacker, LDX and PEMapModder like this.
  3. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    First time i read this i thought you were telling me to learn php XD i was abt to say excuse me i know PHP XD
    LDX and Legoboy0215 like this.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Hardcode winning numbers? Bad bad bad idea. This is as bad as this:
    [​IMG]
    Why not this?
    PHP:
    $winNumber str_pad(mt_rand(09999), 4"0"STR_PAD_LEFT);
    LDX likes this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Let's simulate what will happen here.
    PHP:
       $numbers = array(
       
    "4062","2332","1127","1975",
       
    "8458","9883","4762","3038",
       
    "8459","7111","3858","8814",
       );


       
    $draw array_shift($numbers);

       
    $ticket $numbers[$draw];
    The second statement takes the first number from the array.
    so $draw is "4062"
    The third statement takes the #$draw (#4062) element from $numbers, which does not exist.
    End of story.

    Moreover, starting from the 3rd element ($numbers[2]) onwards, they aren't used at all. Remember that it is a local variable, and it gets redefined every time the function runs. Learn PHP.
  6. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    I realized this after i ran my code and changed it to this
    PHP:
    $draw array_rand($numbers);

    $ticket $numbers[$draw];
    And i removed the foreach... Part because it was unused coding but i appreciate ur thoughtful help ;)
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Is there any difference? $numbers is still $numbers.
  8. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    Your ignorance is quite baffling considering you have created so many plugins and seem to be well edcuated so this is what i want you to do for me since this is im guessing by your standards "wrong" heres the snippet in question i added echo $ticket; to the script i want you to run this code 5 times and then i want you to paste the results on here okay ;)

    PHP:
    <?php

    $numbers 
    = array(
       
    "4062","2332","1127","1975",
       
    "8458","9883","4762","3038",
       
    "8459","7111","3858","8814",
       );

       
       
    $draw array_rand($numbers);
       
       
    $ticket $numbers[$draw];
       echo 
    $ticket;
       
    ?>
  9. XEmAX32
    Offline

    XEmAX32 Active Member

    Joined:
    Feb 1, 2015
    Posts:
    80
    Minecraft User:
    XEmAX32
  10. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    What was the point of this?
  11. XEmAX32
    Offline

    XEmAX32 Active Member

    Joined:
    Feb 1, 2015
    Posts:
    80
    Minecraft User:
    XEmAX32
    I'm joking -.-
  12. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    Because when @PEMapModder comes back online...
  13. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    I dont get the joke
  14. CavinMiana
    Offline

    CavinMiana Active Member

    Joined:
    Aug 26, 2015
    Posts:
    101
    Minecraft User:
    CavinMiana
    Basically your dead lol
    LDX and Taha_The_Hacker like this.
  15. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    I dont see why
  16. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Armageddon...
    You will get the joke when he comes back on... Hehehe...
    Lol, this ain't the first time someones done something like this... ;)
    LDX likes this.
  17. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    Not sure what i did
    LDX likes this.
  18. CavinMiana
    Offline

    CavinMiana Active Member

    Joined:
    Aug 26, 2015
    Posts:
    101
    Minecraft User:
    CavinMiana
    Lol
    LDX likes this.
  19. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Technically you fired the first shot in the next flame wars. :p
    LDX likes this.
  20. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    Ahhh so i see...well its obvious what is happenin in the code his comments were very ignorant(trying to be polite) because he did not use common sense
    Also he was online when i said this earlier and he said nothing back :p #win

    And i still not getting flame wars?

Share This Page

Advertisement