Tetris and Hangman Try3 Program-100988

<?xml version=”1.0″ encoding=”UTF-8″ standalone=”no”?>

<actionScriptProperties analytics=”false” mainApplicationPath=”TetrisAndHangmanTry3.as” projectUUID=”1685e6f9-0d2b-4b3a-b45e-a1687220bdb8″ version=”11″>

<compiler additionalCompilerArguments=”-locale en_US” advancedTelemetry=”false” autoRSLOrdering=”true” copyDependentFiles=”true” fteInMXComponents=”false” generateAccessible=”false” htmlExpressInstall=”true” htmlGenerate=”false” htmlHistoryManagement=”false” htmlPlayerVersionCheck=”true” includeNetmonSwc=”false” outputFolderPath=”bin-debug” removeUnusedRSL=”true” sourceFolderPath=”src” strict=”true” targetPlayerVersion=”0.0.0″ useApolloConfig=”true” useDebugRSLSwfs=”true” useFlashSDK=”true” verifyDigests=”true” warn=”true”>

<compilerSourcePath/>

<libraryPathdefaultLinkType=”0″>

<libraryPathEntry kind=”4″ path=””>

<excludedEntries>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/automation_charts.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”1″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/locale/{locale}”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/advancedgrids.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/qtp.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/charts.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/automation_air.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/air/airspark.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/framework.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/mx/mx.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/netmon.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/spark.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/sparkskins.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/rpc.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/datavisualization.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/qtp_air.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/videoPlayer.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/spark_dmv.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/automation.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/automation_dmv.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/flash-integration.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/automation_flashflexkit.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/air/airframework.swc” useDefaultLinkType=”false”/>

<libraryPathEntry kind=”3″ linkType=”1″ path=”${PROJECT_FRAMEWORKS}/libs/automation_agent.swc” useDefaultLinkType=”false”/>

</excludedEntries>

</libraryPathEntry>

</libraryPath>

<sourceAttachmentPath/>

</compiler>

<applications>

<application path=”TetrisAndHangmanTry3.as”>

<airExcludes/>

</application>

</applications>

<modules/>

<workers/>

<buildCSSFiles/>

<flashCatalystvalidateFlashCatalystCompatibility=”false”/>

<buildTargets>

<buildTargetbuildTargetName=”default” platformId=”default”>

<airSettingsairCertificatePath=”” airTimestamp=”true” anePathSet=”false” version=”1″>

<airExcludes/>

<anePaths/>

</airSettings>

<actionScriptSettings version=”1″/>

</buildTarget>

</buildTargets>

</actionScriptProperties>

 

 

<?xml version=”1.0″ encoding=”UTF-8″?>

<projectDescription>

<name>TetrisAndHangmanTry3</name>

<comment></comment>

<projects>

</projects>

<buildSpec>

<buildCommand>

<name>com.adobe.flexbuilder.project.flexbuilder</name>

<arguments>

</arguments>

</buildCommand>

<buildCommand>

<name>com.adobe.flexbuilder.project.apollobuilder</name>

<arguments>

</arguments>

</buildCommand>

</buildSpec>

<natures>

<nature>com.adobe.flexbuilder.project.apollonature</nature>

<nature>com.adobe.flexbuilder.project.actionscriptnature</nature>

</natures>

</projectDescription>

 

 

