home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / progs / CB / DATA.Z / FOOTMAIN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-21  |  10.0 KB  |  427 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "footmain.h"
  6. #include "instr.h"
  7. //---------------------------------------------------------------------------
  8. #pragma resource "*.dfm"
  9. TForm1 *Form1;
  10. //---------------------------------------------------------------------------
  11. __fastcall TForm1::TForm1(TComponent* Owner)
  12.   : TForm(Owner)
  13. {
  14. }
  15. //---------------------------------------------------------------------------
  16. void __fastcall TForm1::MoveForward(TObject *Sender)
  17. {
  18.     if ((OnOffSwitch->Position == 2) || (LastSack != NULL))
  19.         return;
  20.  
  21.     if (!running)
  22.     {
  23.         running = true;
  24.         Timer->Enabled = true;
  25.     }
  26.  
  27.     if (Runningback->Left < 260)
  28.     {
  29.         if (field[rbx+1][rby].player != NULL)
  30.         {
  31.             Sacked(field[rbx+1][rby].player);
  32.             return;
  33.         }
  34.         field[rbx][rby].player = NULL;
  35.         field[rbx][rby].rb = false;
  36.         Runningback->Left += 22;
  37.         YardsToGo--;
  38.         FieldPosition++;
  39.         if (FieldPosition == 100)
  40.         {
  41.             MessageBeep(MB_ICONASTERISK);
  42.             running = false;
  43.             HideField();
  44.             Home+=7;
  45.             YardsToGo=10;
  46.             Down=1;
  47.             FieldPosition=20;
  48.             return;
  49.         }
  50.     rbx++;
  51.     field[rbx][rby].player = Runningback;
  52.     field[rbx][rby].rb = true;
  53.     }
  54.     else
  55.     {
  56.         if (field[0][rby].player != NULL)
  57.         {
  58.             Sacked(field[0][rby].player);
  59.             return;
  60.         }
  61.         field[rbx][rby].player = NULL;
  62.         field[rbx][rby].rb = false;
  63.         Runningback->Left = RBLEFT;
  64.         rbx = 0;
  65.         field[rbx][rby].player = Runningback;
  66.         field[rbx][rby].rb = true;
  67.     }
  68. }
  69. //---------------------------------------------------------------------
  70. void __fastcall TForm1::MoveUp(TObject *Sender)
  71. {
  72.     if ((OnOffSwitch->Position == 2) || (LastSack != NULL))
  73.         return;
  74.  
  75.     if (!running)
  76.     {
  77.         running = true;
  78.         Timer->Enabled = true;
  79.     }
  80.  
  81.     if (Runningback->Top == RBTOP)
  82.         return; // already as up as it gets
  83.  
  84.     if (field[rbx][rby-1].player != NULL)
  85.     {
  86.         Sacked(field[rbx][rby-1].player);
  87.         return;
  88.     }
  89.  
  90.     if (Runningback->Top == RBBOTTOM)
  91.         Runningback->Top = RBMIDDLE;
  92.     else if (Runningback->Top == RBMIDDLE)
  93.         Runningback->Top = RBTOP;
  94.  
  95.     field[rbx][rby].player = NULL;
  96.     field[rbx][rby].rb = false;
  97.     rby--;
  98.     field[rbx][rby].player = Runningback;
  99.     field[rbx][rby].rb = true;
  100. }
  101. //---------------------------------------------------------------------
  102. void __fastcall TForm1::MoveDown(TObject *Sender)
  103. {
  104.     if ((OnOffSwitch->Position == 2) || (LastSack != NULL))
  105.         return;
  106.  
  107.     if (!running)
  108.     {
  109.         running = true;
  110.         Timer->Enabled = true;
  111.     }
  112.  
  113.     if (Runningback->Top == RBBOTTOM)
  114.         return; // already as down as it gets
  115.  
  116.     if (field[rbx][rby+1].player != NULL)
  117.     {
  118.         Sacked(field[rbx][rby+1].player);
  119.         return;
  120.     }
  121.  
  122.     if (Runningback->Top == RBTOP)
  123.         Runningback->Top = RBMIDDLE;
  124.     else if (Runningback->Top == RBMIDDLE)
  125.         Runningback->Top = RBBOTTOM;
  126.  
  127.     field[rbx][rby].player = NULL;
  128.     field[rbx][rby].rb = false;
  129.     rby++;
  130.     field[rbx][rby].player = Runningback;
  131.     field[rbx][rby].rb = true;
  132. }
  133. //---------------------------------------------------------------------
  134. void __fastcall TForm1::Switched(TObject *Sender)
  135. {
  136.     switch (OnOffSwitch->Position)
  137.     {
  138.             case 1:    {
  139.                     Timer->Interval = 250;
  140.                     ResetGame(NULL);
  141.                     break;
  142.                 }
  143.                 case 2:    {
  144.                     HideField();
  145.                     break;
  146.                 }
  147.                 case 3:    {
  148.                     Timer->Interval = 100;
  149.                     ResetGame(NULL);
  150.                     break;
  151.                 }
  152.         }
  153. }
  154. //---------------------------------------------------------------------
  155. void __fastcall TForm1::HideField()
  156. {
  157.     Runningback->Visible = false;
  158.     Tackler1->Visible = false;
  159.     Tackler2->Visible = false;
  160.     Tackler3->Visible = false;
  161.     Tackler4->Visible = false;
  162.     Tackler5->Visible = false;
  163.  
  164. }
  165. //---------------------------------------------------------------------
  166. void __fastcall TForm1::TimerTimer(TObject *Sender)
  167. {
  168.     int x, y, direction;
  169.  
  170.     y = random(3);
  171.     x = random(10);
  172.     direction = random(3);
  173.  
  174.     if (!running)
  175.     {
  176.         if (LastSack != NULL)
  177.             LastSack->Visible = !LastSack->Visible;
  178.         return;
  179.     }
  180.  
  181.     if (field[x][y].rb == true)
  182.         return; // can't move the runningback!
  183.  
  184.     if (field[x][y].player == NULL)
  185.         return; // no tacker at this spot
  186.  
  187.     if (field[x][y].player->Left <= 64)
  188.         return; // already at the endzone
  189.  
  190.     if ((direction == 0) && (x > 0))
  191.     {
  192.         if (field[x-1][y].rb == true)
  193.         {
  194.             Sacked(field[x][y].player);
  195.             return;
  196.         }
  197.         if (field[x-1][y].player == NULL)
  198.         // going forward, not out of range, and not blocked
  199.         {
  200.             field[x][y].player->Left -= 22;
  201.             field[x-1][y].player = field[x][y].player;
  202.             field[x][y].player = NULL;
  203.             return;
  204.         }
  205.     }
  206.  
  207.     if ((direction == 1) && (y > 0))
  208.     {
  209.         if (field[x-1][y].rb == true)
  210.         {
  211.             Sacked(field[x][y].player);
  212.             return;
  213.         }
  214.         if (field[x][y-1].player == NULL)
  215.         // going up, not out of range, and not blocked
  216.         {
  217.             field[x][y].player->Top -= 16;
  218.             field[x][y-1].player = field[x][y].player;
  219.             field[x][y].player = NULL;
  220.             return;
  221.         }
  222.     }
  223.  
  224.     if ((direction == 0) && (y < 2))
  225.     {
  226.         if (field[x-1][y].rb == true)
  227.         {
  228.             Sacked(field[x][y].player);
  229.             return;
  230.         }
  231.         if (field[x][y+1].player == NULL)
  232.         // going down, not out of range, and not blocked
  233.         {
  234.             field[x][y].player->Top += 16;
  235.             field[x][y+1].player = field[x][y].player;
  236.             field[x][y].player = NULL;
  237.             return;
  238.         }
  239.     }
  240. }
  241. //---------------------------------------------------------------------
  242. void __fastcall TForm1::Sacked(TLabel *player)
  243. {
  244.     MessageBeep(MB_OK);
  245.     running = false;
  246.     LastSack = player;
  247.     if (YardsToGo <=0)
  248.     {
  249.         Down = 1;
  250.         YardsToGo = 10;
  251.     }
  252.     else
  253.     {
  254.         Down++;
  255.         if (Down > 5)
  256.         {
  257.             YardsToGo = 10;  // this will need to change
  258.             Down = 1;
  259.         }
  260.     }
  261. }
  262. //---------------------------------------------------------------------
  263. void __fastcall TForm1::ResetGame(TObject *Sender)
  264. {
  265.     YardsToGo=10;
  266.     Down=1;
  267.     FieldPosition=20;
  268.     Home=0;
  269.     Visitor=0;
  270.     TimeLeft=15;
  271.     randomize;
  272.     ResetField();
  273. }
  274. //---------------------------------------------------------------------
  275. void __fastcall TForm1::ResetField()
  276. {
  277.     running = false;
  278.     Timer->Enabled = false;
  279.     LastSack = NULL;
  280.  
  281.     // empty the field
  282.     for (int y=0; y<3; y++)
  283.         for (int x=0; x<10; x++)
  284.         {
  285.             field[x][y].player = NULL;
  286.             field[x][y].rb = false;
  287.         }
  288.  
  289.     // initial locations of players
  290.     field[0][1].player=Runningback;
  291.     field[0][1].rb=true;
  292.     rbx = 0;
  293.     rby = 1;
  294.     field[3][0].player=Tackler1;
  295.     field[3][1].player=Tackler2;
  296.     field[3][2].player=Tackler3;
  297.     field[5][1].player=Tackler4;
  298.     field[9][1].player=Tackler5;
  299.  
  300.     Runningback->Left = RBLEFT;
  301.     Runningback->Top = RBMIDDLE;
  302.     Tackler1->Left = TACKLEROW1;
  303.     Tackler1->Top = TACKLETOP;
  304.     Tackler2->Left = TACKLEROW1;
  305.     Tackler2->Top = TACKLEMIDDLE;
  306.     Tackler3->Left = TACKLEROW1;
  307.     Tackler3->Top = TACKLEBOTTOM;
  308.     Tackler4->Left = TACKLEROW2;
  309.     Tackler4->Top = TACKLEMIDDLE;
  310.     Tackler5->Left = TACKLEROW3;
  311.     Tackler5->Top = TACKLEMIDDLE;
  312.  
  313.     Runningback->Visible = true;
  314.     Tackler1->Visible = true;
  315.     Tackler2->Visible = true;
  316.     Tackler3->Visible = true;
  317.     Tackler4->Visible = true;
  318.     Tackler5->Visible = true;
  319. }
  320. //---------------------------------------------------------------------
  321. void __fastcall TForm1::Exit1Click(TObject *Sender)
  322. {
  323.     Application->Terminate();  
  324. }
  325. //---------------------------------------------------------------------
  326. void __fastcall TForm1::About1Click(TObject *Sender)
  327. {
  328.     About->ShowModal();
  329. }
  330. //---------------------------------------------------------------------
  331. void __fastcall TForm1::ShowStats(TObject *Sender, TMouseButton Button,
  332.       TShiftState Shift, Integer X, Integer Y)
  333. {
  334.     if ((OnOffSwitch->Position == 2) || (running))
  335.         return;
  336.  
  337.     RightLabel->Caption = "YDS TO GO";
  338.     MiddleLabel->Caption = "FIELD POS";
  339.     LeftLabel->Caption = "DOWN";
  340.      RightDisplay->Caption = IntToStr(YardsToGo);
  341.  
  342.     if (FieldPosition <= 50)
  343.         MiddleDisplay->Caption = IntToStr(FieldPosition) + " <";
  344.     else
  345.         MiddleDisplay->Caption = "> " + IntToStr(100 - FieldPosition);
  346.  
  347.     LeftDisplay->Caption = IntToStr(Down);
  348.  
  349.     HideField();
  350.     ShowDisplay();
  351. }
  352. //---------------------------------------------------------------------
  353. void __fastcall TForm1::HideStatsScore(TObject *Sender, TMouseButton Button,
  354.       TShiftState Shift, Integer X, Integer Y)
  355. {
  356.     if ((OnOffSwitch->Position == 2) || (running))
  357.         return;
  358.  
  359.     HideDisplay();
  360.     ResetField();
  361. }
  362. //---------------------------------------------------------------------
  363. void __fastcall TForm1::ShowDisplay()
  364. {
  365.     RightLabel->Visible = true;
  366.     MiddleLabel->Visible = true;
  367.     LeftLabel->Visible = true;
  368.     RightDisplay->Visible = true;
  369.     MiddleDisplay->Visible = true;
  370.     LeftDisplay->Visible = true;
  371. }
  372. //---------------------------------------------------------------------
  373. void __fastcall TForm1::HideDisplay()
  374. {
  375.     RightLabel->Visible = false;
  376.     MiddleLabel->Visible = false;
  377.     LeftLabel->Visible = false;
  378.     RightDisplay->Visible = false;
  379.     MiddleDisplay->Visible = false;
  380.     LeftDisplay->Visible = false;
  381. }
  382. //---------------------------------------------------------------------
  383. void __fastcall TForm1::ShowScore(TObject *Sender, TMouseButton Button,
  384.       TShiftState Shift, Integer X, Integer Y)
  385. {
  386.     if ((OnOffSwitch->Position == 2) || (running))
  387.         return;
  388.  
  389.     RightLabel->Caption = "VISITOR";
  390.     MiddleLabel->Caption = "TIME LEFT";
  391.     LeftLabel->Caption = "HOME";
  392.      RightDisplay->Caption = IntToStr(Visitor);
  393.     MiddleDisplay->Caption = IntToStr(TimeLeft);
  394.     LeftDisplay->Caption = IntToStr(Home);
  395.  
  396.     HideField();
  397.     ShowDisplay();
  398. }
  399. //---------------------------------------------------------------------
  400. void __fastcall TForm1::Kick(TObject *Sender)
  401. {
  402.     if ((running) || (Down != 4))
  403.         return;  // button only valid just before fourth down
  404.  
  405.     HideField();
  406.     FieldPosition += random(100);
  407.     if (FieldPosition >= 100)
  408.     {
  409.         MessageBeep(MB_ICONASTERISK);
  410.         running = false;
  411.         HideField();
  412.         Home+=3;
  413.         YardsToGo=10;
  414.         Down=1;
  415.         FieldPosition=20;
  416.     }
  417.     else
  418.     {
  419.         MessageBeep(MB_OK);
  420.         running = false;
  421.         YardsToGo=10;  // this will change when visitor starts working
  422.         Down=1;
  423.     }
  424.  
  425. }
  426. //---------------------------------------------------------------------
  427.