块语言编程游戏最后一关怎么过

发布网友 发布时间:2022-04-23 06:39

我来回答

3个回答

热心网友 时间:2022-06-16 18:48

var cs1 = 0;
var cs2 = 180;

while(true){
var random = Math.random()*360;
move(random);
shut(random);
}

function move(random){
swim(cs1);
}

function shut(random){
if(scan(cs1,20)<=70){
if(scan(cs2,20)<=70){
cs2 = cs1-15;
cannon(cs1-5,scan(cs1-10,10))
}else{
cs1 += 5;
cs2 = cs1-15;
cannon(cs1-5,scan(cs1-10,10))
}
}else if(scan(cs2,20)<=70){
cs1 -= 5;
cs2 = cs1-15;
cannon(cs1-5,scan(cs1-10,10))
}else{
cs1 += 20;
}
}

————————————————
版权声明:本文为CSDN博主「猫儿不哭」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:

/* sniper */
/* strategy: since a scan of the entire battlefield can be done in 90 */
/* degrees from a corner, sniper can scan the field quickly. */

/* external variables, that can be used by any function */
var corner = 0; /* current corner 0, 1, 2, or 2 */
var sc = 0; /* current scan start */

var range; /* range to target */

/* initialize the corner info */
/* x and y location of a corner, and starting scan degree */
var c1x = 2, c1y = 2, s1 = 0;
var c2x = 2, c2y = 98, s2 = 270;
var c3x = 98, c3y = 98, s3 = 180;
var c4x = 98, c4y = 2, s4 = 90;
var closest = Infinity;
new_corner(); /* start at a random corner */
var d = damage(); /* get current damage */
var dir = sc; /* starting scan direction */

while (true) { /* loop is executed forever */
while (dir < sc + 90) { /* scan through 90 degree range */
range = scan(dir, 2); /* look at a direction */
if (range <= 70) {
while (range > 0) { /* keep firing while in range */
closest = range; /* set closest flag */
cannon(dir, range); /* fire! */
range = scan(dir, 1); /* check target again */
if (d + 15 > damage()) /* sustained several hits, */
range = 0; /* goto new corner */
}
dir -= 10; /* back up scan, in case */
}

dir += 2; /* increment scan */
if (d != damage()) { /* check for damage incurred */
new_corner(); /* we're hit, move now */
d = damage();
dir = sc;
}
}

if (closest == Infinity) { /* check for any targets in range */
new_corner(); /* nothing, move to new corner */
d = damage();
dir = sc;
} else { /* targets in range, resume */
dir = sc;
}
closest = Infinity;
}

/* new corner function to move to a different corner */
function new_corner() {
var x, y;

var rand = Math.floor(Math.random() * 4); /* pick a random corner */
if (rand == corner) /* but make it different than the */
corner = (rand + 1) % 4;/* current corner */
else
corner = rand;
if (corner == 0) { /* set new x,y and scan start */
x = c1x;
y = c1y;
sc = s1;
}
if (corner == 1) {
x = c2x;
y = c2y;
sc = s2;
}
if (corner == 2) {
x = c3x;
y = c3y;
sc = s3;
}
if (corner == 3) {
x = c4x;
y = c4y;
sc = s4;
}

/* find the heading we need to get to the desired corner */
var angle = plot_course(x,y);

/* start drive train, full speed */

/* keep traveling until we are within 15 meters */
/* speed is checked in case we run into wall, other robot */
/* not terribly great, since were are doing nothing while moving */

while (distance(getX(), getY(), x, y) > 15)
drive(angle, 100);

/* cut speed, and creep the rest of the way */

while (distance(getX(), getY(), x, y) > 1)
drive(angle, 20);

/* stop drive, should coast in the rest of the way */
drive(angle, 0);
} /* end of new_corner */

/* classical pythagorean distance formula */
function distance(x1, y1, x2, y2) {
var x = x1 - x2;
var y = y1 - y2;
return Math.sqrt((x * x) + (y * y));
}

/* plot course function, return degree heading to */
/* reach destination x, y; uses atan() trig function */
function plot_course(xx, yy) {
var d;
var x,y;
var curx, cury;

curx = getX(); /* get current location */
cury = getY();
x = curx - xx;
y = cury - yy;

/* atan only returns -90 to +90, so figure out how to use */
/* the atan() value */

if (x == 0) { /* x is zero, we either move e north or south */
if (yy > cury)
d = 90; /* north */
else
d = 270; /* south */
} else {
if (yy < cury) {
if (xx > curx)
d = 360 + Math.atan_deg(y / x); /* south-east, quadrant 4 */
else
d = 180 + Math.atan_deg(y / x); /* south-west, quadrant 3 */
} else {
if (xx > curx)
d = Math.atan_deg(y / x); /* north-east, quadrant 1 */
else
d = 180 + Math.atan_deg(y / x); /* north-west, quadrant 2 */
}
}
return d;
}

/* rabbit */
// rabbit runs around the field, randomly and never fires; use as a target.

/* go - go to the point specified */
function go (dest_x, dest_y) {
var course = plot_course(dest_x, dest_y);
while (distance(getX(), getY(), dest_x, dest_y) > 5) {
drive(course, 25);
}
while (speed() > 0) {
drive(course, 0);
}
}

/* distance forumula. */
function distance(x1, y1, x2, y2) {
var x = x1 - x2;
var y = y1 - y2;
return Math.sqrt((x * x) + (y * y));
}

/* plot_course - figure out which heading to go. */
function plot_course(xx, yy) {
var d;
var curx = getX();
var cury = getY();
var x = curx - xx;
var y = cury - yy;

if (x == 0) {
if (yy > cury) {
d = 90;
} else {
d = 270;
}
} else {
if (yy < cury) {
if (xx > curx) {
d = 360 + Math.atan_deg(y / x);
} else {
d = 180 + Math.atan_deg(y / x);
}
} else {
if (xx > curx) {
d = Math.atan_deg(y / x);
} else {
d = 180 + Math.atan_deg(y / x);
}
}
}
return d;
}

while (true) {
// Go somewhere in the field.
var x = Math.random() * 100;
var y = Math.random() * 100;
go(x, y);
}

/* counter */
/* scan in a counter-clockwise direction (increasing degrees) */
/* moves when hit */

var range;
var last_dir = 0;

var res = 2;
var d = damage();
var angle = Math.random() * 360;
while (true) {
while ((range = scan(angle, res)) != Infinity) {
if (range > 70) { /* out of range, head toward it */
drive(angle, 50);
var i = 1;
while (i++ < 50) /* use a counter to limit move time */
;
drive (angle, 0);
if (d != damage()) {
d = damage();
run();
}
angle -= 3;
} else {
while (!cannon(angle, range))
;
if (d != damage()) {
d = damage();
run();
}
angle -= 15;
}
}
if (d != damage()) {
d = damage();
run();
}
angle += res;
angle %= 360;
}

/* run moves around the center of the field */
function run() {
var i = 0;
var x = getX();
var y = getY();

if (last_dir == 0) {
last_dir = 1;
if (y > 51) {
drive(270, 100);
while (y - 10 < getY() && i++ < 50)
;
drive(270, 0);
} else {
drive(90, 100);
while (y + 10 > getY() && i++ < 50)
;
drive(90, 0);
}
} else {
last_dir = 0;
if (x > 51) {
drive(180, 100);
while (x - 10 < getX() && i++ < 50)
;
drive(180, 0);
} else {
drive(0, 100);
while (x + 10 > getX() && i++ < 50)
;
drive(0, 0);
}
}
}

/* rook.r - scans the battlefield like a rook, i.e., only 0,90,180,270 */
/* move horizontally only, but looks horz and vertically */

/* move to center of board */
if (getY() < 50) {
while (getY() < 40) /* stop near center */
drive(90, 100); /* start moving */
} else {
while (getY() > 60) /* stop near center */
drive(270, 100); /* start moving */
}
drive(0, 0);
while (speed() > 0)
;

/* initialize starting parameters */
var d = damage();
var course = 0;
var boundary = 99;
drive(course, 30);

/* main loop */
while(true) {
/* look all directions */
look(0);
look(90);
look(180);
look(270);

/* if near end of battlefield, change directions */
if (course == 0) {
if (getX() > boundary || speed() == 0)
change();
}
else {
if (getX() < boundary || speed() == 0)
change();
}
}

