A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: [so close to 1kb] Blackjack

  1. #1
    Run for your life! Phlook's Avatar
    Join Date
    Jul 2003
    Location
    Vancouver, Canada
    Posts
    679

    [so close to 1kb] Blackjack

    Ive been bored lately, and as a result, been working on a small blackjack game (small as in currently 1.19kb), heres the code i used, ive become tired of it, and frustrated that i cant get it any smaller
    code:

    d = 0;
    de = p=1;
    _root.de_s = _root.p_s=_root.de_s2=_root.p_s2=0;
    function dC(num, s, yp, pv, pl) {
    /*tI("DE:"+de);
    tI("P:"+p);*/
    n2 = n3=num;
    if (num == "K" || num == "Q" || num == "J") {
    n2 = 10;
    n3 = 10;
    }
    if (num == "A") {
    n2 = 1;
    n3 = 11;
    }
    _root[pl+"_s2"] += n3;
    _root[pl+"_s"] += n2;
    /*tI(pl+" score: "+_root[pl+"_s"]);
    tI(pl+" score2: "+_root[pl+"_s2"]);*/
    _root.createEmptyMovieClip("c"+d, d);
    x = 75;
    y = 100;
    sx = (x*pv)+(10*pv)-x;
    sy = yp;
    ax = [x, x, 0, 0];
    ay = [0, y, y, 0];
    _root["c"+d].lineStyle(0);
    for (i=0; i<ax.length; i++) {
    _root["c"+d].lineTo(ax[i], ay[i]);
    }
    _root["c"+d].createTextField("t1", 0, 0, 0, 25, 25);
    _root["c"+d].createTextField("t2", 1, x-25, y-25, 25, 25);
    ct1 = _root["c"+d].t1;
    ct2 = _root["c"+d].t2;
    //ct1.selectable = ct2.selectable=false;
    //ct1.autoSize = ct2.autoSize="center";
    ct1.text = ct2.text=num;
    if (s == false) {
    _root["c"+d].t1._visible = _root["c"+d].t2._visible=false;
    }
    _root["c"+d]._x = sx;
    _root["c"+d]._y = sy;
    _root[pl]++;
    if (p>5) {
    if (_root.p_s<=21) {
    tI("you win!");
    }
    eG();
    }
    if (_root.p_s>21) {
    tI("You bust");
    eG();
    }
    d++;
    }
    function cH() {
    c = ["A", "K", "Q", "J"];
    for (i=10; i>1; i--) {
    c.push(i);
    }
    for (j=0; j<2; j++) {
    sx = 10;
    r = c[random((c.length))];
    dC(r, true, 190, p, "p");
    }
    cD();
    }
    function cD() {
    for (j=0; j<2; j++) {
    r = c[random((c.length))];
    dC(r, false, 10, de, "de");
    }
    }
    function cB(t_, xb, yb) {
    _root.createEmptyMovieClip("b"+d, d);
    bx = [100, 100, 0, 0];
    by = [0, 50, 50, 0];
    _root["b"+d].lineStyle(0);
    _root["b"+d].beginFill(0xFFFFFF);
    for (i=0; i<bx.length; i++) {
    _root["b"+d].lineTo(bx[i], by[i]);
    }
    _root["b"+d].endFill();
    _root["b"+d].createTextField("t", 0, 25, 10, 50, 30);
    _root["b"+d].t.text = t_;
    _root["b"+d].onRelease = function() {
    if (this.t.text == "Hit Me") {
    r = c[random((c.length))];
    dC(r, true, 190, p, "p");
    /*if (de_s<14) {
    r = c[random((c.length))];
    dC(r, false, 190, de, "de");
    }*/
    } else if (this.t.text == "Stay") {
    eG();
    }
    };
    _root["b"+d]._x = xb;
    _root["b"+d]._y = yb;
    d++;
    }
    function bG() {
    cH();
    createTextField("o", -200, 290, 125, 150, 50);
    cB("Hit Me", 50, 125);
    cB("Stay", 175, 125);
    d++;
    }
    function eG() {
    for (i=0; i<d; i++) {
    _root["c"+i].t1._visible = _root["c"+i].t2._visible=true;
    _root["b"+i].removeMovieClip();
    }
    if (p_s2<=21) {
    tI("Score: "+p_s2);
    } else {
    tI("Score: "+p_s);
    }
    if (de_s2<=21) {
    tI("Dealer Score: "+de_s2);
    } else {
    tI("Dealer Score: "+de_s);
    }
    }
    function tI(a) {
    o.text += a+"\n";
    }
    bG();



    I omitted some parts of it, and deleted one by accident

    Screen resolution: 435 x 300
    Last edited by Phlook; 11-12-2004 at 03:58 PM.

  2. #2
    Shenanigans JimmyDinner's Avatar
    Join Date
    Mar 2003
    Location
    Vancouver
    Posts
    175
    it looks like you're using stuff like _root["b"+d] a lot.. try using something like..

    var a = _root["b"+d];

    a.lineStyle(0);
    a.beginFill(0xFFFFFF);

    instead.

  3. #3
    the thud of the body rabbitkiller's Avatar
    Join Date
    Jan 2004
    Location
    Royal Oak, Mi
    Posts
    318
    If your intensions to make a complete decent game it'l be around 100 kb. at least (depends on graphics). No one's gonna play that kinda thing. I understand thats just only alpha

    thats how my alpha of the 'Fool' card game looks...
    full game is about 200kb. at www.durak.nm.ru
    world[i] = new world();

  4. #4
    Run for your life! Phlook's Avatar
    Join Date
    Jul 2003
    Location
    Vancouver, Canada
    Posts
    679
    My intentions are a working blackjack game which is <=1kb in size

    I could easily do a blackjack game, but i like a challenge, and i've become lazy and stumped with this one, so i'm putting the code up for anyone else if they want to try to finish it

  5. #5
    the thud of the body rabbitkiller's Avatar
    Join Date
    Jan 2004
    Location
    Royal Oak, Mi
    Posts
    318
    Code it in assembler and it'll be around 200 bytes or so...
    world[i] = new world();

  6. #6
    rabbitkiller, I think you missed the previous threads about this kinda thing... seems to have been a drive for some to see what games they can make in flash under 1k (me I'd be happy if I'd just finish a game )

    examples:
    1KB Tetris
    1KB Pong
    1KB Snake

  7. #7
    Senior Member ihoss.com's Avatar
    Join Date
    Oct 2004
    Location
    Norway
    Posts
    581
    Yeah, Strille made a snake game in less than 1 kb and Andre Michelle made a PAc Man game in less than 1 kb (or was it a certain number of lines?).

    Next challenge: space invaders!

  8. #8
    Say hello to Bob Kakihara's Avatar
    Join Date
    Jul 2004
    Location
    kent, England
    Posts
    1,067
    yeh i seen those, there was also a 1kb pong game (yeh i know that aint as hard as the others but hey its 1kb), slightly bigger was a file that was entered for a competition, i think it was 5kb doom, anyone know where that can be found because i would really like to see how that was done?

    the only thing i can see to optimize it is what jimmy said, set the _root parts as variables that are made up of 1 character, like the first guy said you could rename all things with one character, it would probably be a good idea to make a document of all variables and there names though.
    Last edited by Kakihara; 11-13-2004 at 11:54 AM.
    If our body is a clock ticking away and if while we experience all that this world has to offer time has still continued to pass, are we living or just experiencing a slow death?

  9. #9
    the thud of the body rabbitkiller's Avatar
    Join Date
    Jan 2004
    Location
    Royal Oak, Mi
    Posts
    318
    I see...
    In that case I think it's very difficult to keep it under 1Kb, cause there's many more things to do... like another round, a bet, split (up to 4 hands), double down, and such... Cause it's a casino game that kinda things should be there... otherwise it's not really a BlackJack.
    I'm not trying to be negative, thats just my opinion...
    world[i] = new world();

  10. #10
    Untitled-1.fla strille's Avatar
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    1,626
    Pretty nice, you still got about 200 bytes to shave off before it's under 1Kb, but I think that's possible... and maybe even add a "retry" button as well.

    I managed to shave off 19 bytes by removing the endFill in the cB function, and rewriting the release function to:
    code:

    _root["b"+d].onRelease = function() {
    if (this.t.text == "Hit Me") {
    r = c[random((c.length))];
    dC(r, true, 190, p, "p");
    return;
    }
    eG();
    };



    Edit: Wolfenstein 5Kb can be found here: http://www.the5k.org/description.asp/entry_id=946
    (the game did not work for me though...)
    Last edited by strille; 11-13-2004 at 05:46 PM.

  11. #11
    Cubed Member Soccr743's Avatar
    Join Date
    Mar 2004
    Location
    Maryland
    Posts
    163
    Meh, I spent a couple minutes on it and I got it down to 1178 bytes for the swf.

    code:

    d = 0;
    de = p=1;
    des = ps=des2=ps2=0;
    function dC(num, s, yp, pv, pl) {
    n2 = n3=num;
    if (num == "K" || num == "Q" || num == "J") {
    n2 = n3=10;
    }
    if (num == "A") {
    n2 = 1;
    n3 = 11;
    }
    _root[pl+"s2"] += n3;
    _root[pl+"s"] += n2;
    _root.createEmptyMovieClip("c"+d, d);
    x = 75;
    y = 100;
    sx = (x*pv)+(10*pv)-x;
    sy = yp;
    ax = [x, x, 0, 0];
    ay = [0, y, y, 0];
    eval("c"+d).lineStyle(0);
    for (i=0; i<ax.length; i++) {
    eval("c"+d).lineTo(ax[i], ay[i]);
    }
    eval("c"+d).createTextField("t1", 0, 0, 0, 25, 25);
    eval("c"+d).createTextField("t2", 1, x-25, y-25, 25, 25);
    ct1 = eval("c"+d).t1;
    ct2 = eval("c"+d).t2;
    ct1.text = ct2.text=num;
    if (!s) {
    eval("c"+d).t1._visible = eval("c"+d).t2._visible=0;
    }
    eval("c"+d)._x = sx;
    eval("c"+d)._y = sy;
    _root[pl]++;
    if (p>5) {
    if (_root.ps<=21) {
    tI("You win");
    }
    eG();
    }
    if (_root.ps>21) {
    tI("You bust");
    eG();
    }
    d++;
    }
    function cH() {
    c = ["A", "K", "Q", "J"];
    for (i=10; i>1; i--) {
    c.push(i);
    }
    for (j=0; j<2; j++) {
    sx = 10;
    r = c[random((c.length))];
    dC(r, true, 190, p, "p");
    }
    cD();
    }
    function cD() {
    for (j=0; j<2; j++) {
    r = c[random((c.length))];
    dC(r, false, 10, de, "de");
    }
    }
    function cB(t_, xb, yb) {
    _root.createEmptyMovieClip("b"+d, d);
    bx = [100, 100, 0, 0];
    by = [0, 50, 50, 0];
    eval("b"+d).lineStyle(0);
    eval("b"+d).beginFill(0xFFFFFF);
    for (i=0; i<4; i++) {
    eval("b"+d).lineTo(bx[i], by[i]);
    }
    eval("b"+d).createTextField("t", 0, 25, 10, 50, 30);
    eval("b"+d).t.text = t_;
    eval("b"+d).onRelease = function() {
    if (this.t.text == "Hit") {
    r = c[random((c.length))];
    dC(r, true, 190, p, "p");
    return;
    }
    eG();
    };
    eval("b"+d)._x = xb;
    eval("b"+d)._y = yb;
    d++;
    }
    function bG() {
    cH();
    createTextField("o", -200, 290, 125, 150, 50);
    cB("Hit", 50, 125);
    cB("Stay", 175, 125);
    d++;
    }
    function eG() {
    for (i=0; i<d; i++) {
    eval("c"+i).t1._visible = eval("c"+i).t2._visible=1;
    eval("b"+i).removeMovieClip();
    }
    (ps2<=21) ? tI("Score: "+ps2) : tI("Score: "+ps);
    (des2<=21) ? tI("Dealer Score: "+des2) : tI("Dealer Score: "+des);
    }
    function tI(a) {
    o.text += a+"\n";
    }
    bG();



    I hope that helps some...

    -----Soccr743-----

  12. #12
    Untitled-2.fla
    Join Date
    Jul 2002
    Posts
    391
    a little more shaving 1.11 KB (1,143 bytes)
    ~yarr
    code:
    d = 0;
    de = p=1;
    des = ps=des2=ps2=0;
    function dC(n, s, yp, pv, pl) {
    n2 = n3=n;
    if (n == "K" || n == "Q" || n == "J") {
    n2 = n3=10;
    }
    if (n == "A") {
    n2 = 1;
    n3 = 11;
    }
    _root[pl+"s2"] += n3;
    _root[pl+"s"] += n2;
    _root.createEmptyMovieClip("c"+d, d);
    x = 75;
    y = 100;
    sx = (x*pv)+(10*pv)-x;
    sy = yp;
    ax = [x, x, 0, 0];
    ay = [0, y, y, 0];
    eval("c"+d).lineStyle(0);
    for (i=0; i<ax.length; i++) {
    eval("c"+d).lineTo(ax[i], ay[i]);
    }
    eval("c"+d).createTextField("t1", 0, 0, 0, 25, 25);
    eval("c"+d).createTextField("t2", 1, x-25, y-25, 25, 25);
    ct1 = eval("c"+d).t1;
    ct2 = eval("c"+d).t2;
    ct1.text = ct2.text=n;
    // if (!s) {
    eval("c"+d).t1._visible = eval("c"+d).t2._visible=s;
    //false;
    // }
    eval("c"+d)._x = sx;
    eval("c"+d)._y = sy;
    _root[pl]++;
    if (p>5) {
    if (_root.ps<=21) {
    o.text += "You win";
    }
    eG();
    }
    if (_root.ps>21) {
    o.text += "You bust";
    eG();
    }
    d++;
    }
    function cH() {
    c = ["A", "K", "Q", "J"];
    for (i=10; i>1; i--) {
    c.push(i);
    }
    for (j=0; j<2; j++) {
    sx = 10;
    r = c[random((c.length))];
    dC(r, true, 190, p, "p");
    }
    //cD();
    for (j=0; j<2; j++) {
    r = c[random((c.length))];
    dC(r, 0, 10, de, "de");
    }
    }
    /*
    function cD() {
    for (j=0; j<2; j++) {
    r = c[random((c.length))];
    dC(r, false, 10, de, "de");
    }
    }
    */
    function cB(t, xb, yb) {
    _root.createEmptyMovieClip("b"+d, d);
    bx = [100, 100, 0, 0];
    by = [0, 50, 50, 0];
    eval("b"+d).lineStyle(0);
    eval("b"+d).beginFill(0xFFFFFF);
    for (i=0; i<4; i++) {
    eval("b"+d).lineTo(bx[i], by[i]);
    }
    eval("b"+d).createTextField("t", 0, 25, 10, 50, 30);
    eval("b"+d).t.text = t;
    eval("b"+d).onRelease = function() {
    if (this.t.text == "Hit") {
    r = c[random((c.length))];
    dC(r, true, 190, p, "p");
    return;
    }
    eG();
    };
    eval("b"+d)._x = xb;
    eval("b"+d)._y = yb;
    d++;
    }
    function bG() {
    cH();
    createTextField("o", -200, 290, 125, 150, 50);
    cB("Hit", 50, 125);
    cB("Stay", 175, 125);
    d++;
    }
    function eG() {
    for (i=0; i<d; i++) {
    eval("c"+i).t1._visible = eval("c"+i).t2._visible=true;
    eval("b"+i).removeMovieClip();
    }
    //(ps2<=21) ? tI("Score: "+ps2) : tI("Score: "+ps);
    o.text += "Score:"+((ps2<=21) ? ps2 : ps)+newline;
    o.text += "Dealer Score:"+((des2<=21) ? des2 : des);
    // (des2<=21) ? tI("Dealer Score: "+des2) : tI("Dealer Score: "+des);
    }
    /*
    function tI(a) {
    o.text += a+"\n";
    }
    */
    bG();

    Last edited by token 3; 11-14-2004 at 01:49 PM.

  13. #13
    Cubed Member Soccr743's Avatar
    Join Date
    Mar 2004
    Location
    Maryland
    Posts
    163
    Damn, token, very nice job there. I will try later tonight for a little while to get it down even more...

    -----Soccr743-----

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center