c++编程简易计算器、JavaScript游戏

大家好,我是纳米核心38,我“精通”C++、C、JavaScript,请大家多多指教。
计算器代码:

#include<bits/stdc++.h>
#include<windows.h>
#define p 3.1415926535897932384646433832795028841971693993751058209749445923078164062862089986280348253421170679821480
#define r p/180
using namespace std;
char ch[6]={'A','B','C','D','E','F'};
void TrunDate(int,int);
int fac(float);
int main(){float i,j,k;
int l,m,n,a[10];
char cmd;
LOOP:
system("cls");
printf("\t ***********************\n");
printf("\t *******简易计算器******\n");
printf("\t ***********************\n");
printf("\n\t 本计算器提供+、-、*、/运算及以下运算:\n");
printf("\t p-代表圆周率pai。\n");
printf("\t R-代表十进制转换为二进制。\n");
printf("\t b-代表十进制转换为八进制。\n");
printf("\t l-代表十进制转换为十六进制。\n");
printf("\t d-代表该数值开方。\n");
printf("\t e-代表该数值开立方。\n");
printf("\t ^-代表求几次方。\n");
printf("\t S-代表sin。\n");
printf("\t C-代表cos。\n");
printf("\t T-代表tan。\n");
printf("\t s-代表asin。\n");
printf("\t c-代表acos。\n");
printf("\t t-代表atan。\n");
printf("\t !-代表阶乘。\n");
printf("\t 请输入要计算的数字和运算符号,输入“#”时,结束;输入“?”时复位。\n");scanf("%f",&k);
while((cmd=getchar())!='#')
{if(i!=0)
switch(cmd)
{case '+': scanf("%f",&i);
k+=i;
printf("=%5.2f",k);
break; case '-': scanf("%f",&i);
k-=i;
printf("=%5.2f",k);
break; case '*': scanf("%f",&i);
k*=i;
printf("=%5.2f",k);
break; case '/': scanf("%f",&i);
if(i==0) {cout<<"数学错误Math ERROR\n";
break;
}
k/=i;
printf("=%5.2f",k);
break;case 'p': k=k*p;
printf("%6.4f",k);
break; case '^': printf("请输入要求该数字的几次方:");
scanf("%d",&n);
i=k;
for(m=0;m<n-1;m++)
k=k*i;
printf("%5.2f",k);
break; case 'R': printf("转换成二进制\n");
TrunDate(k,2);
break;
case 'b':
printf("转换成八进制\n");
TrunDate(k,8);
break;case 'l': printf("转换成十六进制\n");
TrunDate(k,16);
break;
case 'e': printf("该数值开立方得\n");
i=pow(k,1.0/3);
printf("%5.2f",i );
break;case 'd': printf("该数值开方得\n");
i=k/2;
j=sqrt(k);
printf("%5.2f",j);
break; case 'S': k=k*r;
i=sin(k);
printf("%5.2f",i);
break;case 'C': k*=r;
i=cos(k);
printf("%5.2f",i);
break; case 'T': k=k*r;
i=tan(k);
printf("%5.2f",i);
break;case 's': k=k*r;if(k>=1){cout<<"数学错误MathERROR\n";break;}
i=asin(k);
printf("%5.2f",i);
break;
case 'c': k*=r;
if(k>=1){cout<<"数学错误MathERROR\n";break;
}
i=acos(k);
printf("%.2f",i);
break;
case 't': k*=r;
if(k>=1){cout<<"数学错误MathERROR\n";break;
}
i=atan(k);
printf("%.2f",i);
break;
case '!':k=fac(k);printf("%d",k);break;case '?': goto LOOP;default:cout<<"语法错误Syntax ERROR\n";}}
}
int fac(float X){(int) X;return X==0?  1:X*fac(X-1);
}
void TrunDate(int n,int a){int x[17],i,j,k=0;if(n<0) cout<<'-'; j=abs(n);do{k++;i=j%a;x[k]=i; }while(j!=0);for(int h=k;h>=1;--h)if(x[h]<10) cout<<x[h];else cout<<ch[x[h]-10];
}

可以在DEV-C++中复制粘贴;
游戏代码:

