Posts Tagged ‘Code’

The final result of my card game can be found here. Please note for some reason it has not uploaded correctly so things that should be hidden are visible (I tried uploading several times).

Evaluation:

I decided to try and make a game based off the Final Fantasy trading card game not released in the west. This involved getting card images and importing a deck of my own, translating them and learning to play. I then spent time doing initial sketches and researched the layouts of existing card games looking for features or displays I could use in my own game.

My biggest challenge was trying to learn flash, but any card tutorials I found were irrelevant or incomplete which lead me to try and create a completely scripted battle. This is what lead me to create a tutorial but due to my lack of knowledge with flash things took a lot longer than they should have and I took the long way of doing things writing 500+ lines of code for most slides. This is why the tutorial is so short.

If I could do this all again I would make a background track for the level, create a better looking menu screen and spend less time translating cards as only a hand full were actually used due to my limitations in coding meaning I could not set up a random draw function like I had hopped. Overall I am pleased with the progress I made learning flash and over coming numerous problems but taking the flash as a product on its own it is far from what I imagined been little more than a 12 slide sideshow were the user has to choose the right options to progress. Though it does manage to demonstrate the type of game I was proposing to make, which is the purpose of the flash. In closing I hope to be able to improve my skills even further in my next flash based project.

Advertisements

I tryed to follow a video tutorial on how to code a blackjack game in flash to give me a basic idea of how to code a simple cardgame but there was only one video and an incomplete resource that were missing the five of hearts and the ace of dimonds. I tryed to create a deck function but I could not get it to work.

flash blog 1

First I added linkage to all the movie files. I then added the code that would use the linkage to place the movie file in the field.

var c1:card1 = new card1();
var c2:card2 = new card2();
var c3:card3 = new card3();
var c4:card4 = new card4();
var c5:card5 = new card5();
var c6:card6 = new card6();
var c7:card7 = new card7();
var c8:card8 = new card8();
var c9:card9 = new card9();
var c10:card10 = new card10();
var c11:card11 = new card11();
var c12:card12 = new card12();
var c13:card13 = new card13();
var c14:card14 = new card14();
var c15:card15 = new card15();
var c16:card16 = new card16();
var c17:card17 = new card17();
var c18:card18 = new card18();
var c19:card19 = new card19();
var c20:card20 = new card20();
var c21:card21 = new card21();
var c22:card22 = new card22();
var c23:card23 = new card23();
var c24:card24 = new card24();
var c25:card25 = new card25();
var c26:card26 = new card26();
var c27:card27 = new card27();
var c28:card28 = new card28();
var c29:card29 = new card29();
var c30:card30 = new card30();
var c31:card31 = new card31();
var c32:card32 = new card32();
var c33:card33 = new card33();
var c34:card34 = new card34();
var c35:card35 = new card35();
var c36:card36 = new card36();
var c37:card37 = new card37();
var c38:card38 = new card38();
var c39:card39 = new card39();
var c40:card40 = new card40();
var c41:card41 = new card41();
var c42:card42 = new card42();
var c43:card43 = new card43();
var c44:card44 = new card44();
var c45:card45 = new card45();
var c46:card46 = new card46();
var c47:card47 = new card47();
var c48:card48 = new card48();
var c49:card49 = new card49();
var c50:card50 = new card50();
var c51:card51 = new card51();
var cb:cardback = new cardback();

//var cardClip:MovieClip = new MovieClip;
//cardClip.addChild(c1);
addChild(c1);
//cardClip.addChild(c2);
addChild(c2);
addChild(c3);
addChild(c4);
addChild(c5);
addChild(c6);
addChild(c7);
addChild(c8);
addChild(c9);
addChild(c10);
addChild(c11);
addChild(c12);
addChild(c13);
addChild(c14);
addChild(c15);
addChild(c16);
addChild(c17);
addChild(c18);
addChild(c19);
addChild(c20);
addChild(c21);
addChild(c22);
addChild(c23);
addChild(c24);
addChild(c25);
addChild(c26);
addChild(c27);
addChild(c28);
addChild(c29);
addChild(c30);
addChild(c31);
addChild(c32);
addChild(c33);
addChild(c34);
addChild(c35);
addChild(c36);
addChild(c37);
addChild(c38);
addChild(c39);
addChild(c40);
addChild(c41);
addChild(c42);
addChild(c43);
addChild(c44);
addChild(c45);
addChild(c46);
addChild(c47);
addChild(c48);
addChild(c49);
addChild(c50);
addChild(c51);
addChild(cb);

This succeeded in placing all the cards ontop of eachother in a stack in the top left hand corner of the screen.

