dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Help!!

Hybrid View

  1. #1
    Join Date
    Feb 2014
    Posts
    2

    Lightbulb Help!!

    Ok so i am a beginner getting into web dev=development. as of right now i am learning html,css javascript, jquery and will be getting into programming in the near future. What i need help with is the direction to go if i want to learn how to implement a simple game like tic-tac-toe, onto a website and whoever is the winner receives the prize. I know this sound pretty complicated but if you know what i should be studying to achieve this, please post down below.
    Thank You

  2. #2
    Join Date
    Jan 2014
    Posts
    19
    I don't think tic tac toe is the best place to start learning web development. sounds like something for a school project.

  3. #3
    Join Date
    Feb 2014
    Location
    india
    Posts
    14
    code:<html>
    <head>
    <script src='http://code.jquery.com/jquery-1.7.2.js'></script>
    <script>
    (function () {

    var squares = [],
    EMPTY = "\xA0",
    score,
    moves,
    turn = "X",
    oldOnload,


    wins = [7, 56, 448, 73, 146, 292, 273, 84],

    startNewGame = function () {
    var i;

    turn = "X";
    score = {"X": 0, "O": 0};
    moves = 0;
    for (i = 0; i < squares.length; i += 1) {
    squares[i].firstChild.nodeValue = EMPTY;
    }
    },


    win = function (score) {
    var i;
    for (i = 0; i < wins.length; i += 1) {
    if ((wins[i] & score) === wins[i]) {
    return true;
    }
    }
    return false;
    },


    set = function () {
    if (this.firstChild.nodeValue !== EMPTY) {
    return;
    }
    this.firstChild.nodeValue = turn;
    moves += 1;
    score[turn] += this.indicator;
    if (win(score[turn])) {
    alert(turn + " wins!");
    startNewGame();
    } else if (moves === 9) {
    alert("Cat\u2019s game!");
    startNewGame();
    } else {
    turn = turn === "X" ? "O" : "X";
    }
    },


    play = function () {
    var board = document.createElement("table"),
    indicator = 1,
    i, j,
    row, cell,
    parent;
    board.border = 1;
    for (i = 0; i < 3; i += 1) {
    row = document.createElement("tr");
    board.appendChild(row);
    for (j = 0; j < 3; j += 1) {
    cell = document.createElement("td");
    cell.width = cell.height = 50;
    cell.align = cell.valign = 'center';
    cell.indicator = indicator;
    cell.onclick = set;
    cell.appendChild(document.createTextNode(""));
    row.appendChild(cell);
    squares.push(cell);
    indicator += indicator;
    }
    }

    // Attach under tictactoe if present, otherwise to body.
    parent = document.getElementById("tictactoe") || document.body;
    parent.appendChild(board);
    startNewGame();
    };

    if (typeof window.onload === "function") {
    oldOnLoad = window.onload;
    window.onload = function () {
    oldOnLoad();
    play();
    };
    } else {
    window.onload = play;
    }
    }());
    </script>
    </head>
    <body>
    <div id="tictactoe"></div>
    </body>
    </html>

  4. #4
    Join Date
    Feb 2014
    Location
    india
    Posts
    14
    you need to learn jquery -->javascript--> html
    http://www.w3schools.com/ here you can learn all these things
    but most important is algorithm for that you just need to think out of box...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles