Beispiel #1
0
/*!
    \fn swText::op_bg( std::string::const_iterator& )
 */
bool swText::op_bg( std::string::const_iterator& _e)
{
    swTAttr::Color C(0,0);
    if( _clear) {
        C.fg = attr.FgColor();
        C.bg = _defaultAttributes.BgColor();
        attr << C;
        _clear  = false;
        return true;
    }
    ++_e;
    int v;
    stripws(_e);
   // gDebug << *_e;
    if( (v=cnum( *_e )) < 0 ){
        Dbg << "Illegal value:" << *_e << " <=> " << v ; DEND;
        return false;
    }
    int fg = attr.FgColor();
    C.bg = v;
    C.fg = fg;
    attr << C;
   // Dbg << " Bg set to " << v; DEND;
    _clear = false;
    return true;
}
int main(int argc, char* argv[])
{
	srand(time(NULL));
	apvector<apstring> yourdeck(numofcards,"0");
	apvector<type> cvalue(numofcards,land);
	apvector<int> cast(numofcards,0);
	apvector<int> clife(numofcards,0);
	apmatrix<int> castcost(numofcards,2,0);
	apvector<int> castcostco(numofcards,0);
	apvector<fly> fornot(numofcards,notflying);
	apvector<int> num(numofcards,1);
	apvector<int> cnum(numofcards,1);
	apvector<int> yhand(11,-1);
	apvector<int> chand(11,-1);
	apvector<int> table(1,-1);
	filldeck(yourdeck,cvalue,cast,clife,castcost,castcostco,fornot,num);
	cnum=num;
	firstdrow(yhand,num,cvalue);
	firstdrow(chand,cnum,cvalue);
	for(int u=0;u<11;u++)
	{
		cout<<u+1<<","<<yourdeck[yhand[u]];
		if(cvalue[yhand[u]]==land)
			cout<<" land"<<endl;
		else
			cout<<" Creature"<<endl;

	}
	int ypoints=20,cpoints=20,z=0;
	char the;
	while(the!='n'&&ypoints>0&&cpoints>0)
	{
		putdown(yhand,table,yourdeck);
		the=drawtwo(yhand,num);
		if(the!='n')
		{
			cout<<"\nhand\n-------\n";
			for(z=0;z<yhand.length();z++)
			{
				cout<<z+1<<","<<yourdeck[yhand[z]]<<endl;
			}
			cout<<"\nTabel\n-------\n";
			for(int k=0;k<table.length();k++)
			{
				cout<<k+1<<","<<yourdeck[table[k]]<<endl;
			}
		}
		
	}

	return 0;
}
Beispiel #3
0
/*!
    \fn swText::op_fg( std::string::const_iterator& )
 */
