Files
2026-01-02 12:43:16 +02:00

169 lines
4.5 KiB
Python

# Scoundrel card roguelike game port to T-DeckARD
# Created by Luxferre in 2026, released into public domain
from deck.input import input
from deck.menu import confirm
try:
from random import shuffle
except:
from random import randint
def shuffle(items):
for i in range(len(items) - 1, 0, -1):
j = randint(0, i)
items[i], items[j] = items[j], items[i]
def scoundrel():
# prepare the deck: M02 to M14 (2x), W02 to W10, P02 to P10
deck = []
for i in range(2, 11):
idx = f'{i:02}'
deck.append('M'+idx)
deck.append('M'+idx)
deck.append('W'+idx)
deck.append('P'+idx)
for i in range(11, 15):
idx = f'{i:02}'
deck.append('M'+idx)
deck.append('M'+idx)
shuffle(deck)
# init main stats
hp = 20
weapon = 0
durability = 0
can_run = True
engaged = 0
potion_drank = False
last_potion_val = 0 # for final full-HP win scoring
# room holder
room = []
print('===============')
print('Scoundrel--2026')
print(' by Luxferre')
print('===============')
print(' Good luck!')
while hp > 0 and len(deck) > 0: # start main game loop
# get current room
if engaged == 0:
while len(room) < 4:
try:
val = deck.pop()
if val is not None:
room.append(val)
except: # reached the end of the deck
break
else:
can_run = False
# print your stats
print(f'---------------\nHP:{hp:02} W:{weapon:02} D:{durability:02}\n---------------')
# print the current room state
print(' '.join(room))
valid_choices='abcdrq'
if can_run:
print(' a b c d r)un->')
else:
print(' a b c d')
valid_choices='abcdq'
choice = ''
while choice not in(valid_choices) or choice == '':
choice = input('Your choice: ').strip().lower()
item = ' '
if choice == 'q':
print('Quitting the game...')
return 0
elif choice == 'r' and can_run:
shuffle(room)
for el in room:
deck.insert(0, el)
room = []
can_run = False
continue
elif choice == 'a':
item = room[0]
room[0] = ' '
elif choice == 'b':
item = room[1]
room[1] = ' '
elif choice == 'c':
item = room[2]
room[2] = ' '
elif choice == 'd':
item = room[3]
room[3] = ' '
if item == ' ':
print('Invalid item choice!')
continue
itemtype = item[0].upper()
itemval = int(item[1:])
if itemtype == 'M': # monster
engaged += 1
healthlost = itemval
print(f'You fight a {itemval}-level monster.')
if durability >= itemval:
print(f'You\'ll lose {itemval} HP if fighting with bare hands.')
print(f'You\'ll lose {max(itemval-weapon, 0)} HP if using your weapon.')
if confirm(f'Use weapon?'):
healthlost -= weapon
if healthlost < 0: healthlost = 0
durability = itemval - 1
if durability < 2: # lose weapon when slaying the weakest monster
print('You lose your weapon.')
durability = 0
weapon = 0
hp -= healthlost
if hp < 0: hp = 0 # GGWP
print(f'You lost {healthlost} HP. New HP: {hp}.')
if weapon > 0:
print(f'Your weapon\'s durability decreased to {durability}.')
elif itemtype == 'W': # equip a weapon
engaged += 1
weapon = itemval
print(f'You equip a {weapon}-level weapon.')
durability = 14
elif itemtype == 'P': # drink a potion
engaged += 1
if not potion_drank:
potion_drank = True
hp += itemval
if hp > 20: hp = 20
print(f'You drink a {itemval}-level potion. New HP: {hp}')
if len(deck) == 0:
last_potion_val = itemval
else:
print('You already drank a potion in this room. Discarding.')
else: # we shouldn't get here but...
print('Invalid item choice!')
continue
if hp > 0 and engaged == 3: # used three items in a room, moving on to next
print('Room clear, moving to the next...')
engaged = 0
potion_drank = False
can_run = True
room = list(filter(lambda s: s!=' ', room))
# score the result
score = 0
if hp > 0: # win
score = hp
if hp == 20:
score += last_potion_val
else: # fail
for el in room:
if el != ' ':
deck.insert(0, el)
for item in deck:
itemtype = item[0].upper()
itemval = int(item[1:])
if itemtype == 'M':
score -= itemval
if score > 0:
print('You won! Your score:', score)
else:
print('You lost! Your score:', score)
return score