【发布时间】:2022-10-13 12:38:57
【问题描述】:
我正在开发一个围绕重新启动机制的游戏,但是,我希望它在每次重新启动程序时随机生成一个不同的单词,但是我有足够的时间,因为它会在单击不同时随机化钥匙。这里有什么问题?
我试过在不同的位置随机化它,包括在 setup();但是,这也不起作用。这就是我到目前为止所拥有的-
float bx=1500/2;
float by=900/2;
float b=0;
float ix=20;
float iy=20;
String [] sus={"strange","interesting","odd", "unsusual","abnormal","different","irregular","deviant","funny"};
boolean restart;
int c1=0;
int rest=0;
void setup(){
size(1500,900);
println(c1);
if( restart == true){
println(c1);
}
}
void draw(){
background(240,240,250);
rect(bx,by,20,20);
rect(ix,iy,40,40);
// interactivity
// player movement
if( keyPressed == true){
b=5;
if( key == 'w'|| key== 'W'){
by=by-b;
}
}
if( key == 'a'|| key== 'A'){
bx=bx-b;
}
if( key == 's'|| key== 'S'){
by=by+b;
}
if( key == 'd'|| key== 'D'){
bx=bx+b;
}
if( key == CODED){
if(keyCode == UP){
by=by-b;
}
}
if( key == CODED){
if(keyCode == LEFT){
bx=bx-b;
}
}
if( key == CODED){
if(keyCode == RIGHT){
bx=bx+b;
}
}
if( key == CODED){
if(keyCode == DOWN){
by=by+b;
}
}
//braking mechanisim
if( keyPressed == false){
b=0;
}
//interactivity
if( key == ' '){
if(dist( bx, by, ix, iy) < 50){
textSize(20);
text(sus[c1], 100,100,width/2,height/2);
}
fill(20,172,218);
}
if( key == CODED){
if( key == ENTER){
rest++;
}
}
}
void keyReleased(){
if(key == CODED){
if(key == ENTER){
for(int i = 0; i<3; i++){
c1=int(random(0,sus.length-1));
}
}
}
}
【问题讨论】:
-
您看到的问题和行为到底是什么?我不清楚,但我可以在您的代码中看到一些问题。一方面,您在 for 循环中生成 3 次随机数,但每次都覆盖结果。有效地使其成为 1 个随机选择,因为只有最后一个才重要。
标签: processing