-
-
Save Epitaph64/2bee5c5bb42ed91578b3 to your computer and use it in GitHub Desktop.
Casino Game
This file contains 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 unicurses import * | |
from objects import * | |
from text import * | |
def atm(player, currentRoom): | |
clear() | |
attron(COLOR_PAIR(4)) | |
draw_info(player, currentRoom) | |
for i in range(76): | |
mvaddch(3, i+2, CCHAR('$')) | |
mvaddch(9, i+2, CCHAR('$')) | |
printCenter(5, 'THANK YOU FOR CHOOSING BANK OF MONEY') | |
printCenter(7, 'YOU HAVE ${:,.2f} REMAINING IN YOUR ACCOUNT'.format(player.bank)) | |
attron(A_BOLD) | |
printCenter(11, 'HELPFUL TIPS') | |
attroff(A_BOLD) | |
printCenter(13, 'Withdraw - Withdraws an amount (ex: withdraw 100)') | |
printCenter(14, 'Deposit - Deposits an amount (ex: deposit 250)') | |
printCenter(15, 'Logout - Log out of your account.') | |
while True: | |
draw_info(player, currentRoom) | |
printCenter(7, 'YOU HAVE ${:,.2f} REMAINING IN YOUR ACCOUNT'.format(player.bank)) | |
printLine(23, ' INPUT: ') | |
input = getstr() | |
input = input.lower().split() | |
terms = len(input) | |
if terms > 0: | |
if input[0] == 'leave': | |
printCenter(20, 'Are you really going to leave without logging out?') | |
elif input[0] == 'logout': | |
attroff(COLOR_PAIR(4)) | |
break | |
elif input[0] == 'deposit': | |
if terms > 1 and input[1].isdigit(): | |
deposit = int(input[1]) | |
if deposit <= player.money: | |
player.money -= deposit | |
player.bank += deposit | |
printCenter(20, "I just deposited ${:,.2f}.".format(deposit)) | |
else: | |
printCenter(20, "I don't have that much.") | |
else: | |
if terms <= 1: | |
printCenter(20, "Use what?") | |
else: | |
printCenter(20, "Please enter an integer.") | |
elif input[0] == 'withdraw': | |
if terms > 1 and input[1].isdigit(): | |
withdrawal = int(input[1]) | |
if withdrawal <= player.bank: | |
player.bank -= withdrawal | |
player.money += withdrawal | |
printCenter(20, "I just withdrew ${:,.2f}.".format(withdrawal)) | |
else: | |
printCenter(20, "I don't have that much money in my account.") | |
else: | |
if terms <= 1: | |
printCenter(20, "Use what?") | |
else: | |
printCenter(20, "Please enter an integer.") | |
else: | |
printCenter(20, "Command {0} not recognized".format(input[0])) | |
return | |
This file contains 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 unicurses import * | |
from text import * | |
from objects import * | |
from atm import * | |
from slots import * | |
#Global constants | |
const_map_width = 10 | |
const_map_height = 10 | |
#Global object declaration | |
stdscr = initscr() | |
player = Player([4, 4], 500.00) | |
floorPlan = {} | |
def addRoom(room): | |
floorPlan[(room.x, room.y)] = room | |
for x in range(0, 10): | |
for y in range(0, 10): | |
floorPlan[(x, y)] = None | |
#Room floor plan: | |
# lounge | |
#food main slots | |
room_Main = Room('Main Room', 4, 4) | |
room_Main.hasChair = True | |
room_Slots = Room('Slots', 5, 4) | |
room_Slots.hasSlots = True | |
room_Lounge = Room('Lounge', 5, 3) | |
room_Lounge.locked = True | |
room_Food = Room('Food Court', 3, 4) | |
room_Food.hasATM = True | |
room_Garden = Room('Garden', 4, 5) | |
room_Garden.isOutside = True | |
addRoom(room_Main) | |
addRoom(room_Slots) | |
addRoom(room_Lounge) | |
addRoom(room_Food) | |
addRoom(room_Garden) | |
currentRoom = floorPlan[(player.x, player.y)] | |
def changeRoom(x, y): | |
global player, currentRoom, messages | |
horzOk = False | |
vertOk = False | |
if y > 0: | |
if player.y < const_map_height - 1: | |
vertOk = True | |
elif y < 0: | |
if player.y > 0: | |
vertOk = True | |
if x > 0: | |
if player.x < const_map_width - 1: | |
horzOk = True | |
elif x < 0: | |
if player.x > 0: | |
horzOk = True | |
if horzOk or vertOk: | |
room = floorPlan[(player.x + x, player.y + y)] | |
if room: | |
if room.locked: | |
if room.name == 'Lounge' and player.hasRedKeyCard: | |
post('You insert your red key card into the door and it opens!') | |
room.locked = False | |
else: | |
post('It seems like the door leading to the {0} is locked.'.format(floorPlan[(player.x + x, player.y + y)].name)) | |
return | |
else: | |
player.x += x | |
player.y += y | |
currentRoom = floorPlan[(player.x, player.y)] | |
messages = [] | |
return | |
post('I cannot go that direction from here.') | |
def useObject(objectName): | |
if objectName == 'atm': | |
if currentRoom.hasATM: | |
atm(player, currentRoom) | |
else: | |
post('There is no ATM machine in sight.') | |
elif objectName == 'slots': | |
if currentRoom.hasSlots: | |
slots(player, currentRoom) | |
else: | |
post('There is no slot machine in sight.') | |
elif objectName == 'chair': | |
if currentRoom.hasChair: | |
post('You sit down in a chair') | |
else: | |
post("You don't see a chair to sit in.") | |
else: | |
post("I don't see a {0}.".format(input[1])) | |
def userInput(): | |
global player, currentRoom, messages | |
printLine(23, ' INPUT: ') | |
input = getstr() | |
input = input.split() | |
terms = len(input) | |
if terms > 0: | |
input[0] = input[0].lower() | |
if input[0] == 'go': | |
post('To move: Type a letter that corresponds with') | |
post('the cardinal direction you want to go') | |
elif input[0] == 'n': | |
changeRoom(0, -1) | |
elif input[0] == 'e': | |
changeRoom(1, 0) | |
elif input[0] == 's': | |
changeRoom(0, 1) | |
elif input[0] == 'w': | |
changeRoom(-1, 0) | |
elif input[0] == 'look': | |
itemsOfInterest = 0 | |
if currentRoom.hasSlots: | |
post('You see a slot machine in the corner of the room') | |
itemsOfInterest += 1 | |
if currentRoom.hasChair: | |
post("There's a vacant chair against the wall") | |
itemsOfInterest += 1 | |
if currentRoom.hasATM: | |
post("An ATM machine stands tall against the wall") | |
itemsOfInterest += 1 | |
if itemsOfInterest == 0: | |
post("You see nothing of interest here.") | |
elif input[0] == 'use': | |
if terms > 1: | |
input[1] = input[1].lower() | |
useObject(input[1]) | |
else: | |
post('Use what?') | |
elif input[0] == 'help': | |
draw_help() | |
elif input[0] == 'shout': | |
if terms > 1: | |
post('You shout "{0}" at the top of your lungs.'.format(' '.join(input[1:]))) | |
else: | |
post('You shout to the heavens!') | |
elif input[0] == 'say': | |
if terms > 1: | |
post('"{0}"'.format(' '.join(input[1:]))) | |
else: | |
post('You say nothing.') | |
elif input[0] == 'rest': | |
post('You lie down on the cold floor') | |
elif input[0] == 'sit': | |
if currentRoom.hasChair: | |
post('You sit down in a chair') | |
else: | |
post('You sit down on the floor') | |
elif input[0] == 'eat': | |
if terms > 1: | |
input[1] = input[1].lower() | |
a = 'a' | |
if input[1][0] in ['a','e','i','o','u']: a = 'an' | |
post("You don't have {0} {1} to eat.".format(a, input[1])) | |
else: | |
post('Eat what?') | |
elif input[0] == 'exit' or input[0] == 'leave': | |
clear() | |
if player.money + player.bank > 0: | |
printCenter(7, "You leave the casino with a net worth of ${:,.2f}!".format(player.money + player.bank)) | |
else: | |
printCenter(7, "You leave the casino empty handed...".format(player.money)) | |
getch() | |
return 'exit' | |
else: | |
post('Command {0} not recognized.'.format(input[0])) | |
def game(): | |
global player, currentRoom, messages | |
clear() | |
input = "" | |
terms = 0 | |
while True: | |
clearBox(0, 0, 80, 23) | |
currentRoom.draw(floorPlan) | |
draw_info(player, currentRoom) | |
drawMessages() | |
if userInput() == 'exit': | |
break | |
def main(): | |
# noecho() | |
curs_set(0) | |
keypad(stdscr, True) | |
nodelay(stdscr, True) | |
splash(player) | |
nodelay(stdscr, False) | |
init_color(COLOR_RED, 700, 0, 0) | |
start_color() | |
init_pair(1, COLOR_YELLOW, COLOR_BLACK) | |
init_pair(2, COLOR_WHITE, COLOR_BLACK) | |
init_pair(3, COLOR_RED, COLOR_BLACK) | |
init_pair(4, COLOR_GREEN, COLOR_BLACK) | |
init_pair(5, COLOR_BLUE, COLOR_BLACK) | |
game() | |
clear() | |
attron(A_BOLD) | |
refresh() | |
clear() | |
refresh() | |
endwin() | |
#playAgain = raw_input('\nPlay Again?: ') | |
#playAgain = playAgain.lower() | |
#if len(playAgain) > 0 and playAgain[0] == 'y': | |
# main() | |
if __name__ == '__main__': | |
main() |
This file contains 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 unicurses import * | |
from text import * | |
class Player: | |
hasRedKeyCard = False | |
wins = 0 | |
loss = 0 | |
money = 0 | |
x = 0 | |
y = 0 | |
bank = 1000.00 | |
def __init__(self, location, money): | |
self.x = location[0] | |
self.y = location[1] | |
self.money = money | |
class Room: | |
name = 'Name' | |
locked = False | |
x = 0 | |
y = 0 | |
hasATM = False | |
hasSlots = False | |
hasChair = False | |
isOutside = False | |
def draw(self, map): | |
clearBox(2, 3, 75, 15) | |
if self.hasATM: | |
drawBox(10, 4, 8, 3, CCHAR('+')) | |
mvaddstr(5, 13, 'ATM') | |
if self.hasSlots: | |
drawBox(55, 4, 8, 3, CCHAR('+')) | |
mvaddstr(5, 57, 'SLOTS') | |
if self.hasChair: | |
drawBox(55, 14, 8, 3, CCHAR('+')) | |
mvaddstr(15, 57, 'CHAIR') | |
if (self.isOutside): | |
drawBox(2, 3, 75, 15, CCHAR('.')) | |
mvaddch(7, 13, CCHAR('^')) | |
mvaddch(5, 51, CCHAR('^')) | |
mvaddch(13, 9, CCHAR('^')) | |
mvaddch(12, 41, CCHAR('^')) | |
mvaddch(16, 72, CCHAR('^')) | |
else: | |
drawBox(2, 3, 75, 15, CCHAR('#')) | |
attron(A_BOLD) | |
if self.y > 0 and map[(self.x, self.y-1)]: | |
printCenterNoClear(3, 1, 78, ' ' + map[(self.x, self.y-1)].name.upper() + ' ') | |
if self.y < 9 and map[(self.x, self.y+1)]: | |
printCenterNoClear(18, 1, 78, ' ' + map[(self.x, self.y+1)].name.upper() + ' ') | |
if self.x > 0 and map[(self.x-1, self.y)]: | |
westName = ' ' + map[(self.x-1, self.y)].name.upper() + ' ' | |
for i in range(len(westName)): | |
mvaddch(11 - len(westName) / 2 + i, 2, CCHAR(westName[i])) | |
if self.x < 9 and map[(self.x+1, self.y)]: | |
eastName = ' ' + map[(self.x+1, self.y)].name.upper() + ' ' | |
for i in range(len(eastName)): | |
mvaddch(11 - len(eastName) / 2 + i, 77, CCHAR(eastName[i])) | |
attroff(A_BOLD) | |
def __init__(self, name, x, y): | |
self.name = name | |
self.x = x | |
self.y = y | |
This file contains 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 unicurses import * | |
from objects import * | |
from text import * | |
import random | |
def slots(player, currentRoom): | |
clear() | |
playing = 1 | |
printCenter(20, "Wager some cash with 'bet' to play!") | |
while playing == 1: | |
player.location = 'Slot Machines' | |
aSlot = random.randint(1, 9) | |
bSlot = random.randint(1, 9) | |
cSlot = random.randint(1, 9) | |
wager = 0 | |
play = 0 | |
drawBox(27, 4, 26, 10, CCHAR('#')) | |
attron(A_BOLD) | |
drawBox(29, 6, 6, 6, CCHAR('#')) | |
drawBox(37, 6, 6, 6, CCHAR('#')) | |
drawBox(45, 6, 6, 6, CCHAR('#')) | |
attroff(A_BOLD) | |
while True: | |
draw_info(player, currentRoom) | |
printLine(23, ' INPUT: ') | |
input = getstr() | |
input = input.lower().split() | |
terms = len(input) | |
if terms > 0: | |
if input[0] == 'help': | |
printCenter(19, 'insert (x) to make a bet.') | |
printCenter(20, 'leave to return to Main Room.') | |
elif input[0] == 'bet': | |
if terms > 1: | |
if input[1].isdigit() and int(input[1]) > 0: | |
wager = int(input[1]) | |
if wager <= player.money: | |
printCenter(19, 'You put ${0:.2f}.00 into the machine'.format(wager)) | |
play = 1 | |
break | |
else: | |
printCenter(20, "You don't have that much money!") | |
else: | |
printCenter(20, 'Please enter a positive integer amount') | |
elif input[0] == 'leave': | |
clear() | |
printCenter(20, 'You head back to the main room.') | |
player.location = 'Main Room' | |
break | |
else: | |
printCenter(20, "Command {0} not recognized".format(input[0])) | |
if play == 0: | |
playing = 0 | |
return | |
attron(A_BOLD) | |
attron(COLOR_PAIR(1)) | |
mvaddstr(9, 32, '{0} {1} {2}'.format(aSlot, bSlot, cSlot)) | |
attroff(A_BOLD) | |
attroff(COLOR_PAIR(1)) | |
#remove wager from player's money | |
player.money = player.money - wager | |
if aSlot == bSlot == cSlot: | |
wager = wager * (aSlot+1) | |
printCenter(17, 'Jackpot! You won ${0:.2f}!'.format(wager)) | |
player.money = player.money + wager | |
if player.hasRedKeyCard == False and wager >= 500: | |
printCenter(18, "Welcome to the Winner's Circle!") | |
printCenter(19, 'You are given a red key card to access the lounge!') | |
player.hasRedKeyCard = True | |
else: | |
move(19, 0) | |
clrtoeol() | |
move(20, 0) | |
clrtoeol() | |
elif aSlot == bSlot or bSlot == cSlot or aSlot == cSlot and wager > 1: | |
wager = wager * 1.5 | |
printCenter(17, 'You won a small prize of ${0:.2f}!'.format(wager)) | |
player.money = player.money + wager | |
move(19, 0) | |
clrtoeol() | |
move(20, 0) | |
clrtoeol() | |
else: | |
printCenter(17, 'You lose your wager! (-${0:.2f})'.format(wager)) | |
move(18, 0) | |
clrtoeol() | |
move(19, 0) | |
clrtoeol() |
This file contains 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 unicurses import * | |
messages = [] | |
def clearBox(x, y, width, height): | |
for i in range(width): | |
for j in range(height): | |
mvaddch(y+j, x+i, CCHAR(' ')) | |
def drawBox(x, y, width, height, char): | |
for i in range(height+1): | |
mvaddch(y+i, x, char) | |
mvaddch(y+i, x+width, char) | |
for i in range(width): | |
mvaddch(y, x+i, CCHAR(char)) | |
mvaddch(y+height, x+i, CCHAR(char)) | |
def fillBox(x, y, width, height, char): | |
for i in range(height): | |
for j in range(width): | |
mvaddch(i+y, j+x, char) | |
def printLine(line, str): | |
mvaddstr(line, 0, str) | |
clrtoeol() | |
def printCenter(line, str): | |
move(line, 0) | |
clrtoeol() | |
mvaddstr(line, 40 - (len(str) / 2), str) | |
def printCenter2(line, start, length, str): | |
move(line, 0) | |
for i in range(length): | |
mvaddch(line, start + i, CCHAR(' ')) | |
mvaddstr(line, length / 2 - len(str) / 2 + start, str) | |
def printCenterNoClear(line, start, length, str): | |
mvaddstr(line, length / 2 - len(str) / 2 + start, str) | |
def draw_info(player, currentRoom): | |
attron(A_BOLD) | |
printCenter(0, 'Location: {0}'.format(currentRoom.name)) | |
printCenter(1, 'Money: ${:,.2f}'.format(player.money)) | |
attroff(A_BOLD) | |
def post(str): | |
global messages | |
messages = messages[len(messages)-7:] | |
messages.append(str) | |
def drawMessages(): | |
line = 19 | |
for message in messages: | |
printCenter(line, message) | |
line += 1 | |
if line > 22: break | |
def draw_directions(north, east, south, west): | |
for i in range(78): | |
mvaddch(4, i+1, CCHAR('-')) | |
mvaddch(5, i+1, CCHAR('_')) | |
mvaddch(11, i+1, CCHAR('_')) | |
attron(A_BOLD) | |
printCenterNoClear(4, 0, 40, 'Name') | |
printCenterNoClear(4, 40, 40, 'Direction') | |
attroff(A_BOLD) | |
printCenter2(7, 0, 40, north) | |
printCenter2(7, 40, 40, 'North') | |
printCenter2(8, 0, 40, east) | |
printCenter2(8, 40, 40, 'East') | |
printCenter2(9, 0, 40, south) | |
printCenter2(9, 40, 40, 'West') | |
printCenter2(10, 0, 40, west) | |
printCenter2(10, 40, 40, 'South') | |
for i in range(8): | |
mvaddch(i+4, 1, CCHAR('.')) | |
mvaddch(i+4, 78, CCHAR('.')) | |
def draw_help(): | |
clear() | |
attron(A_BOLD) | |
printCenter(3, 'COMMANDS') | |
printCenter(9, 'TIPS') | |
attroff(A_BOLD) | |
printCenter(5, 'N, E, S, W - Move in that direction') | |
printCenter(6, 'Use - Attempt to use a specific object or function (if able)') | |
printCenter(7, 'Help - Display this screen.') | |
printCenter(10, 'Money - A useful commodity in a casino indeed! You want to get as much of it as possible.') | |
printCenter(11, 'There are random events that can occur.') | |
printCenter(12, 'Be perceptive of any notices given to you') | |
getch() | |
def splash(player): | |
clear() | |
timer = 0 | |
redraw = 1 | |
while True: | |
k = getch() | |
if k > 0: | |
break | |
else: | |
timer += 1 | |
if timer > 9000: | |
attron(A_BOLD) | |
redraw = 1 | |
if redraw: | |
#title text | |
printCenter(3, '#### #### #### # #### ####') | |
printCenter(4, '# # # # # # # # #') | |
printCenter(5, '# #### #### # # # # #') | |
printCenter(6, '# # # # # # # # #') | |
printCenter(7, '#### # # #### # # # ####') | |
attron(A_BOLD) | |
#version number | |
attroff(A_BOLD) | |
printCenter(1, '==---==---==---==---==---==--==') | |
printCenter(9, '==---==---==---==---==---==--==') | |
mvaddstr(9, 53, 'r3') | |
printCenter(12, 'Welcome to the Casino!') | |
printCenter(13, 'You have ${:,.2f} in hand and are ready to win it big!'.format(player.money)) | |
printCenter(14, "You can withdraw more from an ATM but don't forget you have bills to pay...") | |
redraw = 0 | |
if timer > 10000: | |
timer = 0 | |
redraw = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment