CÁC GIẢI PHÁP LẬP TRÌNH C# - Trang 340

340
Chương 8: Đồ họa, đa phương tiện, và in ấn

{

// (Bỏ qua phần mã designer.)

// Đối tượng agent hiện tại.

private AgentObjects.IAgentCtlCharacter mSpeaker;

// Phương thức thụ lý sự kiện KeyDown của txtLocation.

private void txtLocation_KeyDown(object sender,

System.Windows.Forms.KeyEventArgs e)

{

if (e.KeyCode == Keys.Enter)

{

// Thiết lập nơi lưu trữ nhân vật vào txtLocation.

string location = txtLocation.Text;

// Khởi tạo các nhân vật.

try

{

// Nạp các nhân vật vào đối tượng agent.

mainAgent.Characters.Load("Genie", location & "Genie.acs")

mainAgent.Characters.Load("Merlin", location + "Merlin.acs");

mainAgent.Characters.Load("Peedy", location & "Peedy.acs")

mainAgent.Characters.Load("Robby", location & "Robby.acs")

// Vô hiệu txtLocation và kích hoạt các điều kiểm khác.

txtLocation.Enabled = false;

txtSpeech.Enabled = true;

cmdSpeak.Enabled = true;

characterCombo.Enabled = true;

actionsCombo.Enabled = true;

// Thiết lập nhân vật hiện tại là Merlin và hiện nhân vật này.

mSpeaker = mainAgent.Characters["Merlin"];

GetAnimationNames(); // Thu lấy danh sách hành động.