//Tic Tac Toe- By Brian (http://scriptasylum.com/bgaudiodr/)
//Modified by Yossi Cohen (yossi@prosite.co.il)
//Featured on Dynamicdrive.com
//Visit http://www.dynamicdrive.com for this script
var image1=new Image(); image1.src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEim7L0zM-5chN1MjM-iZcSQwl7dGW1JJ8uNNI9wnhVeO64h77wKY13YqGUGjEWMFAFwPI4wPTUq2_rlqXdnyTsxJVPTaKiz7_zPQlQbKmrdeJ3hrVDsc8wvcoxdcDFjQeRaF4L92feuz1M/s400/ex.gif";
var image2=new Image(); image2.src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLO6wBH1dCDqYmroC0LCviWCWHBHR5NKiwKzViVL2NMBbyx_Vh6r0T2aZXD3KKTUH-zbaleDW2G-Y3j2O5iDLPSJi6Hj7Eyw95Mbtu6xogsxnFhU6Roy4HcTrxRlcV49vkYcQcJ5jUf70/s400/oh.gif";
var level=1, myway, mynextmove;
var tmp, done, iswon, content;
var pcwins=[0,0,0,0];
var playerwins=[0,0,0,0];
var draws=[0,0,0,0];
var playerstarts=true;
var moves=new Array();
var game=new Array(9);
var choices=[11,12,13,21,22,23,31,32,33];
var corners=[11,13,31,33];
var ways=new Array();
ways[1]=[0,11,12,13];
ways[2]=[0,21,22,23];
ways[3]=[0,31,32,33];
ways[4]=[0,11,21,31];
ways[5]=[0,12,22,32];
ways[6]=[0,13,23,33];
ways[7]=[0,11,22,33];
ways[8]=[0,13,22,31];
var w3c=(document.getElementById)?true:false;
var ns4=(document.layers)?true:false;
var ie4=(document.all && !w3c)?true:false;
var ie5=(document.all && w3c)?true:false;
var ns6=(w3c && navigator.appName.indexOf("Netscape")>=0)?true:false;
function init(){
oktoplay=true;
iswon=false;
done=0;
writetext(4);
moves[11]=0; moves[12]=0; moves[13]=0; moves[21]=0; moves[22]=0; moves[23]=0; moves[31]=0; moves[32]=0; moves[33]=0;
for(i=0;i<=8;i++){
document.images['rc'+choices[i]].src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkp4ImPQWqjTmUeJdKjBd2zYELO4VLEqL0W4UI3UjNjNdtgsidzUtv0MuCiLSACtNceynSZuR4x0B7jSQlfDQRW99GHVF_nIRPxbPG9W0521io-ZOzfOqt24A-zbi7mz0VO1TiTOJmH-E/s400/nothing.gif";
document.images['rc'+choices[i]].alt="";
game[i]=0;
}
if(!playerstarts)pcturn();
}
function writetext(num){
switch(num){
case 1: content='This game is a draw';
break;
case 2: content='The computer won this round.';
break;
case 3: content='You won this round.';
break;
case 4: content='LEVEL: '+level+'\n\nComputer Wins: This level- '+pcwins[level]+' (Total: '+(pcwins[0]+pcwins[1]+pcwins[2]+pcwins[3])+')\nPlayer Wins : This level- '+playerwins[level]+' (Total: '+(playerwins[0]+playerwins[1]+playerwins[2]+playerwins[3])+')\nDraws : This level- '+draws[level]+' (Total: '+(draws[0]+draws[1]+draws[2]+draws[3])+')';
break;
}
document.scores.scores2.value=content
if(num<4 alert="" alt="" bp.blogspot.com="" bug="" bwll3cd88g="" cannot="" cellnum="" document.images="" done="" else="" ex.gif="" finding="" findwinner="" for="" function="" g="" game="" here="" http:="" if="" init="" istowin="" iswon="" jf-wkonlecc="" level="" move="" moves="" mpkloho_oi="" ou="" pcstrategy="" quot="" rc="" roger="" s400="" setbutton="" setlevel="" settimeout="" src="" thanks="" this="" to="" true="" x="">0){
var str=(istowin)? 2 : 1;
for(n=1;n<=8;n++){
if((moves[ways[n][1]]==str) && (moves[ways[n][2]]==str) && (moves[ways[n][3]]==0)) tmp=ways[n][3];
if((moves[ways[n][1]]==str) && (moves[ways[n][3]]==str) && (moves[ways[n][2]]==0)) tmp=ways[n][2];
if((moves[ways[n][2]]==str) && (moves[ways[n][3]]==str) && (moves[ways[n][1]]==0)) tmp=ways[n][1];
}}}
function selecCorner(which){
if (which=="empty"){
do{
tmp=corners[Math.floor(Math.random()*4)];
}while(moves[tmp]!=0);
}
else
tmp=corners[Math.floor(Math.random()*4)];
}
function pcdontlose(){
if (!playerstarts){
if (done==0){
tmp=choices[2*Math.floor(Math.random()*5)];
if (tmp==22) myway=1;
else myway=2;
}
else if (done==2){
if (myway==1){
if (game[1]==11 || game[1]==13 || game[1]==31 || game[1]==33)
tmp=44-game[1];
else{
dlta=22-game[1];
op0=22+dlta+(10/dlta);
op1=22+dlta-(10/dlta);
tmp=eval("op"+Math.floor(Math.random()*2));
}}
else if (myway==2){
if (game[1]==22){
tmp=44-game[0];
myway=21;
}
else if (game[1]==11 || game[1]==13 || game[1]==31 || game[1]==33){
selecCorner("empty");
myway=22;
}
else{
tmp=22;
myway=23;
}}}
else if (done==4){
if (myway==22){
for (i=0; i<4 1="" 2="" :="" amp="" any="" break="" corners="" dlta="22-game[0];" done="" else="" empty="" findwinner="" for="" function="" game="" i="" if="" isplayer="" iswon="" level="" me="" moves="" mynextmove="tmp+dlta;" myway="=3){" n="" op0="game[0]+(10/dlta);" op1="game[0]-(10/dlta);" op2="game[2]+dlta;" pcwins="" playerstarts="false;" playerwins="" quot="" seleccorner="" tmp="mynextmove;" ways="" writetext="">8){
draws[level]++;
playerstarts=!playerstarts;
writetext(1);
}else if(isplayer) pcturn();
}}
function pcrandom(){
do{
tmp=choices[Math.floor(Math.random()*9)];
}while(moves[tmp]!=0);
}
function pcturn(){
tmp='00';
pcstrategy(true);
if(tmp=='00')pcstrategy(false);
if(tmp=='00' && level>1)
pcdontlose();
if(tmp=='00')
pcrandom();
moves[tmp]=2;
game[done]=tmp;
document.images['rc'+tmp].src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLO6wBH1dCDqYmroC0LCviWCWHBHR5NKiwKzViVL2NMBbyx_Vh6r0T2aZXD3KKTUH-zbaleDW2G-Y3j2O5iDLPSJi6Hj7Eyw95Mbtu6xogsxnFhU6Roy4HcTrxRlcV49vkYcQcJ5jUf70/s400/oh.gif";
document.images['rc'+tmp].alt=" O ";
done++;
findwinner(false);
}
window.onload=init;
window.onresize=function(){
if(ns4)setTimeout('history.go(0)',400);
}
4>4>
Комментариев нет:
Отправить комментарий
Примечание. Отправлять комментарии могут только участники этого блога.