Skip to content

Commit

Permalink
Lab_assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
radmosley committed Dec 15, 2017
1 parent 48c9a97 commit 87173aa
Show file tree
Hide file tree
Showing 56 changed files with 1,550 additions and 0 deletions.
Empty file added github_for_beginners/github.py
Empty file.
Empty file.
37 changes: 37 additions & 0 deletions lab_assignments/adventure_fun_time.py/actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import player


class Action():
def __init__(self, method, name, hotkey, **kwargs):
self.method = method
self.hotkey = hotkey
self.name = name
self.kwargs = kwargs

def __str__(self):
return"{}: {}".format(self.hotkey, self.name)

class Up(Action):
def __init__(self):
super().__init__(method = Player.up, name = 'Move Up', hotkey = 'w')

class Down(Action):
def __init__(self):
super().__init__(method = Player.down, name = 'Move Down', hotkey = 's')

class Left(Action):
def __init__(self):
super().__init__(method = Player.left, name = 'Move Left', hotkey = 'a')

class Right(Action):
def __init__(self):
super().__init__(method = Player.move_right, name = 'Move Right', hotkey = 'd')

class ViewInventory(Action):
"""Prints the player's inventory"""
def __init__(self):
super().__init(method = Player.print_inventory, name ='view inventory', hotkey='i')

class Attack(Action):
def __init__(self, Creature):
super().__init__(method = Player.attack, name ='Attack', hotkey='a', creature = Creature)
4 changes: 4 additions & 0 deletions lab_assignments/adventure_fun_time.py/credit_card.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
print('What is your credit card number? ')
card_number = list(input())

print(card_number)
23 changes: 23 additions & 0 deletions lab_assignments/adventure_fun_time.py/game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import world
from player import Player

def play():
world.load_tiles()
player = Player()
while player.is_alive() and not player.victory:
room = world.tile_exists(player.location_x, player.location_y)
room.modify_player(player)
#Check again since the room could have change
if player.is_alive() and not player.victory:
print("Choose an action: \n")
available_actions = room.available_actions()
for action in available_actions = room.available_actions():
print(action)
action_input = input('Action: ').lower()
for action in available_actions:
if action_input == action.hotkey:
player.do_action(action, **action.kwargs)
break

if __name__ = '__main__':
play()
78 changes: 78 additions & 0 deletions lab_assignments/adventure_fun_time.py/game_parts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import random

class Item:
def __init__(self, name, description):
self.name = name
self.description = description

def __str__(self):
return "{}\n=====\n{}\n".format(self.name, self.description)

class Weapon(Item):
def __init__(name, atk, loc):
self.dmg = dmg
super().__init(name, description, value)

def __str__(self):
return "{}\n=====\nDamage: {}".format(self.name, self.description, self.damage)
class r_sword(Weapon):
def __init(self):
super().__init__(
name = 'Ruby Sword'
description = "A sword that shines with a red glow."
dmg = 10)

class c_sword(Weapon):
def __init__(self):
super().__init__(
name = 'Cobalt Sword'
description = "A sword that shines with a blue glow."
dmg = 20)

class d_sword(Weapon):
def __init__(self):
super().__init__(
name = 'Diamond Sword'
description = "A sword that shines with a white glow."
dmg = 30
)
class Potion(Item):
def __init__(health_plus):
self.health_plus = health_plus
super()__init__(
name = 'Health Potion'
description = 'Increase health points by 10 pts'
)

class Creature:
def __init__(self, name, hp, atk):
self.name = name
self.healthpoints = hp
self.attack = atk

def is_alive(self):
return self.healthpoints > 0

class red_dragon(Creature):
def __init__(self):
super().__init__(
name = "Red Dragon"
hp = 100
atk = 20
)

class Blue_dragon(Creature):
def __init__(self):
super().__init__(
name = "Blue Dragon"
hp = 125
atk = 30
)

class Black_dragon(Creature):
def __init__(self):
super().__init__(
name = "Black Dragon"
hp = 150
atk = 50
)
51 changes: 51 additions & 0 deletions lab_assignments/adventure_fun_time.py/player.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import game_parts

class Player():
def __init__(self):
self.inventory = [Item.r_sword(), Item.Potion()]
self.hp = 100
self.location_x, self.location_y = world.starting_position
self.victory = False

def is_alive(self):
return self.hp > 0

def print_inventory(self):
for item in self.inventory:
print(item, '\n')
def move(self, dx, dy):
self.location_x += dx
self.location_y = dy
print(world.tile_exists(self.location_x, self.location_y).intro_text())

def move_up(self):
self.move(dx=0, dy=-1)

def move_down(self):
self.move(dx=0, dy=-1)

def move_left(self):
self.move(dx=1, dy=0)

def move_right(self):
self.move(dx=-1, dy=0)

