home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
-
- #include "footmain.h"
- #include "instr.h"
- //---------------------------------------------------------------------------
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::MoveForward(TObject *Sender)
- {
- if ((OnOffSwitch->Position == 2) || (LastSack != NULL))
- return;
-
- if (!running)
- {
- running = true;
- Timer->Enabled = true;
- }
-
- if (Runningback->Left < 260)
- {
- if (field[rbx+1][rby].player != NULL)
- {
- Sacked(field[rbx+1][rby].player);
- return;
- }
- field[rbx][rby].player = NULL;
- field[rbx][rby].rb = false;
- Runningback->Left += 22;
- YardsToGo--;
- FieldPosition++;
- if (FieldPosition == 100)
- {
- MessageBeep(MB_ICONASTERISK);
- running = false;
- HideField();
- Home+=7;
- YardsToGo=10;
- Down=1;
- FieldPosition=20;
- return;
- }
- rbx++;
- field[rbx][rby].player = Runningback;
- field[rbx][rby].rb = true;
- }
- else
- {
- if (field[0][rby].player != NULL)
- {
- Sacked(field[0][rby].player);
- return;
- }
- field[rbx][rby].player = NULL;
- field[rbx][rby].rb = false;
- Runningback->Left = RBLEFT;
- rbx = 0;
- field[rbx][rby].player = Runningback;
- field[rbx][rby].rb = true;
- }
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::MoveUp(TObject *Sender)
- {
- if ((OnOffSwitch->Position == 2) || (LastSack != NULL))
- return;
-
- if (!running)
- {
- running = true;
- Timer->Enabled = true;
- }
-
- if (Runningback->Top == RBTOP)
- return; // already as up as it gets
-
- if (field[rbx][rby-1].player != NULL)
- {
- Sacked(field[rbx][rby-1].player);
- return;
- }
-
- if (Runningback->Top == RBBOTTOM)
- Runningback->Top = RBMIDDLE;
- else if (Runningback->Top == RBMIDDLE)
- Runningback->Top = RBTOP;
-
- field[rbx][rby].player = NULL;
- field[rbx][rby].rb = false;
- rby--;
- field[rbx][rby].player = Runningback;
- field[rbx][rby].rb = true;
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::MoveDown(TObject *Sender)
- {
- if ((OnOffSwitch->Position == 2) || (LastSack != NULL))
- return;
-
- if (!running)
- {
- running = true;
- Timer->Enabled = true;
- }
-
- if (Runningback->Top == RBBOTTOM)
- return; // already as down as it gets
-
- if (field[rbx][rby+1].player != NULL)
- {
- Sacked(field[rbx][rby+1].player);
- return;
- }
-
- if (Runningback->Top == RBTOP)
- Runningback->Top = RBMIDDLE;
- else if (Runningback->Top == RBMIDDLE)
- Runningback->Top = RBBOTTOM;
-
- field[rbx][rby].player = NULL;
- field[rbx][rby].rb = false;
- rby++;
- field[rbx][rby].player = Runningback;
- field[rbx][rby].rb = true;
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::Switched(TObject *Sender)
- {
- switch (OnOffSwitch->Position)
- {
- case 1: {
- Timer->Interval = 250;
- ResetGame(NULL);
- break;
- }
- case 2: {
- HideField();
- break;
- }
- case 3: {
- Timer->Interval = 100;
- ResetGame(NULL);
- break;
- }
- }
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::HideField()
- {
- Runningback->Visible = false;
- Tackler1->Visible = false;
- Tackler2->Visible = false;
- Tackler3->Visible = false;
- Tackler4->Visible = false;
- Tackler5->Visible = false;
-
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::TimerTimer(TObject *Sender)
- {
- int x, y, direction;
-
- y = random(3);
- x = random(10);
- direction = random(3);
-
- if (!running)
- {
- if (LastSack != NULL)
- LastSack->Visible = !LastSack->Visible;
- return;
- }
-
- if (field[x][y].rb == true)
- return; // can't move the runningback!
-
- if (field[x][y].player == NULL)
- return; // no tacker at this spot
-
- if (field[x][y].player->Left <= 64)
- return; // already at the endzone
-
- if ((direction == 0) && (x > 0))
- {
- if (field[x-1][y].rb == true)
- {
- Sacked(field[x][y].player);
- return;
- }
- if (field[x-1][y].player == NULL)
- // going forward, not out of range, and not blocked
- {
- field[x][y].player->Left -= 22;
- field[x-1][y].player = field[x][y].player;
- field[x][y].player = NULL;
- return;
- }
- }
-
- if ((direction == 1) && (y > 0))
- {
- if (field[x-1][y].rb == true)
- {
- Sacked(field[x][y].player);
- return;
- }
- if (field[x][y-1].player == NULL)
- // going up, not out of range, and not blocked
- {
- field[x][y].player->Top -= 16;
- field[x][y-1].player = field[x][y].player;
- field[x][y].player = NULL;
- return;
- }
- }
-
- if ((direction == 0) && (y < 2))
- {
- if (field[x-1][y].rb == true)
- {
- Sacked(field[x][y].player);
- return;
- }
- if (field[x][y+1].player == NULL)
- // going down, not out of range, and not blocked
- {
- field[x][y].player->Top += 16;
- field[x][y+1].player = field[x][y].player;
- field[x][y].player = NULL;
- return;
- }
- }
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::Sacked(TLabel *player)
- {
- MessageBeep(MB_OK);
- running = false;
- LastSack = player;
- if (YardsToGo <=0)
- {
- Down = 1;
- YardsToGo = 10;
- }
- else
- {
- Down++;
- if (Down > 5)
- {
- YardsToGo = 10; // this will need to change
- Down = 1;
- }
- }
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::ResetGame(TObject *Sender)
- {
- YardsToGo=10;
- Down=1;
- FieldPosition=20;
- Home=0;
- Visitor=0;
- TimeLeft=15;
- randomize;
- ResetField();
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::ResetField()
- {
- running = false;
- Timer->Enabled = false;
- LastSack = NULL;
-
- // empty the field
- for (int y=0; y<3; y++)
- for (int x=0; x<10; x++)
- {
- field[x][y].player = NULL;
- field[x][y].rb = false;
- }
-
- // initial locations of players
- field[0][1].player=Runningback;
- field[0][1].rb=true;
- rbx = 0;
- rby = 1;
- field[3][0].player=Tackler1;
- field[3][1].player=Tackler2;
- field[3][2].player=Tackler3;
- field[5][1].player=Tackler4;
- field[9][1].player=Tackler5;
-
- Runningback->Left = RBLEFT;
- Runningback->Top = RBMIDDLE;
- Tackler1->Left = TACKLEROW1;
- Tackler1->Top = TACKLETOP;
- Tackler2->Left = TACKLEROW1;
- Tackler2->Top = TACKLEMIDDLE;
- Tackler3->Left = TACKLEROW1;
- Tackler3->Top = TACKLEBOTTOM;
- Tackler4->Left = TACKLEROW2;
- Tackler4->Top = TACKLEMIDDLE;
- Tackler5->Left = TACKLEROW3;
- Tackler5->Top = TACKLEMIDDLE;
-
- Runningback->Visible = true;
- Tackler1->Visible = true;
- Tackler2->Visible = true;
- Tackler3->Visible = true;
- Tackler4->Visible = true;
- Tackler5->Visible = true;
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::Exit1Click(TObject *Sender)
- {
- Application->Terminate();
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::About1Click(TObject *Sender)
- {
- About->ShowModal();
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::ShowStats(TObject *Sender, TMouseButton Button,
- TShiftState Shift, Integer X, Integer Y)
- {
- if ((OnOffSwitch->Position == 2) || (running))
- return;
-
- RightLabel->Caption = "YDS TO GO";
- MiddleLabel->Caption = "FIELD POS";
- LeftLabel->Caption = "DOWN";
- RightDisplay->Caption = IntToStr(YardsToGo);
-
- if (FieldPosition <= 50)
- MiddleDisplay->Caption = IntToStr(FieldPosition) + " <";
- else
- MiddleDisplay->Caption = "> " + IntToStr(100 - FieldPosition);
-
- LeftDisplay->Caption = IntToStr(Down);
-
- HideField();
- ShowDisplay();
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::HideStatsScore(TObject *Sender, TMouseButton Button,
- TShiftState Shift, Integer X, Integer Y)
- {
- if ((OnOffSwitch->Position == 2) || (running))
- return;
-
- HideDisplay();
- ResetField();
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::ShowDisplay()
- {
- RightLabel->Visible = true;
- MiddleLabel->Visible = true;
- LeftLabel->Visible = true;
- RightDisplay->Visible = true;
- MiddleDisplay->Visible = true;
- LeftDisplay->Visible = true;
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::HideDisplay()
- {
- RightLabel->Visible = false;
- MiddleLabel->Visible = false;
- LeftLabel->Visible = false;
- RightDisplay->Visible = false;
- MiddleDisplay->Visible = false;
- LeftDisplay->Visible = false;
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::ShowScore(TObject *Sender, TMouseButton Button,
- TShiftState Shift, Integer X, Integer Y)
- {
- if ((OnOffSwitch->Position == 2) || (running))
- return;
-
- RightLabel->Caption = "VISITOR";
- MiddleLabel->Caption = "TIME LEFT";
- LeftLabel->Caption = "HOME";
- RightDisplay->Caption = IntToStr(Visitor);
- MiddleDisplay->Caption = IntToStr(TimeLeft);
- LeftDisplay->Caption = IntToStr(Home);
-
- HideField();
- ShowDisplay();
- }
- //---------------------------------------------------------------------
- void __fastcall TForm1::Kick(TObject *Sender)
- {
- if ((running) || (Down != 4))
- return; // button only valid just before fourth down
-
- HideField();
- FieldPosition += random(100);
- if (FieldPosition >= 100)
- {
- MessageBeep(MB_ICONASTERISK);
- running = false;
- HideField();
- Home+=3;
- YardsToGo=10;
- Down=1;
- FieldPosition=20;
- }
- else
- {
- MessageBeep(MB_OK);
- running = false;
- YardsToGo=10; // this will change when visitor starts working
- Down=1;
- }
-
- }
- //---------------------------------------------------------------------
-