How to play Tank game

1. Run the programming below.
2. Click the “watch video” to watch the background story of this game.
3. Click the “start game” to start the game.
4. Press the “e” to end the game.
5. Press the “r” to restart the game.
6. Press the “up arrow”, “down arrow”, “left arrow”, “right arrow” key to move up, down, left, right.
7. Press the “space” key to shoot.
8. The total bullet number is 30, if your bullet number is zero, you can’t shoot. You can add bullet by getting bullet box .
9. You can still kill green tank by colliding with them, then your blood will minus one. When green tank enters into your home, blood will minus one. When blood equal zero, you die. You can add blood by getting aid box .
10. You will win, if you and your family survive for one week.

step=0.2;pos={2.5,0.3};edge=5;edge1=5;radius=0.1;stop=0;end=0;shoot=0;dir=1;speed=0.5;possibility=0.9;killnum=0;bulletnum=30;start=0;
win=0;
lose=0;
fireworknum=1;
tankposup={{RandomReal[{-edge,edge}],edge,1}};tankvec={{0,-RandomReal[{0,step}],0}};
bulletpos={};bulletvec={};bulletboxpos={};aidboxpos={};time=0;appeartime=100;disappeartime=20;gamespeed=0.35;addnum=30;
homepos={0,0};level=1;blood=10;addblood=10;
tank=ImageResize[,{80,80}];badtank=ImageResize[,{50,50}];bomb=ImageResize[,{80,80}];
bulletbox=ImageResize[,{60,60}];aidbox=ImageResize[,{60,60}];home=ImageResize[,{80,80}];startstory=ImageResize[,All];badnews=ImageResize[,All];
firework={,,,,,,,};
mytank={tank,ImageRotate[tank,180Degree],ImageRotate[tank,90Degree],ImageRotate[tank,-90Degree]};
tankrun=mytank[[1]];
EventHandler[Dynamic[Graphics[If[start==0,Inset[startstory,{0,0},Center,10],If[win==1,{Inset[firework[[fireworknum]],{0,0},Center,10],Text[Style["You protect your family. Best Wishes!",20],{0,-4.7}]},If[lose==1,{Inset[badnews,{0,0},Center,10],Text[Style["Press r to restart",20],{0,-4.7}]},{Table[Inset[ImageRotate[badtank,If[tankposup[[i,3]]==1,180Degree,If[tankposup[[i,3]]==2,0Degree,If[tankposup[[i,3]]==3,-90Degree,If[tankposup[[i,3]]==4,90Degree]]]]],{tankposup[[i,1]],tankposup[[i,2]]},Center,0.8],{i,Length[tankposup]}],Inset[tankrun,pos,Center,1],If[shoot==1,Table[Disk[bulletpos[[i]],radius],{i,1,Length[bulletpos]}]],If[Length[bombpos]>0,Table[Inset[bomb,bombpos[[i]],Center,0.8],{i,Length[bombpos]}]],If[Length[bulletboxpos]>0,Inset[bulletbox,bulletboxpos,Center,0.8]],If[Length[aidboxpos]>0,Inset[aidbox,aidboxpos,Center,0.8]],Inset[home,homepos,Center,1],Text[Style[StringForm["kill num: ``",killnum],17],{4.0,4.7}],Text[Style[StringForm["bullet num: ``",bulletnum],17],{4.0,4.3}],Text[Style[StringForm["day: ``",level],17],{4.0,3.9}],Text[Style[StringForm["blood: ``",blood],17],{4.0,3.5}]}//Flatten[#,1]&]]],PlotRange->edge,Frame->True,FrameTicks->None,ImageSize->Large]],{"UpArrowKeyDown":>{If[pos[[2]]<edge-radius,pos[[2]]=pos[[2]]+step];tankrun=mytank[[1]];dir=1},
"DownArrowKeyDown":>{If[pos[[2]]>-edge+radius,pos[[2]]=pos[[2]]-step;];tankrun=mytank[[2]];dir=2},"LeftArrowKeyDown":>{If[pos[[1]]>-edge+radius,pos[[1]]=pos[[1]]-step];tankrun=mytank[[3]];dir=3},"RightArrowKeyDown":>{If[pos[[1]]<edge-radius,pos[[1]]=pos[[1]]+step];tankrun=mytank[[4]];dir=4},{"KeyDown","p"}:>{stop=stop/.{1->0,0->1}},{"KeyDown","e"}:>{end=1},{"KeyDown"," "}:>{If[bulletnum>0,shoot=1;bulletpos=Append[bulletpos,pos];bulletnum=bulletnum-1;If[dir==1,bulletvec=Append[bulletvec,{0,speed}]];If[dir==2,bulletvec=Append[bulletvec,{0,-speed}]];
If[dir==3,bulletvec=Append[bulletvec,{-speed,0}]];
If[dir==4,bulletvec=Append[bulletvec,{speed,0}]]]},{"KeyDown","r"}:>{lose=0;blood=10;killnum=0;bulletnum=30;start=0;},"MouseClicked":>{If[start==0,If[(-2.3<MousePosition["Graphics"][[1]]<2.5)&&(-1<MousePosition["Graphics"][[2]]<0.3),start=1;];If[(-2.3<MousePosition["Graphics"][[1]]<2.5)&&(1<MousePosition["Graphics"][[2]]<2.3),SystemOpen["https://youtu.be/qhHtsshUwAw"];]]}}]

While[True,If[start==0,Pause[1];,If[win==1,Pause[1];If[fireworknum==8,Pause[1];fireworknum=0;];fireworknum=fireworknum+1;If[end==1,Break[]];,If[lose==1,Pause[1];If[end==1,Break[]];,Pause[gamespeed];
outnum={};
tanknumout={};

bombpos={};rand=RandomReal[{-1,1},3];If[rand[[3]]>possibility,If[rand[[1]]>0&&rand[[2]]>0,tankposup=Append[tankposup,{RandomReal[{-edge1,edge1}],edge,1}];tankvec=Append[tankvec,{0,-RandomReal[{0,step}],0}]];If[rand[[1]]<0&&rand[[2]]>0,tankposup=Append[tankposup,{RandomReal[{-edge1,edge1}],-edge,2}];tankvec=Append[tankvec,{0,RandomReal[{0,step}],0}]];If[rand[[1]]<0&&rand[[2]]<0,tankposup=Append[tankposup,{-edge,RandomReal[{-edge1,edge1}],3}];tankvec=Append[tankvec,{RandomReal[{0,step}],0,0}]];If[rand[[1]]>0&&rand[[2]]<0,tankposup=Append[tankposup,{edge,RandomReal[{-edge1,edge1}],4}];tankvec=Append[tankvec,{-RandomReal[{0,step}],0,0}]]];tankposup=tankposup+tankvec;
If[Length[bulletboxpos]==0&&time==appeartime,bulletboxpos=RandomReal[{-edge+1,edge-1},2];];
If[Length[bulletboxpos]>0,If[Total[(((bulletboxpos-pos))^2)]<0.5,bulletboxpos={};bulletnum=addnum;time=0;,If[time==appeartime+disappeartime,bulletboxpos={};time=0;]]];
If[Length[aidboxpos]==0&&time==appeartime/2,aidboxpos=RandomReal[{-edge+1,edge-1},2];];
If[Length[aidboxpos]>0,If[Total[(((aidboxpos-pos))^2)]<0.5,aidboxpos={};blood=addblood;,If[time==appeartime/2+disappeartime,aidboxpos={};]]];
time=time+1;

For[i=1,i<Length[tankposup]+1,i=i+1,If[Max[Abs[tankposup[[i]]]]>6,tanknumout=Append[tanknumout,{i}];]];
For[i=1,i<Length[tankposup]+1,i=i+1,If[Total[((tankposup[[i,1;;2]])^2)]<1,tanknumout=Append[tanknumout,{i}];blood=blood-1;]];
For[i=1,i<Length[tankposup]+1,i=i+1,If[If[Length[bulletpos]==0,False,Min[Total[(((Table[Delete[tankposup[[i]],3],{j,Length[bulletpos]}]-bulletpos))^2),{2}]]<0.5],tanknumout=Append[tanknumout,{i}];
index=Ordering[Total[(((Table[Delete[tankposup[[i]],3],{j,Length[bulletpos]}]-bulletpos))^2),{2}],1];
outnum=Append[outnum,index];
bombpos=Append[bombpos,bulletpos[[index[[1]]]]];

killnum=killnum+1;level=IntegerPart[killnum/10]+1;possibility=1-0.12*Sqrt[level];step=0.15*Sqrt[level];edge1=5-level*0.4;]];
For[i=1,i<Length[tankposup]+1,i=i+1,If[Total[(((pos-tankposup[[i,1;;2]]))^2)]<0.5,
tanknumout=Append[tanknumout,{i}];
blood=blood-1;
killnum=killnum+1;
bombpos=Append[bombpos,tankposup[[i,1;;2]]];]];
tankposup=Delete[tankposup,tanknumout];
tankvec=Delete[tankvec,tanknumout];
If[shoot==1,bulletpos=bulletpos+bulletvec;For[i=1,i<Length[bulletpos]+1,i=i+1,If[Max[Abs[bulletpos[[i]]]]>6,outnum=Append[outnum,{i}];]];bulletpos=Delete[bulletpos,outnum];bulletvec=Delete[bulletvec,outnum];
];
If[stop==1,Pause[10]];If[end==1,Break[]];If[level==8,Pause[2];tankposup={};bombpos={};Pause[2];win=1;];If[blood==0,Pause[2];lose=1;]]]]]