Compare commits
11 Commits
418420063a
...
d329c0f7ab
Author | SHA1 | Date | |
---|---|---|---|
d329c0f7ab | |||
8bc369c31c | |||
e8236a7e4a | |||
468237429e | |||
ab37e797de | |||
344f2e2909 | |||
bc3d3b59c9 | |||
855e53befe | |||
8dd2035167 | |||
a9b8409928 | |||
5b74ecef52 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
|
||||
tester.py
|
31
GameLogic.py
31
GameLogic.py
@ -5,14 +5,13 @@ from Player import *
|
||||
|
||||
class GameLogic():
|
||||
|
||||
def __init__(self, gameMap, playerList, winRowLength, individualMoves):
|
||||
def __init__(self, gameMap, playerList, winRowLength = 3, individualMoves = 1):
|
||||
|
||||
self.gameMap = gameMap
|
||||
self.playerList = playerList
|
||||
self.winRowLength = winRowLength
|
||||
self.individualMoves = individualMoves
|
||||
self.score = 0
|
||||
|
||||
self.wait_for_input()
|
||||
|
||||
|
||||
@ -20,9 +19,31 @@ class GameLogic():
|
||||
pass
|
||||
|
||||
|
||||
def check_for_win(self, playerList):
|
||||
for player in playerList:
|
||||
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 get_time(self):
|
||||
return str(datetime.now() - self.startTime)
|
||||
|
@ -18,15 +18,17 @@ 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, 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 or 0, max_x - " + str(self.max_size_x) + ", max_y - " + str(self.max_size_y)
|
||||
raise IndexError(errorMessage)
|
||||
|
||||
|
||||
|
7
Main.py
7
Main.py
@ -1,2 +1,7 @@
|
||||
import pygame
|
||||
from tkinter import *
|
||||
from GameLogic import *
|
||||
|
||||
root = Tk()
|
||||
root.title("Tic-Far-Toe v0.1")
|
||||
|
||||
root.mainloop()
|
@ -8,9 +8,17 @@ 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
Normal file
27
tester.py
Normal file
@ -0,0 +1,27 @@
|
||||
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