<body></body>
<script src="/three.js"></script>
<script src="/physi.js"></script>
<script src="/scoreboard.js"></script><script>// Physics settingsPhysijs.scripts.ammo = '/ammo.js';Physijs.scripts.worker = '/physijs_worker.js';// The "scene" is where stuff in our game will happen:var scene = new Physijs.Scene({ fixedTimeStep: 2 / 60 });scene.setGravity(new THREE.Vector3( 0, -100, 0 ));var flat = {flatShading: true};var light = new THREE.HemisphereLight('white', 'grey', 0.7);scene.add(light);// The "camera" is what sees the stuff:var width = window.innerWidth,height = window.innerHeight,aspectRatio = width / height;var camera = new THREE.PerspectiveCamera(75, aspectRatio, 1, 10000);// var camera = new THREE.OrthographicCamera(//   -width/2, width/2, height/2, -height/2, 1, 10000// );camera.position.z = 500;camera.position.y = 200;camera.lookAt(new THREE.Vector3(0,0,0));scene.add(camera);// The "renderer" draws what the camera sees onto the screen:var renderer = new THREE.WebGLRenderer({antialias: true});renderer.setSize(window.innerWidth, window.innerHeight);document.body.appendChild(renderer.domElement);document.body.style.backgroundColor = '#ffffff';// ******** START CODING ON THE NEXT LINE ********function Launcher(location) {this.location = location;this.color = 'yellow';if (location == 'right') this.color = 'lightblue';this.angle = 0;this.power = 0;this.draw();this.keepScore();}Launcher.prototype.draw = function() {var direction = new THREE.Vector3(0, 1, 0);var x = 0;if (this.location == 'left') x = -100;if (this.location == 'right') x = 100;var position = new THREE.Vector3( x, -100, 250 );var length = 100;this.arrow = new THREE.ArrowHelper(direction,position,length,this.color);scene.add(this.arrow);};Launcher.prototype.vector = function() {return new THREE.Vector3(Math.sin(this.angle),Math.cos(this.angle),0);};Launcher.prototype.moveLeft = function(){this.angle = this.angle - Math.PI / 100;this.arrow.setDirection(this.vector());};Launcher.prototype.moveRight = function(){this.angle = this.angle + Math.PI / 100;this.arrow.setDirection(this.vector());};Launcher.prototype.powerUp = function(){if (this.power >= 100) return;this.power = this.power + 5;this.arrow.setLength(this.power);};Launcher.prototype.launch = function(){var shape = new THREE.SphereGeometry(10);var material = new THREE.MeshPhongMaterial({color: this.color});var ball = new Physijs.SphereMesh(shape, material, 1);ball.name = 'Game Ball';ball.scoreboard = this.scoreboard;var p = this.arrow.position;ball.position.set(p.x, p.y, p.z);scene.add(ball);var speedVector = new THREE.Vector3(2.5 * this.power * this.vector().x,2.5 * this.power * this.vector().y,-80);ball.setLinearVelocity(speedVector);this.power = 0;this.arrow.setLength(100);};Launcher.prototype.keepScore = function(){var scoreboard = new Scoreboard('top' + this.location);scoreboard.countdown(60);scoreboard.score(0);var moveKeys;if (this.location == 'left') moveKeys = 'A和 D';if (this.location == 'right') moveKeys = 'J和L';if (this.location == 'left') aKeys = 'A and D';if (this.location == 'right') aKeys = 'J and L';var launchKeys;if (this.location == 'left') launchKey = 'S';if (this.location == 'right') launchKey = 'K';scoreboard.help('用'+moveKeys+'键调整发射角度!'+'用'+launchKey+'键储力!'+'松开'+launchKey+'键发射球!'+'小心有风!'+'Use the' + aKeys +'  keys to point the launcher. ' +'Press and hold the ' + launchKey + ' key to power up the launcher. ' +'Let go of the ' + launchKey + ' key to launch. ' +'Watch out for the wind!!!');scoreboard.onTimeExpired(timeExpired);function timeExpired() {if (launcher2.scoreboard.getScore() < launcher1.scoreboard.getScore()) {launcher2.scoreboard.message("游戏结束,你输了):,别灰心,用R键再来一次!Game Over you lost): not lose hear,keep the R key again!");launcher1.scoreboard.message("游戏结束,你赢了(:,用R键再来一次!Game Over you win(:,keep the R key again!");}else if(launcher2.scoreboard.getScore() == launcher1.scoreboard.getScore())  {scoreboard.message("游戏结束,平局,用R键再来一次!Game Over,keep the R key again!");}else {launcher1.scoreboard.message("游戏结束,你输了):,别灰心用R键再来一次!Game Over you lost): not lose hear,keep the R key again!");launcher2.scoreboard.message("游戏结束,你赢了(:,用R键再来一次!Game Over you win(:,keep the R key again!");}}this.scoreboard = scoreboard;};Launcher.prototype.reset = function(){var scoreboard = this.scoreboard;if (scoreboard.getTimeRemaining() > 0) return;};function Basket(size, points) {this.size = size;this.points = points;this.height = 100/Math.log10(size);var r = Math.random;this.color = new THREE.Color(r(), r(), r());this.draw();}Basket.prototype.draw = function() {var cover = new THREE.MeshPhongMaterial({color: this.color,shininess: 50,specular: 'white'});var shape = new THREE.CubeGeometry(this.size, 1, this.size);var goal = new Physijs.BoxMesh(shape, cover, 0);goal.position.y = this.height / 100;scene.add(goal);var halfSize = this.size/2;var halfHeight = this.height/2;shape = new THREE.CubeGeometry(this.size, this.height, 1);var side1 = new Physijs.BoxMesh(shape, cover, 0);side1.position.set(0, halfHeight, halfSize);scene.add(side1);var side2 = new Physijs.BoxMesh(shape, cover, 0);side2.position.set(0, halfHeight, -halfSize);scene.add(side2);shape = new THREE.CubeGeometry(1, this.height, this.size);var side3 = new Physijs.BoxMesh(shape, cover, 0);side3.position.set(halfSize, halfHeight, 0);scene.add(side3);var side4 = new Physijs.BoxMesh(shape, cover, 0);side4.position.set(-halfSize, halfHeight, 0);scene.add(side4);this.waitForScore(goal);};Basket.prototype.waitForScore = function(goal){goal.addEventListener('collision', this.score.bind(this));};Basket.prototype.score = function(ball){var scoreboard = ball.scoreboard;if (scoreboard.getTimeRemaining() == 0) return;scoreboard.addPoints(this.points);scene.remove(ball);};function Wind() {this.draw();this.change();}Wind.prototype.draw = function(){var dir = new THREE.Vector3(1, 0, 0);var start = new THREE.Vector3(0, 200, 250);this.arrow = new THREE.ArrowHelper(dir, start, 1, 'lightblue');scene.add(this.arrow);};Wind.prototype.change = function(){if (Math.random() < 0.5) this.direction = -1;else this.direction = 1;this.strength = 20*Math.random();this.arrow.setLength(5 * this.strength);this.arrow.setDirection(this.vector());setTimeout(this.change.bind(this), 10000);};Wind.prototype.vector = function(){var x = this.direction * this.strength;return new THREE.Vector3(x, 0, 0);};var launcher1 = new Launcher('left');var launcher2 = new Launcher('right');var scoreboard = launcher1.scoreboard;var goal1 = new Basket(200, 10);var goal2 = new Basket(40, 100);var wind = new Wind();var light = new THREE.PointLight( 0xffffff, 1, 0 );light.position.set(120, 150, -150);scene.add(light);function allBalls() {var balls = [];for (var i=0; i<scene.children.length; i++) {if (scene.children[i].name.startsWith('Game Ball')) {balls.push(scene.children[i]);}}return balls;}// Animate motion in the gamefunction animate() {if (scoreboard.getTimeRemaining() == 0) return;requestAnimationFrame(animate);renderer.render(scene, camera);}animate();// Run physicsfunction gameStep() {if (scoreboard.getTimeRemaining() == 0) return;scene.simulate();var balls = allBalls();for (var i=0; i<balls.length; i++) {balls[i].applyCentralForce(wind.vector());if (balls[i].position.y < -100) scene.remove(balls[i]);}// Update physics 60 times a second so that motion is smoothsetTimeout(gameStep, 1000/60);}gameStep();function reset() {if (scoreboard.getTimeRemaining() > 0) return;launcher1.scoreboard.message('');launcher2.scoreboard.message('');launcher1.reset();launcher2.reset();launcher1.scoreboard.score(0);launcher1.scoreboard.countdown(60);launcher2.scoreboard.score(0);launcher2.scoreboard.countdown(60);var balls = allBalls();for (var i=0; i<balls.length; i++) {scene.remove(balls[i]);}animate();gameStep();}var powerUp1;var powerUp2;function powerUpLauncher1(){ launcher1.powerUp(); }function powerUpLauncher2(){ launcher2.powerUp(); }document.addEventListener('keydown', sendKeyDown);function sendKeyDown(event) {if (event.repeat) return;var code = event.code;if (code == 'KeyA') launcher1.moveLeft();if (code == 'KeyD') launcher1.moveRight();if (code == 'KeyS') {clearInterval(powerUp1);powerUp1 = setInterval(powerUpLauncher1, 20);}if (code == 'KeyJ') launcher2.moveLeft();if (code == 'KeyL') launcher2.moveRight();if (code == 'KeyK') {clearInterval(powerUp2);powerUp2 = setInterval(powerUpLauncher2, 20);}if (code == 'KeyR') reset();}document.addEventListener('keyup', sendKeyUp);function sendKeyUp(event){var code = event.code;if (code == 'KeyS') {launcher1.launch();clearInterval(powerUp1);}if (code == 'KeyK') {launcher2.launch();clearInterval(powerUp2);}}
</script>

呵呵,有些长,要使用代码,先打开3DE代码编辑器,网址如下:www.code3Dgames.com/3de

点击有三条横线的菜单按钮,然后选择“new”命令,接着输入一个项目名,再点击“save”按钮,然后删除新项目中的所有代码,再输入我的代码。
我还有以下代码:
C++万年历:

/*
*  功能: 实现一个万年历程序
*  作者:纳米核心38
*  时间: 2022年2月4日
*/
#define _CRT_STCURE_NO_DEPRECATE
//标准C++头文件
#include<bits/stdc++.h>
#include<ctime>
#include<cfloat>
#include<cctype>
#include<cerrno>
#include<clocale>
#include<cwchar>
#include<cwctype>
#include<iomanip>
#include<ios>
#include<iosfwd>
//c99头文件;
#include<stdbool.h>
#include<stdint.h>
#include<inttypes.h>
#include<complex.h>
#include<windows.h>
#include<tgmath.h>//通用数学宏;
using namespace std;
int main(){/**********  START CODEING ON THE NEXT LINE  ***********/int Year,Month;        //年、月int FirstDay_Year,FirstDay_Month;   //某年的第一天是星期几,某年某月的第一天是星期几(范围是0~6,其中0代表星期日)int IsLeapYear;        //是否为闰年,0表示不是闰年,1表示是闰年int i,d,y;         //临时变量char YN;         //Yes No,程序是否要继续int Days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};      //Days[1~12]存储每个月有多少天,其中二月的天数是可变的(闰年29天,平年28天),这里初始化为28天XunHuan1:          //循环标号1(可以通过goto跳转到这里)system("cls");printf("请输入年份<0000~9999>: ");   //提示输入年份(0~9999)scanf("%d",&Year);       //把输入的年份赋值给变量Yearif(Year>=10000 || Year<0) {cout<<"无效操作,年份超出范围,请输入0000~9999间的年份:\r\n";system("pause");goto XunHuan1;//重复操作}XunHuan2: //循环标号2(可以通过goto跳转到这里)system("cls");printf("请输入年份<0000~9999>: %d\n",Year);printf("请输入月份<0~12>: ");    //提示输入月份(1~12)scanf("%d",&Month);       //把输入的月份赋值给变量Monthif(Month>=13 || Month<=0) {cout<<"无效操作,月份超出范围,请输入1~12间的月份:\r\n";system("pause");goto XunHuan2;//重复操作 } y=Year;FirstDay_Year=5*(y/4)+(y%4)-(y/100)+(y/400);//蔡勒公式(计算某年的第一天是星期几)IsLeapYear=(y%4==4&&y%100!=100||y%400==0)?1:0;        //判断是否为闰年Days[2]=(IsLeapYear==1)?29:28;    //闰年二月29天,非闰年二月28天for(i=1,d=0;i<Month;i++) d=d+Days[i];FirstDay_Month=(d+FirstDay_Year)%7;   //当月的第一天是星期几(0代表星期日)printf(" \t\t\t万年历\n");    //打印标题printf("\n****************************************************\n");printf("\t\t公元 %d 年 %2d 月",Year,Month);  //打印年月printf("\n****************************************************\n");printf("   星期日 星期一 星期二 星期三 星期四 星期五 星期六\n");//打印星期表头for(i=0;i<FirstDay_Month;i++) printf("%7c",' ');      //当某月的第一天不是星期日时打印空格占位 for(d=1;d<=Days[Month];d++)     //循环,从每个月的第一天开始打印{printf("%7d",d);if(((d+FirstDay_Month)%7)==0 && d<Days[Month]) printf("\n");      //当输出了星期六而且还未输出所有天数时,换行}printf("\n****************************************************\n");printf("\n"); XunHuan3:printf("是否继续<Y/N>?\n");scanf("%c",&YN);scanf("%c",&YN);if(YN=='Y' || YN=='y')goto XunHuan1;else if((YN!='Y') && (YN != 'y') && (YN!='N') && (YN!='n')) {cout<<"无效操作,继续字符超出范围,请输入Y或N:\n";system("pause");system("cls");goto XunHuan3; }     return 0;
}

