当前位置:   article > 正文

一个简易的QQ魔法卡片炼卡消耗计算器_魔法卡片计算器

魔法卡片计算器

昨天晚上做了一个很简单的腾讯网页游戏魔法卡片的炼卡消耗计算器,先放地址:https://coding-pages-bucket-462845-1308815-2934-343840-1251231260.cos-website.ap-hongkong.myqcloud.com/

GIT仓库地址:https://dtid_a67c3477ddaa7b17.coding.net/public/BrowserSupport/QQ/git/files/master/index.html

做这东西的起因是,前端时间魔法卡片搞了周年活动,炼两套《里程征途》的卡,现在活动结束了,我小号上的《里程征途下》的卡差3张辛丑条约就可以炼成,而我大号上有4张辛丑条约,只要换给小号,就可以搞定。

但是我发现我大号上总共有素材卡75张,我就想能不能大号炼一些上面的卡,把小号身上的卡换过来,让大号来集齐这一套卡。于是,打开Excel算了半天,也没算明白身上的卡够不够炼成。就去搜了一下魔法卡片计算器,不过当时搜得匆忙,没有找到好用的,后来做完之后,倒是发现一个很不错的。

本来打算用C#做,后来想想做成微信小程序应该不错,不过最后还是偷了个懒,写成了网页。

