Advertisement
Guest User

conway checkers reverse

a guest
Feb 24th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.81 KB | None | 0 0
  1. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  2. <style type="text/css">
  3.     td{height:19px;width:14px;line-height:16px;overflow:hidden;text-align:center;cursor:pointer;}
  4.     body{background:#999;text-align:center}
  5.     table{margin:auto;table-layout:fixed;}
  6. </style>
  7. <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  8. <script type="text/javascript">
  9.     $(document).ready(function()
  10.     {
  11.         $("#butt").click(function(ev)
  12.         {
  13.             ev.preventDefault()
  14.             var settings = JSON.parse($("#settings").val())
  15.             $("#form").css("display","none")
  16.             var tablecode = '<table border=1 id="t" style="width:' + (settings.table_cols*14) +'px">'
  17.             for(var x = 0;x < settings.table_rows; x++)
  18.            {
  19.                if(x == 10)
  20.                {
  21.                    tablecode += '<tr style="background:lightgray">'
  22.                 }
  23.                 else
  24.                 {
  25.                     tablecode += '<tr>'
  26.                 }
  27.                
  28.                 for(var y = 0; y < settings.table_cols;y++)
  29.                {
  30.                    tablecode += '<td></td>'
  31.                 }
  32.                 tablecode += '</tr>'
  33.             }
  34.             tablecode += '</table>'
  35.             $("body").append(tablecode)
  36.             var selected_cell = $("#t tr:eq(5) td:eq("+ Math.floor(settings.table_cols /2)+")")
  37.             function select_cell(cell)
  38.             {
  39.                 selected_cell.css("background","unset")
  40.                 cell.css("background","yellow")
  41.                 selected_cell = cell
  42.             }
  43.             function coords(cell)
  44.             {
  45.                 return {
  46.                     x: cell.index(),
  47.                     y: cell.parent().index(),
  48.                 }
  49.             }
  50.             selected_cell.html("x")
  51.             $("td").click(function()
  52.             {
  53.                 var cell = $(this)
  54.                 cell.x = coords(cell).x
  55.                 cell.y = coords(cell).y
  56.                 if(cell.html() == "x")
  57.                 {
  58.                     select_cell(cell)
  59.                 }
  60.                 else
  61.                 {
  62.                     if(cell.x == selected_cell.x && cell.y == (selected_cell.y + 2))
  63.                    {
  64.                        var midcell = $("#t tr:eq(" + (selected_cell.y + 1) + ") td:eq(" + selected_cell.x + ")")
  65.                        if(midcell.html() == "")
  66.                        {
  67.                            selected_cell.html("")
  68.                            midcell.html("x")
  69.                            cell.html("x")
  70.                        }
  71.                        console.log(coords(selected_cell),"->",coords(cell))
  72.                        select_cell(cell)
  73.                    }
  74.                    if(cell.x == selected_cell.x && cell.y == (selected_cell.y - 2))
  75.                    {
  76.                        var midcell = $("#t tr:eq(" + (selected_cell.y - 1) + ") td:eq(" + selected_cell.x + ")")
  77.                        if(midcell.html() == "")
  78.                        {
  79.                            selected_cell.html("")
  80.                            midcell.html("x")
  81.                            cell.html("x")
  82.                        }
  83.                        console.log(coords(selected_cell),"->",coords(cell))
  84.                        select_cell(cell)
  85.                    }
  86.                    if(cell.x == (selected_cell.x + 2) && cell.y == selected_cell.y)
  87.                    {
  88.                        var midcell = $("#t tr:eq(" + (selected_cell.y) + ") td:eq(" + (selected_cell.x + 1) + ")")
  89.                        if(midcell.html() == "")
  90.                        {
  91.                            selected_cell.html("")
  92.                            midcell.html("x")
  93.                            cell.html("x")
  94.                        }
  95.                        console.log(coords(selected_cell),"->",coords(cell))
  96.                        select_cell(cell)
  97.                    }
  98.                    if(cell.x == (selected_cell.x - 2) && cell.y == selected_cell.y)
  99.                    {
  100.                        var midcell = $("#t tr:eq(" + (selected_cell.y) + ") td:eq(" + (selected_cell.x - 1) + ")")
  101.                        if(midcell.html() == "")
  102.                        {
  103.                            selected_cell.html("")
  104.                            midcell.html("x")
  105.                            cell.html("x")
  106.                        }
  107.                        console.log(coords(selected_cell),"->",coords(cell))
  108.                        select_cell(cell)
  109.                    }
  110.                }
  111.            })
  112.        })
  113.    })
  114. </script>
  115. <div id="form">
  116. <textarea id="settings" cols="60" rows="10">
  117. {
  118.    "table_rows": 100,
  119.    "table_cols": 80
  120. }
  121. </textarea>
  122. <button id="butt">Start</button>
  123. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement