HTANoid 用hta编写的一个经典的游戏(编写hello world)全程干货

随心笔谈1年前发布 编辑
153 0

<head>

 APPLICATIONNAME=”HTAnoid”

 BORDER=”thick” | “dialog” | “none”  | “thin”

 BORDERSTYLE=”normal” | “complex” | “raised”  | “static”  | “sunken”

 CAPTION=”yes” CONTEXTMENU=”yes”

 ID=”oHTA” alert(oHTA.applicationName);

 INNERBORDER=”yes” MAXIMIZEBUTTON=”yes” MINIMIZEBUTTON=”yes”

 NAVIGABLE=”no” SCROLL=”no” SCROLLFLAT=”no”

 SELECTION=”yes” SHOWINTASKBAR=”yes” SINGLEINSTANCE=”no”

 SYSMENU=”yes” VERSION=”0.5″

 WINDOWSTATE=”normal” | “maximize” | “minimize”>

Option explicit

Const C_ScreenW=400

Const C_NbX=12

Const C_NbY=10

Dim Terrain(10,12)

Dim RaqX,RaqW,Playing,BalleX,BalleY

Dim DirBX,DirBY ‘Direction balle X,Y

Dim BordDroit

BordDroit=C_ScreenW-32

Sub Document_onKeyPress()

 Select Case UCase(Chr(Window.Event.keyCode))

 Case “P”

  Msgbox “pause”

  ‘Window.ClearTimeOut

 End Select

End Sub

Sub Document_onClick()

 Playing=True

 ‘document.title=”click ” & window.event.button

End Sub

Sub Document_onMouseMove()

 RaqX=window.event.clientX-RaqW ‘.shiftKey .keyCode .ctrlKey .button .altKey

 If RaqX<16 Then RaqX=16 ‘Mur gauche

 If RaqX+RaqW>BordDroit Then RaqX=BordDroit-RaqW

 Raquette.style.Left=RaqX

 If Not Playing Then

  BalleX=RaqX+RaqW/2

  Balle.Style.Left=BalleX

 End If

End Sub

Sub DrawLevel(n)

 Dim k,x,y

 set k=document.getElementById(“Raquette”)

 For y=0 To C_NbY

  For x=0 To C_NbX

   Terrain(y,x)=0 ‘Nb de coups restant à porter

  Next

 Next

 Select Case n

 Case 1

  ‘Bricks

  For y=0 To 5

   For x=0 To C_NbX

    k.insertAdjacentHTML “beforeBegin”,”

    & “;width=25;height=10;’ bgcolor=” & Array(“silver”,”red”,”yellow”,”blue”,”magenta”,”lightgreen”)(y) & “>”

   Next

  Next

 End Select

 Randomize

 BalleY=400

 DirBX=Int(Rnd()*3)+1

 DirBY=0-(Int(Rnd()*4)+1)

End Sub

Sub Init

 Dim x,y,k

 Window.MoveTo screen.Width/2-200,0

 Window.ReSizeTo C_ScreenW,484

 RaqW=Int(Replace(Raquette.style.width,”pc”,””)*1.6)

 ‘Lives Left

 set k=document.getElementById(“Raquette”)

 ‘CreateElement + insertAdjacentElement

 For x=0 To 2

  k.insertAdjacentHTML “beforeBegin”,”

   & “;width:15pc;height:5pc;’>” _

   & “”

 Next

 DrawLevel 1

 Playing=False

 window.setTimeout “Gere”,10

End Sub

Sub Gere

 If Playing Then

  ‘Déplacement de la balle

  If DirBX>0 Then

   If BalleX+DirBX>BordDroit-10 Then DirBX=0-DirBx

  Else

   If BalleX+DirBX<16 Then DirBX=0-DirBx

  End If

  If DirBY>0 Then

   If BalleY+DirBY>400 Then DirBY=0-DirBY

  Else

   If BalleY+DirBY<50 Then DirBY=0-DirBY

  End If

  BalleX=BalleX+DirBX

  BalleY=BalleY+DirBY

  Balle.Style.Left=BalleX

  Balle.Style.Top=BalleY

 Else

  document.title=Now

 End If

 window.setTimeout “Gere”,10

End Sub

 v\:* {behavior:url(#default#VML);}

 t\:* {behavior:url(#default#time2)}

BODY {

  font-family: “Verdana, Arial, Helvetica, sans-serif”;

  background-color=#003159;

  color:#0000FF;

  font-size: 8pt;

 }

TABLE,TD {

  border:’0pix groove’;

  cursor:W-resize;

 }

.score {

  color:white;

  font-size: 10pt;

 }

–>

</STYLE>


HIGH SCORE
<div id=Score class=score>1234</div></td><td><div id=HighScore class=score>123400</div></td></tr></table></CENTER>

 </td>

 <td width=100%>

 </v:oval>

 </v:group>

</table>

© 版权声明

相关文章