个性化阅读
专注于IT技术分析

如何解决(解决方案)Google的”程序员”游戏:海龟级

本文概述

Google的Blockly Games是一系列教编程的教育游戏。它基于Blockly库。所有代码都是免费和开源的。 Turtle Level旨在使你深入循环。使用嵌套循环绘制多个形状和图片。游戏引擎和源代码可以在Github上作为开源项目获得。

在本文中, 我们将与你分享”龟背游戏”中所有9个级别的解决方案。

1级

创建一个绘制正方形的程序。

Google的Blockly Games Turtle Level 1

第一层的相应JavaScript解释是:

for (var count = 0; count < 4; count++) {
    moveForward(100);
    turnRight(90);
}

2级

更改程序以绘制五边形而不是正方形。

Google的Blockly Games Turtle Level 2

第二级的相应JavaScript解释是:

for (var count = 0; count < 5; count++) {
    moveForward(100);
    turnRight(72);
}

3级

有一个新块, 可让你更改颜色, 绘制黄色星形。

Google龟龟等级3

第三级的相应JavaScript解释是:

penColour('#ffff00');

for (var count = 0; count < 5; count++) {
    moveForward(100);
    turnRight(144);
}

4级

有一个新块, 可让你在移动时将笔从纸上抬起。画一个黄色的小星星, 然后在上面画一条线。

Google龟龟等级4

第四块的相应JavaScript代码为:

penColour('#ffff00');

for (var count = 0; count < 5; count++) {
    moveForward(50);
    turnRight(144);
}

penUp();
moveForward(150);
penDown();
moveForward(20);

5级

你可以绘制四颗正方形排列的星星, 而不是一颗星星吗?

Google Blocklys Turtle 5级

第五块的相应JavaScript代码为:

penColour('#ffff00');
for (var count = 0; count < 5; count++) {
  moveForward(50);
  turnRight(144);
}
penUp();
moveForward(150);
penDown();
turnRight(90);
for (var count2 = 0; count2 < 5; count2++) {
  moveForward(50);
  turnRight(144);
}
penUp();
moveForward(150);
penDown();
turnRight(90);
for (var count3 = 0; count3 < 5; count3++) {
  moveForward(50);
  turnRight(144);
}
penUp();
moveForward(150);
penDown();
turnRight(90);
for (var count4 = 0; count4 < 5; count4++) {
  moveForward(50);
  turnRight(144);
}

6级

画星星, 然后画线。

Google的龟龟等级6

第六块的相应JavaScript代码为:

penColour('#ffff00');
for (var count2 = 0; count2 < 3; count2++) {
  for (var count = 0; count < 5; count++) {
    moveForward(50);
    turnRight(144);
  }
  penUp();
  moveForward(150);
  penDown();
  turnRight(120);
}
penUp();
turnRight(90);
turnRight(90);
turnRight(90);
moveForward(100);
penDown();
moveForward(50);

7级

画星星, 然后画四根白线。

Google龟龟等级7

第七块的相应JavaScript代码为:

penColour('#ffff00');
for (var count2 = 0; count2 < 3; count2++) {
  for (var count = 0; count < 5; count++) {
    moveForward(50);
    turnRight(144);
  }
  penUp();
  moveForward(150);
  penDown();
  turnRight(120);
}
penUp();
for (var count3 = 0; count3 < 3; count3++) {
  turnRight(90);
}
moveForward(100);
penDown();
for (var count4 = 0; count4 < 3; count4++) {
  turnRight(45);
}
moveForward(50);
for (var count6 = 0; count6 < 3; count6++) {
  penUp();
  turnRight(90);
  turnRight(90);
  moveForward(50);
  penDown();
  for (var count5 = 0; count5 < 3; count5++) {
    turnRight(45);
  }
  moveForward(50);
}

8级

绘制360条白线看起来像满月。

Google的龟龟等级8

第八个块的相应JavaScript代码为:

penColour('#ffff00');
for (var count2 = 0; count2 < 3; count2++) {
  for (var count = 0; count < 5; count++) {
    moveForward(50);
    turnRight(144);
  }
  penUp();
  moveForward(150);
  penDown();
  turnRight(120);
}
penUp();
for (var count3 = 0; count3 < 3; count3++) {
  turnRight(90);
}
moveForward(100);
penDown();
for (var count4 = 0; count4 < 3; count4++) {
  turnRight(45);
}
moveForward(50);
for (var count6 = 0; count6 < 360; count6++) {
  penUp();
  turnRight(90);
  turnRight(90);
  moveForward(50);
  penDown();
  for (var count5 = 0; count5 < 3; count5++) {
    turnRight(1);
  }
  moveForward(50);
}

9级

你可以添加一个黑色圆圈, 使月亮变成月牙吗?

Google的龟龟等级9

第九个块的相应JavaScript代码为:

penColour('#ffff00');
for (var count2 = 0; count2 < 3; count2++) {
  for (var count = 0; count < 5; count++) {
    moveForward(50);
    turnRight(144);
  }
  penUp();
  moveForward(150);
  turnRight(120);
  penDown();
}
penUp();
turnLeft(90);
moveForward(100);
penDown();
penColour('#ffffff');
for (var count3 = 0; count3 < 360; count3++) {
  moveForward(50);
  turnRight(90);
  turnRight(90);
  moveForward(50);
  turnLeft(90);
  turnLeft(90);
  turnRight(1);
}
turnRight(120);
moveForward(20);
penColour('#000000');
for (var count4 = 0; count4 < 360; count4++) {
  moveForward(50);
  turnRight(90);
  turnRight(90);
  moveForward(50);
  turnLeft(90);
  turnLeft(90);
  turnRight(1);
}

编码愉快!

赞(0)
未经允许不得转载:srcmini » 如何解决(解决方案)Google的”程序员”游戏:海龟级

评论 抢沙发

评论前必须登录!