Enjoy programming more!
Kidspod is a post site which supports young programmers.
First step to join us.
Register as a member
For members

2017/01/23 20:47:34

MixJuice GET URL : kidspod.club/mj/148

タイトルなし

  • No registered tag exist.

SOURCE CODE

// Galaxy
var boardX=17,boardY=21;
var boalX=0,boalY=0;
var boalVx=0,boalVy=0;
var targetX=0,targetY=0;
var time=0,score=-1;
 
function main(){
 
  if(boalVx*(boalX<=0)+boalVx*(30<=boalX)) boalVx=-1*boalVx;
 
  if(boalVy*(boalY<=1)) boalVy=-1*boalVy;
 
  if(boalVx){
    boalX=boalX+boalVx;
    boalY=boalY+boalVy;
  }
 
  if(boalY==(boardY-1)*(boardX-2<boalX)*(boalX<boardX+2)) boalVy=-1*boalVy;
 
  if(boalVy*(21<boalY)){
    boalX=0;
    boalY=0;
    boalVx=0;
    boalVy=0;
  }
 
  if(boalVx*(boalY==targetY)*(targetX-2<boalX)*(boalX<targetX+2)) time=0;
 
  if(time==0) score=score+1;
 
  if(time%30==0){
    targetX=rnd(29)+1;
    targetY=rnd(17)+1;
  }
 
  cls();
  lc(0,0);log("SCORE:",score);
  lc(boardX-1,boardY);log("===");
 
  if(boalVx){
    lc(boalX,boalY);log("o");
  }
 
  lc(targetX-1,targetY);log("###");
 
  time=time+1;
 
  setTout(main,100);
}
 
function kf(key){
  if(key==28){
    if(1<boardX) boardX=boardX-1;
  }
 
  if(key==29){
    if(boardX<29) boardX=boardX+1;
  }
 
  if(key==32){
    boalX=boardX;
    boalY=boardY-1;
    boalVx=1;
    boalVy=-1;
  }
}
 
setKprs(kf);
main();

COMMENT