shawind 发表于 2009-5-10 14:02:17

一个Web游戏的超初级wg

只做到获取两个参数,就发现写不下去了。好像dwin库中的IE OLE部分还不支持childNodes,找不到没有id,name的组件。


import dwin.sys.win32.ie.IE;
import dfl.all;
import Integer = tango.text.convert.Integer;

pragma(lib, "dwin.lib");
pragma(lib, "pcre.lib");
pragma(lib, "dfl.lib");
pragma(lib, "uuid.lib");

char[] to(uint u)
{
    return Integer.format(new char, u);
}

uint to(char[] c)
{
    return Integer.atoi(c);
}

class MyIE : Form
{
    IWebBrowser2 ie;
    Button OBtn;
    Button CBtn;
    ComboBox ServerListBox;
    Button TBtn;
    this()
    {
      this.text = "牧场OnWeb控制台";
      this.clientSize = Size(400,225);
      this.startPosition = FormStartPosition.CENTER_SCREEN;
      this.maximizeBox = false;

      ServerListBox = new ComboBox();
      ServerListBox.bounds = Rect(0,0,80,18);
      ServerListBox.items.add("稻香");
      ServerListBox.items.add("麦浪");
      ServerListBox.items.add("桃源");
      ServerListBox.items.add("爱情");
      ServerListBox.text = "爱情";
      ServerListBox.parent = this;

      OBtn = new Button();
      OBtn.text = "打开IE";
      OBtn.bounds = Rect(82,0,80,18);
      OBtn.parent = this;
      OBtn.click ~= &this.createIE;

      CBtn = new Button();
      CBtn.text = "关闭IE";
      CBtn.bounds = Rect(164,0,80,18);
      CBtn.parent = this;
      CBtn.click ~= &this.closeIE;

      TBtn = new Button();
      TBtn.text = "测试";
      TBtn.bounds = Rect(246,0,80,18);
      TBtn.parent = this;
      TBtn.click ~= &this.test;
    }

    private void createIE(Object o, EventArgs e)
    {
      switch(ServerListBox.text)
      {
            case "稻香":
                ie = ieCreate(null, "Width",1020, "Height",780,"Navigate", "http://web.iyoyo.com.cn/Account/LoginServer.aspx?SiteID=1&GameID=9&ServerID=1");
                break;
            case "麦浪":
                ie = ieCreate(null, "Width",1020, "Height",780,"Navigate", "http://web.iyoyo.com.cn/Account/LoginServer.aspx?SiteID=1&GameID=9&ServerID=2");
                break;
            case "桃源":
                ie = ieCreate(null, "Width",1020, "Height",780,"Navigate", "http://web.iyoyo.com.cn/Account/LoginServer.aspx?SiteID=1&GameID=9&ServerID=3");
                break;
            case "爱情":
                ie = ieCreate(null, "Width",1020, "Height",780,"Navigate", "http://web.iyoyo.com.cn/Account/LoginServer.aspx?SiteID=1&GameID=9&ServerID=4");
                break;
            default:
                msgBox("没指定现有的服务器!");
      }
    }

    private void closeIE(Object o, EventArgs e)
    {
      ie.Quit();
    }

    private void test(Object o, EventArgs e)
    {
      if(ie is null)
      {
            msgBox("没有打开网页");
      }
      else
      {
            msgBox(to(getMoney(ie)));
            msgBox(to(getPower(ie)));
      }
    }

    private uint getMoney(IWebBrowser2 i)
    {
      auto money = getElementById(i, "tipMoney");
      return to(getInnerText(money));
    }

    private uint getPower(IWebBrowser2 i)
    {
      auto power = getElementById(i, "main");
      return to(getInnerText(power));
    }
}


void main()
{
    int result = 0;

    try
    {
      Application.enableVisualStyles();
      Application.run(new MyIE());
    }
    catch(Object o)
    {
      msgBox(o.toString(), "Fatal Error", MsgBoxButtons.OK, MsgBoxIcon.ERROR);
      
      result = 1;
    }
   
    return result;
}

貘良了 发表于 2009-5-10 14:37:49

朋友每月花15元去买 逐鹿天下 那个webgame的WG,真不知道他怎么想的。

我是理解不了花钱买WG的乐趣了。

shawind 发表于 2009-5-10 14:45:00

引用第1楼貘良了于2009-05-10 14:37发表的:
朋友每月花15元去买 逐鹿天下 那个webgame的WG,真不知道他怎么想的。

我是理解不了花钱买WG的乐趣了。

人和人不一样,各取所需吧。

shawind 发表于 2009-5-10 14:47:15

又看了下,原来dwin中还有com,再来试试看这个东西能不能有完整功能。
页: [1]
查看完整版本: 一个Web游戏的超初级wg