小编Lew*_*wie的帖子

使用 jQuery 和 Math.random() 选择嵌套对象属性

我正在创建一个随机报价机,它将显示来自不同哲学家的随机报价。

我有一个包含哲学家及其引号的嵌套对象的对象文字。使用 jQuery 函数和 Math.random(),如何从对象文字结构中选择随机引号?有没有更好的方法来组织数据?

我从一个 jQuery 闭包开始,它会显示一个我想使用 Math.random() 修改的指定引用。

由于我是初学者,因此正在寻找解决方案的解释。提前致谢。

示例对象字面量:

var quotes = 
{
  awatts: {
    name: "Alan Watts",
    quote: "The only way to make          sense out of change is to            plunge into it, move with it,        and join the dance."
  },
  etolle: {
    name: "Eckhart Tolle",
    quote: "Realize deeply that the       present moment is all you ever       have."
  },
  tmckenna: {
    name: "Terrence Mckenna",
    quote: "“The cost of sanity in        this society, is a certain          level of …
Run Code Online (Sandbox Code Playgroud)

javascript random jquery javascript-objects

5
推荐指数
1
解决办法
490
查看次数

检查整数序列是否在增加

我只是部分地通过了下面的问题.

给定一系列整数,检查是否有可能通过从中删除不超过一个元素来获得严格增加的序列.

sequence = [1, 3, 2, 1]
almostIncreasingSequence(sequence) = false

sequence = [1, 3, 2]
almostIncreasingSequence(sequence) = true
Run Code Online (Sandbox Code Playgroud)

我的代码只传递了一些例子:

bool almostIncreasingSequence(int[] sequence) {
   int seqIncreasing = 0;
    if (sequence.Length == 1) return true;
    for (int i = 0;i < sequence.Length-2;i++)
    {
        if ((sequence[i] == sequence[++i]+1)||(sequence[i] == sequence[++i])) 
        {
            seqIncreasing++; 
        } 
    } 
    return ((seqIncreasing == sequence.Length) || (--seqIncreasing == sequence.Length));
}
Run Code Online (Sandbox Code Playgroud)

失败的例子:

Input:
    sequence: [1, 3, 2]
Output:
    false
Expected Output:
    true

Input:
    sequence: [10, 1, 2, 3, 4, …
Run Code Online (Sandbox Code Playgroud)

c#

4
推荐指数
2
解决办法
3072
查看次数

Phaser3 图像资源未加载 | 404(未找到)

我正在按照本教程使用 Phtomstorm 的样板构建多场景游戏模板。我在 GameScene.js 的 preload() 函数中添加的徽标图像收到 404 错误。我觉得我已经按照 T 的说明进行操作,但可能没有正确暴露 webpack 中的资源,因为我是这个工具的新手。

\n

我在让这个 logo.png 显示在屏幕上时做错了什么?

\n

教程 - https://phasertutorials.com/creating-a-phaser-3-template-part-1/

\n

项目模板 - https://github.com/photonstorm/phaser3-project-template.git

\n

索引.js

\n
import Phaser from "phaser";\nimport config from \'./Config/config\';\nimport GameScene from \'./Scenes/GameScene\';\n \nclass Game extends Phaser.Game {\n  constructor () {\n    super(config);\n    this.scene.add(\'Game\', GameScene);\n    this.scene.start(\'Game\');\n  }\n}\n \nwindow.game = new Game();\n
Run Code Online (Sandbox Code Playgroud)\n

配置文件

\n
import \'phaser\';\n \nexport default {\n  type: Phaser.AUTO,\n  parent: \'phaser-example\',\n  width: 800,\n  height: 600\n};\n
Run Code Online (Sandbox Code Playgroud)\n

游戏场景.js

\n
import \'phaser\';\n \nexport default class GameScene …
Run Code Online (Sandbox Code Playgroud)

javascript node.js phaser-framework webpack babeljs

2
推荐指数
1
解决办法
1879
查看次数