kremala

Κώδικας, πληροφορίες, ερωτήσεις και απαντήσεις σχετικές με την JavaScript.

Συντονιστές: WebDev Moderators, Super-Moderators

Απάντηση
Άβαταρ μέλους
Nidas
Honorary Member
Δημοσιεύσεις: 2348
Εγγραφή: 03 Απρ 2003 13:09
Τοποθεσία: Germany/Wuppertal-Hellas/Preveza

kremala

Δημοσίευση από Nidas » 03 Μάιος 2003 13:17

Κώδικας: Επιλογή όλων

<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Score</title>
</head>

<body>
<SCRIPT>

/*
Code Written by Cory Fogliani &#40;Email&#58; cory@ijustdontcare.com&#41;
Testers&#58; Cory Fogliani, Chris Gordon
Featured on JavaScript Kit &#40;http&#58;//javascriptkit.com&#41;
For this and over 400+ free scripts, visit http&#58;//javascriptkit.com
*/

//if IE4/NS6, apply style
if &#40;document.all||document.getElementById&#41;&#123;
document.write&#40;'<style>.tictac&#123;'&#41;
document.write&#40;'width&#58;50px;height&#58;50px;'&#41;
document.write&#40;'&#125;</style>'&#41;
&#125;

var sqr1
var sqr2
var sqr3
var sqr4
var sqr5
var sqr6
var sqr7
var sqr8
var sqr9
var sqr1T = 0
var sqr2T = 0
var sqr3T = 0
var sqr4T = 0
var sqr5T = 0
var sqr6T = 0
var sqr7T = 0
var sqr8T = 0
var sqr9T = 0
var moveCount = 0
var turn = 0
var mode = 1

function vari&#40;&#41;
&#123;
sqr1 = document.tic.sqr1.value
sqr2 = document.tic.sqr2.value
sqr3 = document.tic.sqr3.value
sqr4 = document.tic.sqr4.value
sqr5 = document.tic.sqr5.value
sqr6 = document.tic.sqr6.value
sqr7 = document.tic.sqr7.value
sqr8 = document.tic.sqr8.value
sqr9 = document.tic.sqr9.value
&#125;
function check&#40;&#41;
&#123;
  if&#40;sqr1 == " X " && sqr2 == " X " && sqr3 == " X "&#41;
  &#123;
    alert&#40;"You Win!"&#41;
    reset&#40;&#41;
  &#125; 
  else if&#40;sqr4 == " X " && sqr5 == " X " && sqr6 == " X "&#41;
  &#123;
    alert&#40;"You Win!"&#41;
    reset&#40;&#41;
  &#125; 
  else if&#40;sqr7 == " X " && sqr8 == " X " && sqr9 == " X "&#41;
  &#123;
    alert&#40;"You Win!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr1 == " X " && sqr5 == " X " && sqr9 == " X "&#41;
  &#123;
    alert&#40;"You Win!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr1 == " X " && sqr4 == " X " && sqr7 == " X "&#41;
  &#123;
    alert&#40;"You Win!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr2 == " X " && sqr5 == " X " && sqr8 == " X "&#41;
  &#123;
    alert&#40;"You Win!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr3 == " X " && sqr6 == " X " && sqr9 == " X "&#41;
  &#123;
    alert&#40;"You Win!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr1 == " X " && sqr5 == " X " && sqr9 == " X "&#41;
  &#123;
    alert&#40;"You Win!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr3 == " X " && sqr5 == " X " && sqr7 == " X "&#41;
  &#123;
    alert&#40;"You Win!"&#41;
    reset&#40;&#41;
  &#125;
  else
  &#123;
    winCheck&#40;&#41;
    check2&#40;&#41;
    drawCheck&#40;&#41;  
  &#125; 
&#125;

function check2&#40;&#41;
&#123;
  vari&#40;&#41;
  drawCheck&#40;&#41;
  if&#40;sqr1 == " O " && sqr2 == " O " && sqr3 == " O "&#41;
  &#123;
    alert&#40;"You Lose!"&#41;
    reset&#40;&#41;
  &#125; 
  else if&#40;sqr4 == " O " && sqr5 == " O " && sqr6 == " O "&#41;
  &#123;
    alert&#40;"You Lose!"&#41;
    reset&#40;&#41;
  &#125; 
  else if&#40;sqr7 == " O " && sqr8 == " O " && sqr9 == " O "&#41;
  &#123;
    alert&#40;"You Lose!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr1 == " O " && sqr5 == " O " && sqr9 == " O "&#41;
  &#123;
    alert&#40;"You Lose!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr1 == " O " && sqr4 == " O " && sqr7 == " O "&#41;
  &#123;
    alert&#40;"You Lose!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr2 == " O " && sqr5 == " O " && sqr8 == " O "&#41;
  &#123;
    alert&#40;"You Lose!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr3 == " O " && sqr6 == " O " && sqr9 == " O "&#41;
  &#123;
    alert&#40;"You Lose!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr1 == " O " && sqr5 == " O " && sqr9 == " O "&#41;
  &#123;
    alert&#40;"You Lose!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr3 == " O " && sqr5 == " O " && sqr7 == " O "&#41;
  &#123;
    alert&#40;"You Lose!"&#41;
    reset&#40;&#41;
  &#125;
&#125;

function player1Check&#40;&#41;
&#123;
  if&#40;sqr1 == " X " && sqr2 == " X " && sqr3 == " X "&#41;
  &#123;
    alert&#40;"Player 1 wins!"&#41;
    reset&#40;&#41;
  &#125; 
  else if&#40;sqr4 == " X " && sqr5 == " X " && sqr6 == " X "&#41;
  &#123;
    alert&#40;"Player 1 wins!"&#41;
    reset&#40;&#41;
  &#125; 
  else if&#40;sqr7 == " X " && sqr8 == " X " && sqr9 == " X "&#41;
  &#123;
    alert&#40;"Player 1 wins!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr1 == " X " && sqr5 == " X " && sqr9 == " X "&#41;
  &#123;
    alert&#40;"Player 1 wins!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr1 == " X " && sqr4 == " X " && sqr7 == " X "&#41;
  &#123;
    alert&#40;"Player 1 wins!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr2 == " X " && sqr5 == " X " && sqr8 == " X "&#41;
  &#123;
    alert&#40;"Player 1 wins!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr3 == " X " && sqr6 == " X " && sqr9 == " X "&#41;
  &#123;
    alert&#40;"Player 1 wins!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr1 == " X " && sqr5 == " X " && sqr9 == " X "&#41;
  &#123;
    alert&#40;"Player 1 wins!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr3 == " X " && sqr5 == " X " && sqr7 == " X "&#41;
  &#123;
    alert&#40;"Player 1 wins!"&#41;
    reset&#40;&#41;
  &#125;
  else
  &#123;
    player2Check&#40;&#41;
    drawCheck&#40;&#41;  
  &#125; 
&#125;

function player2Check&#40;&#41;
&#123;
  vari&#40;&#41;
  drawCheck&#40;&#41;
  if&#40;sqr1 == " O " && sqr2 == " O " && sqr3 == " O "&#41;
  &#123;
    alert&#40;"Player 2 wins!"&#41;
    reset&#40;&#41;
  &#125; 
  else if&#40;sqr4 == " O " && sqr5 == " O " && sqr6 == " O "&#41;
  &#123;
    alert&#40;"Player 2 wins!"&#41;
    reset&#40;&#41;
  &#125; 
  else if&#40;sqr7 == " O " && sqr8 == " O " && sqr9 == " O "&#41;
  &#123;
    alert&#40;"Player 2 wins!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr1 == " O " && sqr5 == " O " && sqr9 == " O "&#41;
  &#123;
    alert&#40;"Player 2 wins!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr1 == " O " && sqr4 == " O " && sqr7 == " O "&#41;
  &#123;
    alert&#40;"Player 2 wins!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr2 == " O " && sqr5 == " O " && sqr8 == " O "&#41;
  &#123;
    alert&#40;"Player 2 wins!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr3 == " O " && sqr6 == " O " && sqr9 == " O "&#41;
  &#123;
    alert&#40;"Player 2 wins!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr1 == " O " && sqr5 == " O " && sqr9 == " O "&#41;
  &#123;
    alert&#40;"Player 2 wins!"&#41;
    reset&#40;&#41;
  &#125;
  else if&#40;sqr3 == " O " && sqr5 == " O " && sqr7 == " O "&#41;
  &#123;
    alert&#40;"Player 2 wins!"&#41;
    reset&#40;&#41;
  &#125;
&#125;

function drawCheck&#40;&#41;
&#123;
  vari&#40;&#41;
  moveCount = sqr1T + sqr2T + sqr3T + sqr4T + sqr5T + sqr6T + sqr7T + sqr8T + sqr9T 
  if&#40;moveCount == 9&#41;
  &#123;
    reset&#40;&#41;
    alert&#40;"Draw"&#41; 
  &#125;
&#125;

function winCheck&#40;&#41;
&#123;
  check2&#40;&#41;
  if&#40;sqr1 == " O " && sqr2 == " O " && sqr3T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr3.value = " O "
    sqr3T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr2 == " O " && sqr3 == " O " && sqr1T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr1.value = " O "
    sqr1T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr4 == " O " && sqr5 == " O " && sqr6T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr6.value = " O "
    sqr6T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr5 == " O " && sqr6 == " O " && sqr4T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr4.value = " O "
    sqr4T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr7 == " O " && sqr8 == " O " && sqr9T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr9.value = " O "
    sqr9T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr8 == " O " && sqr9 == " O " && sqr7T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr7.value = " O "
    sqr7T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr1 == " O " && sqr5 == " O " && sqr9T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr9.value = " O "
    sqr9T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr5 == " O " && sqr9 == " O " && sqr1T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr1.value = " O "
    sqr1T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr3 == " O " && sqr5 == " O " && sqr7T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr7.value = " O "
    sqr7T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr7 == " O " && sqr5 == " O " && sqr3T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr3.value = " O "
    sqr3T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr1 == " O " && sqr3 == " O " && sqr2T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr2.value = " O "
    sqr2T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr4 == " O " && sqr6 == " O " && sqr5T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr5.value = " O "
    sqr5T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr7 == " O " && sqr9 == " O " && sqr8T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr8.value = " O "
    sqr8T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr1 == " O " && sqr7 == " O " && sqr4T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr4.value = " O "
    sqr4T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr2 == " O " && sqr8 == " O " && sqr5T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr5.value = " O "
    sqr5T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr3 == " O " && sqr9 == " O " && sqr6T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr6.value = " O "
    sqr6T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr1 == " O " && sqr5 == " O " && sqr9T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr9.value = " O "
    sqr9T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr4 == " O " && sqr7 == " O " && sqr1T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr1.value = " O "
    sqr1T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr5 == " O " && sqr8 == " O " && sqr2T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr2.value = " O "
    sqr2T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr6 == " O " && sqr9 == " O " && sqr3T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr3.value = " O "
    sqr3T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr1 == " O " && sqr4 == " O " && sqr7T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr7.value = " O "
    sqr7T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr2 == " O " && sqr5 == " O " && sqr8T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr8.value = " O "
    sqr8T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr3 == " O " && sqr6 == " O " && sqr9T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr9.value = " O "
    sqr9T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr1 == " O " && sqr9 == " O " && sqr5T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr5.value = " O "
    sqr5T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr3 == " O " && sqr7 == " O " && sqr5T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr5.value = " O "
    sqr5T = 1;
    turn = 0;
  &#125;
  else
  &#123;
    computer&#40;&#41;
  &#125;
  check2&#40;&#41;
