2017年9月25日 星期一

指標與陣列應用例

#include <iostream>
using namespace std;

char * rd(char * s)
{
int i=0;
while (s[i]!='\0')
i++;
s[i-1]='\0';

return s;
}

char * fd(char * s)
{
int i=1;
while (s[i]!='\0')
{
  s[i-1] = s[i];
  i++;
}
s[i-1]='\0';

return s;
}



int main(){
char  t[]="123456789";
cout << t<<endl;

fd(t);
cout << t<<endl;

fd(t);
cout << t<<endl;

rd(t);
cout << t<<endl;

rd(t);
cout << t<<endl;


int i;
cin >> i;

}

2017年8月10日 星期四

Blockly Games : Pond

























var ang, dx, dy;

function cDirection(){
  if (dx == true && dy == true) {
    ang = 45;
    swim(ang);
  }
  if (dx == true && dy == false) {
    ang = 315;
    swim(ang);
  }
  if (dx == false && dy == true) {
    ang = 135;
    swim(ang);
  }
  if (dx == false && dy == false) {
    ang = 225;
    swim(ang);
  }
}

function check() {
  if (loc_x() > 95) {
    dx = false;
    cDirection();
  }
  if (loc_x() < 5) {
    dx = true;
    cDirection();
  }
  if (loc_y() > 95) {
    dy = false;
    cDirection();
  }
  if (loc_y() < 5) {
    dy = true;
    cDirection();
  }
}

function action() {
  for (var i = 0; i < 32; i++) {
    if (scan(i * 10, 15) <= 70)
    {
    cannon(i * 10, scan(i * 10, 15));
    ang = i*10;
    swim(ang);
    }
  }
}

ang = 45;
dx = true;
dy = true;
while (true) {
  check();
  action();
}