package  {

importflash.display.Sprite;

importflash.utils.Timer;

importflash.events.TimerEvent;

importflash.events.KeyboardEvent;

public class TetrisTry1 extends Sprite {

privateconstTS:uint=24;

privatevarfieldArray:Array;

privatevarfieldSprite:Sprite;

privatevartetrominoes:Array = new Array();

privatevar colors: Array = new Array();

privatevartetromino: Sprite;

privatevarcurrentTetromino: uint;

privatevarnextTetromino: uint;

privatevarcurrentRotation: uint;

privatevartRow: int;

privatevartCol: int;

privatevartimeCount:Timer=new Timer(500);

privatevargameOver:Boolean = false;

varsquare:Sprite;

public function simple_shape(){

square = new Sprite();

addChild(square);

square.graphics.lineStyle(3,0x00ff00);

square.graphics.beginFill(0x0000FF);

square.graphics.drawRect(0,0,100,100);

square.graphics.endFill();

square.x = stage.stageWidth/2-square.width/2;

square.y = stage.stageHeight/2-square.height/2;

}

public function TetrisTry1() {

generateField();

initTetrominoes();

nextTetromino = Math.floor(Math.random() * 7);

generateTetromino();

stage.addEventListener(KeyboardEvent.KEY_DOWN, onKDown);

}

private function generateField():void {

varcolors:Array=new Array(“0x444444″,”0x555555”);

fieldArray=new Array  ;

varfieldSprite:Sprite=new Sprite  ;

addChild(fieldSprite);

fieldSprite.graphics.lineStyle(0,0×000000);

for (var i:uint=0; i<20; i++) {

fieldArray[i]=new Array  ;

fieldArray[i]=new Array  ;

for (var j:uint=0; j<10; j++) {

fieldArray[i][j]=0;

fieldSprite.graphics.beginFill(colors[(j%2+i%2)%2]);

fieldSprite.graphics.drawRect(TS*j,TS*i,TS,TS);

fieldSprite.graphics.endFill();

}

}

}

private function initTetrominoes():void {

// I

tetrominoes[0]=[[[0,0,0,0],[1,1,1,1],[0,0,0,0],[0,0,0,0]],[[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0]]];

colors[0]=0x00FFFF;

// T

tetrominoes[1]=[[[0,0,0,0],[1,1,1,0],[0,1,0,0],[0,0,0,0]],[[0,1,0,0],[1,1,0,0],[0,1,0,0],[0,0,0,0]],[[0,1,0,0],[1,1,1,0],[0,0,0,0],[0,0,0,0]],[[0,1,0,0],[0,1,1,0],[0,1,0,0],[0,0,0,0]]];

colors[1] = 0xcc33cc;

// L

tetrominoes[2]=[[[0,0,0,0],[1,1,1,0],[1,0,0,0],[0,0,0,0]],[[1,1,0,0],[0,1,0,0],[0,1,0,0],[0,0,0,0]],[[0,0,1,0],[1,1,1,0],[0,0,0,0],[0,0,0,0]],[[0,1,0,0],[0,1,0,0],[0,1,1,0],[0,0,0,0]]];

colors[2]=0xFFA500;

// J

tetrominoes[3]=[[[1,0,0,0],[1,1,1,0],[0,0,0,0],[0,0,0,0]],[[0,1,1,0],[0,1,0,0],[0,1,0,0],[0,0,0,0]],[[0,0,0,0],[1,1,1,0],[0,0,1,0],[0,0,0,0]],[[0,1,0,0],[0,1,0,0],[1,1,0,0],[0,0,0,0]]];

colors[3]=0x0000FF;

// Z

tetrominoes[4]=[[[0,0,0,0],[1,1,0,0],[0,1,1,0],[0,0,0,0]],[[0,0,1,0],[0,1,1,0],[0,1,0,0],[0,0,0,0]]];

colors[4]=0xFF0000;

// S

tetrominoes[5]=[[[0,0,0,0],[0,1,1,0],[1,1,0,0],[0,0,0,0]],[[0,1,0,0],[0,1,1,0],[0,0,1,0],[0,0,0,0]]];

colors[5]=0x00FF00;

// O

tetrominoes[6]=[[[0,1,1,0],[0,1,1,0],[0,0,0,0],[0,0,0,0]]];

colors[6]=0xFFFF00;

}

private function generateTetromino():void {

if (! gameOver) {

currentTetromino = nextTetromino;

nextTetromino = Math.floor(Math.random() * 7);

drawNext();

currentRotation = 0;

tRow = 0;

if (tetrominoes[currentTetromino][0][0].indexOf(1) == -1) {

tRow = -1;

}

tCol = 3;

drawTetromino();

if (canFit(tRow, tCol, currentRotation)) {

timeCount.addEventListener(TimerEvent.TIMER, onTime);

timeCount.start();

} else {

gameOver = true;

}

}

}

private function drawTetromino():void {

varct:uint=currentTetromino;

tetromino=new Sprite  ;

addChild(tetromino);

tetromino.graphics.lineStyle(0,0×000000);

for (var i:int=0; i<tetrominoes[ct][currentRotation].length; i++) {

for (var j:int=0; j<tetrominoes[ct][currentRotation][i].length; j++) {

if (tetrominoes[ct][currentRotation][i][j]==1) {

tetromino.graphics.beginFill(colors[ct]);

tetromino.graphics.drawRect(TS*j,TS*i,TS,TS);

tetromino.graphics.endFill();

}

}

}

placeTetromino();

}

private function placeTetromino():void {

tetromino.x = tCol * TS;

tetromino.y = tRow * TS;

}

private function onKDown(e:KeyboardEvent):void {

if (! gameOver) {

switch (e.keyCode) {

case 37 :

if (canFit(tRow, tCol-1, currentRotation)) {

tCol–;

placeTetromino();

}

break;

case 38 :

varct:uint = currentRotation;

varrot:uint = (ct+1)%tetrominoes[currentTetromino].length;

if (canFit(tRow, tCol, rot)) {

currentRotation = rot;

removeChild(tetromino);

drawTetromino();

placeTetromino();

}

break;

case 39 :

if (canFit(tRow, tCol+1, currentRotation)) {

tCol++;

placeTetromino();

}

break;

case 40 :

if (canFit(tRow+1,tCol, currentRotation)) {

tRow++;

placeTetromino();

} else {

landTetromino();

generateTetromino();

}

break;

}

}

}

private function canFit(row:int,col:int, side:uint):Boolean {

varct:uint=currentTetromino;

for (var i:int=0; i<tetrominoes[ct][currentRotation].length; i++) {

for (var j:int=0; j<tetrominoes[ct][currentRotation][i].length; j++) {

if (tetrominoes[ct][currentRotation][i][j]==1) {

// out of left boundary

if (col+j<0) {

return false;

}

// out of right boundary

if (col+j>9) {

return false;

}

// out of bottom boundary

if (row + i > 19) {

return false;

}

// over another tetromino

if (fieldArray[row + i][col + j] == 1) {

return false;

}

}

}

}

return true;

}

private function landTetromino():void {

varct:uint=currentTetromino;

varlanded:Sprite;

for (var i:int=0; i<tetrominoes[ct][currentRotation].length; i++) {

for (var j:int=0; j<tetrominoes[ct][currentRotation][i].length; j++) {

if (tetrominoes[ct][currentRotation][i][j]==1) {

landed=new Sprite();

addChild(landed);

landed.graphics.lineStyle(0,0×000000);

landed.graphics.beginFill(colors[currentTetromino]);

landed.graphics.drawRect(TS*(tCol+j),TS*(tRow+i),TS,TS);

landed.graphics.endFill();

landed.name = “r” + (tRow + i) + “c” + (tCol + j);

fieldArray[tRow+i][tCol+j]=1;

}

}

}

removeChild(tetromino);

timeCount.removeEventListener(TimerEvent.TIMER, onTime);

timeCount.stop();

checkForLines();

}

private function checkForLines():void {

for (var i:int=0; i<20; i++) {

if (fieldArray[i].indexOf(0)==-1) {

for (var j:int=0; j<10; j++) {

fieldArray[i][j]=0;

removeChild(getChildByName(“r”+i+”c”+j));

}

for (j=i; j>=0; j–) {

for (var k:int=0; k<10; k++) {

if (fieldArray[j][k]==1) {

fieldArray[j][k]=0;

fieldArray[j+1][k]=1;

getChildByName(“r”+j+”c”+k).y+=TS;

getChildByName(“r”+j+”c”+k).name=”r”+(j+1)+”c”+k;

}

}

}

}

}

}

private function onTime(e:TimerEvent):void {

if (canFit(tRow+1, tCol, currentRotation)) {

tRow++;

placeTetromino();

} else {

landTetromino();

generateTetromino();

}

}

private function drawNext():void {

if (getChildByName(“next”)!=null) {

removeChild(getChildByName(“next”));

}

varnext_t:Sprite=new Sprite  ;

next_t.x=300;

next_t.name=”next”;

addChild(next_t);

next_t.graphics.lineStyle(0,0×000000);

for (var i:int=0; i<tetrominoes[nextTetromino][0].length; i++) {

for (var j:int=0; j<tetrominoes[nextTetromino][0][i].length; j++) {

if (tetrominoes[nextTetromino][0][i][j]==1) {

next_t.graphics.beginFill(colors[nextTetromino]);

next_t.graphics.drawRect(TS*j,TS*i,TS,TS);

next_t.graphics.endFill();

}

}

}

}

}

}