dovgqc2648 2014-01-11 21:14
浏览 16
已采纳

从数据库创建数组还是直接? [关闭]

Okey, so I have this javascript app and need some input/tips.

This is what a want to do, and I will go over what I have in mind of solving this:

With this app, users will log in and try to destroy a 'boss' and every user works together in this play. So lets say this 'boss' have 10 million in health and each player takes 1 health per hit or more with boost ( <- but this is not part of the question). So what I do now is that I store each player hits in a database and through ajax I get the total hits all the time so the players will always know how much life this 'boss' have left.

Here comes the real question, how should I set the 'boss' health and image? Because when the 'boss' have been defeated I would like a new boss appear maybe in 24 hours or so(but thats also not apart of this question) and after like 10 different 'bosses' the hole process repeats itself.

This is how Im dealing with this problem right now, I have setup a table in my database with ID, bossHealth, BossImg and BossComplete. So lets if 'boss' number one have been defeated, it will update the database with BossComplete = 1 and if not defeated = 0.

Everything works as it should, but this would take longer time to load and not that mobile if the user has slow internet connection. What I had in mind that maybe setup an array straight in the code, with the same data (health, imgsrc, and so on), and when the 'boss' is defeated it will go to the next 'boss'.

Im looking for other examples on how to solve this or just pointers. Thanks in advance and hope some of you know maybe a better way or more efficient way.

  • 写回答

1条回答 默认 最新

  • drll85318 2014-01-11 21:57
    关注

    I don't think that Ajax would be very good here. I would recommend WebSockets. You can check demos here: http://www.websocket.org/demos.html. For example this seems very nice http://rumpetroll.com/.

    Try to keep it lightweight on server or you will run out of juice as kuroi neko mentioned. For example if every player would be polling requests to server and interfering with database, your service would go down very quickly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害