Compare commits
10 Commits
d329c0f7ab
...
69ce05886d
Author | SHA1 | Date | |
---|---|---|---|
69ce05886d | |||
e53fd7236c | |||
cb8036bc6d | |||
00da6deb24 | |||
00daf53fae | |||
446ffba554 | |||
9c9db7aba9 | |||
7b486881d9 | |||
b11f77f7ef | |||
54a0f42137 |
28
GameLogic.py
28
GameLogic.py
@ -1,23 +1,16 @@
|
|||||||
from datetime import datetime, time
|
|
||||||
|
|
||||||
from GameMap import *
|
from GameMap import *
|
||||||
from Player import *
|
from Player import *
|
||||||
|
from Timer import *
|
||||||
|
|
||||||
class GameLogic():
|
class GameLogic():
|
||||||
|
|
||||||
def __init__(self, gameMap, playerList, winRowLength = 3, individualMoves = 1):
|
def __init__(self, gameMap, playerList, winRowLength=3, individualMoves=1):
|
||||||
|
|
||||||
self.gameMap = gameMap
|
self.gameMap = gameMap
|
||||||
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
|
|
3
Main.py
3
Main.py
@ -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()
|
@ -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
18
Timer.py
Normal 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()
|
@ -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 -
|
||||||
|
Loading…
Reference in New Issue
Block a user