Advertisement
Guest User

Thoughts on panagram code.

a guest
Sep 21st, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. //Panagrams. Do not use yet, the anagram function has to be implemented first.
  2.  
  3. panagram: function(target, room, user) {
  4. if (!this.can('broadcast')) return false;
  5. if (room.panagram) return this.sendReply('There is already a game of Panagram going on.');
  6.  
  7.  
  8. /******* Start *******/
  9. /* var pokedex = [];
  10. for (var i in Tools.data.Pokedex) {
  11. if (Tools.data.Pokedex[i].num > 0) {
  12. pokedex.push(i); // This is pushing the index value...
  13. }
  14. }
  15. var poke = pokedex[Math.floor(Math.random() * pokedex.length)]; // This I believe is picking a number, not a name.
  16. */
  17. /******* End *******/
  18. /* This whole thing could be replaced with
  19.  
  20. var poke = Tools.data.Pokedex[Math.floor(Math.random() * Tools.data.Pokedex.length)]; ? This picks a name, not a number.
  21.  
  22. This is assuming Tools.data.Pokedex is an array of the pokemon names.
  23. As it seems you are caching the pokedex which doesn't need to be done.
  24. It causes the for loop to run 719 times.
  25. If you're going to cache the pokedex, then use pokedex instead of Tool.data.Pokedex in later code (which will reduce processing).
  26. */
  27.  
  28.  
  29. var panagram = this.anagram(poke);
  30. //^^^^^^^ Following my understanding, this is rearranging numbers, not a pokemon when name using your method.
  31. var mixedup = panagram[Math.floor(Math.random() * panagram.length)];
  32. // Doesn't anagram already mix it up? So why the extra mixup?
  33.  
  34.  
  35. /***** The rest looks fine *******/
  36.  
  37. this.add('|html|<div class = "infobox"><center><b>A game of Panagram has been started!</b><br/>' +
  38. 'The scrambled word is <b>' + mixedup + '</b><br/>' +
  39. '<font size = 1>Type in <b>/guessp or /guesspoke [pokemon]</b> to guess the pokemon!');
  40. room.panagram = {};
  41. room.panagram.guessed = [];
  42. room.panagram.chances = 2;
  43. room.panagram.answer = toId(poke);
  44. },
  45.  
  46. guesspoke: 'guessp',
  47. guessp: function(target, room, user, cmd) {
  48. if (!room.panagram) return this.sendReply('There is no game of Panagram going on in this room.');
  49. if (room.panagram[user.userid]) return this.sendReply("You've already guessed once!");
  50. if (!target) return this.sendReply("The proper syntax is /guessp [pokemon]");
  51. if (!Tools.data.Pokedex[toId(target)]) return this.sendReply("'" + target + "' is not a valid pokemon.");
  52. if (Tools.data.Pokedex[toId(target)].num < 1) return this.sendReply(Tools.data.Pokedex[toId(target)] + ' is either an illegal or a CAP Pokemon. These Pokemon are not used in Panagrams.');
  53. if (room.panagram.guessed.indexOf(toId(target)) > -1) return this.sendReply("That Pokemon has already been guessed!");
  54. if (room.panagram.answer == toId(target)) {
  55. this.add('|html|<b>' + user.name + '</b> guessed <b>' + Tools.data.Pokedex[toId(target)].species + '</b>, which was the correct answer! Congratulations!');
  56. delete room.panagram;
  57. } else {
  58. if (room.panagram.chances > 0) {
  59. this.add('|html|<b>' + user.name + '</b> guessed <b>' + Tools.data.Pokedex[toId(target)].species + '</b>, but was not the correct answer...');
  60. room.panagram[user.userid] = toId(target);
  61. room.panagram.guessed.push(toId(target));
  62. room.panagram.chances--;
  63. } else {
  64. this.add('|html|<b>' + user.name + '</b> guessed <b>' + Tools.data.Pokedex[toId(target)].species + '</b>, but was not the correct answer. You have failed to guess the Pokemon, which was <b>' + Tools.data.Pokedex[room.panagram.answer].species + '</b>');
  65. delete room.panagram;
  66. }
  67. }
  68. },
  69.  
  70. panagramend: 'endpanagram',
  71. endpanagram: function(target, room, user) {
  72. if (!room.panagram) return this.sendReply('There is no panagram game going on in this room yet.');
  73. this.add("|html|<b>The game of Panagram has been ended.</b>");
  74. delete room.panagram;
  75. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement