Compare commits
No commits in common. "d329c0f7ab378164498c943ade1bc52dbbf029e9" and "418420063ac0878f492d9bfb90a3272a8209a0e0" have entirely different histories.
d329c0f7ab
...
418420063a
2
.gitignore
vendored
2
.gitignore
vendored
@ -0,0 +1,2 @@
|
||||
|
||||
tester.py
|
31
GameLogic.py
31
GameLogic.py
@ -5,13 +5,14 @@ from Player import *
|
||||
|
||||
class GameLogic():
|
||||
|
||||
def __init__(self, gameMap, playerList, winRowLength = 3, individualMoves = 1):
|
||||
def __init__(self, gameMap, playerList, winRowLength, individualMoves):
|
||||
|
||||
self.gameMap = gameMap
|
||||
self.playerList = playerList
|
||||
self.winRowLength = winRowLength
|
||||
self.individualMoves = individualMoves
|
||||
self.score = 0
|
||||
|
||||
self.wait_for_input()
|
||||
|
||||
|
||||
@ -19,31 +20,9 @@ class GameLogic():
|
||||
pass
|
||||
|
||||
|
||||
def check_who_win(self):
|
||||
# Should have used vectors instead of committing tuples mithosis,
|
||||
# but whatever, it works anyway, and if it works, why code more
|
||||
# for nothing?
|
||||
for player in self.playerList:
|
||||
markList = player.get_markList()
|
||||
# since every mark is checked, there's no need to go into
|
||||
# opposite directions, so, there is (0,1) but no (0, -1).
|
||||
# This twice decreases the amount of computation needed.
|
||||
# maybe TODO - Optimize even more by preventing repeated calculations.
|
||||
directions = ((0, 1), (1, 0), (1,1), (-1, 1))
|
||||
for mark in markList:
|
||||
for direction in directions:
|
||||
if self.is_line(markList, mark, direction):
|
||||
return player
|
||||
return False
|
||||
|
||||
def is_line(self, markList, mark, direction): # INTERNAL, I guess.
|
||||
for i in range(1, self.winRowLength):
|
||||
seeked = (mark[0] + direction[0] * i, mark[1] + direction[1] * i)
|
||||
if seeked in markList:
|
||||
continue
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
def check_for_win(self, playerList):
|
||||
for player in playerList:
|
||||
pass
|
||||
|
||||
def get_time(self):
|
||||
return str(datetime.now() - self.startTime)
|
||||
|
@ -18,17 +18,15 @@ class GameMap:
|
||||
|
||||
|
||||
def add_mark(self, x, y, player):
|
||||
# Can be 0 or can be a max value, so,
|
||||
# this is border-inclusive.
|
||||
if (x <= self.max_size_x and y <= self.max_size_y) and (x >= 0 and y >= 0):
|
||||
if (x, y) not in self.data:
|
||||
self.data[(x,y)] = player
|
||||
player.add_mark(x,y)
|
||||
player.add_mark((x,y))
|
||||
else:
|
||||
errorMessage = "The mark is already busy by the player '" + str(self.data[(x, y)].get_name()) + "'"
|
||||
errorMessage = "The mark is already busy by the Player " + str(self.data[(x, y)].get_name())
|
||||
raise KeyError(errorMessage)
|
||||
else:
|
||||
errorMessage = "The mark" + str((x,y)) + " is beyond preset max values or 0, max_x - " + str(self.max_size_x) + ", max_y - " + str(self.max_size_y)
|
||||
errorMessage = "The mark" + str((x,y)) + " is beyond preset max values, max_x - " + str(self.max_size_x) + ", max_y - " + str(self.max_size_y)
|
||||
raise IndexError(errorMessage)
|
||||
|
||||
|
||||
|
7
Main.py
7
Main.py
@ -1,7 +1,2 @@
|
||||
from tkinter import *
|
||||
import pygame
|
||||
from GameLogic import *
|
||||
|
||||
root = Tk()
|
||||
root.title("Tic-Far-Toe v0.1")
|
||||
|
||||
root.mainloop()
|
@ -8,17 +8,9 @@ class Player():
|
||||
return "Player " + self.name + ': ' + "\n " + str(self.markList)
|
||||
|
||||
|
||||
def get_markList(self):
|
||||
return self.markList
|
||||
|
||||
|
||||
def get_name(self):
|
||||
return self.name
|
||||
|
||||
|
||||
def add_mark(self, x, y):
|
||||
self.markList.append((x, y))
|
||||
|
||||
|
||||
def clear_mark_list():
|
||||
self.markList = []
|
27
tester.py
27
tester.py
@ -1,27 +0,0 @@
|
||||
from GameLogic import *
|
||||
from unittest import *
|
||||
|
||||
gmap = GameMap(10, 10)
|
||||
player1 = Player("first")
|
||||
player2 = Player("second")
|
||||
playerList = [player1, player2]
|
||||
|
||||
gmap.add_mark(4, 4, player1)
|
||||
gmap.add_mark(4, 5, player1)
|
||||
gmap.add_mark(4, 6, player1)
|
||||
gmap.add_mark(10, 10, player2)
|
||||
|
||||
gmap = gameMap(5, 5)
|
||||
print(gmap)
|
||||
print(player1)
|
||||
print(player2)
|
||||
|
||||
glogic = GameLogic(GameMap, playerList)
|
||||
print(glogic.check_who_win())
|
||||
# AAAAAAAAAAAA I AM GOING INSANE OVER THIS BULLSHIELD
|
||||
|
||||
# Outdated this message is, I just work with tuple[0] and tuple[1].
|
||||
# ----
|
||||
# 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 -
|
||||
# as in, (4, 4) * 2 -> (8, 8), and as in, (4, 4) + (-2, 3) -> (2, 7)
|
Loading…
Reference in New Issue
Block a user