Advertisement
132ikl

Program

Feb 12th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.50 KB | None | 0 0
  1. function callScripts()
  2.     dofile("Variables.lua")
  3.     dofile("Function.lua")
  4. end
  5.  
  6. callScripts()
  7.  
  8. clear()
  9. prepareBoard()
  10. printBoard()
  11. getInput()
  12.  
  13. while true do
  14. end
  15.  
  16.  
  17. --Begin Variables--
  18.  
  19. --Random Variables
  20. player=1
  21.  
  22. --Table declaration
  23.  
  24. --Board Table
  25. --0 netrual, 1 x, 2 o
  26. board = {}
  27. board[1] = 0  
  28. board[2] = 0
  29. board[3] = 0
  30. board[4] = 0
  31. board[5] = 0
  32. board[6] = 0
  33. board[7] = 0
  34. board[8] = 0
  35. board[9] = 0
  36.  
  37. --Board String Table
  38. boardString = {}
  39.  
  40. function clear()
  41.     print("")
  42.     print("")
  43.     print("")
  44.     print("")
  45.     print("")
  46.     print("")
  47.     print("")
  48.     print("")
  49.     print("")
  50.     print("")
  51.     print("")
  52.     print("")
  53.     print("")
  54.     print("")
  55.     print("")
  56. end
  57.  
  58. --Begin Functions--
  59. function clear()
  60.     print("")
  61.     print("")
  62.     print("")
  63.     print("")
  64.     print("")
  65.     print("")
  66.     print("")
  67.     print("")
  68.     print("")
  69.     print("")
  70.     print("")
  71.     print("")
  72.     print("")
  73.     print("")
  74.     print("")
  75. end
  76. function getInput()
  77.     if player==1 then
  78.         print("Player 1, type the square you would like to fill. (Ex. 1-9)")
  79.         io.read = player1input
  80.         for i = 1,9 do
  81.             if tostring(i) == player1input then
  82.                 if board[i] == 0 then
  83.                     board[i] = 1
  84.                     player = 2
  85.                 elseif board[i] > 0 then
  86.                     print("This square has already been chosen. Please choose another.")
  87.                 end
  88.             end
  89.         end
  90.     end
  91.     if player==2 then
  92.         print("Player 2, type the sqaure you would like to fill. (Ex. 1-9)")
  93.         io.read = player2input
  94.         for i = 1,9 do
  95.             if tostring(i) == player2input then
  96.                 if board[i] == 0 then
  97.                     board[i] = 1
  98.                     player = 1
  99.                 elseif board[i] > 0 then
  100.                     print("This square has already been chosen. Please choose another.")
  101.                 end
  102.             end
  103.         end
  104.     end    
  105. end
  106.  
  107. function prepareBoard()
  108.     for i = 1,9 do
  109.         if board[i] == 0 then
  110.             boardString[i] = " "
  111.         elseif board[i] == 1 then
  112.             boardString[i] = "X"  
  113.         elseif board[i] == 2 then
  114.             boardString[i] = "O"
  115.         end
  116.     end
  117. end
  118. function printBoard()
  119.     print(boardString[1].."|"..boardString[2].."|"..boardString[3])
  120.     print(boardString[4].."|"..boardString[5].."|"..boardString[6])
  121.     print(boardString[7].."|"..boardString[8].."|"..boardString[9])
  122. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement