Dusty_Wings

Tic Tac Toe E2 Game

Apr 9th, 2016
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.30 KB | None | 0 0
  1. @name Tic Tac Toe
  2. @persist T Points:array Ply2:entity
  3. @persist Turn:entity Click TurnN O:entity
  4. @persist Scale Check:entity ChIn Grid:array
  5. @persist Players:array Turns
  6. @model models/hunter/plates/plate3x3.mdl
  7. runOnTick(1)
  8. runOnChat(1)
  9.  
  10. #if(lastSaid()=="/join"&chatClk()&!Ply2)
  11. #{
  12. #Ply2 = lastSpoke()      
  13. #}
  14.  
  15.  
  16. #Ply2 = owner()
  17.  
  18. if(first())
  19. {
  20. findExcludeEntity(owner())
  21. findByClass("player")
  22. Players = findToArray()
  23. entity():setMaterial("Lights/white005")    
  24. entity():setColor(vec(0,0,0))
  25.  
  26. for(I=1,4)
  27. {
  28. T++    
  29. holoCreate(I)
  30. holoMaterial(I,"Lights/white005")  
  31. Scale = entity():boxSize():x()
  32. holoScale(I,vec(Scale/12,1/10,1/2))
  33. #holoScale(I,vec(150/12,1/10,1/5))
  34. #holoPos(I,entity():pos())
  35. holoParent(I,entity())
  36. }
  37. holoPos(1,entity():pos()+vec(0,Scale/6,0))
  38. holoPos(2,entity():pos()-vec(0,Scale/6,0))
  39. holoPos(3,entity():pos()+vec(Scale/6,0,0))
  40. holoPos(4,entity():pos()-vec(Scale/6,0,0))
  41. holoAng(3,ang(0,90,0))
  42. holoAng(4,ang(0,90,0))
  43.  
  44.  
  45. Points[1,vector]=entity():toLocal(entity():pos()+vec(Scale/3,-Scale/3,0))
  46. Points[2,vector]=entity():toLocal(entity():pos()+vec(Scale/3,0,0))
  47. Points[3,vector]=entity():toLocal(entity():pos()+vec(Scale/3,Scale/3,0))
  48. Points[4,vector]=entity():toLocal(entity():pos()+vec(0,-Scale/3,0))
  49. Points[5,vector]=entity():toLocal(entity():pos()+vec(0,0,0))
  50. Points[6,vector]=entity():toLocal(entity():pos()+vec(0,Scale/3,0))
  51. Points[7,vector]=entity():toLocal(entity():pos()+vec(-Scale/3,-Scale/3,0))
  52. Points[8,vector]=entity():toLocal(entity():pos()+vec(-Scale/3,0,0))
  53. Points[9,vector]=entity():toLocal(entity():pos()+vec(-Scale/3,Scale/3,0))
  54. holoCreate(5)
  55. holoMaterial(5,"Lights/white005")  
  56. holoColor(5,vec(0,255,0))
  57. holoScale(5,vec(Scale/12,Scale/12,1*3)/3)
  58. T++
  59.  
  60.  
  61. }
  62.  
  63. if(!Ply2)
  64. {
  65. for(I=1,Players:count())
  66. {
  67. Player = Players[I,entity]
  68. if(Player:aimEntity()==entity()&Player:keyAttack2())
  69. {
  70. Ply2 = Player
  71. O = owner()
  72. #Ran = randint(0,1)
  73. #if(Ran)
  74. #{
  75. #Turn = Ply2
  76. #TurnN = 1
  77. #}
  78. ##else
  79. #{
  80. Turn = Ply2
  81. TurnN = 1
  82. #Turn = O
  83. #}
  84. break  
  85. }
  86.    
  87. }  
  88.    
  89. }
  90.  
  91. if(Ply2)
  92. {
  93. Click = Turn:keyAttack2()
  94.  
  95. Dist = 10^10^10^10
  96. for(I=1,9)
  97. {
  98. Aim = Turn:aimPos()
  99. CDist = Aim:distance(entity():toWorld(Points[I,vector]))
  100. if(CDist<=Dist)
  101. {
  102. Dist=CDist
  103. Ind = I  
  104. }  
  105. }
  106.  
  107. Pos = Points[Ind,vector]
  108. holoPos(5,entity():toWorld(Pos))
  109. holoAng(5,entity():angles())
  110.  
  111. if(Click&$Click&!changed(Turn))
  112. {
  113. Turns++
  114. for(I=6,T)
  115. {
  116. Pos = entity():toWorld(Points[Ind,vector]+vec(0,0,6))  
  117. if(holoEntity(I):pos()==Pos)
  118. {
  119. Break=1  
  120. break
  121. }
  122. }
  123. if(!Break)
  124. {
  125. #print("ADORABLE!")
  126. T++  
  127. holoCreate(T)
  128. holoParent(T,entity())
  129. if(TurnN==0)
  130. {
  131. holoColor(T,vec(0,0,255))
  132. holoModel(T,"hqtorus2")
  133. holoScale(T,vec(Scale/15,Scale/15,1*3)/3)
  134. holoPos(T,entity():toWorld(Points[Ind,vector]+vec(0,0,6)))    
  135. Grid[Ind,number]=1
  136. Turn=Ply2
  137. }
  138. if(TurnN==1)
  139. {
  140. holoColor(T,vec(255,0,0))    
  141. holoPos(T,entity():toWorld(Points[Ind,vector]+vec(0,0,6)))    
  142. holoScale(T,vec(Scale/15,1,1)/3)
  143. holoAng(T,ang(0,45,0))
  144. T++
  145. holoCreate(T)
  146. holoParent(T,entity())
  147. holoColor(T,vec(255,0,0))    
  148. holoPos(T,entity():toWorld(Points[Ind,vector]+vec(0,0,6)))    
  149. holoScale(T,vec(Scale/15,1,1)/3)
  150. holoAng(T,ang(0,-45,0))
  151. Grid[Ind,number]=-1
  152. Turn = O
  153. }
  154.  
  155. #Pick Up Here!
  156. for(I=0,2)
  157. {
  158. T3 = I*3
  159. GN = Grid[1+T3,number]
  160. GN2 = Grid[1+1+T3,number]
  161. GN3 = Grid[1+2+T3,number]
  162.  
  163. if(GN==GN2&GN==GN3)
  164. {
  165. if(GN==1)
  166. {
  167. print("Player 1 has won!")
  168.  
  169. }
  170. if(GN==-1)
  171. {
  172. print("Player 2 has won!")
  173.    
  174. }
  175. if(GN!=0)
  176. {
  177. timer("reset",5000)
  178. }
  179. }
  180. }
  181.  
  182. for(I=1,3)
  183. {
  184. T3 = I*3
  185. GN = Grid[I,number]
  186. GN2 = Grid[I+3,number]
  187. GN3 = Grid[I+3+3,number]
  188.  
  189. if(GN==GN2&GN==GN3)
  190. {
  191. if(GN==1)
  192. {
  193. print("Player 1 has won!")
  194.    
  195. }
  196. if(GN==-1)
  197. {
  198. print("Player 2 has won!")
  199.    
  200. }
  201. if(GN!=0)
  202. {
  203. timer("reset",5000)
  204. }
  205. }
  206. }
  207.  
  208. GN = Grid[1,number]
  209. GN2 = Grid[1+3+1,number]
  210. GN3 = Grid[1+3+3+2,number]
  211.  
  212. if(GN==GN2&GN==GN3)
  213. {
  214. if(GN==1)
  215. {
  216. print("Player 1 has won!")  
  217. }
  218. if(GN==-1)
  219. {
  220. print("Player 2 has won!")  
  221. }
  222. if(GN!=0)
  223. {
  224. timer("reset",5000)
  225. }
  226. }
  227.  
  228. GN = Grid[3,number]
  229. GN2 = Grid[3+3-1,number]
  230. GN3 = Grid[3+3+3-2,number]
  231.  
  232. if(GN==GN2&GN==GN3)
  233. {
  234. if(GN==1)
  235. {
  236. print("Player 1 has won!")  
  237. }
  238. if(GN==-1)
  239. {
  240. print("Player 2 has won!")  
  241. }
  242. if(GN!=0)
  243. {
  244. timer("reset",5000)
  245. }
  246. }
  247.  
  248. if(Turns>=9)
  249. {
  250. timer("reset",5000)
  251. print("Draw!")    
  252. }
  253.  
  254. TurnN=!TurnN
  255. }
  256. }
  257. if(clk("reset"))
  258. {
  259. reset()  
  260. }
  261. }
Add Comment
Please, Sign In to add comment