bool swText::op_fg( std::string::const_iterator& _e)
{
    //Debug;
    swTAttr::Color C(0,0);
    ++_e;
    int v;
    stripws(_e);
    if( (v=cnum( *_e )) < 0 ) return false;
    int bg = attr.BgColor();
    //Dbg << "CUrrent bg=" << bg;DEND;
    C.fg = v;
    //Dbg "Expected fg: " << v;
    C.bg = bg;
    attr << C;
    _clear = false;
    return true;
}
// ============================================================================
// pxpByteCode
// ============================================================================
pxpByteCode::pxpByteCode( pkgDecompiler* decompiler )
:   Decompiler(decompiler)
,   CToken(NULL)
,   CTokenTree(NULL)
,   CTokenGroup(NULL)
,   CTokenGroupTree(NULL)
,   CTokenItem(NULL)
,   CTokenItemTree(NULL)
,   CTokenGroupCnd(NULL)
,   CTokenGroupCndTree(NULL)
,   unXmlParser()
{
    // temp tree nodes
    unXmlParseTree bytecode   ( wxT("bytecode") );
    unXmlParseTree bgroup     ( wxT("group") );
    unXmlParseTree gname      ( wxT("name") );
    unXmlParseTree gmemo      ( wxT("memo") );

    unXmlParseTree gtoken     ( wxT("token") );
    unXmlParseTree tcode      ( wxT("code") );
    unXmlParseTree tname      ( wxT("name") );
    unXmlParseTree tdesc      ( wxT("desc") );
    unXmlParseTree tdata      ( wxT("data") );

    unXmlParseTree titem      ( wxT("item") );
    unXmlParseTree itype      ( wxT("type") );
    unXmlParseTree iname      ( wxT("name") );

    unXmlParseTree ttext      ( wxT("text") );

    unXmlParseTree gcond      ( wxT("gcond") );
    unXmlParseTree cif        ( wxT("if") );
    unXmlParseTree ceq        ( wxT("eq") );
    unXmlParseTree cthen      ( wxT("then") );
    unXmlParseTree cleft      ( wxT("left") );
    unXmlParseTree cright     ( wxT("right") );

    unXmlParseTree ctstream   ( wxT("tstream") );
    unXmlParseTree cnum       ( wxT("num") );

    unXmlParseTree nfunc      ( wxT("nativefunctions") );
    unXmlParseTree ffirst     ( wxT("first") );
    unXmlParseTree fextended  ( wxT("extended") );

    // token group - pre
    bgroup.AddCommand( new_xpObjCreate<pkgTokenGroup>(txpParseTree) );
    bgroup.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroup, txpTokenGroupObject ) );
    bgroup.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroupTree, txpParseTree ) );
        gname.AddCommand( new_xpFunc1( txpTokenGroup, &pkgTokenGroup::SetName, txpNodeName(txpParseTree) ) );
        gname.AddPostCommand( new_xpFunc1( Decompiler, &pkgDecompiler::AddTokenGroup, txpTokenGroup ) );

    // token group - post
    bgroup.AddPostCommand( new_xpObjClear(txpParseTree) );
    bgroup.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroup ) );
    bgroup.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroupTree ) );

    // gcond = pre
    gcond.AddCommand( new_xpObjCreate<pkgTokenCondition>(txpParseTree) );
    gcond.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroupCnd, txpTokenGroupCndObject ) );
    gcond.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroupCndTree, txpParseTree ) );

    // gcond = post
    gcond.AddPostCommand( new_xpObjClear(txpParseTree) );
    gcond.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroupCnd ) );
    gcond.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroupCndTree ) );

    // token - pre
    gtoken.AddCommand( new_xpObjCreate<dtToken>(txpParseTree) );
    gtoken.AddCommand( new_xpFunc1( this, &pxpByteCode::SetToken, txpTokenObject ) );
    gtoken.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenTree, txpParseTree ) );
        tcode.AddCommand( new_xpFunc1( txpTokenTreeObject, &dtToken::SetTokenData, txpNodeData(txpParseTree) ) );
        tname.AddCommand( new_xpFunc1( txpTokenTreeObject, &dtToken::SetTokenName, txpNodeName(txpParseTree) ) );
        tdesc.AddCommand( new_xpFunc1( txpTokenTreeObject, &dtToken::SetDesc, txpNodeName(txpParseTree) ) );
        tdesc.AddCommand( new_xpFunc1( txpTokenGroup, &pkgTokenGroup::AddToken, txpToken ) );
        tdesc.AddCommand( new_xpFunc2( Decompiler, &pkgDecompiler::AddToken, txpToken, txpTokenGroupCnd ) );

    // token - post
    gtoken.AddPostCommand( new_xpFunc0( txpToken, &dtToken::DumpInfo ) );
    gtoken.AddPostCommand( new_xpObjClear(txpParseTree) );
    gtoken.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearToken ) );
    gtoken.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenTree ) );

    // titem - pre
    titem.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenItemTree, txpParseTree ) );
        itype.AddCommand( new_xpObjFactory( txpTokenItemTree, &GDataTypeFactory, &pkgDataTypeFactory::Create, txpNodeName(txpParseTree) ) );
        itype.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenItem, txpTokenItemTreeObject ) );
        iname.AddCommand( new_xpFunc1( txpTokenItem, &pkgDataType::SetDesc, txpNodeName(txpParseTree) ) );

    // titem - post
    titem.AddPostCommand( new_xpFunc1( txpToken, &dtToken::AddItem, txpTokenItem ) );
    titem.AddPostCommand( new_xpObjClear(txpParseTree) );
    titem.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenItem ) );
    titem.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenItemTree ) );
    
    ffirst.AddCommand( new_xpFunc1( Decompiler, &pkgDecompiler::SetFunctionIdFirst, txpNodeData(txpParseTree) ) );
    fextended.AddCommand( new_xpFunc1( Decompiler, &pkgDecompiler::SetFunctionIdExtended, txpNodeData(txpParseTree) ) );


    // construct tree starting from leaves
    // ie: node on right side *cannot* appear anywhere below on left side

    // token
    gtoken.AddChild( tcode, pl::one );
    gtoken.AddChild( tname, pl::one );
    gtoken.AddChild( tdesc, pl::one );
            titem.AddChild( itype, pl::one );
            titem.AddChild( iname, pl::one );
        tdata.AddChild( titem, pl::minone );
        tdata.AddChild( ttext, pl::maxone );
    gtoken.AddChild( tdata, pl::maxone );

    // if
            cleft.AddChild( ctstream, pl::maxone );
            cleft.AddChild( cnum, pl::maxone );
            cright.AddChild( ctstream, pl::maxone );
            cright.AddChild( cnum, pl::maxone );
        ceq.AddChild( cleft, pl::one );
        ceq.AddChild( cright, pl::one );
    cif.AddChild( ceq, pl::one );

    // then
    cthen.AddChild( gtoken, pl::any );

    // group
    bgroup.AddChild( gname, pl::one );
    bgroup.AddChild( gmemo, pl::any );
        gcond.AddChild( cif, pl::one );
        gcond.AddChild( cthen, pl::one );
    bgroup.AddChild( gcond, pl::maxone );
    bgroup.AddChild( gtoken, pl::any );

    // native functions
    nfunc.AddChild( fextended, pl::one );
    nfunc.AddChild( ffirst, pl::one );

    // bytecode
    bytecode.AddChild( bgroup, pl::minone );
    bytecode.AddChild( nfunc, pl::maxone );

    ParseTree = new unXmlParseTree( bytecode );
}