Files
  • main.py
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import time, replit, xterm
t_loc = "l"
s_loc = "t"
turn = 0
run = 1
loc = {
"t1r1":" ","t1r2":" ","t1r3":" ",
"t2r1":" ","t2r2":" ","t2r3":" ",
"t3r1":" ","t3r2":" ","t3r3":" "}

ttop = {
	"l":"  v     ",
	"m":"    v   ",
	"r":"      v "
}

tside = {
	"t":">",
	"m":" ",
	"b":" "
}

def update_frame():
	global tside,ttop,t_loc, s_loc
	tside["t"] = " "
	tside["m"] = " "
	tside["b"] = " "
	tside[s_loc] = ">"
	replit.clear()
	print(f"It's player {turn}'s turn.\n")
	print(ttop[t_loc])
	print(tside["t"]+" "+loc["t1r1"]+"|"+loc["t1r2"]+"|"+loc["t1r3"])
	print("  -----")
	print(tside["m"]+" "+loc["t2r1"]+"|"+loc["t2r2"]+"|"+loc["t2r3"])
	print("  -----")
	print(tside["b"]+" "+loc["t3r1"]+"|"+loc["t3r2"]+"|"+loc["t3r3"])

@xterm.event("key")
def onKeyPress(key):
	global t_loc, s_loc
	if turn != 0 and key != "ENTER":
		if key == "LEFT":
			if t_loc == "m":
				t_loc = "l"
			elif t_loc == "r":
				t_loc = "m"
		if key == "RIGHT":
			if t_loc == "l":
				t_loc = "m"
			elif t_loc == "m":
				t_loc = "r"
		if key == "UP":
			if s_loc == "m":
				s_loc = "t"
			elif s_loc == "b":
				s_loc = "m"
		if key == "DOWN":
			if s_loc == "t":
				s_loc = "m"
			elif s_loc == "m":
				s_loc = "b"
		update_frame()





print("Tick Tax Too")
print("Instructions: select the location with the arrow keys and\npress ENTER to place your marker there!")
print("BUGS: you may have to press a key multiple times for it to register.")
print("Player 1 is X.")
print("Press ENTER to begin.")
turn = 1
xterm.wait_for_key("ENTER")
while run == 1:
	update_frame()
	while 1:
		xterm.wait_for_key("ENTER")
		if t_loc == "l" and s_loc == "t":
			ploc = "t1r1"
		elif t_loc == "l" and s_loc == "m":
			ploc = "t2r1"
		elif t_loc == "l" and s_loc == "b":
			ploc = "t3r1"
		elif t_loc == "m" and s_loc == "t":
			ploc = "t1r2"
		elif t_loc == "m" and s_loc == "m":
			ploc = "t2r2"
		elif t_loc == "m" and s_loc == "b":
			ploc = "t3r2"
		elif t_loc == "r" and s_loc == "t":
			ploc = "t1r3"
		elif t_loc == "r" and s_loc == "m":
			ploc = "t2r3"
		elif t_loc == "r" and s_loc == "b":
			ploc = "t3r3"

		if loc[ploc] != " ":
			print("Error! That spot is taken! Try again!")
			print("(ENTER to continue)")
			xterm.wait_for_key("ENTER")
		else:
			if turn == 1:
				loc[ploc] = "X"
			else:
				loc[ploc] = "O"
			turn = abs(turn-3)

	#if loc["t1r1"] == "X" and loc["t1r2"] == "X" and loc["t1r3"] == "X":
	#	run = 0
	#	continue

else:
	print("Player 1 wins!")












#  l      m      r
#t  t1r1 | t1r2 | t1r3
#  ------------------
#m  t2r1 | t2r2 | t2r3
#  ------------------
#b  t3r1 | t3r2 | t3r3
Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux