Từ 1 tới 2 trên tổng số 2 kết quả

Đề tài: Làm việc với Agent (Nhân vật hoạt hình) trong lập trình C#

  1. #1
    Ngày gia nhập
    09 2006
    Nơi ở
    /usr/share/.hack@
    Bài viết
    1,433

    Smile Làm việc với Agent (Nhân vật hoạt hình) trong lập trình C#

    Hình mẫu :

    Click vào hình ảnh để lấy hình ảnh lớn

Tên:		agent.png
Lần xem:	20
Size:		24.0 KB
ID:		5057

    Source Code :

    Visual C# Code:
    1. using System;
    2. using System.Drawing;
    3. using System.Collections;
    4. using System.ComponentModel;
    5. using System.Windows.Forms;
    6. using System.Data;
    7.  
    8. namespace AgentTryout
    9. {
    10.   /// <summary>
    11.   /// Summary description for AgentTryout.
    12.   /// </summary>
    13.   public class AgentTryout : System.Windows.Forms.Form
    14.   {
    15.     internal System.Windows.Forms.Button cmdClose;
    16.     internal System.Windows.Forms.GroupBox GroupBox3;
    17.     internal System.Windows.Forms.Label Label2;
    18.     internal System.Windows.Forms.Label Label1;
    19.     internal System.Windows.Forms.TextBox txtY;
    20.     internal System.Windows.Forms.TextBox txtX;
    21.     internal System.Windows.Forms.Button cmdMove;
    22.     internal System.Windows.Forms.GroupBox GroupBox2;
    23.     internal System.Windows.Forms.Button cmdSpeak;
    24.     internal System.Windows.Forms.TextBox txtSpeak;
    25.     internal System.Windows.Forms.GroupBox GroupBox1;
    26.     internal System.Windows.Forms.Button cmdStop;
    27.     internal System.Windows.Forms.Button cmdPlay;
    28.     internal System.Windows.Forms.ListBox lstAnimations;
    29.     private AxAgentObjects.AxAgent axAgent1;
    30.     /// <summary>
    31.     /// Required designer variable.
    32.     /// </summary>
    33.     private System.ComponentModel.Container components = null;
    34.  
    35.     public AgentTryout()
    36.     {
    37.       //
    38.       // Required for Windows Form Designer support
    39.       //
    40.       InitializeComponent();
    41.  
    42.       //
    43.       // TODO: Add any constructor code after InitializeComponent call
    44.       //
    45.     }
    46.  
    47.     /// <summary>
    48.     /// Clean up any resources being used.
    49.     /// </summary>
    50.     protected override void Dispose( bool disposing )
    51.     {
    52.       if( disposing )
    53.       {
    54.         if (components != null)
    55.         {
    56.           components.Dispose();
    57.         }
    58.       }
    59.       base.Dispose( disposing );
    60.     }
    61.  
    62.     #region Windows Form Designer generated code
    63.     /// <summary>
    64.     /// Required method for Designer support - do not modify
    65.     /// the contents of this method with the code editor.
    66.     /// </summary>
    67.     private void InitializeComponent()
    68.     {
    69.       System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(AgentTryout));
    70.       this.cmdClose = new System.Windows.Forms.Button();
    71.       this.GroupBox3 = new System.Windows.Forms.GroupBox();
    72.       this.Label2 = new System.Windows.Forms.Label();
    73.       this.Label1 = new System.Windows.Forms.Label();
    74.       this.txtY = new System.Windows.Forms.TextBox();
    75.       this.txtX = new System.Windows.Forms.TextBox();
    76.       this.cmdMove = new System.Windows.Forms.Button();
    77.       this.GroupBox2 = new System.Windows.Forms.GroupBox();
    78.       this.cmdSpeak = new System.Windows.Forms.Button();
    79.       this.txtSpeak = new System.Windows.Forms.TextBox();
    80.       this.GroupBox1 = new System.Windows.Forms.GroupBox();
    81.       this.axAgent1 = new AxAgentObjects.AxAgent();
    82.       this.cmdStop = new System.Windows.Forms.Button();
    83.       this.cmdPlay = new System.Windows.Forms.Button();
    84.       this.lstAnimations = new System.Windows.Forms.ListBox();
    85.       this.GroupBox3.SuspendLayout();
    86.       this.GroupBox2.SuspendLayout();
    87.       this.GroupBox1.SuspendLayout();
    88.       ((System.ComponentModel.ISupportInitialize)(this.axAgent1)).BeginInit();
    89.       this.SuspendLayout();
    90.       //
    91.       // cmdClose
    92.       //
    93.       this.cmdClose.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
    94.       this.cmdClose.FlatStyle = System.Windows.Forms.FlatStyle.System;
    95.       this.cmdClose.Location = new System.Drawing.Point(295, 331);
    96.       this.cmdClose.Name = "cmdClose";
    97.       this.cmdClose.Size = new System.Drawing.Size(96, 24);
    98.       this.cmdClose.TabIndex = 12;
    99.       this.cmdClose.Text = "Close";
    100.       this.cmdClose.Click += new System.EventHandler(this.cmdClose_Click);
    101.       //
    102.       // GroupBox3
    103.       //
    104.       this.GroupBox3.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
    105.         | System.Windows.Forms.AnchorStyles.Right);
    106.       this.GroupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
    107.                                           this.Label2,
    108.                                           this.Label1,
    109.                                           this.txtY,
    110.                                           this.txtX,
    111.                                           this.cmdMove});
    112.       this.GroupBox3.FlatStyle = System.Windows.Forms.FlatStyle.System;
    113.       this.GroupBox3.Location = new System.Drawing.Point(8, 251);
    114.       this.GroupBox3.Name = "GroupBox3";
    115.       this.GroupBox3.Size = new System.Drawing.Size(384, 64);
    116.       this.GroupBox3.TabIndex = 11;
    117.       this.GroupBox3.TabStop = false;
    118.       this.GroupBox3.Text = "Move";
    119.       //
    120.       // Label2
    121.       //
    122.       this.Label2.Location = new System.Drawing.Point(84, 28);
    123.       this.Label2.Name = "Label2";
    124.       this.Label2.Size = new System.Drawing.Size(20, 16);
    125.       this.Label2.TabIndex = 11;
    126.       this.Label2.Text = "Y:";
    127.       //
    128.       // Label1
    129.       //
    130.       this.Label1.Location = new System.Drawing.Point(16, 28);
    131.       this.Label1.Name = "Label1";
    132.       this.Label1.Size = new System.Drawing.Size(20, 16);
    133.       this.Label1.TabIndex = 10;
    134.       this.Label1.Text = "X:";
    135.       //
    136.       // txtY
    137.       //
    138.       this.txtY.Location = new System.Drawing.Point(104, 24);
    139.       this.txtY.Name = "txtY";
    140.       this.txtY.Size = new System.Drawing.Size(36, 20);
    141.       this.txtY.TabIndex = 9;
    142.       this.txtY.Text = "";
    143.       //
    144.       // txtX
    145.       //
    146.       this.txtX.Location = new System.Drawing.Point(36, 24);
    147.       this.txtX.Name = "txtX";
    148.       this.txtX.Size = new System.Drawing.Size(36, 20);
    149.       this.txtX.TabIndex = 8;
    150.       this.txtX.Text = "";
    151.       //
    152.       // cmdMove
    153.       //
    154.       this.cmdMove.FlatStyle = System.Windows.Forms.FlatStyle.System;
    155.       this.cmdMove.Location = new System.Drawing.Point(248, 24);
    156.       this.cmdMove.Name = "cmdMove";
    157.       this.cmdMove.Size = new System.Drawing.Size(72, 20);
    158.       this.cmdMove.TabIndex = 7;
    159.       this.cmdMove.Text = "Move";
    160.       this.cmdMove.Click += new System.EventHandler(this.cmdMove_Click);
    161.       //
    162.       // GroupBox2
    163.       //
    164.       this.GroupBox2.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
    165.         | System.Windows.Forms.AnchorStyles.Right);
    166.       this.GroupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
    167.                                           this.cmdSpeak,
    168.                                           this.txtSpeak});
    169.       this.GroupBox2.FlatStyle = System.Windows.Forms.FlatStyle.System;
    170.       this.GroupBox2.Location = new System.Drawing.Point(8, 163);
    171.       this.GroupBox2.Name = "GroupBox2";
    172.       this.GroupBox2.Size = new System.Drawing.Size(384, 80);
    173.       this.GroupBox2.TabIndex = 10;
    174.       this.GroupBox2.TabStop = false;
    175.       this.GroupBox2.Text = "Speak";
    176.       //
    177.       // cmdSpeak
    178.       //
    179.       this.cmdSpeak.FlatStyle = System.Windows.Forms.FlatStyle.System;
    180.       this.cmdSpeak.Location = new System.Drawing.Point(248, 20);
    181.       this.cmdSpeak.Name = "cmdSpeak";
    182.       this.cmdSpeak.Size = new System.Drawing.Size(72, 20);
    183.       this.cmdSpeak.TabIndex = 6;
    184.       this.cmdSpeak.Text = "Speak";
    185.       this.cmdSpeak.Click += new System.EventHandler(this.cmdSpeak_Click);
    186.       //
    187.       // txtSpeak
    188.       //
    189.       this.txtSpeak.AcceptsReturn = true;
    190.       this.txtSpeak.Location = new System.Drawing.Point(8, 20);
    191.       this.txtSpeak.Multiline = true;
    192.       this.txtSpeak.Name = "txtSpeak";
    193.       this.txtSpeak.Size = new System.Drawing.Size(232, 48);
    194.       this.txtSpeak.TabIndex = 4;
    195.       this.txtSpeak.Text = "";
    196.       //
    197.       // GroupBox1
    198.       //
    199.       this.GroupBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    200.         | System.Windows.Forms.AnchorStyles.Left)
    201.         | System.Windows.Forms.AnchorStyles.Right);
    202.       this.GroupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
    203.                                           this.axAgent1,
    204.                                           this.cmdStop,
    205.                                           this.cmdPlay,
    206.                                           this.lstAnimations});
    207.       this.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
    208.       this.GroupBox1.Location = new System.Drawing.Point(8, 11);
    209.       this.GroupBox1.Name = "GroupBox1";
    210.       this.GroupBox1.Size = new System.Drawing.Size(384, 144);
    211.       this.GroupBox1.TabIndex = 9;
    212.       this.GroupBox1.TabStop = false;
    213.       this.GroupBox1.Text = "Animate";
    214.       //
    215.       // axAgent1
    216.       //
    217.       this.axAgent1.ContainingControl = this;
    218.       this.axAgent1.Enabled = true;
    219.       this.axAgent1.Location = new System.Drawing.Point(336, 32);
    220.       this.axAgent1.Name = "axAgent1";
    221.       this.axAgent1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAgent1.OcxState")));
    222.       this.axAgent1.Size = new System.Drawing.Size(32, 32);
    223.       this.axAgent1.TabIndex = 7;
    224.       //
    225.       // cmdStop
    226.       //
    227.       this.cmdStop.FlatStyle = System.Windows.Forms.FlatStyle.System;
    228.       this.cmdStop.Location = new System.Drawing.Point(248, 48);
    229.       this.cmdStop.Name = "cmdStop";
    230.       this.cmdStop.Size = new System.Drawing.Size(72, 20);
    231.       this.cmdStop.TabIndex = 6;
    232.       this.cmdStop.Text = "Stop";
    233.       this.cmdStop.Click += new System.EventHandler(this.cmdStop_Click);
    234.       //
    235.       // cmdPlay
    236.       //
    237.       this.cmdPlay.FlatStyle = System.Windows.Forms.FlatStyle.System;
    238.       this.cmdPlay.Location = new System.Drawing.Point(248, 24);
    239.       this.cmdPlay.Name = "cmdPlay";
    240.       this.cmdPlay.Size = new System.Drawing.Size(72, 20);
    241.       this.cmdPlay.TabIndex = 5;
    242.       this.cmdPlay.Text = "Play";
    243.       this.cmdPlay.Click += new System.EventHandler(this.cmdPlay_Click);
    244.       //
    245.       // lstAnimations
    246.       //
    247.       this.lstAnimations.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    248.         | System.Windows.Forms.AnchorStyles.Left);
    249.       this.lstAnimations.IntegralHeight = false;
    250.       this.lstAnimations.Location = new System.Drawing.Point(8, 22);
    251.       this.lstAnimations.Name = "lstAnimations";
    252.       this.lstAnimations.Size = new System.Drawing.Size(232, 109);
    253.       this.lstAnimations.TabIndex = 4;
    254.       //
    255.       // AgentTryout
    256.       //
    257.       this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    258.       this.ClientSize = new System.Drawing.Size(400, 366);
    259.       this.Controls.AddRange(new System.Windows.Forms.Control[] {
    260.                                       this.cmdClose,
    261.                                       this.GroupBox3,
    262.                                       this.GroupBox2,
    263.                                       this.GroupBox1});
    264.       this.Name = "AgentTryout";
    265.       this.Text = "AgentTryout";
    266.       this.Load += new System.EventHandler(this.AgentTryout_Load);
    267.       this.GroupBox3.ResumeLayout(false);
    268.       this.GroupBox2.ResumeLayout(false);
    269.       this.GroupBox1.ResumeLayout(false);
    270.       ((System.ComponentModel.ISupportInitialize)(this.axAgent1)).EndInit();
    271.       this.ResumeLayout(false);
    272.  
    273.     }
    274.     #endregion
    275.  
    276.     /// <summary>
    277.     /// The main entry point for the application.
    278.     /// </summary>
    279.     [STAThread]
    280.     static void Main()
    281.     {
    282.       Application.Run(new AgentTryout());
    283.     }
    284.  
    285.     private AgentController controller;
    286.  
    287.     private void AgentTryout_Load(object sender, System.EventArgs e)
    288.     {
    289.       controller = new AgentController(axAgent1, "Genie");
    290.      
    291.       lstAnimations.DataSource=controller.GetAnimations();
    292.      
    293.       controller.Show();
    294.     }
    295.  
    296.     private void cmdPlay_Click(object sender, System.EventArgs e)
    297.     {
    298.       controller.Animate(lstAnimations.Text);
    299.     }
    300.  
    301.     private void cmdStop_Click(object sender, System.EventArgs e)
    302.     {
    303.       controller.StopAll();
    304.     }
    305.  
    306.     private void cmdSpeak_Click(object sender, System.EventArgs e)
    307.     {
    308.       controller.Speak(txtSpeak.Text);
    309.     }
    310.  
    311.     private void cmdMove_Click(object sender, System.EventArgs e)
    312.     {
    313.       controller.MoveTo(short.Parse(txtX.Text), short.Parse(txtY.Text));
    314.     }
    315.  
    316.     private void cmdClose_Click(object sender, System.EventArgs e)
    317.     {
    318.       this.Close();
    319.     }
    320.   }
    321. }
    322.  
    323.  
    324. //================================================================
    325. //================================================================
    326.  
    327. using System;
    328. using AxAgentObjects;
    329. using System.Collections;
    330.  
    331. namespace AgentTryout
    332. {
    333.   public class AgentController
    334.   {
    335.     // Agent variable.
    336.     private AgentObjects.IAgentCtlCharacterEx agentChar;
    337.  
    338.     // Name of the initialized character.
    339.     private string characterName;
    340.  
    341.     // Balloon constants
    342.     private const short BalloonOn = 1;
    343.     private const short SizeToText = 2;
    344.     private const short AutoHide = 4;
    345.     private const short AutoPace = 8;
    346.  
    347.     public AgentController(AxAgentObjects.AxAgent agentHost,
    348.       string character)
    349.     {
    350.       agentHost.Characters.Load(character, null);
    351.       agentChar = agentHost.Characters[character];
    352.  
    353.       characterName = character;
    354.  
    355.       // You could put your own options in this menu, if desired.
    356.       agentChar.AutoPopupMenu = false;
    357.  
    358.       // Set balloon style.
    359.       agentChar.Balloon.Style = agentChar.Balloon.Style | BalloonOn;
    360.       agentChar.Balloon.Style = agentChar.Balloon.Style | SizeToText;
    361.       agentChar.Balloon.Style = agentChar.Balloon.Style | AutoHide;
    362.       //agentChar.Balloon.Style = agentChar.Balloon.Style & !(AutoPace);
    363.     }
    364.  
    365.     public void Dispose()
    366.     {
    367.       if (agentChar.Visible)
    368.       {
    369.         agentChar.StopAll(null);
    370.         agentChar.Hide(null);
    371.       }
    372.     }
    373.  
    374.     public void Show()
    375.     {
    376.       agentChar.Show(null);
    377.     }
    378.  
    379.     public void Hide()
    380.     {
    381.       agentChar.Hide(null);
    382.     }
    383.  
    384.     public void StopAll()
    385.     {
    386.       agentChar.StopAll(null);
    387.     }
    388.  
    389.     public void Speak(string text)
    390.     {
    391.       agentChar.StopAll(null);
    392.       agentChar.Speak(text, "");
    393.     }
    394.  
    395.     public void Think(string text)
    396.     {
    397.       agentChar.StopAll(null);
    398.       agentChar.Think(text);
    399.     }
    400.  
    401.     public void Animate(string animation)
    402.     {
    403.       agentChar.StopAll(null);
    404.       agentChar.Play(animation);
    405.     }
    406.  
    407.     public void MoveTo(short x, short y)
    408.     {
    409.       agentChar.MoveTo(x, y, null);
    410.     }
    411.  
    412.     public void GestureAt(short x, short y)
    413.     {
    414.       agentChar.GestureAt(x, y);
    415.     }
    416.  
    417.     public Array GetAnimations()
    418.     {
    419.       ArrayList list = new ArrayList();
    420.       foreach (string animation in agentChar.AnimationNames)
    421.       {
    422.         list.Add(animation);
    423.       }
    424.       return list.ToArray(typeof(string));
    425.     }
    426.  
    427.     // Tests if the agent is visible.
    428.     // If the agent is not visible it will be shown.
    429.     private bool IsAgentVisible()
    430.     {
    431.       if (agentChar.Visible)
    432.       {
    433.         return true;
    434.       }
    435.       else
    436.       {
    437.         agentChar.Show(null);
    438.           return false;
    439.       }
    440.     }
    441.   }
    442.  
    443. }
    None!

  2. #2
    Ngày gia nhập
    05 2012
    Nơi ở
    Ho Chi Minh City, Vietnam, Vietnam
    Bài viết
    9

    Lâu quá rồi không thấy ai dùng Microsoft Agent hỉ

Các đề tài tương tự

  1. MS SQL Lỗi Không start được service SQL Server Agent
    Gửi bởi rockblin trong diễn đàn Thắc mắc Microsoft SQL Server & Microsoft Access
    Trả lời: 0
    Bài viết cuối: 07-06-2013, 07:43 AM
  2. Visual Studio 2005 bản quyền cài hoặc kích hoạt được bao nhiêu lần ?
    Gửi bởi shizuoka trong diễn đàn Thắc mắc chung
    Trả lời: 0
    Bài viết cuối: 08-11-2012, 11:24 AM
  3. Kế hoạch chuyển một doanh nghiệp hoặc Văn phòng.
    Gửi bởi thanhhung2013 trong diễn đàn Giới thiệu website, sản phẩm của bạn
    Trả lời: 0
    Bài viết cuối: 20-06-2011, 09:35 AM
  4. Lập trình đồ hoạ trên nền C++ (Full time hoặc Cộng tác viên)
    Gửi bởi bachthuchi trong diễn đàn Tuyển dụng - Việc làm CNTT
    Trả lời: 1
    Bài viết cuối: 05-05-2008, 12:24 AM

Quyền hạn của bạn

  • Bạn không thể gửi đề tài mới
  • Bạn không thể gửi bài trả lời
  • Bạn không thể gửi các đính kèm
  • Bạn không thể chỉnh sửa bài viết của bạn