简体   繁体   English

做个西蒙游戏,不知道哪里错了

[英]Making a Simon Game, can't figure out what is wrong

I am trying to make a Simon game, where the user follows an increasing sequence of randomly generated patterns and I almost finished it.我正在尝试制作一个西蒙游戏,其中用户遵循越来越多的随机生成模式序列,我几乎完成了它。

But I have this problem, at times that appear random the function nextSequence() seems to stop working, which ruins the game, because you are unable to see the next color you have to click on.但我有这个问题,有时出现随机 function nextSequence() 似乎停止工作,这破坏了游戏,因为你看不到你必须点击的下一个颜色。

I have spend a lot of time trying to figure what is wrong but I just can't figure it out, usually it stops working correctly around level 5.我花了很多时间试图找出问题所在,但我无法弄清楚,通常它在 5 级左右停止正常工作。

This is the function:这是 function:

function nextSequence() {
  userClickPattern = [];

  level++;
  $("h1").text("Level " + level);

  let random = Math.floor(Math.random() * 5);
  let randomChosenColor = buttonColors[random];
  gamePattern.push(randomChosenColor);

  $("#" + randomChosenColor)
    .fadeIn(100)
    .fadeOut(100)
    .fadeIn(100);

  makeSound(randomChosenColor);
}

I don't really know if that is the problem but I haven't been able to pinpoint anything else.我真的不知道这是否是问题所在,但我无法确定其他任何问题。

I'm pretty new in asking here and coding, if you need anything else or the question is unclear feel free to tell me how could I improve it.我在这里提问和编码方面很新,如果您需要其他任何内容或问题不清楚,请随时告诉我如何改进它。

Here is the repository: https://github.com/IgnacioGR/SimonGame这是存储库: https://github.com/IgnacioGR/SimonGame

Here is the page: https://ignaciogr.github.io/SimonGame/这是页面: https://ignaciogr.github.io/SimonGame/

Change 5 to 4, you are only selecting between 4 colors only and your array index start with 0 and ends at 3. At some point your code selects an index that out of color array boundaries.将 5 更改为 4,您只能在 4 colors 之间进行选择,并且您的数组索引从 0 开始并以 3 结束。在某些时候,您的代码会选择一个超出颜色数组边界的索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM