CONTROL.CPP
上传用户:abcdshs
上传日期:2007-01-07
资源大小:1858k
文件大小:4k
源码类别:

游戏

开发平台:

Visual C++

  1. // (C) Copyright 1996 by Anthony J. Carin.  All Rights Reserved.
  2. #include "stdafx.h"
  3. #include "control.h"
  4. #include "levels.h"
  5. control::control(baseobject *ptr)
  6. {
  7.    rstep        = FALSE;
  8.    object       = ptr;
  9.    maincmd      = 
  10.    rstepcmd     = 
  11.    lstepcmd     = 
  12.    rruncmd      = 
  13.    lruncmd      = 
  14.    rstepbackcmd = 
  15.    lstepbackcmd = 
  16.    turnleftcmd  = 
  17.    turnrightcmd = 
  18.    pickupcmd    = 
  19.    blockcmd     = NULL;
  20.    loadmaincmd();
  21.    maincmd->purgeold();
  22.    blocking = FALSE;
  23. }
  24. control::~control()
  25. {
  26.    delete maincmd;
  27.    delete rstepcmd;
  28.    delete lstepcmd;
  29.    delete rruncmd;
  30.    delete lruncmd;
  31.    delete rstepbackcmd;
  32.    delete lstepbackcmd;
  33.    delete turnleftcmd;
  34.    delete turnrightcmd;
  35.    delete pickupcmd;
  36.    delete blockcmd;
  37. }
  38. void control::stepfoward()
  39. {
  40.    rstep = (char) !rstep;
  41.    if (rstep)
  42.    {
  43.       loadrstepcmd();
  44. rstepcmd->restart();
  45. maincmd->append(*rstepcmd);
  46.    }
  47.    else
  48.    {
  49.       loadlstepcmd();
  50. lstepcmd->restart();
  51. maincmd->append(*lstepcmd);
  52.    }
  53.    blocking = FALSE;
  54. }
  55. void control::runfoward()
  56. {
  57.    rstep = (char)!rstep;
  58.    if (rstep)
  59.    {
  60.       loadrruncmd();
  61. rruncmd->restart();
  62. maincmd->append(*rruncmd);
  63.    }
  64.    else
  65.    {
  66.       loadlruncmd();
  67. lruncmd->restart();
  68. maincmd->append(*lruncmd);
  69.    }
  70.    blocking = FALSE;
  71. }
  72. void control::stepbackward()
  73. {
  74.    rstep = (char)!rstep;
  75.    if (rstep)
  76.    {
  77.       loadrstepbackcmd();
  78. rstepbackcmd->restart();
  79. maincmd->append(*rstepbackcmd);
  80.    }
  81.    else
  82.    {
  83.       loadlstepbackcmd();
  84. lstepbackcmd->restart();
  85. maincmd->append(*lstepbackcmd);
  86.    }
  87.    blocking = FALSE;
  88. }
  89. void control::turnleft()
  90. {
  91.    loadturnleftcmd();
  92. turnleftcmd->restart();
  93. maincmd->append(*turnleftcmd);
  94.    blocking = FALSE;
  95. }
  96. void control::turnright()
  97. {
  98.    loadturnrightcmd();
  99. turnrightcmd->restart();
  100. maincmd->append(*turnrightcmd);
  101.    blocking = FALSE;
  102. }
  103. void control::pickup()
  104. {
  105.    stopeverything();
  106.    loadpickupcmd();
  107. pickupcmd->restart();
  108. maincmd->append(*pickupcmd);
  109.    blocking = FALSE;
  110. }
  111. void control::block()
  112. {
  113.    loadblockcmd();
  114. blockcmd->restart();
  115. maincmd->append(*blockcmd);
  116.    blocking = TRUE;
  117. }
  118. void control::falldown()
  119. {
  120.    command tmp("falldown.cmd");
  121. maincmd->append(tmp);
  122. }
  123. void control::issuecommands()
  124. {
  125.    if (maincmd->nomore())
  126.       return;
  127.    object->followcommands(*maincmd);
  128. }
  129. void control::stopwalking()
  130. {
  131. maincmd->remove(TURNLEFT);
  132.    maincmd->remove(TURNRIGHT);
  133.    maincmd->remove(MOVEFOWARD);
  134.    maincmd->remove(MOVEBACKWARD);
  135.    blocking = FALSE;
  136. }
  137. void control::stopeverything()
  138. {
  139. maincmd->remove(NOMORE);
  140.    maincmd->restart();
  141.    blocking = FALSE;
  142. }
  143. void control::selectpunch(short v,CString& punch)
  144. {
  145.     stopeverything();
  146.     if (maincmd->isempty())
  147.     {
  148.         CString tmpstr;
  149.         if (v < 0)
  150.             v = 0;
  151.         if (v > 100)
  152.             v = 99;
  153.         float fv = (float) v/100.0f;
  154.         tmpstr = picklist(fv, punch);
  155.         if (!tmpstr.IsEmpty())
  156.         {
  157.             command tmpcom((LPCTSTR) tmpstr);
  158.             maincmd->append(tmpcom);
  159.         }
  160.     }
  161.     blocking = FALSE;
  162. }
  163. void control::gothit(instruction& inst, short bonus)
  164. {
  165.     char tmpptr[20];
  166.     switch (inst())
  167.     {
  168.     case THEYDO:
  169.         strcpy(tmpptr,inst.string());
  170.         strcat(tmpptr,".CMD");
  171.         break;
  172.     case STRIKETOP:
  173.         if (blocking)
  174.             strcpy(tmpptr,"HITTOP.CMD");
  175.         else
  176.             strcpy(tmpptr,"HHITTOP.CMD");
  177.         break;
  178.     case STRIKEMED:
  179.         if (blocking)
  180.             strcpy(tmpptr,"HITMED.CMD");
  181.         else
  182.             strcpy(tmpptr,"HHITMED.CMD");
  183.         break;
  184.     case STRIKEBOT:
  185.         if (blocking)
  186.             strcpy(tmpptr,"HITBOT.CMD");
  187.         else
  188.             strcpy(tmpptr,"HHITBOT.CMD");
  189.         break;
  190.     }
  191.  maincmd->purge();
  192.     command tmpcom(tmpptr);
  193.     if (bonus)
  194.         tmpcom.AddToValue(HURTME, bonus);
  195.     maincmd->append(tmpcom);
  196.     if (blocking)
  197.         block();
  198. }