/* look somewhere, and fire cannon repeatedly at in-range target */
function look(deg) {
var range;
while ((range = scan(deg, 4)) <= 70) {
drive(course, 0);
cannon(deg, range);
if (d + 20 != damage()) {
d = damage();
change();
}
}
}

function change() {
if (course == 0) {
boundary = 1;
course = 180;
} else {
boundary = 99;
course = 0;
}
drive(course, 30);
}

var west = false;
while (true) {
x();
deg();
}

function x(){
for(var i = 0; i <= 360; i += 20){
if(scan(i, 20) <= 70){
cannon(i, scan(i, 20));
}
}
}

function deg(){
if (west) {
if (getX() > 25) {
swim(180, 100);
} else {
west = false;
swim(0, 0);
}
} else {
if (getX() < 75) {
swim(0, 100);
} else {
west = true;
swim(0, 0);
}
}
}

热心网友 时间:2022-06-16 18:48

var L1, L2, L3, LO, sign, x, X1, X2, X3, X4;
L1=0;
L2=0;
L3=0;
LO=0;
x = 0;
X4 = 0;
sign = 0;
while (true) {
if (x >= 270) {
X1 = x - 270;
} else {
X1 = x + 90;
}
if (x >= 180) {
X2 = x - 180;
} else {
X2 = x + 180;
}
if (x >= 90) {
X3 = x - 90;
} else {
X3 = x + 270;
}
if (getX() <= 10) {
swim(0);
}
if (getX() >= 90) {
swim(180);
}
if (getY() >= 90) {
swim(270);
}
if (getY() <= 10) {
swim(90);
}
if (LO == 1) {
if (x >= 90) {
swim(x - 90);
} else {
swim(270 + x);
}
} else if (L1 == 1) {
if (X1 >= 90) {
swim(X1 - 90);
} else {
swim(270 + X1);
}
} else if (L2 == 1) {
if (X2 >= 90) {
swim(X2 - 90);
} else {
swim(270 + X2);
}
} else if (L3 == 1) {
if (X3 >= 90) {
swim(X3 - 90);
} else {
swim(270 + X3);
}
X4 = 0;
sign = 1;
} else {
X4 += 1;
if (X4 <= 30) {
x += 3;
} else if (X4 <= 60) {
x += 5;
} else {

x += 8;
}
}
if(scan(x)<=20)
{
swim(X2);
LO = 0;
cannon(x, scan(x));
}
if (scan(x) <= 70 && scan(x) >= 20) {
cannon(x, scan(x));
LO = 1;
} else {
LO = 0;
}
if(scan(X1)<=20)
{
swim(X3);
L1 = 0;
cannon(X1, scan(X1));
}
if (scan(X1) <= 70 && scan(X1) >= 20) {
cannon(X1, scan(X1));
L1 = 1;
} else {
L1 = 0;
}
if(scan(X2)<=20)
{
swim(x);
L2 = 0;
cannon(X2, scan(X2));
}
if (scan(X2) <= 70 && scan(X2) >= 20) {
cannon(X2, scan(X2));
L2 = 1;
} else {
L2 = 0;
}
if(scan(X3)<=20)
{
swim(X1);
L3 = 0;
cannon(X3, scan(X3));
}
if (scan(X3) <= 70 && scan(X3) >= 20) {
cannon(X3, scan(X3));
L3 = 1;
} else {
L3 = 0;
}
}
我的代码,你可以研究一下。每次都是半血以上过关,过关率百分之百
(横向移动规避灵感来源于星盟冲突,规避远射类武器,没玩过可以无视这一行)

热心网友 时间:2022-06-16 18:49

荒原珠.珍稀
兔女郎
薄纱外套
星河袜圈
吊带网袜
筝迹.黑
兔女郎头饰
豪门耳环
翅影披风
骨牙项链
金属手圈
十字架手链
柳钉手套
薄荷烟
真皮钱包
白色腰带
梦纱
玫瑰花
白领单肩包
曼珠沙华
兔球球
月千重
月香渺
技能最好满级,我也是试了几次就得到s了

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com