kecske123

OOP is disgusting

Jan 4th, 2020
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.83 KB | None | 0 0
  1. Old solution
  2.  
  3. <?php
  4. require("modprot");
  5. class KPO
  6. {
  7.         public $moduleID = -1;
  8.         protected $kpo = array();
  9.  
  10.         public function OnBotCommand($uid, $source, $command, $params)
  11.         {
  12.                 switch ($command)
  13.                 {
  14.                         case "kpo":
  15.                         $chose=array('ko', 'papir', 'ollo');
  16.                         $beats=array('ollo' => 'papir', 'papir' => 'ko', 'ko' => 'ollo');
  17.                         if (!in_array($params, $chose)):
  18.                                 privmsg ($source, "Használat: !kpo ko|papir|ollo");
  19.                                 break;
  20.                         endif;
  21.                         $my = $chose[rand(0,count($chose)-1)];
  22.                         $your = $params;
  23.                         if (empty($this->kpo[$uid])):
  24.                                 $this->kpo[$uid]['Beats'] = 0;
  25.                                 $this->kpo[$uid]['Wins'] = 0;
  26.                         endif;
  27.                         if ($beats[$my] == $your):
  28.                                 $this->kpo[$uid]['Beats'] = $this->kpo[$uid]['Beats'] + 1;
  29.                                 privmsg ($source, User($uid)->Nick.": ".$your." ".User(-2)->Nick.": ".$my." - NYERTEM! (".User($uid)->Nick.": ".$this->kpo[$uid]['Wins']." győzelem, ".$this->kpo[$uid]['Beats']." vereség)");
  30.                                 break;
  31.                         endif;
  32.                         if ($beats[$your] == $my):
  33.                                         $this->kpo[$uid]['Wins'] = $this->kpo[$uid]['Wins'] + 1;
  34.                                         privmsg ($source, User($uid)->Nick.": ".$your." ".User(-2)->Nick.": ".$my." - NYERTÉL! (".User($uid)->Nick.": ".$this->kpo[$uid]['Wins']." győzelem, ".$this->kpo[$uid]['Beats']." vereség)");
  35.                                         break;
  36.                         endif;
  37.                         if ($your == $my):
  38.                                         privmsg ($source, User($uid)->Nick.": ".$your." ".User(-2)->Nick.": ".$my." - döntetlen. (".User($uid)->Nick.": ".$this->kpo[$uid]['Wins']." győzelem, ".$this->kpo[$uid]['Beats']." vereség)");
  39.                                         break;
  40.                         endif;
  41.                         break;
  42.                  }
  43.         }
  44. }
  45. $newmod = new KPO();
  46.  
  47. $cmds = array('!kpo');
  48. ?>
  49.  
  50. New solution
  51. <?php
  52.  
  53. class KPO2
  54. {
  55.         public $moduleID = -1;
  56.  
  57.         public function cmd_kpo($uid, $source, $params)
  58.         {
  59.                 if (KPO::$INVALID_WEAPON == ($weapIDPlayer = KPO::WeaponID($params)))
  60.                         return privmsg($source, User($uid)->Nick.": tiltott fegyver!");
  61.                 $weapIDBot = KPO::RandomWeapon();
  62.  
  63.                 $msg = User($uid)->Nick.": " . KPO::WeaponName($weapIDPlayer);
  64.                 $msg .= " ".User(-2)->Nick.": " . KPO::WeaponName($weapIDBot);
  65.                 $msg .= " - ";
  66.                 if ($weapIDBot == $weapIDPlayer)
  67.                 {
  68.                         UserStore::Call('IncEntry', $uid, 'kpo/games/tie');
  69.                         $msg .= "döntetlen.";
  70.                 }
  71.                 else
  72.                 {
  73.                         if (KPO::IsBeat($weapIDPlayer, $weapIDBot))
  74.                         {
  75.                                 $msg .= "NYERTÉL!";
  76.                                 UserStore::Call("IncEntry", $uid, "kpo/games/win");
  77.                         }
  78.                         else
  79.                         {
  80.                                 $msg .= "NYERTEM!";
  81.                                 UserStore::Call('IncEntry', $uid, "kpo/games/lose");
  82.                         }
  83.                 }
  84.                 $msg .= " (" . User($uid)->Nick . ": " . UserStore::Call('GetEntry', $uid, 'kpo/games/win', 0) . " győzelem, " . UserStore::Call('GetEntry', $uid, 'kpo/games/lose', 0) . " vereség)";
  85.                 privmsg($source, $msg);
  86.         }
  87.         public function usage_kpo()
  88.         {
  89.                 return [ 'desc' => 'Kő-Papír-Olló játék',
  90.                         'usage' => [['fegyvernem' => true]]
  91.                 ];
  92.         }
  93. }
  94.  
  95. class KPO
  96. {
  97.         public static $INVALID_WEAPON = -1;
  98.  
  99.         public static function IsBeat($Attacker, $Victim)
  100.         {
  101.                 return self::$Weapons[$Attacker]['beats'] == $Victim;
  102.         }
  103.  
  104.         public static function WeaponName($WeaponID)
  105.         {
  106.                 return self::$Weapons[$WeaponID]['name'];
  107.         }
  108.  
  109.         public static function WeaponID($WeaponName)
  110.         {
  111.                 $WeaponName = mb_strtolower($WeaponName);
  112.                 foreach (self::$Weapons as $WeaponID => $WeaponData)
  113.                 {
  114.                         if (in_array($WeaponName, $WeaponData['aliases']))
  115.                                 return $WeaponID;
  116.                 }
  117.                 return self::$INVALID_WEAPON;
  118.         }
  119.  
  120.         public static function RandomWeapon()
  121.         {
  122.                 return Veletlenszam(0, count(self::$Weapons)-1);
  123.         }
  124.  
  125.         public static $Weapons = [
  126.                 0 => [
  127.                         'name' => 'kő',
  128.                         'aliases' => ['ko', 'kö', 'kô', 'kő', 'kavics', 'szikla', 'rock', 'stone'],
  129.                         'beats' => 2
  130.                 ],
  131.                 1 => [
  132.                         'name' => 'papír',
  133.                         'aliases' => ['papir', 'papír', 'papirusz', 'papirusztekercs', 'lap', 'újság', 'könyv', 'konyv', 'ujsag', 'tekercs', 'pergamen', 'irat', 'iromány', 'iromany', 'paper', 'sheet'],
  134.                         'beats' => 0
  135.                 ],
  136.                 2 => [
  137.                         'name' => 'olló',
  138.                         'aliases' => ['ollo', 'olló', 'kés', 'kes', 'scissors', 'vago', 'vágó', 'penge', 'él', 'el', 'blade', 'cut'],
  139.                         'beats' => 1
  140.                 ]
  141.         ];
  142. }
  143.  
  144. $newmod = new KPO2;
  145. ?>
Advertisement
Add Comment
Please, Sign In to add comment