0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

javascriptで作る〇✕ゲーム

Posted at

##はじめに
最近、javascriptを学ぶ機会があり簡単なアプリを開発したいと思いました。
そこで、〇✕ゲームを開発しようと考え今回に至ります。
これを作ることができれば、友達との対戦が可能になるので是非見てください!!

##〇✕ゲームとは?
3×3 の格子を用意し、二人が交互に「○」と「×」を書き込んでいき3つ並べるゲームのこと。

##コード
###javascriptのコード

   <script>

        var turn = '×';
        
        function clickHear(e){
            if (turn == '○') {
                turn = '×';
                e.textContent = turn;
            } else {
                turn = '○'
                e.textContent = turn;
        }
    }


       
      
        
    </script>

###HTMLのコード

<!DOCTYPE html>
<html lang="ja">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>〇✕ゲーム</title>


  <style>
      td{
          font-size: 60px;
          width: 120px;
          height: 120px;
          text-align: center;
      }
  </style>

  
 
</head>



<body>

    <h1>〇☓ゲーム</h1>
    <table border="1">
    <tr>
        <td class="cell" onclick="clickHear(this)"></td>
        <td class="cell" onclick="clickHear(this)"></td>
        <td class="cell" onclick="clickHear(this)"></td>
       
    </tr>
    <tr>
        <td class="cell" onclick="clickHear(this)"></td>
        <td class="cell" onclick="clickHear(this)"></td>
        <td class="cell" onclick="clickHear(this)"></td>
       
    </tr>

    <tr>
        <td class="cell" onclick="clickHear(this)"></td>
        <td class="cell" onclick="clickHear(this)"></td>
        <td class="cell" onclick="clickHear(this)"></td>
       
    </tr>
    </table>


</body>
</html>

##感想
javascriptの処理コードは思ったより少なかった。
スタイルに関しては、好みで変えてね!!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?