Last active
August 26, 2020 12:57
-
-
Save TibebeJS/5616f4073c5d5bf85296573e86a885d6 to your computer and use it in GitHub Desktop.
simple BINGO game in Python - WIP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import shuffle | |
import colorama | |
from pyfiglet import Figlet | |
letters = ['B', 'I', 'N', 'G', 'O'] | |
ranges = [(x * 15, (x + 1)* 15) for x in range(5)] | |
# enter the bomb cells here | |
bombs = ['G3', 'G4'] | |
letter_ranges = dict(zip(letters, ranges)) | |
def generateCol(start, end): | |
num_pool = [num + 1 for num in range(start, end)] | |
shuffle(num_pool) | |
return num_pool[:5] | |
board = [ | |
generateCol(*col_range) for col_range in ranges | |
] | |
def printBoard(): | |
print('----------------------------------------') | |
print(''.join(map(lambda x: f"[{x.center(6, ' ')}]", letters))) | |
print('----------------------------------------') | |
for row_counter in range(5): | |
row = zip(map(lambda a: a[row_counter], board)) | |
for i, y in enumerate(row): | |
if letters[i] + str(row_counter+1) not in bombs: | |
print(f"[{str(y[0]).zfill(2).center(6, ' ' if letters[i]+str(y[0]) not in called_numbers else '*')}]", end='') | |
else: | |
print(f"{colorama.Back.LIGHTRED_EX}[{(str(y[0]) if letters[i]+str(y[0]) not in called_numbers else ' ☠ ' ).zfill(2).center(6, ' ') }]{colorama.Back.RESET}", end='') | |
print() | |
print('----------------------------------------\n') | |
called_numbers = [] | |
def checkBoard(): | |
print("\nCurrent status:") | |
printBoard() | |
def is_valid(new_number): | |
if 3 < len(new_number) < 2: | |
return False | |
col = new_number[0] | |
num = new_number[1:] | |
if col not in letters or not num.isdigit(): | |
print("\n[-] not valid input") | |
return False | |
lower_bound, upper_bound = letter_ranges[col] | |
return lower_bound < int(num) <= upper_bound | |
def main(): | |
colorama.init() | |
print(Figlet(font='slant', width=120).renderText('B I N G O')) | |
print(f"Here is your board: [ {colorama.Back.RED} BOMB CELLS: {', '.join(bombs)} {colorama.Back.RESET} ]", end="\n\n") | |
printBoard() | |
while True: | |
new_number = input("[?] Enter the called number (or '0' to exit): ").upper() | |
if not len(new_number): continue | |
elif new_number == '0': | |
print('[+] exiting...') | |
break | |
if is_valid(new_number): | |
if new_number in called_numbers: | |
print("[-] already called\n") | |
else: | |
print("\n[+] valid input") | |
print("[+] updating board...") | |
called_numbers.append(new_number) | |
checkBoard() | |
else: | |
print("[-] Invalid call\n") | |
if __name__ == '__main__': | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[source]] | |
name = "pypi" | |
url = "https://pypi.org/simple" | |
verify_ssl = true | |
[dev-packages] | |
[packages] | |
colorama = "*" | |
pyfiglet = "*" | |
[requires] | |
python_version = "3.8" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 45:
lower_bound, upper_bound = letter_ranges[new_number[0]]