&#125;
function computer&#40;&#41;
&#123;
  check2&#40;&#41;
  if&#40;sqr1 == " X " && sqr2 == " X " && sqr3T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr3.value = " O "
    sqr3T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr2 == " X " && sqr3 == " X " && sqr1T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr1.value = " O "
    sqr1T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr4 == " X " && sqr5 == " X " && sqr6T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr6.value = " O "
    sqr6T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr5 == " X " && sqr6 == " X " && sqr4T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr4.value = " O "
    sqr4T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr7 == " X " && sqr8 == " X " && sqr9T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr9.value = " O "
    sqr9T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr8 == " X " && sqr9 == " X " && sqr7T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr7.value = " O "
    sqr7T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr1 == " X " && sqr5 == " X " && sqr9T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr9.value = " O "
    sqr9T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr5 == " X " && sqr9 == " X " && sqr1T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr1.value = " O "
    sqr1T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr3 == " X " && sqr5 == " X " && sqr7T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr7.value = " O "
    sqr7T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr7 == " X " && sqr5 == " X " && sqr3T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr3.value = " O "
    sqr3T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr1 == " X " && sqr3 == " X " && sqr2T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr2.value = " O "
    sqr2T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr4 == " X " && sqr6 == " X " && sqr5T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr5.value = " O "
    sqr5T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr7 == " X " && sqr9 == " X " && sqr8T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr8.value = " O "
    sqr8T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr1 == " X " && sqr7 == " X " && sqr4T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr4.value = " O "
    sqr4T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr2 == " X " && sqr8 == " X " && sqr5T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr5.value = " O "
    sqr5T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr3 == " X " && sqr9 == " X " && sqr6T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr6.value = " O "
    sqr6T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr1 == " X " && sqr5 == " X " && sqr9T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr9.value = " O "
    sqr9T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr4 == " X " && sqr7 == " X " && sqr1T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr1.value = " O "
    sqr1T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr5 == " X " && sqr8 == " X " && sqr2T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr2.value = " O "
    sqr2T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr6 == " X " && sqr9 == " X " && sqr3T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr3.value = " O "
    sqr3T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr1 == " X " && sqr4 == " X " && sqr7T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr7.value = " O "
    sqr7T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr2 == " X " && sqr5 == " X " && sqr8T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr8.value = " O "
    sqr8T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr3 == " X " && sqr6 == " X " && sqr9T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr9.value = " O "
    sqr9T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr1 == " X " && sqr9 == " X " && sqr5T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr5.value = " O "
    sqr5T = 1;
    turn = 0;
  &#125;
  else if&#40;sqr3 == " X " && sqr7 == " X " && sqr5T == 0 && turn == 1&#41;
  &#123;
    document.tic.sqr5.value = " O "
    sqr5T = 1;
    turn = 0;
  &#125;
  else
  &#123;
    AI&#40;&#41;
  &#125;
  check2&#40;&#41;
&#125;

function AI&#40;&#41;
&#123;
  vari&#40;&#41;
  if&#40;document.tic.sqr5.value == "     " && turn == 1&#41;
  &#123;
    document.tic.sqr5.value = " O "
    turn = 0
    sqr5T = 1
  &#125;
  else if&#40;document.tic.sqr1.value == "     " && turn == 1&#41;
  &#123;
    document.tic.sqr1.value = " O "
    turn = 0
    sqr1T = 1
  &#125;
  else if&#40;document.tic.sqr9.value == "     " && turn == 1&#41;
  &#123;
    document.tic.sqr9.value = " O "
    turn = 0
    sqr9T = 1
  &#125;
  else if&#40;document.tic.sqr6.value == "     " && turn == 1&#41;
  &#123;
    document.tic.sqr6.value = " O "
    turn = 0
    sqr6T = 1
  &#125;
  else if&#40;document.tic.sqr2.value == "     " && turn == 1&#41;
  &#123;
    document.tic.sqr2.value = " O "
    turn = 0
    sqr2T = 1
  &#125;
  else if&#40;document.tic.sqr8.value == "     " && turn == 1&#41;
  &#123;
    document.tic.sqr8.value = " O "
    turn = 0
    sqr8T = 1
  &#125;
  else if&#40;document.tic.sqr3.value == "     " && turn == 1&#41;
  &#123;
    document.tic.sqr3.value = " O "
    turn = 0
    sqr3T = 1
  &#125;
  else if&#40;document.tic.sqr7.value == "     " && turn == 1&#41;
  &#123;
    document.tic.sqr7.value = " O "
    turn = 0
    sqr7T = 1
  &#125;
  else if&#40;document.tic.sqr4.value == "     " && turn == 1&#41;
  &#123;
    document.tic.sqr4.value = " O "
    turn = 0
    sqr4T = 1
  &#125;
  check2&#40;&#41;
&#125;

function reset&#40;&#41;
&#123;
  document.tic.sqr1.value = "     "
  document.tic.sqr2.value = "     "
  document.tic.sqr3.value = "     "
  document.tic.sqr4.value = "     "
  document.tic.sqr5.value = "     "
  document.tic.sqr6.value = "     "
  document.tic.sqr7.value = "     "
  document.tic.sqr8.value = "     "
  document.tic.sqr9.value = "     "
  sqr1T = 0
  sqr2T = 0
  sqr3T = 0
  sqr4T = 0
  sqr5T = 0
  sqr6T = 0
  sqr7T = 0
  sqr8T = 0
  sqr9T = 0
  vari&#40;&#41;
  turn = 0
  moveCount = 0
&#125;

function resetter&#40;&#41;
&#123;
  reset&#40;&#41;
&#125;
</SCRIPT>



<SCRIPT LANGUAGE="javascript">

/*
Script by Mike Mcgrath- http&#58;//website.lineone.net/~mike_mcgrath
Featured on JavaScript Kit &#40;http&#58;//javascriptkit.com&#41;
For this and over 400+ free scripts, visit http&#58;//javascriptkit.com
*/

var alpha=new Array&#40;&#41;;
var alpha_index=0;

var bravo=new Array&#40;&#41;;
var bravo_index=0;

var running=0;
var failnum=0;
var advising=0;

function pick&#40;&#41;
&#123;
  var choice="";
  var blank=0;
 
  for &#40;i=0; i<words&#91;index&#93;.length; i++&#41;
  &#123;
    t=0;
    for&#40;j=0; j<=alpha_index; j++&#41; 
    if&#40;words&#91;index&#93;.charAt&#40;i&#41;==alpha&#91;j&#93; || words&#91;index&#93;.charAt&#40;i&#41;==alpha&#91;j&#93;.toLowerCase&#40;&#41;&#41; t=1;
    
    if &#40;t&#41; choice+=words&#91;index&#93;.charAt&#40;i&#41;+" ";
    else 
    &#123;
      choice+="_ ";
      blank=1;
    &#125;
  &#125;   
    
  document.f.word.value=choice;
    
  if &#40;!blank&#41;
  &#123;
    document.f.tried.value="   === You Win! ===";
    document.f.score.value++;
    running=0;
  &#125;
&#125; 


function new_word&#40;form&#41;
&#123;
  if&#40;!running&#41;
  &#123;
    running=1;
    failnum=0;
    form.lives.value=failnum;
    form.tried.value="";
    form.word.value="";
    index=Math.round&#40;Math.random&#40;&#41;*10000&#41; % 100;
    alpha&#91;0&#93;=words&#91;index&#93;.charAt&#40;0&#41;;
    alpha&#91;1&#93;=words&#91;index&#93;.charAt&#40;words&#91;index&#93;.length-1&#41;;
    alpha_index=1;
    bravo&#91;0&#93;=words&#91;index&#93;.charAt&#40;0&#41;;
    bravo&#91;1&#93;=words&#91;index&#93;.charAt&#40;words&#91;index&#93;.length-1&#41;;
    bravo_index=1;
    pick&#40;&#41;;
  &#125;
  else advise&#40;"A word is already in play!"&#41;;
&#125;

function seek&#40;letter&#41;
&#123;
  if &#40;!running&#41; advise&#40;".....Click GO γία να αρχέισεις !"&#41;;
  else
  &#123;
    t=0;
    for &#40;i=0; i<=bravo_index; i++&#41;
    &#123;
      if &#40;bravo&#91;i&#93;==letter || bravo&#91;i&#93;==letter.toLowerCase&#40;&#41;&#41; t=1;
    &#125;

    if &#40;!t&#41; 
	  &#123;
	    document.f.tried.value+=letter+" "
	    bravo_index++;
	    bravo&#91;bravo_index&#93;=letter;
	    
      for&#40;i=0;i<words&#91;index&#93;.length;i++&#41;
   	  if&#40;words&#91;index&#93;.charAt&#40;i&#41;==letter || words&#91;index&#93;.charAt&#40;i&#41;==letter.toLowerCase&#40;&#41;&#41; t=1;
  	  
      if&#40;t&#41;
      &#123;
  	    alpha_index++;
	      alpha&#91;alpha_index&#93;=letter;
	    &#125;
	    else failnum++;
	
      document.f.lives.value=failnum;
	    if &#40;failnum==6&#41; 
      &#123;
        document.f.tried.value="You lose - Try again!";
        document.f.word.value=words&#91;index&#93;;
        document.f.score.value--;
        running=0;
      &#125;
			else pick&#40;&#41;;
	  &#125;
	  else advise&#40;"Letter "+letter+" is already used!"&#41;;
  &#125;
&#125;

function advise&#40;msg&#41;
&#123;
  if &#40;!advising&#41;
  &#123;
    advising=-1;
    savetext=document.f.tried.value;  
    document.f.tried.value=msg;
    window.setTimeout&#40;"document.f.tried.value=savetext; advising=0;",1000&#41;;
  &#125;
&#125;

var words = new Array&#40;"", "σκουλικομιρμιγκότριπα", "allegiance", "ameliorate", "annihilate", "antiseptic", "articulate", "authoritative", "benefactor", "boisterous", "breakthrough", "carcinogenic", "censorious", "chivalrous", "collarbone", "commendable", "compendium", "comprehensive", "conclusive", "conscientious", "considerate", "deferential", "denouement", "determinate", "diffidence", "disruption", "earthenware", "elliptical", "entanglement", "escutcheon", "extinguish", "extradition", "fastidious", "flamboyant", "forethought", "forthright", "gregarious", "handmaiden", "honeysuckle", "hypocritical", "illustrious", "infallible", "lumberjack", "mischievous", "mollycoddle", "nimbleness", "nonplussed", "obliterate", "obsequious", "obstreperous", "opalescent", "ostensible", "pandemonium", "paraphernalia", "pawnbroker", "pedestrian", "peremptory", "perfunctory", "pernicious", "perpetrate", "personable", "pickpocket", "poltergeist", "precipitous", "predicament", "preposterous", "presumptuous", "prevaricate", "propensity", "provisional", "pugnacious", "ramshackle", "rattlesnake", "reciprocate", "recrimination", "redoubtable", "relinquish", "remonstrate", "repository", "reprehensible", "resolution", "resplendent", "restitution", "retaliation", "retribution", "saccharine", "salubrious", "skulduggery", "skyscraper", "soothsayer", "tearjerker", "transcribe", "turpentine", "unassuming", "underscore", "undertaker", "underwrite", "unobtrusive", "vernacular", "waterfront", "watertight"&#41;; 

</SCRIPT>


<FORM NAME="f">

<TABLE BGCOLOR=#C0C0C0 BORDER=1>
 <TR>
  <TD COLSPAN=4 ALIGN=RIGHT>
   Score &#58; <INPUT TYPE=TEXT NAME="score" VALUE="0" onfocus="score.blur&#40;&#41;;" SIZE=2>
   <BR>
   Fails &#40;6&#41;&#58; <INPUT TYPE=TEXT NAME="lives" VALUE="0" onfocus="lives.blur&#40;&#41;;" SIZE=2>  
  </TD>
  <TD COLSPAN=7 ALIGN=CENTER>
   <INPUT TYPE=TEXT NAME="word" VALUE="    --- Hangman ---" onfocus="word.blur&#40;&#41;;" SIZE=25> 
    <BR>
   <INPUT TYPE=TEXT NAME="tried" VALUE="Click GO to get a word." onfocus="tried.blur&#40;&#41;;" SIZE=25>  
  </TD>
  <TD COLSPAN=2 ALIGN=CENTER>
   <INPUT TYPE=BUTTON onclick="new_word&#40;this.form&#41;;" VALUE=" GO ">   
  </TD>
 </TR>
 <TR>
  <TD><INPUT TYPE=BUTTON VALUE=" A "   onclick="seek&#40;'A'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" B "   onclick="seek&#40;'B'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" C "   onclick="seek&#40;'C'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" D "   onclick="seek&#40;'D'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" E "   onclick="seek&#40;'E'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" F "   onclick="seek&#40;'F'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" G "   onclick="seek&#40;'G'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" H "   onclick="seek&#40;'H'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" I   " onclick="seek&#40;'I'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" J  "  onclick="seek&#40;'J'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" K "   onclick="seek&#40;'K'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" L  "  onclick="seek&#40;'L'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" M "   onclick="seek&#40;'M'&#41;;"></TD>
 </TR>
 <TR>
  <TD><INPUT TYPE=BUTTON VALUE=" N "   onclick="seek&#40;'N'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" O "   onclick="seek&#40;'O'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" P "   onclick="seek&#40;'P'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" Q "   onclick="seek&#40;'Q'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" R "   onclick="seek&#40;'R'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" S "   onclick="seek&#40;'S'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" T "   onclick="seek&#40;'T'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" U "   onclick="seek&#40;'U'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" V "   onclick="seek&#40;'V'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" W "   onclick="seek&#40;'W'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" X  "  onclick="seek&#40;'X'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" Y "   onclick="seek&#40;'Y'&#41;;"></TD>
  <TD><INPUT TYPE=BUTTON VALUE=" Z  "  onclick="seek&#40;'Z'&#41;;"></TD>
 </TR>
</TABLE>

</FORM>

</body>

</html>

Απάντηση

Επιστροφή στο “JavaScript και Frameworks”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 0 επισκέπτες