Welcome

Welcome to my blog. I mainly blog about the basics of running Flash games over the internet, but sometimes I get distracted. Here you will find my efforts at programming turn based Flash games, plus links to all the games I have written. You are free (as in beer) to get all the code, just email me - nicolas_evans at yahoo.com (sorry you cant click on it - I dont want more spam).

Building Multiplayer Games in Flash.

The Posts

Wednesday, April 26, 2006

Hi. I am busy working on my third conversion, Mammoths. You can find it in the links, as its easier keeping those up to date than the posts. Am finding it a lot easier to convert a game now. However I did run into one issue - its not obvious which piece the opponent moved. So I added a shading movieclip with an alpha of 20 percent for the route moved. Here is the code:
// in the constructor
for (i = 0;i<15;i++) {
  mcCa.attachMovie("McMarker","mcMarker" + i,++gnNextDepth,{_x:-100,_y:-100,_alpha:20});
}
// at the start of turn
k = 0;
i = gnStartI;
j = gnStartJ;
mcCa["mcMarker" + k]._x = (i - 11) * 40;
mcCa["mcMarker" + k]._y = (j - 11) * 40;
do {
  if (i < gnEndI)
    i++;
  else if (i > gnEndI)
    i--; 
  if (j < gnEndJ)
    j++;
  else if (j > gnEndJ)
    j--;    
  k++;
  mcCa["mcMarker" + k]._x = (i - 11) * 40;
  mcCa["mcMarker" + k]._y = (j - 11) * 40;
} while ((i != gnEndI || j != gnEndJ) && k < 15)

# posted by nicolas_evans @ 10:35 AM  

The Posts

Friday, April 21, 2006

Hi. I finished converting another game to play over the internet, Navvy. You can find it in the Links section. I have moved to paid hosting on Godaddy (www.godaddy.com), so this meant using php for the backend. This is the code, apologies as this is my first php program:
<?php
 $intVariableCount = 7;

 $filename = $_GET['filename'];
 $action = $_GET['action'];
  
 if (is_numeric($filename)) {}
 else
  die( "v=v&nErrorNumber=" . $intErrorNumber );
  
 if (file_exists("gamefiles/cr" . $filename . ".txt")) {}
 else {
  // File does not exist, so create it. 
  $filePointer = fopen("gamefiles/cr" . $filename . ".txt", "w");
  fclose($filePointer);  
 }
 // Check that we have read and write access to the text file.
 is_readable("gamefiles/cr" . $filename . ".txt") or die("ERROR : Do not have read access to file $filename, consult your server administrator."); 
 is_writeable("gamefiles/cr" . $filename . ".txt") or die("ERROR : Do not have write access to file $filename, consult your server administrator."); 

 // Read the file in
 $contents = file("gamefiles/cr" . $filename . ".txt");
 $maxid = count($contents);
 
 for ($i = $maxid; $i < $intVariableCount ; $i++)  {
  $contents[$i] = " ";
 }
 // Process the actions 

 // Insert a score/name
 if ($action=="INSERT") {
  
  $intErrorNumber = 0;
  // Abandon message if not later than the file

  $contents[0] = $_GET['pno'];
  if ($contents[0] != 1 && $contents[0] != 2) {
   $intErrorNumber = 1;
  }
  
  if ($contents[1] + 1 != $_GET['nTurn'] ) {
   $intErrorNumber = 2;
  }
  $contents[1] = $_GET['nTurn'];

  $contents[2] = $_GET['p1hand'];
  
  $contents[3] = $_GET['p2hand'];
  
  $contents[4] = $_GET['board'];
  
  $contents[5] = $_GET['order'];

  $contents[6] = $_GET['ltm'];
    
  if (is_numeric($_GET['messageID'])) {}
  else
   $intErrorNumber = 8;
    
  if ($intErrorNumber == 0) {         
         $filePointer = fopen("gamefiles/cr" . $filename . ".txt", "w" );
 
   for ($i=0;$i & lt; $intVariableCount;$i++) {
    fwrite($filePointer,"$contents[$i]\n" );
   }
         fclose($filePointer);
   $intTemp = $_GET['messageID'] + 1;
   echo "v=v&messageID=" . $intTemp;

  }
  else {
   echo "v=v&nErrorNumber=" . $intErrorNumber;
  }
 }
 // Clear the list 
 else if ($action=="CLEAR") {
   echo "create empty file";
   for ($i=0;$i & lt; intVariableCount;$i++) {   
    $contents[i] = " "; 
   }
   $contents[0] = "2"; // pno
   $contents[1] = "0"; // nTurn
   
         $filePointer = fopen( "gamefiles/cr" . $filename . ".txt", "w" );
 
   for ($i=0;$i < $intVariableCount;$i++) {
    fwrite($filePointer,"$contents[$i]\n" );
   }
         fclose($filePointer);
 }
 else if ($action=="VIEW") {
  echo "v=v&nErrorNumber=0" ;
  echo "&pno=" . $contents[0]  ;  
  echo "&nTurn=" . $contents[1]  ;  
  echo "&p1hand=" . $contents[2] ;  
  echo "&p2hand=" . $contents[3] ;  
  echo "&board=" . $contents[4] ;  
  echo "&order=" . $contents[5] ;
  echo "<m=" . $contents[6] ;
 }
 else {
  echo "action not recognized" . $action;
 }
?>

# posted by nicolas_evans @ 9:06 AM  

The Posts

Monday, April 17, 2006

Hi. Have started work converting another program to work over the net. I had a big gotcha, I didnt convert a property to numeric when converting from a string to objects. Here is the corrected code, the Number function makes it work.
static function fnConvertStringToObjects (pString:String,bProperties:Boolean):Array {

var i:Number;
var arTemp =new Array();
var arTemp2 =new Array();
var arTempOut = new Array();

arTemp = pString.split(",");  
for (i =0;i<arTemp.length;i++) {
 if (arTemp[i] == "undefined" || arTemp[i] == "") 
  arTempOut.push("Empty");
 else if (!bProperties) {
  if (_level0[arTemp[i]])
   arTempOut.push(_level0[arTemp[i]] );
 }
 else { // parse properties (name:nRotation:bLeaky)
  arTemp2 = arTemp[i].split(":");
  trace (arTemp2)
  if (arTemp2[0] == "undefined" || arTemp2[0] == "") 
   arTempOut.push("Empty");
  else if (_level0[arTemp2[0]]) {
   arTempOut.push(_level0[arTemp2[0]] );
   _level0[arTemp2[0]].nRotation = Number(arTemp2[1]);
   _level0[arTemp2[0]].bLeaky = arTemp2[2];
  }    
 }
}
return arTempOut;
}

# posted by nicolas_evans @ 7:35 PM  

The Posts

Monday, April 10, 2006

Hi. Inspired by a visit to The Old Spaghetti Factory (www.osf.com) and the wonderful designs at CSS Zen Garden I decided to change the theme of my blog. Hope you like it.

# posted by nicolas_evans @ 11:23 AM  

This page is powered by Blogger. Isn't yours?