def attack(self, enemy):
best_weapon = None
max_dmg = 0
for i in self.inventory:
if isinstance(i, Item.Weapon):
if i.damage > max_dmg:
best_weapon = i
print("You use {} against {}!".format(best_weapon.name, enemy.name))
enemy.hp -= best_weapon.damage
if not enemy.is_alive():
print("you Killed {}!".format(enemy.name))

def do_action(self, action, **kwargs):
action_method = getattr(self, action.method.__name__)
if action_method:
action_method(**kwargs)

else:
print("{}HP is {}.".format(enemy.name, enemy.hp))
164 changes: 164 additions & 0 deletions lab_assignments/adventure_fun_time.py/tiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import Weapon, Item, Creature, World

class MapTiles:
def __init__(self, x, y):
self.x = x
self.y = y

def intro_text(self):
raise NotImplementedError()

def modify_player(self, player):
raise NotImplementedError()

def adjacent_moves(self):
if world.tile_exists(self.x + 1, self.y):
moves.append(actions.left())

if world.tile_exists(self.x - 1, self.y):
moves.append(actions.right())

if world.tile_exists(self.x, self.y - 1):
moves.append(actions.up())

if world.tile_exists(self.x, self.y +1):
moves.append(actions.down())

return moves
def available_actions(self):
"""Returns all of the Available actions in this room
"""
moves = self.adjacent_moves()
moves.append(action.ViewInventory())
return moves

class StartRoom(MapTiles):
def intro_text(self):
"""
{}, are you awake now?
We were attacked by a {} and now the town is on fire.
While we put out the flames you've got to find that
wretched creature and destroy him!
""".formate(player, creature)

def modify_player(self, player):
#Room has no action on player
pass

class HideItem(MapTile):
def __init__(self, X, y, item):
self.item = item
super().__init__(x, y)

def add_item(self, player):
player.inventory.append(self.item)

def modify_player(self, player):
self.add_item(player)

class HideCreature(MapTile):
def _init__(self, x, y, enemy):
self.enemy = enemy
super().__init__(x, y)

def modify_player(self, the_player):
if self.enemy.is_alive():
the_player.hp = the_player.hp - self.enemy.damage
print("{} does {} damage.\nYou have {} HP remaining.".format(creature.name, self.enemy.damage, the_player.hp))

def available_actions(self):
if self.enemy.is_alive():
the_player.hp = the_player.hp - self.enemy.damage
return [actions.Flee(tile=self), actions.Attack(creature=self.creature)]
else:
return self.adjacent_moves()

class HideRdDragon(HideCreature):
def __init__(self, x, y):
super().__init__(x, y, creatures.red_dragon())

def intro_text(self):
if self.creature.is_alive():
return """
You find yourself face to face with a Red Dragon. It's belly warm with fire
he lets out a deafening screech.
"""
else:
return """
The carcaus is still warm from your previous battle.
"""

class HideBlDragon(HideCreature):
def __init__(self, x, y):
super().__init__(x, y, Creature.blue_dragon())

def intro_text(self):
if self.creature.is_alive():
return """
You find yourself face to face with a Blue Dragon. She doesn't like to be disturbed.
The dragon lunges at you.
"""
else:
return """
The carcaus is still warm from your previous battle.
"""

class HideBlkDragon(HideCreature):
def __init__(self, x, y):
super().__init__(x, y, Creature.black_dragon())

def intro_text(self):
if self.creature.is_alive():
return """
You find yourself face to face with a Black Dragon.
He lays in a valcano that seems to be the fuel for his rage.
"""
else:
return """
The carcaus is still warm from your previous battle.
"""
class HidePotion(HideItem):
def __init__(self, x, y):
super().__init__(x, y, Item.Potion())

def intro_text(self):
return """
You have found a potion, it will bring you back to life.
"""

class HideRdSword(HideItem):
def __init__(self, x, y):
super().__init__(x, y, Item.r_sword())

def intro_text(self):
return """
You have found a sword that shines Red.
"""

class HideCSword(HideItem):
def __init__(self, x, y):
super().__init__(x, y, Item.c_sword())

def intro_text(self):
return """
You have found a sword that shines blue.
"""

class HideDSword(HideItem):
def __init__(self, x, y):
super().__init__(x, y, Item.d_sword())

def intro_text(self):
return """
You have found a sword that shines with a white light.
"""

class Victory(MapTiles):
def intro_text(self):
return """
You have defeated the great dragon and saved our land!
"""

def modify_player(self, player):
player.victory = True
Binary file not shown.
22 changes: 22 additions & 0 deletions lab_assignments/blackjack/blackjack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#Main game file
print('Would you like to start a new game of Black Jack?: Y or N')
start = input().lower()

yes = 'y'
no = 'n'

print('player one score: \n'
'hand: \n'
'cards played: \n')

print('Dealer one score: \n'
'hand: \n' #have the number of cards but remove the value
'cards played: \n')

#Start a new game

#Score a hand

#Bust if the score is over 21

#Bust if the user draws more the 5 cards
Loading

0 comments on commit 87173aa

Please sign in to comment.