mirror of
https://github.com/sigmasternchen/Wish
synced 2025-03-15 15:38:54 +00:00
commit
f65054fa03
1 changed files with 1 additions and 0 deletions
1
wish-sys/sys-part/usr/bin/snake.js
Normal file
1
wish-sys/sys-part/usr/bin/snake.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
SnakeClass=function(){};SnakeClass.prototype=new Process();B=" :::::::: :::: ::: ::: ::: ::: ::::::::::\n :+: :+: :+:+: :+: :+: :+: :+: :+: :+:\n +:+ :+:+:+ +:+ +:+ +:+ +:+ +:+ +:+\n +#++:++#++ +#+ +:+ +#+ +#++:++#++: +#++:++ +#++:++#\n +#+ +#+ +#+#+# +#+ +#+ +#+ +#+ +#+\n #+# #+# #+# #+#+# #+# #+# #+# #+# #+#\n ######## ### #### ### ### ### ### ##########\n";SnakeClass.prototype.main=function(a){this.g=0;Kernel.Scheduler.add(this);o=this.files["stdout"];o.write("\033[2J");this.d(2,"bitowl presents");o.write("\033[0:5H"+B);this.d(17,"any key to continue");this.d(23,"v 0.1");};SnakeClass.prototype.tick=function(){o=this.files["stdout"];i=this.files["stdin"];if(this.g==1){i=i.read();if(i){switch(i){case 97:case 100:case 119:case 115:this.x=i;break;case 113:this.z();return;}}t=new Date().getTime()-this.l;if(t>=100){this.l+=100;if(Math.random()<0.1){this.f(Math.floor(Math.random()*80),Math.floor(Math.random()*22),3);}switch(this.x){case 97:this.s(this.q-1,this.v);break;case 100:this.s(this.q+1,this.v);break;case 119:this.s(this.q,this.v-1);break;case 115:this.s(this.q,this.v+1);break;}}}else if(this.g==0){i=i.read();if(i){this.e();}}else if(this.g==2){i=i.read();if(i){if(i==113){this.z();return;}else{this.e();}}}o.write("\033[0:0H");};SnakeClass.prototype.e=function(){o=this.files["stdout"];o.write("\033[2J");this.w=new Array(22);for(i=0;i<22;i++){this.w[i]=new Array(80);}this.x=100;this.q=3;this.v=1;this.m=new Array();this.m.push(new A(this.q,this.v));this.m.push(new A(this.q-1,this.v));this.m.push(new A(this.q-2,this.v));this.f(this.q,this.v,1);this.p=0;o.write("\033[0:23Hpress q to exit");o.write("\033[1:0H----Snake----------------------------------------------------------------------");this.h();this.l=new Date().getTime();this.g=1;};SnakeClass.prototype.s = function(a,b){r=1;if(a<0){a=79;}if(b<0){b=21;}if(a>=80){a=0;}if(b>=22){b=0;}switch(this.w[b][a]){case 3:this.p++;this.h();r=0;break;case 2:case 1:this.y();break;}if(r){r=this.m.shift();this.f(r.x,r.y,0);}this.q=a;this.v=b;this.m.push(new A(this.q,this.v));this.f(this.q,this.v,1);};SnakeClass.prototype.f=function(a,b,c){o=this.files["stdout"];this.w[b][a]=c;v="";switch(c){case 0:v=" ";break;case 1:v="\033[33mX\033[0m";break;case 2:v="#";break;case 3:v="\033[32mo\033[0m";break;}o.write("\033["+a+":"+(b+1)+"H"+v);};SnakeClass.prototype.h=function(){o=this.files["stdout"];l=(this.p+"").length;o.write("\033["+(70-l)+":0Hpoints: "+this.p);};SnakeClass.prototype.d=function(a,b){o=this.files["stdout"];o.write("\033["+Math.floor(40-b.length/2)+":"+a+"H"+b);};SnakeClass.prototype.y=function(){o=this.files["stdout"];this.g=2;o.write("\033[0:5H\033[31m ____ ___\n / ___| __ _ _ __ ___ ___ / _ \\ __ __ ___ _ __\n | | _ / _` || '_ ` _ \\ / _ \\ | | | |\\ \\ / // _ \\| '__|\n | |_| || (_| || | | | | || __/ | |_| | \\ V /| __/| |\n \\____| \\__,_||_| |_| |_| \\___| \\___/ \\_/ \\___||_|\n");this.d(15,"press any key to start again");this.d(17,"or q if this game has stressed you enough");};SnakeClass.prototype.z=function(){this.g=3;Kernel.Scheduler.remove(this);o=this.files["stdout"];o.write("\033[2J");o.write("\033[0:6H"+B);this.d(14,"I hope you had fun!");this.d(16,"created by bitowl");this.d(17,"http://bitowl.de");o.write("\033[0:18H\n");this.exit(0);};function A(x,y){this.x=x;this.y=y;}
|
Loading…
Reference in a new issue