代码非常简单,如下:

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>魔法卡片消耗计算器</title>
  6. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
  7. <style>
  8. .table {
  9. width: 100%;
  10. }
  11. .table, .table th, .table td {
  12. border: solid 1px #eee;
  13. border-collapse: collapse;
  14. }
  15. .magic-card {
  16. width: 100px;
  17. height: 160px;
  18. border: solid 2px #888888;
  19. }
  20. .clear-both {
  21. clear: both;
  22. width: 0px;
  23. height: 0px;
  24. overflow: hidden;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <nav aria-label="breadcrumb">
  30. <ol class="breadcrumb">
  31. <li class="breadcrumb-item active" aria-current="page">魔法卡片消耗计算器</li>
  32. </ol>
  33. </nav>
  34. <div class="container-fluid mt-1">
  35. <div class="row">
  36. <div class="col-12">
  37. <div class="form-inline">
  38. 套卡层数:<input class="form-control" type="number" id="numCardLevelCount" min="1" max="15" increment="1" value="3" /><button class="btn btn-primary ml-2" type="button" onclick="createCardSet();">确定</button>
  39. </div>
  40. </div>
  41. </div>
  42. <div class="row mt-1">
  43. <div class="col-12">
  44. <table class="table" id="tblCards">
  45. <thead>
  46. <tr>
  47. <th>层级</th>
  48. <th>卡片</th>
  49. </tr>
  50. </thead>
  51. <tbody></tbody>
  52. </table>
  53. </div>
  54. </div>
  55. <div class="row mt-1">
  56. <div class="col-12 text-center">
  57. <button class="btn btn-success" onclick="computeConsume();">计算消耗</button>
  58. </div>
  59. </div>
  60. </div>
  61. <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
  62. <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
  63. <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
  64. <script>
  65. function cl(obj) {
  66. if (console && console.log) {
  67. console.log(obj);
  68. }
  69. }
  70. </script>
  71. <script>
  72. function createOneCard(level) {
  73. var cardId = level + "-" + $("#tblCards tr[data-level=" + level + "]").find(".card").length;
  74. var html = "";
  75. html += "<div class='card float-left mr-2 mb-2' data-card-id='" + cardId + "' data-level='" + level + "'>";
  76. html += "<div class='card-header'>";
  77. html += cardId;
  78. html += "</div>";
  79. html += "<div class='card-body'>";
  80. if (level > 1) {
  81. html += "<div class='form-inline mb-1'>";
  82. html += "消耗卡片:";
  83. for (var i = 0; i < 3; i++) {
  84. html += "<input class='form-control-sm mr-1' type='text' style='width: 60px;' data-card-id='" + cardId + "'/>";
  85. }
  86. html += "</div>";
  87. }
  88. html += "<div class='form-inline mb-1'>";
  89. html += "已有张数:<input class='form-control-sm mr-1' type='number' style='width: 90px;' data-card-id='" + cardId + "' min='0' value='0'/>";
  90. html += "</div>";
  91. html += "<div class='alert alert-info'>消耗数:" + "1" + "</div>";
  92. html += "</div>";
  93. html += "</div>";
  94. html += "";
  95. return html;
  96. }
  97. function createCards(level) {
  98. var $td = $("#tblCards tr[data-level=" + level + "]").find("td").eq(0);
  99. $td.children().remove();
  100. var cardCount = parseInt($("input[data-level=" + level + "]").val(), 10);
  101. for (var i = 0; i < cardCount; i++) {
  102. $td.append(createOneCard(level));
  103. }
  104. }
  105. function createOneRow(level) {
  106. var rowHtml = "<tr data-level='" + level + "'>";
  107. rowHtml += "<th>";
  108. rowHtml += "第" + level + "层";
  109. rowHtml += "<div class='form-inline'>";
  110. rowHtml += "卡数:" + "<input class='form-control' style='width: 90px;' type='number' data-level='" + level + "' min='1' max='15' value='1'/>";
  111. rowHtml += "<button class='btn btn-sm btn-primary ml-2' onclick='createCards(" + level + ")'>";
  112. rowHtml += "确定";
  113. rowHtml += "</button>";
  114. rowHtml += "</div>";
  115. rowHtml += "</th>";
  116. rowHtml += "<td>" + createOneCard(level) + "</td>";
  117. rowHtml += "</tr>";
  118. return rowHtml;
  119. }
  120. function createCardSet() {
  121. $("#tblCards tbody").children().remove();
  122. var levels = parseInt($("#numCardLevelCount").val(), 10);
  123. for (var i = levels; i >= 1; i--) {
  124. var rowHtml = createOneRow(i);
  125. $("#tblCards tbody").append(rowHtml);
  126. }
  127. }
  128. $(function () {
  129. createCardSet();
  130. });
  131. </script>
  132. <script>
  133. var hasCards = {};
  134. function computeConsume() {
  135. var $cards = $("#tblCards tbody tr").find("div[data-card-id]");
  136. var $hasCards = $cards.find("input[type=number][data-card-id]");
  137. for (var i = 0; i < $hasCards.length; i++) {
  138. hasCards[$hasCards.eq(i).data("card-id")] = parseInt($hasCards.eq(i).val(), 10);
  139. }
  140. var consumes = {};
  141. for (var i = 0; i < $cards.length; i++) {
  142. var consume = computeOneCardConsume($cards.eq(i).data("card-id"));
  143. for (var attr in consume) {
  144. if (consumes[attr]) {
  145. consumes[attr] += consume[attr];
  146. } else {
  147. consumes[attr] = consume[attr];
  148. }
  149. }
  150. }
  151. for (var cardId in consumes) {
  152. $("#tblCards tbody tr").find("div[data-card-id=" + cardId + "]").find("div.alert-info")
  153. .text("消耗数:" + consumes[cardId]);
  154. }
  155. }
  156. function computeOneCardConsume(cardId) {
  157. var ret = {};
  158. ret[cardId] = 1;
  159. var $card = $("div[data-card-id=" + cardId + "]");
  160. var level = parseInt($card.data("level"), 10);
  161. if (level > 1) {
  162. if (hasCards[cardId] > 0) {
  163. hasCards[cardId]--;
  164. } else {
  165. var $consumeCards = $card.find("input[type=text][data-card-id=" + cardId + "]");
  166. for (var i = 0; i < $consumeCards.length; i++) {
  167. var consume = computeOneCardConsume($consumeCards.eq(i).val());
  168. for (var attr in consume) {
  169. if (ret[attr]) {
  170. ret[attr] += consume[attr];
  171. } else {
  172. ret[attr] = consume[attr];
  173. }
  174. }
  175. }
  176. }
  177. }
  178. return ret;
  179. }
  180. </script>
  181. </body>
  182. </html>

然后就拿来算了一下消耗,总共需要消耗素材卡58张,素材卡是够了。

本来以为有戏,结果换了个算法算了一下,发现,因为3-1(西安事变)也需要消耗辛丑条约,所以就算全走右边这条线,也需要7张辛丑条约,有3张缺口,而卡友这边的话,辛丑条约基本都不可能换到,所以还是只能将辛丑条约换给小号去合成了。

最后,通过腾讯云的GIT仓库把这个静态网页发布到了腾讯云上面,有需要的可以用。

以后还可以考虑加些默认套卡模版的功能,再说吧。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/670543
推荐阅读
相关标签
  

闽ICP备14008679号