flash blog 2

 I then found another website that had code to create a deck function:

function newDeck()
{
    var values = 13;
    var suits = [“S”, “C”, “H”, “D”];

    var Deck = new Array();

    for(var s=0; s<suits.length; s++) // “s” for suits
    {
        for(var v=1; v<=values; v++) // “v” for values
        {
            Deck.push( {value: v, suit: suits[s]} );
        }
    }

    return Deck;
}

Deck = newDeck();

So I then tryed to add it to my code and give the movie clips the suit and numerical values by typing them in the brackets of the code:

var c1:card1 = new card1({value: 1, suit: “C”});
var c2:card2 = new card2({value: 1, suit: “S”});
var c3:card3 = new card3({value: 1, suit: “H”});
var c4:card4 = new card4({value: 13, suit: “C”});
var c5:card5 = new card5({value: 13, suit: “S”});
var c6:card6 = new card6({value: 13, suit: “H”});
var c7:card7 = new card7({value: 13, suit: “D”});
var c8:card8 = new card8({value: 12, suit: “C”});
var c9:card9 = new card9({value: 12, suit: “S”});
var c10:card10 = new card10({value: 12, suit: “H”});
var c11:card11 = new card11({value: 12, suit: “D”});
var c12:card12 = new card12({value: 11, suit: “C”});
var c13:card13 = new card13({value: 11, suit: “S”});
var c14:card14 = new card14({value: 11, suit: “H”});
var c15:card15 = new card15({value: 11, suit: “D”});
var c16:card16 = new card16({value: 10, suit: “C”});
var c17:card17 = new card17({value: 10, suit: “S”});
var c18:card18 = new card18({value: 10, suit: “H”});
var c19:card19 = new card19({value: 10, suit: “D”});
var c20:card20 = new card20({value: 9, suit: “C”});
var c21:card21 = new card21({value: 9, suit: “S”});
var c22:card22 = new card22({value: 9, suit: “H”});
var c23:card23 = new card23({value: 9, suit: “D”});
var c24:card24 = new card24({value: 8, suit: “C”});
var c25:card25 = new card25({value: 8, suit: “S”});
var c26:card26 = new card26({value: 8, suit: “H”});
var c27:card27 = new card27({value: 8, suit: “D”});
var c28:card28 = new card28({value: 7, suit: “C”});
var c29:card29 = new card29({value: 7, suit: “S”});
var c30:card30 = new card30({value: 7, suit: “H”});
var c31:card31 = new card31({value: 7, suit: “D”});
var c32:card32 = new card32({value: 6, suit: “C”});
var c33:card33 = new card33({value: 6, suit: “S”});
var c34:card34 = new card34({value: 6, suit: “H”});
var c35:card35 = new card35({value: 6, suit: “D”});
var c36:card36 = new card36({value: 5, suit: “C”});
var c37:card37 = new card37({value: 5, suit: “S”});
var c38:card38 = new card38({value: 5, suit: “H”});
var c39:card39 = new card39({value: 5, suit: “D”});
var c40:card40 = new card40({value: 4, suit: “C”});
var c41:card41 = new card41({value: 4, suit: “S”});
var c42:card42 = new card42({value: 4, suit: “H”});
var c43:card43 = new card43({value: 4, suit: “D”});
var c44:card44 = new card44({value: 3, suit: “C”});
var c45:card45 = new card45({value: 3, suit: “S”});
var c46:card46 = new card46({value: 3, suit: “H”});
var c47:card47 = new card47({value: 3, suit: “D”});
var c48:card48 = new card48({value: 2, suit: “C”});
var c49:card49 = new card49({value: 2, suit: “S”});
var c50:card50 = new card50({value: 2, suit: “H”});
var c51:card51 = new card51({value: 2, suit: “D”});
var cb:cardback = new cardback();

//var cardClip:MovieClip = new MovieClip;
//cardClip.addChild(c1);
addChild(c1);
//cardClip.addChild(c2);
addChild(c2);
addChild(c3);
addChild(c4);
addChild(c5);
addChild(c6);
addChild(c7);
addChild(c8);
addChild(c9);
addChild(c10);
addChild(c11);
addChild(c12);
addChild(c13);
addChild(c14);
addChild(c15);
addChild(c16);
addChild(c17);
addChild(c18);
addChild(c19);
addChild(c20);
addChild(c21);
addChild(c22);
addChild(c23);
addChild(c24);
addChild(c25);
addChild(c26);
addChild(c27);
addChild(c28);
addChild(c29);
addChild(c30);
addChild(c31);
addChild(c32);
addChild(c33);
addChild(c34);
addChild(c35);
addChild(c36);
addChild(c37);
addChild(c38);
addChild(c39);
addChild(c40);
addChild(c41);
addChild(c42);
addChild(c43);
addChild(c44);
addChild(c45);
addChild(c46);
addChild(c47);
addChild(c48);
addChild(c49);
addChild(c50);
addChild(c51);
addChild(cb);

function newDeck()
{
    var values = 13;
    var suits = [“S”, “C”, “H”, “D”];

    var Deck = new Array();

    for(var s=0; s<suits.length; s++) // “s” for suits
    {
        for(var v=1; v<=values; v++) // “v” for values
        {
            Deck.push( {value: v, suit: suits[s]} );
        }
    }

    return Deck;
}

Deck = newDeck();

This didn’t do anything because you cant give an image the values this way and () isthe equevilant of full stop in code, I learned after someone pointed it out to me. I then decided to start again this time I made the linkage much simpler so insted of just putting card1 through 51 I put the letter of the suit and the cards value for example the king of hearts would be H13 and the ace of spades would be S1. I also added notes to the code to note which cards were missing from each suit.

var cb:cardback = new cardback();//back of cards
var s1:card2 = new card2();
var s13:card5 = new card5();
var s12:card9 = new card9();
var s11:card13 = new card13();
var s10:card17 = new card17();
var s9:card21 = new card21();
var s8:card25 = new card25();
var s7:card29 = new card29();
var s6:card33 = new card33();
var s5:card37 = new card37();
var s4:card41 = new card41();
var s3:card45 = new card45();
var s2:card49 = new card49();//end Spades
var c1:card1 = new card1();
var c13:card4 = new card4();
var c12:card8 = new card8();
var c11:card12 = new card12();
var c10:card16 = new card16();
var c9:card20 = new card20();
var c8:card24 = new card24();
var c7:card28 = new card28();
var c6:card32 = new card32();
var c5:card36 = new card36();
var c4:card40 = new card40();
var c3:card44 = new card44();
var c2:card48 = new card48();//end Clubs
var h1:card3 = new card3();
var h13:card6 = new card6();
var h12:card10 = new card10();
var h11:card14 = new card14();
var h10:card18 = new card18();
var h9:card22 = new card22();
var h8:card26 = new card26();
var h7:card30 = new card30();
var h6:card34 = new card34();
var h4:card42 = new card42();
var h3:card46 = new card46();
var h2:card50 = new card50();//end Hearts (missing 5 of hearts)
var d13:card7 = new card7();
var d12:card11 = new card11();
var d11:card15 = new card15();
var d10:card19 = new card19();
var d9:card23 = new card23();
var d8:card27 = new card27();
var d7:card31 = new card31();
var d6:card35 = new card35();
var d5:card39 = new card39();
var d4:card43 = new card43();
var d3:card47 = new card47();
var d2:card51 = new card51();//end Dimonds (missing Ace)

I then tryed to groupe each suit as a deck:

var cb:cardback = new cardback();//back of cards
var s1:card2 = new card2();
var s13:card5 = new card5();
var s12:card9 = new card9();
var s11:card13 = new card13();
var s10:card17 = new card17();
var s9:card21 = new card21();
var s8:card25 = new card25();
var s7:card29 = new card29();
var s6:card33 = new card33();
var s5:card37 = new card37();
var s4:card41 = new card41();
var s3:card45 = new card45();
var s2:card49 = new card49();//end Spades
var c1:card1 = new card1();
var c13:card4 = new card4();
var c12:card8 = new card8();
var c11:card12 = new card12();
var c10:card16 = new card16();
var c9:card20 = new card20();
var c8:card24 = new card24();
var c7:card28 = new card28();
var c6:card32 = new card32();
var c5:card36 = new card36();
var c4:card40 = new card40();
var c3:card44 = new card44();
var c2:card48 = new card48();//end Clubs
var h1:card3 = new card3();
var h13:card6 = new card6();
var h12:card10 = new card10();
var h11:card14 = new card14();
var h10:card18 = new card18();
var h9:card22 = new card22();
var h8:card26 = new card26();
var h7:card30 = new card30();
var h6:card34 = new card34();
var h4:card42 = new card42();
var h3:card46 = new card46();
var h2:card50 = new card50();//end Hearts (missing 5 of hearts)
var d13:card7 = new card7();
var d12:card11 = new card11();
var d11:card15 = new card15();
var d10:card19 = new card19();
var d9:card23 = new card23();
var d8:card27 = new card27();
var d7:card31 = new card31();
var d6:card35 = new card35();
var d5:card39 = new card39();
var d4:card43 = new card43();
var d3:card47 = new card47();
var d2:card51 = new card51();//end Dimonds (missing Ace)
Deck = [  
  {value: s1, suit: “S”},
  {value: s2, suit: “S”),
  {value: s3, suit: “S”},
  {value: s4, suit: “S”},
  {value: s5, suit: “S”},
  {value: s6, suit: “S”},
  {value: s7, suit: “S”},
  {value: s8, suit: “S”},
  {value: s9, suit: “S”},
  {value: s10, suit: “S”},
  {value: s11, suit: “S”},
  {value: s12, suit: “S”},
  {value: s13, suit: “S”},
  ]

 This once again didnt work, I was then pointed in the direction of using an XML document to sort the images into a database structure which you can code to select images at random to simulate a drawing system this is a method I will consider trying when I start making my final demo or I will make a scripted battel scenario which gives the player the feel of how the game would work without having to spent to long thinking  about how to code the full game.

 

