Sxw1212

Tic-Tac-Toe Client

Aug 4th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. function clear()
  2. term.clear()
  3. term.setCursorPos(1,1)
  4. end
  5. function drawBoard(b)
  6. clear()
  7. write(b[1])
  8. write("|")
  9. write(b[2])
  10. write("|")
  11. print(b[3])
  12. print("-----")
  13. write(b[4])
  14. write("|")
  15. write(b[5])
  16. write("|")
  17. print(b[6])
  18. print("-----")
  19. write(b[7])
  20. write("|")
  21. write(b[8])
  22. write("|")
  23. print(b[9])
  24. end
  25. function fromID(id)
  26. while true do
  27. local tid, msg=rednet.receive()
  28. if tid == id then
  29. return msg
  30. end
  31. end
  32. end
  33. clear()
  34. print("ID:"..os.getComputerID())
  35. write("Server ID:")
  36. local server=read()+0
  37. write("Rednet side:")
  38. rednet.open(read())
  39. board={}
  40. for i=1,9 do
  41. board[i]=" "
  42. end
  43. stat=""
  44. while true do
  45. clear()
  46. drawBoard(board)
  47. act=fromID(server)
  48. if act=="start" then
  49. print("Start!")
  50. else if act=="win" then
  51. print("You win!")
  52. sleep(5)
  53. break
  54. else if act=="lose" then
  55. print("You lose!")
  56. sleep(5)
  57. break
  58. else if act=="Play" then
  59. print("Whats your play?")
  60. rednet.send(server,read())
  61. else if act=="Place" then
  62. board[(fromID(server)+0)]=fromID(server)
  63. else
  64. print("Error")
  65. sleep(5)
  66. os.reboot()
  67. end
  68. end
  69. end
  70. end
  71. end
  72. end
Advertisement
Add Comment
Please, Sign In to add comment