c++成绩计算器:

/*
*  功能:实现一个成绩计算器程序
*  作者:纳米核心38
*  时间:  2022年2月2日
*/
#define _CRT_STCURE_NO_DEPRECATE
//标准C++头文件
#include<bits/stdc++.h>
#include<ctime>
#include<cfloat>
#include<cctype>
#include<cerrno>
#include<clocale>
#include<cwchar>
#include<cwctype>
#include<iomanip>
#include<ios>
#include<iosfwd>
//c99头文件;
#include<stdbool.h>
#include<stdint.h>
#include<inttypes.h>
#include<complex.h>
#include<windows.h>
#include<tgmath.h>//通用数学宏;
using namespace std;
struct student{string name;float chin,math,en;float total;
};
student a[110];
float n;
int main(){/**********  START CODEING ON THE NEXT LINE  ***********/scanf("%f",&n);for(int i=0;i<n;i++){cin>>a[i].name;cin>>a[i].chin>>a[i].math>>a[i].en;a[i].total=a[i].chin+a[i].math+a[i].en;}for(int i=n-1;i>0;i--)for(int j=0;j<i;j++)      if(a[j].total<a[j+1].total)swap(a[j],a[j+1]);cout<<"排名"<<setw(10)<<"姓名"<<setw(10)<<"语文成绩"<<setw(10)<<"数学成绩";cout<<setw(10)<<"英语成绩"<<setw(7)<<"总分"<<endl;     for(int i=0;i<n;i++){cout<<"No."<<i+1<<setw(10)<<a[i].name<<setw(10)<<a[i].chin;cout<<setw(10)<<a[i].math<<setw(10)<<a[i].en<<setw(7)<<a[i].total<<"\n"; }          system("pause");return 0;
}

还有:
JavaScript游戏:

<body></body>
<script src="/three.js"></script>
<script src="/physi.js"></script>
<script src="/scoreboard.js"></script>
<script src="/controls/OrbitControls.js"></script>
<script>// Physics settingsPhysijs.scripts.ammo = '/ammo.js';Physijs.scripts.worker = '/physijs_worker.js';// The "scene" is where stuff in our game will happen:var scene = new Physijs.Scene({ fixedTimeStep: 2 / 60 });scene.setGravity(new THREE.Vector3( 0, -100, 0 ));var flat = {flatShading: true};var light = new THREE.HemisphereLight('wient', 'grey', 0.7);scene.add(light);// The "camera" is what sees the stuff:var width = window.innerWidth,height = window.innerHeight,aspectRatio = width / height;var camera = new THREE.PerspectiveCamera(75, aspectRatio, 1, 10000);// var camera = new THREE.OrthographicCamera(//   -width/2, width/2, height/2, -height/2, 1, 10000// );camera.position.z = 500;camera.position.y = 200;camera.lookAt(new THREE.Vector3(0,0,0));scene.add(camera);// The "renderer" draws what the camera sees onto the screen:var renderer = new THREE.WebGLRenderer({antialias: true});renderer.setSize(window.innerWidth, window.innerHeight);document.body.appendChild(renderer.domElement);document.body.style.backgroundColor = '#ffffff';
//new THREE.OrbitControls(camera, renderer.domElement);/********* START CODING ON THE NEXT LINE *********///Launcher;function Launcher() {this.angle = 0;this.power = 0;this.draw();}Launcher.prototype.draw = function() {var direction = new THREE.Vector3(0, 1, 0);var position = new THREE.Vector3(0, -100, 250);var length = 100;this.arrow = new THREE.ArrowHelper(direction,position,length,'yellow');scene.add(this.arrow);};Launcher.prototype.vector = function(){return new THREE.Vector3(Math.sin(this.angle),Math.cos(this.angle),0);};Launcher.prototype.moveLeft = function(){this.angle = this.angle - Math.PI/100;this.arrow.setDirection(this.vector());};Launcher.prototype.moveRight = function(){this.angle = this.angle + Math.PI/100;this.arrow.setDirection(this.vector());};Launcher.prototype.moveUp = function(){if(this.power >= 100) return;this.power = this.power  + 5;this.arrow.setLength(this.power);};Launcher.prototype.launch = function(){var shape = new THREE.SphereGeometry(10);var material = new THREE.MeshPhongMaterial({color:'yellow'});var ball = new Physijs.SphereMesh(shape, material, 1);ball.name = 'Game Ball';ball.position.set(0,0,300);scene.add(ball);var speedVector = new THREE.Vector3(2.5*this.power*this.vector().x,2.5*this.power*this.vector().y,-80);ball.setLinearVelocity(speedVector);this.power = 0;this.arrow.setLength(100);};//scoreboard;var scoreboard = new Scoreboard();scoreboard.countdown(100);scoreboard.score();scoreboard.help("ahsgadjaysg");scoreboard.onTimeExpired(timeExpired);function timeExpired(){scoreboard.message("Game Over");}//basketfunction Basket(size, points){this.size = size;this.points = points;this.height = 100/Math.log10(size);var r = Math.random;this.color = new THREE.Color(r(),r(),r());this.draw();} Basket.prototype.draw = function(){var cover = new THREE.MeshPhongMaterial({color:this.color,shininess: 50,specular: 'white'});var shape = new THREE.CubeGeometry(this.size,1 ,this.size);var goal = new Physijs.BoxMesh(shape, cover, 0);goal.position.y = this.height / 100;scene.add(goal);var halfSize = this.size/2;var halfHeight = this.height/2;shape = new THREE.CubeGeometry(this.size, this.height,1);var side1 = new Physijs.BoxMesh(shape, cover,0);side1.position.set(0, halfHeight,halfSize);scene.add(side1);var side2 = new Physijs.BoxMesh(shape, cover,0);side2.position.set(0, halfHeight,-halfSize);scene.add(side2);shape = new THREE.CubeGeometry(1, this.height , this.size);var side3 = new Physijs.BoxMesh(shape, cover,0);side3.position.set(halfSize,halfHeight,0);scene.add(side3);var side4 = new Physijs.BoxMesh(shape, cover,0);side4.position.set (-halfSize,halfHeight,0);scene.add(side4);this.waitForScore(goal);};Basket.prototype.waitForScore = function(goal){goal.addEventListener("collision",this.score.bind(this));};Basket.prototype.score = function(ball){if(scoreboard.getTimeRemaining() == 0)return;scoreboard.addPoints(this.points);scene.remove(ball);};
//wind
function Wind(){this.draw();this.change();
}Wind.prototype.draw = function(){var dir = new THREE.Vector3(1,0,0);var start = new THREE.Vector3(0,200,250);this.arrow = new THREE.ArrowHelper(dir,start,1,'lightblue');scene.add(this.arrow);
};
Wind.prototype.change = function(){if(Math.random() < 0.5) this.direction = -1;else this.direction = 1;this.strength = 20*Math.random();this.arrow.setLength(5*this.strength);this.arrow.setDirection(this.vector());setTimeout(this.change.bind(this),10000);};
Wind.prototype.vector = function(){var x = this.direction * this.strength;return new THREE.Vector3(x, 0, 0);
};//allbals and wind(wind)
function allBalls(){var balls=[];for(var i=0; i<scene.children.length; i++){if(scene.children[i].name.startsWith('Game Ball')){balls.push(scene.children[i]);}
}
return balls;
}//keydown/keyupdocument.addEventListener('keydown', sendKeyDown);function sendKeyDown(event){var code = event.code;if(code == 'ArrowLeft') launcher.moveLeft();if(code == 'ArrowRight') launcher.moveRight();if(code == 'ArrowDown') launcher.moveUp();}document.addEventListener('keyup', sendKeyUp);function sendKeyUp(event){var code = event.code;if(code == 'ArrowDown') launcher.launch();}//variable;var launcher = new Launcher();var goal1 = new Basket(200,10);var goal2 = new Basket(40,100);var wind = new Wind();// Animate motion in the gamefunction animate() {requestAnimationFrame(animate);renderer.render(scene, camera);}animate();// Run physics,gameStepfunction gameStep() {scene.simulate();var balls = allBalls();for(var i=0; i<balls.length; i++){balls[i].applyCentralForce(wind.vector());if(balls[i].position.y < -100) scene.remove(balls[i]);}// Update physics 60 times a second so that motion is smoothsetTimeout(gameStep, 1000/60);}gameStep();
</script>
JavaScript游戏:
<body></body>
<script src="/three.js"></script>
<script src="/physi.js"></script>
<script src="/controls/OrbitControls.js"></script>
<script src="/scoreboard.js"></script>
<script src="/noise.js"></script>
<script src="/sounds.js"></script>
<script>// Physics settingsPhysijs.scripts.ammo = '/ammo.js';Physijs.scripts.worker = '/physijs_worker.js';// The "scene" is where stuff in our game will happen:var scene = new Physijs.Scene();scene.setGravity(new THREE.Vector3( 0, -10, 0 ));var flat = {flatShading: true};var light = new THREE.AmbientLight('white', 0.2);scene.add(light);var sunlight = new THREE.DirectionalLight('white', 0.8);sunlight.castShadow = true;scene.add(sunlight);var d = 10;sunlight.shadow.camera.left = -d;sunlight.shadow.camera.right = d;sunlight.shadow.camera.top = d;sunlight.shadow.camera.bottom = -d;// The "camera" is what sees the stuff:var aspectRatio = window.innerWidth / window.innerHeight;var camera = new THREE.PerspectiveCamera(75, aspectRatio, 0.1, 100);camera.position.set(-8, 8, 8);scene.add(camera);var abovecam = camera;  // The "renderer" draws what the camera sees onto the screen:var renderer = new THREE.WebGLRenderer({antialias: true});renderer.setClearColor('skyblue');renderer.shadowMap.enabled = true;renderer.setSize(window.innerWidth, window.innerHeight);document.body.appendChild(renderer.domElement);// ******** START CODING ON THE NEXT LINE ********
var gameOver;
var ground = addGround();
var water = addWater();
var scoreboard = addScoreboard();
var Raft = addRaft();
reset();function addGround() {var faces = 99;var shape = new THREE.PlaneGeometry(10, 20, faces, faces);var riverPoints = [];var numVertices = shape.vertices.length;var noiseMaker = new SimplexNoise();for (var i=0; i<numVertices; i++) {var vertex = shape.vertices[i];var noise = 0.25 * noiseMaker.noise(vertex.x, vertex.y);vertex.z = noise;}for (var j=50; j<numVertices; j+=100) {var curve = 20 * Math.sin(7*Math.PI * j/numVertices);var riverCenter = j + Math.floor(curve);riverPoints.push(shape.vertices[riverCenter]);for (var k=-20; k<20; k++) {shape.vertices[riverCenter + k].z = -1;}}shape.computeFaceNormals();shape.computeVertexNormals();var _cover = new THREE.MeshPhongMaterial({color: 'green', shininess: 0});var cover = new Physijs.createMaterial(_cover, 0.8, 0.1);var mesh = new Physijs.HeightfieldMesh(shape, cover, 0);mesh.rotation.set(-0.475 * Math.PI, 0, 0);mesh.receiveShadow = true;mesh.castShadow = true;mesh.riverPoints = riverPoints;scene.add(mesh);return mesh;
}function addWater() {var shape = new THREE.CubeGeometry(10, 20, 1);var _cover = new THREE.MeshPhongMaterial({color: 'blue'});var cover = new Physijs.createMaterial(_cover, 0, 0.6);var mesh = new Physijs.ConvexMesh(shape, cover, 0);mesh.rotation.set(-0.475 * Math.PI, 0, 0);mesh.position.y = -0.8;mesh.receiveShadow = true;scene.add(mesh);
}function addScoreboard() {var scoreboard = new Scoreboard();scoreboard.score(0);scoreboard.timer();scoreboard.help("用左右方向键控制木筏方向!"+"用空格键或下方向键加速!"+"球体是水果,方块是障碍!"+"加速前进!越快越好!吃掉水果!躲避障碍!"+'Links/Rechpfeiltasten zum drehen. ' +'Leertaste zum vorwärtsbewegen. ' +'R zum neustart');return scoreboard;
}function addRaft() {var shape = new THREE.TorusGeometry(0.1, 0.05, 8, 20);var _cover = new THREE.MeshPhongMaterial({visible: false});var cover = new Physijs.createMaterial(_cover, cover, 0.25);var mesh = new Physijs.ConvexMesh(shape, cover, 0.25);mesh.rotation.x = -Math.PI/2;var furFace = rColor();cover = new THREE.MeshPhongMaterial({color: furFace});var tube = new THREE.Mesh(shape, cover);tube.position.z = -0.08;tube.castShadow = true;mesh.add(tube);mesh.tube = tube;shape = new THREE.SphereGeometry(0.02);cover = new THREE.MeshBasicMaterial({color: 'white'});var rudder = new THREE.Mesh(shape, cover);rudder.position.set(0.15, 0, 0);tube.add(rudder);scene.add(mesh);mesh.setAngularFactor(new THREE.Vector3(0, 0, 0));return mesh;
}function reset() {resetPoweDowns();resetPoweDowns1();resetPoweDowns2();resetPoweUps();abovecam.position.set(0,-1,2);abovecam.lookAt(new THREE.Vector3(0, 0, 0));Raft.add(abovecam);scoreboard.message('');scoreboard.resetTimer();scoreboard.score(0);Raft.__dirtyPosition = true;Raft.position.set(0.75, 2, -9.6);Raft.setLinearVelocity(new THREE.Vector3(0, 0, 0));gameOver = false;animate();scene.onSimulationResume();gameStep();
}// Animate motion in the gamefunction animate() {if (gameOver) return;requestAnimationFrame(animate);renderer.render(scene, camera);}var aspectRatio = window.innerWidth / window.innerHeight;var qCam = new THREE.PerspectiveCamera(75, aspectRatio, 0.1, 100);qCam.position.set(-8, 8, 8);scene.add(qCam);new THREE.OrbitControls(qCam, renderer.domElement);// Run physicsfunction gameStep() {if (gameOver) return;checkForgameOver();scene.simulate();// Update physics 60 times a second so that motion is smoothsetTimeout(gameStep, 1000/60);}function checkForgameOver(){if (Raft.position.z > 9.8){if (scoreboard.getTime() < 100){gameOver = true;scoreboard.stopTimer();scoreboard.message("你成功了 !!");Sounds.drip.play();}}if (Raft.position.z > 9.8) {if (scoreboard.getTime() > 100){gameOver = true;scoreboard.stopTimer();scoreboard.message("有点慢哟!");Sounds.spring.play();}}if (scoreboard.getTime() > 180) {gameOver = true;scoreboard.stopTimer();scoreboard.message(" 时间到!太慢了!别灰心,再来一次!!");Sounds.knock.play();}if (gameOver){var score = Math.floor(101-scoreboard.getTime());scoreboard.addPoints(score);if(scoreboard.getTime() < 80) scoreboard.addPoints(100);if(scoreboard.getTime() < 60) scoreboard.addPoints(200);if(scoreboard.getTime() < 50) scoreboard.addPoints(500);      }}function resetPoweDowns1() {removeOldPowerDowns1();var random50 = 50 + Math.floor(10*Math.random());var p50 = ground.riverPoints[random50];addPowerDown1(p50);var random65 = 65 + Math.floor(10*Math.random());var p65 = ground.riverPoints[random65];addPowerDown1(p65);
}function addPowerDown1(riverPoint){ground.updateMatrixWorld();var x = riverPoint.x + 4 * (Math.random() - 0.5);var y = riverPoint.y;var z = -0.5;var p  = new THREE.Vector3(x, y, z);ground.localToWorld(p);var shape =  new THREE.BoxGeometry(0.2, 0.5, 0.2);var cover = new THREE.MeshNormalMaterial({color:'black'});var mesh = new Physijs.BoxMesh(shape, cover, 0);mesh.position.copy(p);mesh.powerDown1 = true;scene.add(mesh);mesh.addEventListener('collision',function() {for (var i=0; i < scene.children.length; i++) {var obj = scene.children[i];if (obj == mesh) scene.remove(obj);}scoreboard.addPoints(-18);scoreboard.message('哎呀!撞到障碍物了!下次小心哦!!');setTimeout(function() {scoreboard.clearMessage();}, 5*1000);    Sounds.swish.play();    });return mesh;
}
function resetPoweDowns() {removeOldPowerDowns1();var random47 = 47 + Math.floor(10*Math.random());var p47 = ground.riverPoints[random47];addPowerDown1(p47);var random84 = 84 + Math.floor(10*Math.random());var p84 = ground.riverPoints[random84];addPowerDown1(p84);
}function removeOldPowerDowns1() {var last = scene.children.length - 1;for (var i=last; i>=0; i--) {var obj = scene.children[i];if (obj.powerDown) scene.remove(obj);}
}
function addPowerDown(riverPoint){ground.updateMatrixWorld();var x = riverPoint.x + 4 * (Math.random() - 0.5);var y = riverPoint.y;var z = -0.5;var p  = new THREE.Vector3(x, y, z);ground.localToWorld(p);var shape =  new THREE.BoxGeometry(0.2, 0.5, 0.2);var cover = new THREE.MeshNormalMaterial({color:'black'});var mesh = new Physijs.BoxMesh(shape, cover, 0);mesh.position.copy(p);mesh.powerDown1 = true;scene.add(mesh);mesh.addEventListener('collision',function() {for (var i=0; i < scene.children.length; i++) {var obj = scene.children[i];if (obj == mesh) scene.remove(obj);}scoreboard.addPoints(-18);scoreboard.message('哎呀!撞到障碍物了!下次小心哦!!');setTimeout(function() {scoreboard.clearMessage();}, 5*1000);Sounds.swish.play();});return mesh;
}function removeOldPowerDowns() {var last = scene.children.length - 1;for (var i=last; i>=0; i--) {var obj = scene.children[i];if (obj.powerDown) scene.remove(obj);}
}function resetPoweDowns2() {removeOldPowerDowns2();var random36 = 36 + Math.floor(10*Math.random());var p36 = ground.riverPoints[random36];addPowerDown2(p36);var random58 = 58+ Math.floor(10*Math.random());var p58 = ground.riverPoints[random70];addPowerDown2(p58);
}function addPowerDown2(riverPoint){ground.updateMatrixWorld();var x = riverPoint.x + 4 * (Math.random() - 0.5);var y = riverPoint.y;var z = -0.5;var p  = new THREE.Vector3(x, y, z);ground.localToWorld(p);var shape =  new THREE.BoxGeometry(0.2, 0.5, 0.2);var cover = new THREE.MeshNormalMaterial({color:'black'});var mesh = new Physijs.BoxMesh(shape, cover, 0);mesh.position.copy(p);mesh.powerDown = true;scene.add(mesh);mesh.addEventListener('collision',function() {for (var i=0; i < scene.children.length; i++) {var obj = scene.children[i];if (obj == mesh) scene.remove(obj);}scoreboard.addPoints(-18);scoreboard.message('哎呀!撞到障碍物了!下次小心哦!!');setTimeout(function() {scoreboard.clearMessage();}, 5*1000); Sounds.swish.play();});return mesh;
}function removeOldPowerDowns2() {var last = scene.children.length - 1;for (var i=last; i>=0; i--) {var obj = scene.children[i];if (obj.powerDown) scene.remove(obj);}
}function resetPoweDowns2() {removeOldPowerDowns2();var random20 = 20 + Math.floor(10*Math.random());var p20 = ground.riverPoints[random20];addPowerDown2(p20);var random70 = 70 + Math.floor(10*Math.random());var p70 = ground.riverPoints[random70];addPowerDown2(p70);
}function addPowerDown2(riverPoint){ground.updateMatrixWorld();var x = riverPoint.x + 4 * (Math.random() - 0.5);var y = riverPoint.y;var z = -0.5;var p  = new THREE.Vector3(x, y, z);ground.localToWorld(p);var shape =  new THREE.BoxGeometry(0.2, 0.5, 0.2);var cover = new THREE.MeshNormalMaterial({color:'black'});var mesh = new Physijs.BoxMesh(shape, cover, 0);mesh.position.copy(p);mesh.powerDown = true;scene.add(mesh);mesh.addEventListener('collision',function() {for (var i=0; i < scene.children.length; i++) {var obj = scene.children[i];if (obj == mesh) scene.remove(obj);}scoreboard.addPoints(-18);scoreboard.message('哎呀!撞到障碍物了!下次小心哦!!');setTimeout(function() {scoreboard.clearMessage();}, 5*1000);Sounds.swish.play(); });return mesh;
}function removeOldPowerDowns2() {var last = scene.children.length - 1;for (var i=last; i>=0; i--) {var obj = scene.children[i];if (obj.powerDown) scene.remove(obj);}
}function resetPoweUps() {removeOldPowerUps();var random20 = 20 + Math.floor(10*Math.random());var p20 = ground.riverPoints[random20];addPowerUp(p20);var random70 = 70 + Math.floor(10*Math.random());var p70 = ground.riverPoints[random70];addPowerUp(p70);
}function addPowerUp(riverPoint){ground.updateMatrixWorld();var x = riverPoint.x + 4 * (Math.random() - 0.5);var y = riverPoint.y;var z = -0.5;var p  = new THREE.Vector3(x, y, z);ground.localToWorld(p);var shape =  new THREE.SphereGeometry(0.25,25,18);var cover = new THREE.MeshNormalMaterial();var mesh = new Physijs.SphereMesh(shape, cover, 0);mesh.position.copy(p);mesh.powerDown = true;scene.add(mesh);mesh.addEventListener('collision',function() {for (var i=0; i<scene.children.length; i++) {var obj = scene.children[i];if (obj == mesh) scene.remove(obj);}scoreboard.addPoints(200);scoreboard.message('好吃!');setTimeout(function() {scoreboard.clearMessage();}, 5*1000);Sounds.bubble.play();});return mesh;
}function removeOldPowerUps() {var last = scene.children.length - 1;for (var i=last; i>=0; i--) {var obj = scene.children[i];if (obj.powerUp) scene.remove(obj);}
}document.addEventListener('keydown',sendKeyDown);function sendKeyDown(event){var code = event.code;if (code == 'ArrowLeft') rotateRaft(1);if (code == 'ArrowRight') rotateRaft(-1);if (code == 'ArrowDown') pushRaft();if (code == 'Space') pushRaft();if (code == 'KeyR') reset();if (code == 'KeyC') switchCamera();}function rotateRaft(direction){Raft.tube.rotation.z = Raft.tube.rotation.z + direction * Math.PI/10;}function pushRaft(){var angle = Raft.tube.rotation.z;var force = new THREE.Vector3(Math.cos(angle), 0, -Math.sin(angle));Raft.applyCentralForce(force);Sounds.click.play();}function switchCamera() {if (camera == qCam) camera = abovecam;else camera = qCam;}function r(max){if (max) return max * Math.random();return Math.random();
}function rColor(){return new THREE.Color(r(), r(), r());
}
</script>

