tmscli 0.5.0__tar.gz → 0.6.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: tmscli
3
- Version: 0.5.0
3
+ Version: 0.6.1
4
4
  Summary: runs minesweeper in your terminal, type rules for how to play
5
5
  Description-Content-Type: text/markdown
6
6
 
@@ -4,10 +4,11 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "tmscli"
7
- version = "0.5.0"
7
+ version = "0.6.1"
8
8
  description = "runs minesweeper in your terminal, type rules for how to play"
9
9
  readme="README.md"
10
10
  dependencies = []
11
11
 
12
12
  [project.scripts]
13
13
  tms = "tmscli.main:run"
14
+ top_score = "tmscli.main:get_top"
@@ -0,0 +1 @@
1
+ username,time,size,mine num, score
@@ -1,6 +1,8 @@
1
1
  import random
2
2
  import argparse
3
3
  import importlib.metadata
4
+ import csv
5
+ from time import time
4
6
  colors=['\033[31m','\033[32m','\033[33m','\033[34m','\033[35m','\033[36m','\033[37m','\033[38m','\033[39m']
5
7
  MINE='\033[30m'
6
8
  FLAG='\033[29m'
@@ -11,6 +13,15 @@ class minesweeper():
11
13
  self.size=size
12
14
  self.num=num
13
15
  ['uncovered?','flagged?','display']
16
+ def log(self,user,t,size,num,score):
17
+ with open('./src/tmscli/.scores/high_scores.csv', mode='a', newline='', encoding='utf-8') as file:
18
+ writer = csv.writer(file)
19
+ writer.writerow([user,t,size,num,round(score)])
20
+
21
+ def get_score(self,t,size,num):
22
+ ratio=size/num
23
+ score=1000/(t*ratio)
24
+ return t,size,num,score
14
25
  def colored(self,string):
15
26
  new=f'|'
16
27
  c=0
@@ -88,14 +99,15 @@ class minesweeper():
88
99
  print(self.colored(buffer))
89
100
  bottom=' '+(len(top)-1)*'-'
90
101
  print(bottom)
91
- exit()
92
102
  def check_success(self,board):
93
103
  for i in board:
94
104
  for j in i:
95
105
  if j[2]!='M':
96
106
  if not j[0]:
97
107
  return False
98
- return True
108
+ # end=time()
109
+
110
+ return 1
99
111
  def check_death(self,board):
100
112
  for i in board:
101
113
  for j in i:
@@ -109,7 +121,7 @@ class minesweeper():
109
121
  return True
110
122
  elif self.check_success(board):
111
123
  print('YOU WIN')
112
- return True
124
+ return 1
113
125
  return False
114
126
  def richochet(self,board,coord):
115
127
  x,y=coord
@@ -133,6 +145,7 @@ terminal_minesweeper=minesweeper(9,5)
133
145
  def throw():
134
146
  print('unrecognised command, please try again')
135
147
  def main_loop(board):
148
+ start=time()
136
149
  try:
137
150
  while True:
138
151
  terminal_minesweeper.print_board(board)
@@ -167,17 +180,18 @@ def main_loop(board):
167
180
  else:
168
181
  throw()
169
182
  continue
170
- if terminal_minesweeper.check(board):
183
+ k=terminal_minesweeper.check(board)
184
+ if k:
171
185
  terminal_minesweeper.print_ending(board)
186
+ if k==1:
187
+ end=time()
188
+ print(f'Score:{round(terminal_minesweeper.get_score(round(end-start,3),terminal_minesweeper.size,terminal_minesweeper.num)[3])}')
189
+ a,b,c,d=terminal_minesweeper.get_score(round(end-start,3),terminal_minesweeper.size,terminal_minesweeper.num)
190
+ terminal_minesweeper.log(input('Username >>> '),a,b,c,d)
172
191
  exit()
173
192
  except KeyboardInterrupt:
174
193
  print('Interrupted')
175
194
  terminal_minesweeper.print_ending(board)
176
- except:
177
- if terminal_minesweeper.check(board):
178
- exit()
179
- print('ERROR')
180
- terminal_minesweeper.print_ending(board)
181
195
  def run():
182
196
  try:
183
197
  __version__ = importlib.metadata.version("tmscli")
@@ -250,4 +264,31 @@ If you step on a mine you lose, the number on the square is how many mines are a
250
264
  print(i.rstrip())
251
265
  input()
252
266
  input('press enter to start:')
253
- run()
267
+ def upper(l):
268
+ return int(l[4])
269
+ def get_top(num=5):
270
+ p=argparse.ArgumentParser(description='scoreboard')
271
+ p.add_argument(
272
+ '-s','--scores',
273
+ type=int,
274
+ default=5,
275
+ help='set size to x'
276
+ )
277
+ args=p.parse_args()
278
+ if args.scores:
279
+ num=args.scores
280
+ with open('./src/tmscli/.scores/high_scores.csv', mode='r') as file:
281
+ reader=csv.reader(file)
282
+ header=next(reader)
283
+ head=['time','size','mines','score']
284
+ r=list(reader)
285
+ r.sort(key=upper)
286
+ r.reverse()
287
+ for i in range(num):
288
+ print(str(i+1)+'. '+r[i][0])
289
+ for j in range(4):
290
+ print(' '+head[j]+': '+ r[i][j+1])
291
+
292
+
293
+ # get_top()
294
+ # run()
@@ -1,4 +1,4 @@
1
- /* style.css — shared across all pages */
1
+
2
2
 
3
3
  * {
4
4
  margin: 0;
@@ -16,7 +16,7 @@ body {
16
16
  min-height: 100vh;
17
17
  }
18
18
 
19
- /* header & navigation */
19
+
20
20
  header {
21
21
  background: #0f2b3d;
22
22
  color: #e2e8f0;
@@ -73,8 +73,8 @@ nav a.active {
73
73
  font-weight: 600;
74
74
  }
75
75
 
76
- /* main container */
77
- .container {
76
+
77
+ .containe {
78
78
  max-width: 1100px;
79
79
  margin: 2rem auto 3rem;
80
80
  padding: 0 2rem;
@@ -118,7 +118,7 @@ p {
118
118
  color: #1e2f3f;
119
119
  }
120
120
 
121
- /* cards on main page */
121
+
122
122
  .card-grid {
123
123
  display: grid;
124
124
  grid-template-columns: 1fr 1fr;
@@ -147,7 +147,7 @@ p {
147
147
  padding-bottom: 0.5rem;
148
148
  }
149
149
 
150
- /* lorem block */
150
+
151
151
  .lorem-block {
152
152
  background: #eef6fb;
153
153
  padding: 2rem 2rem 1.2rem;
@@ -159,8 +159,6 @@ p {
159
159
  .lorem-block h2 {
160
160
  margin-top: 0;
161
161
  }
162
-
163
- /* about page */
164
162
  .about-section {
165
163
  background: #ffffff;
166
164
  padding: 1.8rem 2rem 1rem;
@@ -174,7 +172,6 @@ p {
174
172
  margin-top: 0;
175
173
  }
176
174
 
177
- /* installation + usage */
178
175
  .install-card {
179
176
  background: #0f2b3d;
180
177
  color: #e2e8f0;
@@ -253,7 +250,6 @@ pre code {
253
250
  .dependency-link:hover{
254
251
  color:rgb(125,125,150);
255
252
  }
256
- /* footer */
257
253
  footer {
258
254
  text-align: center;
259
255
  padding: 1.8rem 2rem;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes