📄 ch29.htm
字号:
{
public:
__fastcall THero(TGame *AGame): TByzCharacter(AGame) {}
};
class TBadGuy : public TByzCharacter
{
public:
__fastcall TBadGuy(TGame *AGame): TByzCharacter(AGame) {}
};
class TByzGame : public TGame
{
protected:
virtual void CreateCharacters(void);
public:
__fastcall TByzGame(void): TGame() {}
};
extern TByzGame *ByzGame;
#endif
</FONT></PRE>
<H3 ALIGN="CENTER"><FONT COLOR="#0066FF"></FONT></H3>
<P><A NAME="Heading12"></A><FONT
COLOR="#000077"><B>Listing 29.4. The main source
for the game objects specific to Byzantium.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">///////////////////////////////////////
// File: ByzEngine1.cpp
// Project: GameObjects
// Copyright (c) 1997 by
Charlie Calvert
//
#include <vcl.h>
#pragma hdrstop
#include "ByzEngine1.h"
TByzGame *ByzGame;
void TByzGame::CreateCharacters(void)
{
Hero = new THero(this);
BadGuy = new TBadGuy(this);
}
__fastcall
TByzCharacter::TByzCharacter(TGame *AGame)
: TCharacter(AGame)
{
}
__fastcall TByzCharacter::~TByzCharacter(void)
{
}
int TByzCharacter::GetArmor(void)
{
return Creature->GetCustomInt("Armor");
}
void
TByzCharacter::SetArmor(int Value)
{
Creature->SetCustomInt("Armor", Value);
}
int TByzCharacter::GetHitPoints(void)
{
return Creature->GetCustomInt("Hit Points");
}
void TByzCharacter::SetHitPoints(int Value)
{
Creature->SetCustomInt("Hit Points", Value);
}
int TByzCharacter::GetHunger(void)
{
return Creature->GetCustomInt("Hunger");
}
void TByzCharacter::SetHunger(int Value)
{
Creature->SetCustomInt("Hunger", Value);
}
int TByzCharacter::GetWeapon(void)
{
return Creature->GetCustomInt("Weapon");
}
void TByzCharacter::SetWeapon(int Value)
{
Creature->SetCustomInt("Weapon", Value);
}
int TByzCharacter::GetStrength(void)
{
return Creature->GetCustomInt("Strength");
}
void TByzCharacter::SetStrength(int Value)
{
Creature->SetCustomInt("Strength", Value);
}
void TByzCharacter::SetVisible(bool Value)
{
Creature->Visible = Value;
FVisible = Value;
if (!Value)
ByzGame->UpdateMap();
}
int GetResistanceChance()
{
int i
= random(49);
i -= (24);
return i;
}
int GetWeaponChance()
{
return 0;
}
void PlaySound(AnsiString S)
{
sndPlaySound(S.c_str(), SND_ASYNC);
}
bool TByzCharacter::DefendYourself(TByzCharacter *Attacker)
{
int Resistance =
(Strength - Attacker->Strength) + (Armor - Attacker->Weapon);
if (Resistance + GetResistanceChance() < 0)
{
HitPoints -= (Attacker->Weapon - GetWeaponChance());
PlaySound("..\\media\\bang.wav");
return
False;
}
else
{
PlaySound("..\\media\\rev.wav");
return True;
}
}
</FONT></PRE>
<H3 ALIGN="CENTER"><FONT COLOR="#0066FF"></FONT></H3>
<P><A NAME="Heading13"></A><FONT COLOR="#000077"><B>Listing 29.5. The header file
for the game form.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">///////////////////////////////////////
// GameForm1.h
// Byzantium Project
// Copyright (c) 1997 by Charlie Calvert
//
#ifndef GameForm1H
#define GameForm1H
#include
<Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "globals.h"
#include "Creatures1.hpp"
#include "FightClass1.h"
#include "Mercury2.h"
class TGameForm : public TForm
{
__published:
THermes *Hermes1;
THermesChart *HermesChart1;
TFileCreatureList *FileCreatureList1;
TScene *Scene1;
TSpriteScene *SpriteScene1;
TSprite *Hero1;
TSprite *BadQueen1;
void __fastcall
FormShow(TObject *Sender);
void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall FormDestroy(TObject *Sender);
void __fastcall HermesChart1DrawScene(TObject *Sender);
void __fastcall
SpriteScene1SetupSurfaces(TObject *Sender);
void __fastcall FormMouseMove(TObject *Sender, TShiftState Shift, int X,
int Y);
void __fastcall SpriteScene1DrawScene(TObject *Sender);
void __fastcall
FormMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall Scene1DrawScene(TObject *Sender);
void __fastcall HermesChart1HeroMove(TObject *Sender, const tagPOINT
&NewPos,
int NewType, bool &MoveOk);
private:
// TNotifyEvent FHitCreatureProc;
TFightClass *FFightClass;
MESSAGE void StartShow(TMessage &Msg);
public:
virtual __fastcall
TGameForm(TComponent* Owner);
void Run(void);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_STARTSHOW, TMessage, StartShow);
END_MESSAGE_MAP(TForm);
};
extern TGameForm *GameForm;
#endif
</FONT></PRE>
<H3 ALIGN="CENTER"><FONT
COLOR="#0066FF"></FONT></H3>
<P><A NAME="Heading14"></A><FONT COLOR="#000077"><B>Listing 29.6. The main source
for the game form.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">///////////////////////////////////////
// GameForm1.cpp
// Byzantium Project
// Copyright (c) 1997 by Charlie Calvert
//
#include <vcl.h>
#pragma hdrstop
#include "Globals.h"
#include "ByzEngine1.h"
#include "GameForm1.h"
#pragma link "Creatures1"
#pragma link
"Mercury2"
#pragma resource "*.dfm"
TGameForm *GameForm;
__fastcall TGameForm::TGameForm(TComponent* Owner)
: TForm(Owner)
{
FFightClass = NULL;
ByzGame = new TByzGame();
ByzGame->CurrentScene = mrIntroMap;
}
void __fastcall TGameForm::FormDestroy(TObject *Sender)
{
delete ByzGame;
}
///////////////////////////////////////
// Run
///////////////////////////////////////
void TGameForm::Run(void)
{
if (FFightClass)
{
delete
FFightClass;
FFightClass = NULL;
}
switch(ByzGame->CurrentScene)
{
case mrWorldMap:
Hermes1->Scene = HermesChart1;
break;
case mrIntroMap:
Hermes1->Scene = Scene1;
break;
case
mrFightMap:
Hermes1->Scene = SpriteScene1;
FFightClass = new TFightClass(Handle, SpriteScene1);
break;
}
Hermes1->InitObjects();
ByzGame->Initialize(this, Hermes1->CreatureList);
Hermes1->Flip();
}
void __fastcall TGameForm::FormShow(TObject *Sender)
{
PostMessage(Handle, WM_STARTSHOW, 0, 0);
}
void TGameForm::StartShow(TMessage &Msg)
{
Run();
}
void __fastcall TGameForm::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if ((Shift.Contains(ssAlt)) && (Key=='X'))
{
if (Hermes1->Exclusive)
Hermes1->EndExclusive();
Close();
}
else if ((Shift.Contains(ssAlt)) && (Key=='A'))
{
ByzGame->CurrentScene = mrIntroMap;
Run();
}
else if ((Shift.Contains(ssAlt)) && (Key=='B'))
{
ByzGame->CurrentScene = mrWorldMap;
Run();
}
else if (ByzGame)
dynamic_cast<THero*>(ByzGame->Hero)->Move(Key);
}
void __fastcall TGameForm::HermesChart1DrawScene(TObject *Sender)
{
AnsiString S;
S = "Col: " + IntToStr(ByzGame->Hero->Col);
// S = S + " Scr Col: " +
IntToStr(ByzGame->Hero->Creature->ScreenCol);
// S = S + " Map Col: " + IntToStr(Hermes1->CreatureList->MapCol);
S = S + "Hit Points: " + dynamic_cast<TByzCharacter*>(ByzGame->Hero)->HitPoints;
HermesChart1->WriteXY(370, 410, S);
S = "Row: " + IntToStr(ByzGame->Hero->Row);
// S = S + " Scr Row: " + IntToStr(ByzGame->Hero->Creature->ScreenRow);
// S = S + " Map Row: " +
IntToStr(Hermes1->CreatureList->MapRow);
S = S + " Hunger: " + dynamic_cast<TByzCharacter*>(ByzGame->Hero)->Hunger;
HermesChart1->WriteXY(370, 430, S);
}
void __fastcall
TGameForm::SpriteScene1SetupSurfaces(TObject *Sender)
{
SpriteScene1->AddSprite(Hero1);
SpriteScene1->AddSprite(BadQueen1);
}
void __fastcall TGameForm::FormMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
if (ByzGame->CurrentScene == mrFightMap)
{
if (BadQueen1->IsHit(X, Y))
Screen->Cursor = crCross;
else
Screen->Cursor = crDefault;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -