Compare commits

..

10 Commits

Author SHA1 Message Date
oto
69ce05886d did some formatting 2022-08-17 12:38:04 +03:00
oto
e53fd7236c Added a timer 2022-08-15 07:31:52 +03:00
oto
cb8036bc6d Removed an excessive method
There's no main loop for this game, bruh. Why I put it here?..
2022-08-15 07:30:21 +03:00
oto
00da6deb24 Removed shared score var
A design flaw, makes no sense.
2022-08-15 07:29:50 +03:00
oto
00daf53fae soft internalized some methods
Have learned how to "internalize" methods 😆
2022-08-15 07:29:25 +03:00
oto
446ffba554 Pulled out code into Timer.py
Made a separate class instead of keeping it in GameLogic.
2022-08-15 07:28:17 +03:00
oto
9c9db7aba9 PEP Compliance edit 2022-08-15 07:26:45 +03:00
oto
7b486881d9 Create Timer.py
Pulled it out of GameLogic class. Makes sense to keep it separate.
2022-08-15 07:26:15 +03:00
oto
b11f77f7ef Update tester.py 2022-08-15 07:25:39 +03:00
oto
54a0f42137 Added score counting
It makes no sense to keep one score for everyone, in GameMap. A design flaw.
2022-08-15 07:25:25 +03:00
5 changed files with 29 additions and 27 deletions

View File

@ -1,7 +1,6 @@
from datetime import datetime, time
from GameMap import * from GameMap import *
from Player import * from Player import *
from Timer import *
class GameLogic(): class GameLogic():
@ -11,13 +10,7 @@ class GameLogic():
self.playerList = playerList self.playerList = playerList
self.winRowLength = winRowLength self.winRowLength = winRowLength
self.individualMoves = individualMoves self.individualMoves = individualMoves
self.score = 0 self.timer = Timer()
self.wait_for_input()
def wait_for_input(self):
pass
def check_who_win(self): def check_who_win(self):
# Should have used vectors instead of committing tuples mithosis, # Should have used vectors instead of committing tuples mithosis,
@ -32,11 +25,11 @@ class GameLogic():
directions = ((0, 1), (1, 0), (1,1), (-1, 1)) directions = ((0, 1), (1, 0), (1,1), (-1, 1))
for mark in markList: for mark in markList:
for direction in directions: for direction in directions:
if self.is_line(markList, mark, direction): if self._is_line(markList, mark, direction):
return player return player
return False return False
def is_line(self, markList, mark, direction): # INTERNAL, I guess. def _is_line(self, markList, mark, direction):
for i in range(1, self.winRowLength): for i in range(1, self.winRowLength):
seeked = (mark[0] + direction[0] * i, mark[1] + direction[1] * i) seeked = (mark[0] + direction[0] * i, mark[1] + direction[1] * i)
if seeked in markList: if seeked in markList:
@ -44,14 +37,3 @@ class GameLogic():
else: else:
return False return False
return True return True
def get_time(self):
return str(datetime.now() - self.startTime)
def reset_time(self):
self.startTime = datetime.now()
def get_score(self):
return self.score

View File

@ -1,7 +1,8 @@
from tkinter import * from tkinter import *
from GameLogic import * from GameLogic import *
VERSION_NUMBER = "0.1"
root = Tk() root = Tk()
root.title("Tic-Far-Toe v0.1") root.title("Tic-Far-Toe v{}".format(VERSION_NUMBER))
root.mainloop() root.mainloop()

View File

@ -1,8 +1,9 @@
class Player(): class Player():
def __init__(self, name): def __init__(self, name, personalScore=0):
self.name = name self.name = name
self.markList = [] self.markList = []
self.personalScore = personalScore
def __str__(self): def __str__(self):
return "Player " + self.name + ': ' + "\n " + str(self.markList) return "Player " + self.name + ': ' + "\n " + str(self.markList)
@ -18,7 +19,7 @@ class Player():
def add_mark(self, x, y): def add_mark(self, x, y):
self.markList.append((x, y)) self.markList.append((x, y))
self.personalScore += 10
def clear_mark_list(): def clear_mark_list():
self.markList = [] self.markList = []

18
Timer.py Normal file
View File

@ -0,0 +1,18 @@
from datetime import datetime, time
class Timer():
def __init__(self):
self.startTime = 0
def has_second_passed(self):
return self.get_time() > 1
def get_time(self):
return str(datetime.now() - self.startTime)
def reset_time(self):
self.startTime = datetime.now()

View File

@ -20,7 +20,7 @@ glogic = GameLogic(GameMap, playerList)
print(glogic.check_who_win()) print(glogic.check_who_win())
# AAAAAAAAAAAA I AM GOING INSANE OVER THIS BULLSHIELD # AAAAAAAAAAAA I AM GOING INSANE OVER THIS BULLSHIELD
# Outdated this message is, I just work with tuple[0] and tuple[1]. # Outdated this message is, I will just work with tuple[0] and tuple[1].
# ---- # ----
# Anyway, a reminder when you'll get to the web - figure out how to manipulate # Anyway, a reminder when you'll get to the web - figure out how to manipulate
# tuples (or replace them altogether) so they'll behave like math matrices - # tuples (or replace them altogether) so they'll behave like math matrices -