<class>
  <keyword > class </keyword>
  <identifier class, defined> SquareGame </identifier>
  <symbol > { </symbol>
  <classVarDec>
    <keyword > field </keyword>
    <identifier > Square </identifier>
    <identifier name=square type=Square kind=Field index=0 declared> square </identifier>
    <symbol > ; </symbol>
  </classVarDec>
  <classVarDec>
    <keyword > field </keyword>
    <keyword > int </keyword>
    <identifier name=direction type=int kind=Field index=1 declared> direction </identifier>
    <symbol > ; </symbol>
  </classVarDec>
  <subroutineDec>
    <identifier > SquareGame </identifier>
    <identifier subroutine, defined> new </identifier>
    <symbol > ( </symbol>
    <parameterList>
    </parameterList>
    <symbol > ) </symbol>
    <subroutineBody>
      <symbol > { </symbol>
      <statements>
        <letStatement>
          <keyword > let </keyword>
          <identifier name=square type=Square kind=Field index=0 used> square </identifier>
          <symbol > = </symbol>
          <expression>
            <term>
              <identifier class, used> Square </identifier>
              <symbol > . </symbol>
              <identifier function, used> new </identifier>
              <symbol > ( </symbol>
              <symbol > ) </symbol>
            </term>
          </expression>
          <symbol > ; </symbol>
        </letStatement>
        <letStatement>
          <keyword > let </keyword>
          <identifier name=direction type=int kind=Field index=1 used> direction </identifier>
          <symbol > = </symbol>
          <expression>
            <term>
              <integerConstant > 0 </integerConstant>
            </term>
          </expression>
          <symbol > ; </symbol>
        </letStatement>
        <returnStatement>
          <keyword > return </keyword>
          <expression>
            <term>
              <keyword > this </keyword>
            </term>
          </expression>
          <symbol > ; </symbol>
        </returnStatement>
      </statements>
      <symbol > } </symbol>
    </subroutineBody>
  </subroutineDec>
  <subroutineDec>
    <keyword > void </keyword>
    <identifier subroutine, defined> dispose </identifier>
    <symbol > ( </symbol>
    <parameterList>
    </parameterList>
    <symbol > ) </symbol>
    <subroutineBody>
      <symbol > { </symbol>
      <statements>
        <doStatement>
          <keyword > do </keyword>
          <identifier class, used> square </identifier>
          <symbol > . </symbol>
          <identifier function, used> dispose </identifier>
          <symbol > ( </symbol>
          <symbol > ) </symbol>
          <symbol > ; </symbol>
        </doStatement>
        <doStatement>
          <keyword > do </keyword>
          <identifier class, used> Memory </identifier>
          <symbol > . </symbol>
          <identifier function, used> deAlloc </identifier>
          <symbol > ( </symbol>
          <symbol > ) </symbol>
          <symbol > ; </symbol>
        </doStatement>
        <returnStatement>
          <keyword > return </keyword>
          <symbol > ; </symbol>
        </returnStatement>
      </statements>
      <symbol > } </symbol>
    </subroutineBody>
  </subroutineDec>
  <subroutineDec>
    <keyword > void </keyword>
    <identifier subroutine, defined> moveSquare </identifier>
    <symbol > ( </symbol>
    <parameterList>
    </parameterList>
    <symbol > ) </symbol>
    <subroutineBody>
      <symbol > { </symbol>
      <statements>
        <ifStatement>
          <keyword > if </keyword>
          <symbol > ( </symbol>
          <expression>
            <term>
              <identifier name=direction type=int kind=Field index=1 used> direction </identifier>
            </term>
            <symbol > = </symbol>
            <term>
              <integerConstant > 1 </integerConstant>
            </term>
          </expression>
          <symbol > ) </symbol>
          <symbol > { </symbol>
          <statements>
            <doStatement>
              <keyword > do </keyword>
              <identifier class, used> square </identifier>
              <symbol > . </symbol>
              <identifier function, used> moveUp </identifier>
              <symbol > ( </symbol>
              <symbol > ) </symbol>
              <symbol > ; </symbol>
            </doStatement>
          </statements>
          <symbol > } </symbol>
        </ifStatement>
        <ifStatement>
          <keyword > if </keyword>
          <symbol > ( </symbol>
          <expression>
            <term>
              <identifier name=direction type=int kind=Field index=1 used> direction </identifier>
            </term>
            <symbol > = </symbol>
            <term>
              <integerConstant > 2 </integerConstant>
            </term>
          </expression>
          <symbol > ) </symbol>
          <symbol > { </symbol>
          <statements>
            <doStatement>
              <keyword > do </keyword>
              <identifier class, used> square </identifier>
              <symbol > . </symbol>
              <identifier function, used> moveDown </identifier>
              <symbol > ( </symbol>
              <symbol > ) </symbol>
              <symbol > ; </symbol>
            </doStatement>
          </statements>
          <symbol > } </symbol>
        </ifStatement>
        <ifStatement>
          <keyword > if </keyword>
          <symbol > ( </symbol>
          <expression>
            <term>
              <identifier name=direction type=int kind=Field index=1 used> direction </identifier>
            </term>
            <symbol > = </symbol>
            <term>
              <integerConstant > 3 </integerConstant>
            </term>
          </expression>
          <symbol > ) </symbol>
          <symbol > { </symbol>
          <statements>
            <doStatement>
              <keyword > do </keyword>
              <identifier class, used> square </identifier>
              <symbol > . </symbol>
              <identifier function, used> moveLeft </identifier>
              <symbol > ( </symbol>
              <symbol > ) </symbol>
              <symbol > ; </symbol>
            </doStatement>
          </statements>
          <symbol > } </symbol>
        </ifStatement>
        <ifStatement>
          <keyword > if </keyword>
          <symbol > ( </symbol>
          <expression>
            <term>
              <identifier name=direction type=int kind=Field index=1 used> direction </identifier>
            </term>
            <symbol > = </symbol>
            <term>
              <integerConstant > 4 </integerConstant>
            </term>
          </expression>
          <symbol > ) </symbol>
          <symbol > { </symbol>
          <statements>
            <doStatement>
              <keyword > do </keyword>
              <identifier class, used> square </identifier>
              <symbol > . </symbol>
              <identifier function, used> moveRight </identifier>
              <symbol > ( </symbol>
              <symbol > ) </symbol>
              <symbol > ; </symbol>
            </doStatement>
          </statements>
          <symbol > } </symbol>
        </ifStatement>
        <doStatement>
          <keyword > do </keyword>
          <identifier class, used> Sys </identifier>
          <symbol > . </symbol>
          <identifier function, used> wait </identifier>
          <symbol > ( </symbol>
          <symbol > ) </symbol>
          <symbol > ; </symbol>
        </doStatement>
        <returnStatement>
          <keyword > return </keyword>
          <symbol > ; </symbol>
        </returnStatement>
      </statements>
      <symbol > } </symbol>
    </subroutineBody>
  </subroutineDec>
  <subroutineDec>
    <keyword > void </keyword>
    <identifier subroutine, defined> run </identifier>
    <symbol > ( </symbol>
    <parameterList>
    </parameterList>
    <symbol > ) </symbol>
    <subroutineBody>
      <symbol > { </symbol>
      <varDec>
        <keyword > var </keyword>
        <keyword > char </keyword>
        <identifier name=key type=char kind=Var index=0 declared> key </identifier>
        <symbol > ; </symbol>
      </varDec>
      <varDec>
        <keyword > var </keyword>
        <keyword > boolean </keyword>
        <identifier name=exit type=boolean kind=Var index=1 declared> exit </identifier>
        <symbol > ; </symbol>
      </varDec>
      <statements>
        <letStatement>
          <keyword > let </keyword>
          <identifier name=exit type=boolean kind=Var index=1 used> exit </identifier>
          <symbol > = </symbol>
          <expression>
            <term>
              <keyword > false </keyword>
            </term>
          </expression>
          <symbol > ; </symbol>
        </letStatement>
        <whileStatement>
          <keyword > while </keyword>
          <symbol > ( </symbol>
          <expression>
            <term>
              <symbol > ~ </symbol>
              <term>
                <identifier name=exit type=boolean kind=Var index=1 used> exit </identifier>
              </term>
            </term>
          </expression>
          <symbol > ) </symbol>
          <symbol > { </symbol>
          <statements>
            <whileStatement>
              <keyword > while </keyword>
              <symbol > ( </symbol>
              <expression>
                <term>
                  <identifier name=key type=char kind=Var index=0 used> key </identifier>
                </term>
                <symbol > = </symbol>
                <term>
                  <integerConstant > 0 </integerConstant>
                </term>
              </expression>
              <symbol > ) </symbol>
              <symbol > { </symbol>
              <statements>
                <letStatement>
                  <keyword > let </keyword>
                  <identifier name=key type=char kind=Var index=0 used> key </identifier>
                  <symbol > = </symbol>
                  <expression>
                    <term>
                      <identifier class, used> Keyboard </identifier>
                      <symbol > . </symbol>
                      <identifier function, used> keyPressed </identifier>
                      <symbol > ( </symbol>
                      <symbol > ) </symbol>
                    </term>
                  </expression>
                  <symbol > ; </symbol>
                </letStatement>
                <doStatement>
                  <keyword > do </keyword>
                  <identifier function, used> moveSquare </identifier>
                  <symbol > ( </symbol>
                  <symbol > ) </symbol>
                  <symbol > ; </symbol>
                </doStatement>
              </statements>
              <symbol > } </symbol>
            </whileStatement>
            <ifStatement>
              <keyword > if </keyword>
              <symbol > ( </symbol>
              <expression>
                <term>
                  <identifier name=key type=char kind=Var index=0 used> key </identifier>
                </term>
                <symbol > = </symbol>
                <term>
                  <integerConstant > 81 </integerConstant>
                </term>
              </expression>
              <symbol > ) </symbol>
              <symbol > { </symbol>
              <statements>
                <letStatement>
                  <keyword > let </keyword>
                  <identifier name=exit type=boolean kind=Var index=1 used> exit </identifier>
                  <symbol > = </symbol>
                  <expression>
                    <term>
                      <keyword > true </keyword>
                    </term>
                  </expression>
                  <symbol > ; </symbol>
                </letStatement>
              </statements>
              <symbol > } </symbol>
            </ifStatement>
            <ifStatement>
              <keyword > if </keyword>
              <symbol > ( </symbol>
              <expression>
                <term>
                  <identifier name=key type=char kind=Var index=0 used> key </identifier>
                </term>
                <symbol > = </symbol>
                <term>
                  <integerConstant > 90 </integerConstant>
                </term>
              </expression>
              <symbol > ) </symbol>
              <symbol > { </symbol>
              <statements>
                <doStatement>
                  <keyword > do </keyword>
                  <identifier class, used> square </identifier>
                  <symbol > . </symbol>
                  <identifier function, used> decSize </identifier>
                  <symbol > ( </symbol>
                  <symbol > ) </symbol>
                  <symbol > ; </symbol>
                </doStatement>
              </statements>
              <symbol > } </symbol>
            </ifStatement>
            <ifStatement>
              <keyword > if </keyword>
              <symbol > ( </symbol>
              <expression>
                <term>
                  <identifier name=key type=char kind=Var index=0 used> key </identifier>
                </term>
                <symbol > = </symbol>
                <term>
                  <integerConstant > 88 </integerConstant>
                </term>
              </expression>
              <symbol > ) </symbol>
              <symbol > { </symbol>
              <statements>
                <doStatement>
                  <keyword > do </keyword>
                  <identifier class, used> square </identifier>
                  <symbol > . </symbol>
                  <identifier function, used> incSize </identifier>
                  <symbol > ( </symbol>
                  <symbol > ) </symbol>
                  <symbol > ; </symbol>
                </doStatement>
              </statements>
              <symbol > } </symbol>
            </ifStatement>
            <ifStatement>
              <keyword > if </keyword>
              <symbol > ( </symbol>
              <expression>
                <term>
                  <identifier name=key type=char kind=Var index=0 used> key </identifier>
                </term>
                <symbol > = </symbol>
                <term>
                  <integerConstant > 131 </integerConstant>
                </term>
              </expression>
              <symbol > ) </symbol>
              <symbol > { </symbol>
              <statements>
                <letStatement>
                  <keyword > let </keyword>
                  <identifier name=direction type=int kind=Field index=1 used> direction </identifier>
                  <symbol > = </symbol>
                  <expression>
                    <term>
                      <integerConstant > 1 </integerConstant>
                    </term>
                  </expression>
                  <symbol > ; </symbol>
                </letStatement>
              </statements>
              <symbol > } </symbol>
            </ifStatement>
            <ifStatement>
              <keyword > if </keyword>
              <symbol > ( </symbol>
              <expression>
                <term>
                  <identifier name=key type=char kind=Var index=0 used> key </identifier>
                </term>
                <symbol > = </symbol>
                <term>
                  <integerConstant > 133 </integerConstant>
                </term>
              </expression>
              <symbol > ) </symbol>
              <symbol > { </symbol>
              <statements>
                <letStatement>
                  <keyword > let </keyword>
                  <identifier name=direction type=int kind=Field index=1 used> direction </identifier>
                  <symbol > = </symbol>
                  <expression>
                    <term>
                      <integerConstant > 2 </integerConstant>
                    </term>
                  </expression>
                  <symbol > ; </symbol>
                </letStatement>
              </statements>
              <symbol > } </symbol>
            </ifStatement>
            <ifStatement>
              <keyword > if </keyword>
              <symbol > ( </symbol>
              <expression>
                <term>
                  <identifier name=key type=char kind=Var index=0 used> key </identifier>
                </term>
                <symbol > = </symbol>
                <term>
                  <integerConstant > 130 </integerConstant>
                </term>
              </expression>
              <symbol > ) </symbol>
              <symbol > { </symbol>
              <statements>
                <letStatement>
                  <keyword > let </keyword>
                  <identifier name=direction type=int kind=Field index=1 used> direction </identifier>
                  <symbol > = </symbol>
                  <expression>
                    <term>
                      <integerConstant > 3 </integerConstant>
                    </term>
                  </expression>
                  <symbol > ; </symbol>
                </letStatement>
              </statements>
              <symbol > } </symbol>
            </ifStatement>
            <ifStatement>
              <keyword > if </keyword>
              <symbol > ( </symbol>
              <expression>
                <term>
                  <identifier name=key type=char kind=Var index=0 used> key </identifier>
                </term>
                <symbol > = </symbol>
                <term>
                  <integerConstant > 132 </integerConstant>
                </term>
              </expression>
              <symbol > ) </symbol>
              <symbol > { </symbol>
              <statements>
                <letStatement>
                  <keyword > let </keyword>
                  <identifier name=direction type=int kind=Field index=1 used> direction </identifier>
                  <symbol > = </symbol>
                  <expression>
                    <term>
                      <integerConstant > 4 </integerConstant>
                    </term>
                  </expression>
                  <symbol > ; </symbol>
                </letStatement>
              </statements>
              <symbol > } </symbol>
            </ifStatement>
            <whileStatement>
              <keyword > while </keyword>
              <symbol > ( </symbol>
              <expression>
                <term>
                  <symbol > ~ </symbol>
                  <term>
                    <symbol > ( </symbol>
                    <expression>
                      <term>
                        <identifier name=key type=char kind=Var index=0 used> key </identifier>
                      </term>
                      <symbol > = </symbol>
                      <term>
                        <integerConstant > 0 </integerConstant>
                      </term>
                    </expression>
                    <symbol > ) </symbol>
                  </term>
                </term>
              </expression>
              <symbol > ) </symbol>
              <symbol > { </symbol>
              <statements>
                <letStatement>
                  <keyword > let </keyword>
                  <identifier name=key type=char kind=Var index=0 used> key </identifier>
                  <symbol > = </symbol>
                  <expression>
                    <term>
                      <identifier class, used> Keyboard </identifier>
                      <symbol > . </symbol>
                      <identifier function, used> keyPressed </identifier>
                      <symbol > ( </symbol>
                      <symbol > ) </symbol>
                    </term>
                  </expression>
                  <symbol > ; </symbol>
                </letStatement>
                <doStatement>
                  <keyword > do </keyword>
                  <identifier function, used> moveSquare </identifier>
                  <symbol > ( </symbol>
                  <symbol > ) </symbol>
                  <symbol > ; </symbol>
                </doStatement>
              </statements>
              <symbol > } </symbol>
            </whileStatement>
          </statements>
          <symbol > } </symbol>
        </whileStatement>
        <returnStatement>
          <keyword > return </keyword>
          <symbol > ; </symbol>
        </returnStatement>
      </statements>
      <symbol > } </symbol>
    </subroutineBody>
  </subroutineDec>
  <symbol > } </symbol>
</class>
