赞
踩
昨天晚上做了一个很简单的腾讯网页游戏魔法卡片的炼卡消耗计算器,先放地址: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#做,后来想想做成微信小程序应该不错,不过最后还是偷了个懒,写成了网页。
代码非常简单,如下:
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="utf-8" />
- <title>魔法卡片消耗计算器</title>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
- <style>
- .table {
- width: 100%;
- }
-
- .table, .table th, .table td {
- border: solid 1px #eee;
- border-collapse: collapse;
- }
-
- .magic-card {
- width: 100px;
- height: 160px;
- border: solid 2px #888888;
- }
-
- .clear-both {
- clear: both;
- width: 0px;
- height: 0px;
- overflow: hidden;
- }
- </style>
- </head>
-
- <body>
- <nav aria-label="breadcrumb">
- <ol class="breadcrumb">
- <li class="breadcrumb-item active" aria-current="page">魔法卡片消耗计算器</li>
- </ol>
- </nav>
- <div class="container-fluid mt-1">
- <div class="row">
- <div class="col-12">
- <div class="form-inline">
- 套卡层数:<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>
- </div>
- </div>
- </div>
- <div class="row mt-1">
- <div class="col-12">
- <table class="table" id="tblCards">
- <thead>
- <tr>
- <th>层级</th>
- <th>卡片</th>
- </tr>
- </thead>
- <tbody></tbody>
- </table>
- </div>
- </div>
- <div class="row mt-1">
- <div class="col-12 text-center">
- <button class="btn btn-success" onclick="computeConsume();">计算消耗</button>
- </div>
- </div>
- </div>
- <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>
- <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
- <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>
- <script>
- function cl(obj) {
- if (console && console.log) {
- console.log(obj);
- }
- }
- </script>
- <script>
- function createOneCard(level) {
- var cardId = level + "-" + $("#tblCards tr[data-level=" + level + "]").find(".card").length;
- var html = "";
- html += "<div class='card float-left mr-2 mb-2' data-card-id='" + cardId + "' data-level='" + level + "'>";
- html += "<div class='card-header'>";
- html += cardId;
- html += "</div>";
- html += "<div class='card-body'>";
- if (level > 1) {
- html += "<div class='form-inline mb-1'>";
- html += "消耗卡片:";
- for (var i = 0; i < 3; i++) {
- html += "<input class='form-control-sm mr-1' type='text' style='width: 60px;' data-card-id='" + cardId + "'/>";
- }
- html += "</div>";
- }
- html += "<div class='form-inline mb-1'>";
- html += "已有张数:<input class='form-control-sm mr-1' type='number' style='width: 90px;' data-card-id='" + cardId + "' min='0' value='0'/>";
- html += "</div>";
- html += "<div class='alert alert-info'>消耗数:" + "1" + "</div>";
- html += "</div>";
- html += "</div>";
- html += "";
- return html;
- }
-
- function createCards(level) {
- var $td = $("#tblCards tr[data-level=" + level + "]").find("td").eq(0);
- $td.children().remove();
- var cardCount = parseInt($("input[data-level=" + level + "]").val(), 10);
- for (var i = 0; i < cardCount; i++) {
- $td.append(createOneCard(level));
- }
- }
-
- function createOneRow(level) {
- var rowHtml = "<tr data-level='" + level + "'>";
- rowHtml += "<th>";
- rowHtml += "第" + level + "层";
- rowHtml += "<div class='form-inline'>";
- rowHtml += "卡数:" + "<input class='form-control' style='width: 90px;' type='number' data-level='" + level + "' min='1' max='15' value='1'/>";
- rowHtml += "<button class='btn btn-sm btn-primary ml-2' onclick='createCards(" + level + ")'>";
- rowHtml += "确定";
- rowHtml += "</button>";
- rowHtml += "</div>";
- rowHtml += "</th>";
- rowHtml += "<td>" + createOneCard(level) + "</td>";
- rowHtml += "</tr>";
- return rowHtml;
- }
-
- function createCardSet() {
- $("#tblCards tbody").children().remove();
- var levels = parseInt($("#numCardLevelCount").val(), 10);
- for (var i = levels; i >= 1; i--) {
- var rowHtml = createOneRow(i);
- $("#tblCards tbody").append(rowHtml);
- }
- }
-
- $(function () {
- createCardSet();
- });
- </script>
- <script>
- var hasCards = {};
- function computeConsume() {
- var $cards = $("#tblCards tbody tr").find("div[data-card-id]");
- var $hasCards = $cards.find("input[type=number][data-card-id]");
- for (var i = 0; i < $hasCards.length; i++) {
- hasCards[$hasCards.eq(i).data("card-id")] = parseInt($hasCards.eq(i).val(), 10);
- }
- var consumes = {};
- for (var i = 0; i < $cards.length; i++) {
- var consume = computeOneCardConsume($cards.eq(i).data("card-id"));
- for (var attr in consume) {
- if (consumes[attr]) {
- consumes[attr] += consume[attr];
- } else {
- consumes[attr] = consume[attr];
- }
- }
- }
- for (var cardId in consumes) {
- $("#tblCards tbody tr").find("div[data-card-id=" + cardId + "]").find("div.alert-info")
- .text("消耗数:" + consumes[cardId]);
- }
- }
-
- function computeOneCardConsume(cardId) {
- var ret = {};
- ret[cardId] = 1;
- var $card = $("div[data-card-id=" + cardId + "]");
- var level = parseInt($card.data("level"), 10);
- if (level > 1) {
- if (hasCards[cardId] > 0) {
- hasCards[cardId]--;
- } else {
- var $consumeCards = $card.find("input[type=text][data-card-id=" + cardId + "]");
- for (var i = 0; i < $consumeCards.length; i++) {
- var consume = computeOneCardConsume($consumeCards.eq(i).val());
- for (var attr in consume) {
- if (ret[attr]) {
- ret[attr] += consume[attr];
- } else {
- ret[attr] = consume[attr];
- }
- }
- }
- }
- }
- return ret;
- }
- </script>
- </body>
-
- </html>
然后就拿来算了一下消耗,总共需要消耗素材卡58张,素材卡是够了。
本来以为有戏,结果换了个算法算了一下,发现,因为3-1(西安事变)也需要消耗辛丑条约,所以就算全走右边这条线,也需要7张辛丑条约,有3张缺口,而卡友这边的话,辛丑条约基本都不可能换到,所以还是只能将辛丑条约换给小号去合成了。
最后,通过腾讯云的GIT仓库把这个静态网页发布到了腾讯云上面,有需要的可以用。
以后还可以考虑加些默认套卡模版的功能,再说吧。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。