This is the second flash tutorial I was given. My finished result can be found here please click Play flash full screen for full effect. Here is the code I wrote for this animation:

import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.*;

star_mc.addEventListener(MouseEvent.CLICK, rotateStar);
function rotateStar(e:MouseEvent):void {
star_mc.rotation += 5;
}

addEventListener(Event.ENTER_FRAME, starMove);
function starMove(e:Event):void {
if (star_mc.x < stage.stageWidth) {
star_mc.x += 2;
} else {
star_mc.x = 0;
}
}
var instrument:MovieClip = banjo;
instrument_txt.text = “The Banjo has been selected.”;
violin.addEventListener(MouseEvent.CLICK,onViolin);
banjo.addEventListener(MouseEvent.CLICK,onBanjo);
trumpet.addEventListener(MouseEvent.CLICK,onTrumpet);
glock.addEventListener(MouseEvent.CLICK,onGlock);

function onViolin(e:MouseEvent):void {
instrument = violin;
instrument_txt.text = “The Violin has been selected.”;
}
function onBanjo(e:MouseEvent):void {
instrument = banjo;
instrument_txt.text = “The Banjo has been selected.”;
}
function onTrumpet(e:MouseEvent):void {
instrument = trumpet;
instrument_txt.text = “The Trumpet has been selected.”;
}
function onGlock(e:MouseEvent):void {
instrument = glock;
instrument_txt.text = “The Glockenspiel has been selected.”;
}
grow_btn.addEventListener(MouseEvent.CLICK, grow);
shrink_btn.addEventListener(MouseEvent.CLICK, shrink);
rotate_btn.addEventListener(MouseEvent.CLICK, rotate);
hide_btn.addEventListener(MouseEvent.CLICK, hideClip);
show_btn.addEventListener(MouseEvent.CLICK, showClip);
fadeOut_btn.addEventListener(MouseEvent.CLICK, fadeOut);
fadeIn_btn.addEventListener(MouseEvent.CLICK, fadeIn);

function grow(e:MouseEvent):void {
instrument.scaleX += .1;
instrument.scaleY += .1;
}
function shrink(e:MouseEvent):void {
instrument.scaleX -= .1;
instrument.scaleY -= .1;
}
function rotate(e:MouseEvent):void {
var spin:Tween = new Tween(instrument, “rotation”, Elastic.easeOut, 0, 360, 5, true);
}
function hideClip(e:MouseEvent):void {
instrument.visible = false;
}
function showClip(e:MouseEvent):void {
instrument.visible = true;
}
function fadeOut(e:MouseEvent):void {
var tweenFadeOut:Tween = new Tween(instrument, “alpha”, None.easeOut, 1, 0, 3, true);
}
function fadeIn(e:MouseEvent):void {
var tweenFadeIn:Tween = new Tween(instrument, “alpha”, None.easeIn, 0, 1, 3, true);
}

To help me learn flash I was given a tutorial to complete. my finished animation can be found here. Here is the code I wrote for this animation:

Code for frame 1:

/* Click to Go to Web Page
Clicking on the specified symbol instance loads the URL in a new browser window.

Instructions:
1. Replace http://www.adobe.com with the desired URL address.
Keep the quotation marks (“”).
*/

help_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage);

function fl_ClickToGoToWebPage(event:MouseEvent):void
{
navigateToURL(new URLRequest(“http://www.adobe.com/support/flash“), “_blank”);
}
var count:Number = 1;

Code for frame 30:

if(count>9){
gotoAndStop(“home”);
}else{
gotoAndPlay(“loop”);
}
count++;

Code for Frame 50:

info_txt.text = “Welcome to the Sea”;