Skip to content

Commit

Permalink
added input functionality to board
Browse files Browse the repository at this point in the history
  • Loading branch information
victorknox committed Mar 10, 2022
1 parent 865ebc0 commit 44a65d4
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 16 deletions.
Binary file added __pycache__/Board.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/Building.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/input.cpython-39.pyc
Binary file not shown.
27 changes: 27 additions & 0 deletions game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import random
from src.board import *
from src.building import *
from src.input import *

def main():

board = Board()
while(True):
os.system('clear')
board.display()
ip = input_to()
if(ip == 'q'):
os.system('clear')
exit()
else:
print(ip)
print("Invalid Move!")
# pass





if __name__ == "__main__":
main()
12 changes: 0 additions & 12 deletions main.py

This file was deleted.

Binary file added src/__pycache__/board.cpython-310.pyc
Binary file not shown.
Binary file added src/__pycache__/building.cpython-310.pyc
Binary file not shown.
Binary file added src/__pycache__/input.cpython-310.pyc
Binary file not shown.
11 changes: 9 additions & 2 deletions Board.py → src/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,12 @@ def display(self):
for row in self.content:
print(''.join(row))

def update(self):
pass
def update(self, building):
for row in range(building.height):
self.content[building.y + row][building.x: building.x + building.length] = building.content[row]
# for row in range(building.height):
# for col in range(building.length):
# self.content[building.y + row][building.x + col] = building.content[row][col]
# for row in range(building.height):
# for col in range(building.length):
# self.content[building.y + row][building.x + col] = building.content[row][col]
46 changes: 46 additions & 0 deletions src/building.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
from colorama import Fore, Back, Style, init

init()



class Building:
def __init__(self, height, length, health):
self.health = health
self.height = height
self.length = length
self.content = [[Fore.GREEN + 'X']*self.length for tile in range(self.height)]

def attacked(self):
self.health -= 1
if self.health == 0:
self.destroy()

def destroy(self):
self.content = [[' ']*self.length for tile in range(self.height)]

def update_color(self, color):
for row in self.content:
for i in range(len(row)):
row[i] = color + row[i] + Fore.RESET

class Spawn(Building):
def __init__(self, height, length, health):
super().__init__(height, length, health)
self.content = [[Fore.BLUE + 'S']*self.length for tile in range(self.height)]

class TownHall(Building):
def __init__(self, height, length, health):
super().__init__(height, length, health)
self.content = [[Fore.YELLOW + 'T']*self.length for tile in range(self.height)]

class Hut(Building):
def __init__(self, height, length, health):
super().__init__(height, length, health)
self.content = [[Fore.RED + 'H']*self.length for tile in range(self.height)]

class Wall(Building):
def __init__(self, height, length, health):
super().__init__(height, length, health)
self.content = [['X']*self.length for tile in range(self.height)]
4 changes: 2 additions & 2 deletions input.py → src/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def alarmHandler(signum, frame):
raise AlarmException


def input_to(getch, timeout=0.1):
def input_to(timeout=0.1):
"""Taking input from user."""
signal.signal(signal.SIGALRM, alarmHandler)
signal.setitimer(signal.ITIMER_REAL, timeout)
try:
text = getch()
text = Get()()
signal.alarm(0)
return text
except AlarmException:
Expand Down

0 comments on commit 44a65d4

Please sign in to comment.