作为游戏开发者,工作中难免需要在网上拷贝代码,并且在国内因为某些原因,大家大部分会选择在百度上搜索。并且在搜索结果中CSDN上的内容往往会出现在结果列表的前面。所以大家对这个网站应该是非常熟悉的。
然而不知什么时候开始,当我们需要从CSDN上复制点代码时,上面赫然写着:登录后复制
what???
我不知道这个网站的产品经理(也可能是被迫的)对他们的内容质量有多大的自信,大家不过是图个方便,懒得往下翻了。现在居然要求登录后才能复制,这不是故意制造大家的不方便吗?

后来我基本就选择性忽略搜索结果中CSDN的内容,本来上面内容质量就不高,很多广告和重复垃圾,现在还变得盲目自信了,或者也可以叫不要脸了。

骂够了,我们来说说怎么绕过这个人造的坑。

方法一
打开浏览器F2,点击console,输入:

document.body.contentEditable=‘true’

回车搞定,这个方法优点是适用范围广,缺点的稍有麻烦(当然比输入用户名,密码,验证码登录方便点)。

方法二
相比方法一,这个方法更加方便,只需要添加一个书签,并在书签的网址栏输入如下内容:

javascript:document.body.contentEditable=‘true’;document.designMode=‘on’; void 0

然后每次需要复制是,点击一下这个书签即可

方法三
如果连点一下也不想点,那么可以用这个方法。首先添加chrome扩展程序:Simple Allow Copy

然后在拓展程序详情页面,将「允许此扩展程序读取和更改您在所访问的网站上留存的所有数据」选项改为:「在特定网站上」,然后将CSDN的网址添加上即可,如图:

之后就可以复制了,不再需要做任何操作,一劳永逸。唯一一个缺点是安装chrome扩展程序可能需要FQ。
记得关注!

c++编程简易计算器、JavaScript游戏相关推荐

  1. 数据库实验【2】 | 可视化界面编程——简易计算器的设计

    这次实验课是学习可视化编程的入门,任务是完成一个简单的计算器 之前学Java的时候学习过可视化编程,可是当时觉得用Java写类似计算器的程序代码过于繁复,所以也没有学的太好,这次尝试跟着老师使用C#, ...

  2. python编程简易计算器_Python编程练习049:简单计算器实现

    以下代码用于实现简单计算器实现,包括两个数基本的加减乘除运算: 定义函数 def add(x, y): """相加""" return x ...

  3. c语言可循环计算器代码,可编程简易计算器(代码)

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 while(sign[0]!='a'){ //if(input[index]){ for(int i=0;i<4;i++) { if(firstti ...

  4. 科学计算机怎么编程游戏,官泄 可编程科学计算器开发游戏

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 citingspace ::gdi_test::game_test::gemgem function print_line(s) endf functio ...

  5. c语言编程简易计算器代码,可编程简易计算器(代码)

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 while(sign[0]!='a'){ //if(input[index]){ for(int i=0;i<4;i++) { if(firstti ...

  6. 前端 JavaScript 实现一个简易计算器

    前端使用 JavaScript 实现一个简易计算器,没有难度,但是里面有些小知识还是需要注意的,算是一次基础知识回顾吧. 题目 实现一个简易版的计算器,需求如下: 1.除法操作时,如果被除数为0,则结 ...

  7. 麒麟子Javascript游戏编程零基础教程大纲

    大家好,我是麒麟子, 开源项目<幼麟棋牌-四川麻将>(泄漏版叫 <达达麻将>)作者,成都幼麟科技创始人. 开源项目地址(Github与Gitee同步更新): Github ht ...

  8. JavaScript初学入门(JS打印9*9乘法表,JS制作简易计算器)

    目录 网页的三部分组成: Java和JavaScript的关系: JavaScript的三种使用方式: Js的5种输出方式: Js的语法初始: js中值的类型: JS中的运算符: JS中的流程控制语句 ...

  9. JavaScript函数式编程入门-计算器应用

    目录 预备知识 函数式编程 模块化 计算器示例 功能分析 创建index.html 计算过程显示栏实现 创建计算过程显示栏 输出栏组件实现 创建输出栏组件 键盘组件实现 创建键盘组件 完成计算器 函数 ...

  10. 单片机编程简易计算机的设计,简易计算器设计

    <简易计算器设计>由会员分享,可在线阅读,更多相关<简易计算器设计(25页珍藏版)>请在人人文库网上搜索. 1.广东海洋大学寸金学院单片机课程设计论文题目: 简易计算器设计系 ...

最新文章

  1. 【Java报错】MultipartFile 类型文件上传 Current request is not a multipart request 问题处理(postman添加MultipartFile)
  2. OpenCASCADE:形状愈合之修复工具
  3. 用php求n个分数的和,php关于数组n个随机数分成x组,使每组值相近的算法
  4. .NET 4.5 Task异步编程学习资料
  5. json请求 post vue_Spring Boot+Vueaxios异步请求数据的12种操作(上篇)
  6. java被放弃了_为什么学Java那么容易放弃?
  7. 计算机c语言笔试试题,计算机二级c语言笔试题和面试题答案(2019最新)
  8. 软考信息系统项目管理师_信息系统项目管理基础---软考高级之信息系统项目管理师009
  9. 移动电话用户突破6亿大关
  10. java 修改分辨率_JAVA程序分辨率修改及自适屏修改
  11. 算法小结——KM算法
  12. 社会性动物1: 从众的原因,如何避免
  13. c语言里的除法运算定律,加法乘法运算,乘法需要打括号吗?
  14. 吉林大学嵌入式原理课程课堂作业
  15. 有道云笔记如何修改全局默认字体样式
  16. 互联网寒冬下如何过冬?厚积薄发还是直接开摆?我选这个
  17. Java程序员非技术性面试题目
  18. ChatGPT技术报告
  19. 郭德纲恶心人台词大全
  20. java找出和最接近指定值_如何找到数组元素与特定值最接近的和?

热门文章

  1. 「米聊」突然复活,雷布斯真的是出其不意
  2. Sectigo邮件签名证书安装指南
  3. 搭建Hadoop集群后一直使用的start-all.sh到底是个什么操作
  4. 笔试面试常见逻辑题及答案
  5. 躲避球av_躲避球HTML!
  6. ALS模拟环境光传感芯片的工作原理
  7. wp-bugku-秋名山老司机
  8. 不刷机,京东云路由进openwrt后台
  9. openlayers 设置边界线外圈遮罩
  10. 2021年金融科技书单推荐