-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
151 lines (126 loc) · 5.63 KB
/
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
###########################################################################################
# Date: 2nd Jan, 2018 # TimesTable is a game that my 6yo daughter used #
# Author: Tiberiu Gociu # to play to learn the ... times table! :) #
# Project: Times Table self playing game # This exercise is to have a program that plays #
# using curses library # with itself and creates data for future use. #
############################################################################################
# CURSES uses teh Y,X coordinates #
###########################################
import curses
import numpy
from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN
from random import randint
def createTilePool():
for i in range(0,11):
for j in range(0,11):
# print '*********', i, '*', j, '=', i*j
if i*j not in tilePool:
tilePool.append(i*j)
tilePoolCount.append(1)
else:
tilePoolCount[tilePool.index(i*j)]+=1
return
# initialize the screen
curses.initscr()
# define the screen size
win = curses.newwin(20, 60, 0, 0)
# curses interprets input from keyboard
win.keypad(1)
# Leave echo mode. Echoing of input characters is turned off.
curses.noecho()
# Set the cursor state. visibility can be set to 0, 1, or 2, for invisible, normal, or very visible.
curses.curs_set(0)
# Draws a border around the screen
win.border(0)
# If yes is 1, getch() will be non-blocking.
win.nodelay(1)
# create the matrix to hold the tile values using NUMPY library
tilePool = []
tilePoolCount = []
##########################################################
# creating the pool of valid tile values
# actual results of two numbers between [0,10]
createTilePool()
##########################################################
# TODO adjust tileMatrix to hold valid values only.
tileMatrix = numpy.random.random_integers(100,size=(4,4))
for i in range(0,4):
for j in range(0,4):
tile = tilePool[numpy.random.random_integers(42,size=(1))]
while tile not in tileMatrix :
tileMatrix[i][j] = tile
tile = tilePool[numpy.random.random_integers(42,size=(1))]
# create the matrix to hold the matched tile values
matchedTileMatrix = numpy.zeros((4,4), int)
# assigning a value to KEY_RIGHT
key = KEY_RIGHT
win.addstr( 4, 5, str(tileMatrix[0][0]))
win.addstr( 4, 9, str(tileMatrix[0][1]))
win.addstr( 4,13, str(tileMatrix[0][2]))
win.addstr( 4,17, str(tileMatrix[0][3]))
win.addstr( 5, 5, str(tileMatrix[1][0]))
win.addstr( 5, 9, str(tileMatrix[1][1]))
win.addstr( 5,13, str(tileMatrix[1][2]))
win.addstr( 5,17, str(tileMatrix[1][3]))
win.addstr( 6, 5, str(tileMatrix[2][0]))
win.addstr( 6, 9, str(tileMatrix[2][1]))
win.addstr( 6,13, str(tileMatrix[2][2]))
win.addstr( 6,17, str(tileMatrix[2][3]))
win.addstr( 7, 5, str(tileMatrix[3][0]))
win.addstr( 7, 9, str(tileMatrix[3][1]))
win.addstr( 7,13, str(tileMatrix[3][2]))
win.addstr( 7,17, str(tileMatrix[3][3]))
# MAIN WHILE LOOP START
# while the ESC key is not pressed, do the following
while key != 27:
# print the windows border
win.border(0)
# TODO display the matrix that holds the tile values
# TODO highlight tile values as soon as they are matched
# print the two 12 faced dice values:
xx = randint(0,10)
yy = randint(0,10)
win.addstr(1, 1, ' Die #1 * #2 = Total')
win.addstr(2, 1, ' xx * yy = xyz ')
win.addstr(2, 1, ' ')
win.addstr(2, 1, ' ' + str(xx))
win.addstr(2, 8, ' * ' + str(yy))
win.addstr(2, 13, ' = ' + str(xx*yy)+' ')
# win.addstr(4, 3, ' 111 222 333 444 ')
# win.addstr(5, 3, ' 111 222 333 444 ')
# win.addstr(6, 3, ' 111 222 333 444 ')
# win.addstr(7, 3, ' 111 222 333 444 ')
'''
win.addstr(0, 27, ' SNAKE ') # 'SNAKE' strings
win.addstr(1, 27, ' SNAKE ',curses.A_BLINK) # 'SNAKE' strings
win.addstr(2, 27, ' SNAKE ',curses.A_BOLD) # 'SNAKE' strings
win.addstr(3, 27, ' SNAKE ',curses.A_DIM) # 'SNAKE' strings
win.addstr(4, 27, ' SNAKE ',curses.A_REVERSE) # 'SNAKE' strings
win.addstr(5, 27, ' SNAKE ',curses.A_STANDOUT) # 'SNAKE' strings
win.addstr(6, 27, ' SNAKE ',curses.A_UNDERLINE) # 'SNAKE' strings
#win.addstr(7, 27, ' SNAKE ',) # 'SNAKE' strings
#win.addstr(8, 27, ' SNAKE ',) # 'SNAKE' strings
#win.refresh()
'''
win.addstr(2, 27, ' ')
win.addstr(2, 27, str(numpy.argwhere(tileMatrix == xx*yy)))
if str(len(numpy.argwhere(tileMatrix == xx*yy)))==1:
win.addstr(3, 27, ' ')
win.addstr(3, 27, str(numpy.argwhere(tileMatrix == xx*yy)[1]))
else:
win.addstr(3, 27, ' ')
win.addstr(4, 27, str(len(numpy.argwhere(tileMatrix == xx*yy))))
win.timeout(2000)
prevKey = key # Previous key pressed
event = win.getch()
key = key if event == -1 else event
if key == ord(' '): # If SPACE BAR is pressed, wait for another
key = -1 # one (Pause/Resume)
while key != ord(' '):
key = win.getch()
key = prevKey
continue
if key not in [KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN, 27]: # If an invalid key is pressed
key = prevKey
# MAIN WHILE LOOP END
curses.endwin()