JonB
Posts: 220
Joined: Tue Nov 29, 2011 9:26 pm

Re: A program to type in, like you used to

Sat Feb 18, 2012 8:30 pm

rurwin said:


NAB said:


Not sure I like code without curly braces!


It takes a while to get used to. Then it"s another bug that never happens.

C Bug


if (something)

do something

do something else


Another one that never bites you is the dangling else:

Another C bug


if (something)

if (another)

do something

else

do something else


Of course the simple solution to both of those is to use curly braces without fail.


Amen to that! And a consistent indentation and commenting style.

@Jongleur : OK.. I"ve not tried it on my Beeb but it should work. It works on the modern BASIC interpreter I have on my MacBook Air (which I think is "Squirrel BASIC"). Main problem for me is I don"t know how to get a BASIC program in text form onto the Beeb; the saved programs are all tokenised. I do have an SD card reader attached to the User port which works well, so getting the actual text file on there is pretty easy, but getting BBC BASIC to actually accept it.. I dunno about that.

Besides, like I said, I wrote it for my Micro UK101 computer:



Above: The Micro UK101 component layout.

Below : Underside of the board. It"s all point-to-point with prototyping wire…



…and here it is running via a terminal emulator (Hyperterm). Wow, nearly 32K of RAM, look at that!!



More info about the build and the problems I encountered here : http://forum.6502.org/viewtopi.....php?t=1795

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4257
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: A program to type in, like you used to

Sat Feb 18, 2012 11:50 pm

@JonB, what BASIC should I use for that? I tried Brandy but got an address out of range on line 260... not that I think I should have. Maybe the Ubuntu package I have is too old.

Here's my game, I'm afraid it's a bit larger than the BASIC one. I wrote it in BASIC style though with only minimal use of objects and stuff and loads of global variables, with the objective of making it approachable.

It will work in Python 2 or 3, and you can start it by double-clicking it in Windows.

There are still one or two bugs that you can find and fix and plenty of room for enhancements.from __future__ import absolute_import, division, generators, unicode_literals, print_function, nested_scopes, with_statement
from random import randint, seed, randrange
import sys
from math import sqrt,atan2
from time import sleep

boardsize = 100
exitlevel = 6

if sys.version_info < (3,):
input = raw_input

class MonsterClass(object):
def __init__(self, name, probgood, health, offence=0, defence=0):
self.name = name
self.probgood = probgood
self.health = health
self.offence = offence
self.defence = defence

MonsterClasses = [ MonsterClass("Gold Horse", 80, 100,10,10),
MonsterClass("Goblin", 20, 30),
MonsterClass("Ghost", 20, 80,5,5),
MonsterClass("Demon", 10, 200,15,15),
MonsterClass("Knight", 100, 100,5,5),
MonsterClass("Mage", 50, 100,0,0),
MonsterClass("Kobold", 20, 10,-3,-3),
MonsterClass("Elf", 80, 100,0,0),
MonsterClass("Dragon", 50, 300,20,20),
MonsterClass("Vampire", 20, 200,10,10),
MonsterClass("Giant Spider", 20, 100,0,0),
MonsterClass("Dwarf", 80, 100,0,0),
MonsterClass("Mummy", 50, 100,5,5),
MonsterClass("Goblin", 20, 30,3,3)]

class Monster(object):
def __init__(self, mclass, level):
self.mclass = mclass
self.name = mclass.name
probgood = mclass.probgood/level
if randint(1,100) < probgood:
self.align = "good"
elif randint(1,100) < 50/level:
self.align = "neutral"
else:
self.align = "evil"

self.health = mclass.health
self.offence = mclass.offence
self.defence = mclass.defence

def __str__(self):
return self.name

def take_damage(self,damage):
self.health = self.health – damage

def isalive(self):
return self.health > 0

def populate_board():
num_monsters = boardsize**2 / ((exitlevel-level)/2+1)
for m in range(int(num_monsters)):
m_x, m_y = (randint(1,boardsize), randint(1,boardsize))
while (m_x, m_y) in board:
m_x, m_y = (randint(1,boardsize), randint(1,boardsize))
monster = Monster(MonsterClasses[randrange(len(MonsterClasses))], level)
board[(m_x, m_y)] = monster

def new_level():
global x, y, exit_x, exit_y, board
x = randint(1,100)
y = randint(1,100)
exit_x = x
exit_y = y
while exit_x == x and exit_y == y:
exit_x = randint(1,100)
exit_y = randint(1,100)

board = dict()
populate_board()

def get_move():
global x, y, health

if "light" not in inventory.get_capabilities():
input("Hit Enter to enter a room")
nx = x
ny = y
while nx == x and ny == y:
nx = randint(1,boardsize)
ny = randint(1,boardsize)
x = nx
y = ny
else:
gotit = False
while not gotit:
try:
x, y = [int(n) for n in input("Which room do you want to enter? (x,y): ").split(",")]
if not (1 0:
s = s + " containing "+str(self.gold)+" gold pieces"
return s

class Inventory(object):
def __init__(self):
self.items = []
self.wealth = 0

def print(self):
print (strlist(self.items))

def append(self, item):
if type(item) is list:
self.items = self.items + item
else:
self.items.append(item)

def get_capabilities(self):
capabilities = set()
for item in self.items:
capabilities = capabilities | item.capabilities
return capabilities

def len(self):
return len(self.items)

def lose(self):
i = randrange(len(self.items))
item = self.items
del self.items
return item

def defence(self):
d = 0
for item in self.items:
d = d + item.defence
return d

def offence(self):
a = 0
for item in self.items:
a = a + item.offence
return a

def minimum(x,y):
return x if x < y else y

def booty():
items = []
if randrange(0,100) < 75:
capabilities = inventory.get_capabilities()
if "light" not in capabilities:
items.append(Item("lantern", 0,0, {"light"}))
elif "distance" not in capabilities:
items.append(Item("distance meter", 0,0, {"distance"}))
elif "compass" not in capabilities and level > 1:
items.append(Item("compass", 0,0, {"compass"}))
elif "bearing" not in capabilities and level > 2:
items.append(Item("compass calibration", 0,0, {"bearing"}))
if randrange(0,100) < 50:
if randrange(0,100) < 25:
items.append(Item("sword", 3,0))
elif randrange(0,100) < 25:
items.append(Item("spear", 2,0))
elif randrange(0,100) < 25:
items.append(Item("dagger", 1,0))
elif randrange(0,100) < 25:
items.append(Item("mace", 4,0))
elif randrange(0,100) < 25:
items.append(Item("pike", 3,0))
if randrange(0,100) < 50:
if randrange(0,100) < 50:
items.append(Item("piece of leather armour", 0,1))
elif randrange(0,100) < 50:
items.append(Item("piece of chain armour", 0,2))
elif randrange(0,100) < 50:
items.append(Item("piece of plate armour", 0,3))

money = randint(1,10)
items.append(Item("Money Pouch",gold=money))
return items

def strlist(items):
i = len(items)
if i == 0:
s = "nothing"
elif i == 1:
s = str(items[0])
elif i == 2:
s = str(items[0])+" and "+str(items[1])
else:
s = ""
for j in range(i-2):
s = s + str(items[j]) + ", "
s = s + strlist(items[-2:])
return s

def good_encounter(monster):
global health

print ("The", str(monster), "is friendly")
if health < 100:
extra = minimum(100-health, monster.health/2)
print ("The", str(monster), "heals you of", extra, "points")
health = health + extra
return True
items = booty()
print ("The", str(monster), "gives you", strlist(items))
inventory.append(items)
return True

def attack(offence, defence):
damage = randint(1,20)+offence-defence
if damage < 0:
damage = 0
return damage

def evil_encounter(monster, surprise=False):
global health

while monster.isalive() and health > 0:
if surprise:
damage = attack(inventory.offence(), monster.defence)
print ("You attack the", str(monster), "and wound it for", damage,"points")
monster.take_damage(damage)
if not monster.isalive():
print ("You killed it!")
items = booty()
print ("You find", strlist(items))
inventory.append(items)
return True

if monster.isalive() and health > 0:
print ("The", str(monster), "attacks")
surprise = True
damage = attack(monster.offence, inventory.defence())
print ("The", str(monster), "attacks you and wounds you for", damage,"points")
health = health – damage
print ("Your health is", health,"%")
if health 0:
action = ""
while len(action) == 0 or action[0:1] not in "raRA":
action = input("Do you want to Run or Attack? ")
if action[0] in "Rr":
damage = attack(monster.offence, inventory.defence())
print ("The", str(monster), "attacks you and wounds you for", damage,"points")
health = health – damage
print ("Your health is", health,"%")
if health0:
well_encounter()

def print_position():
capabilities = inventory.get_capabilities()
dx = x – exit_x
dy = y – exit_y

if "light" in capabilities:
print ("You are in room (", x, ",", y, ")")

if "compass" in capabilities:
dir =""
if abs(dy) > abs(dx)/3:
if dy < 0:
dir = dir + "N"
else:
dir = dir + "S"
if abs(dx) > abs(dy)/3:
if dx < 0:
dir = dir + "E"
else:
dir = dir + "W"

print ("You need to head", dir)

if "bearing" in capabilities:
b = atan2(-dy,-dx)
print (b)
b = b/3.1415926/2*360
b = b – 90
b = 360 – b
print (b)
if b < 0: b = b + 360
print ("The exit is on a bearing of", int(b), "degrees")

if "distance" in capabilities:
print ("The exit is ", sqrt(dx*dx + dy*dy), "away")

level = 1
moves = 0
health = 100
alive = True
seed()
new_level()
inventory = Inventory()
#magic_box = Item("magic box", 0,0, {"light", "compass", "distance", "bearing"})
#inventory.append(magic_box)

while health > 0 and level < exitlevel:
moves = moves + 1
print ("nMove ", moves, ":")
print("Your health is ", health, "%")
old_health = health
sleep(0.5)
print_position()
sleep(0.5)
get_move()
if health > 0:
encounter()
if x == exit_x and y == exit_y:
print ("**** Well done! you have found the stairs ****")
sleep(3)
level = level + 1
new_level()

if health < 100 and old_health == health:
health = health + 1

sleep(2)

if health > 0:
print ("Sunlight! You got out alive after", moves, "moves, with…")
inventory.print()
else:
print ("Sorry; you died on level ", level)

input("(Hit Enter to Exit)")

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4257
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: A program to type in, like you used to

Sat Feb 18, 2012 11:58 pm

Backstory:

You fall down a pit into a dangerous dungeon. The dungeon is a grid of identical rooms, some of which contain monsters. It is dark and you start stumbling around. If you can survive long enough you can gather items to help you find your way out, some of the monsters are friendly and will give you stuff and if you can beat the evil ones you can take stuff off them, but as you work your way up and out, the monster become more evil and more difficult to beat.

In the centre of the dungeon is a deep well of healing water, but there is a cost.

Lynbarn
Posts: 464
Joined: Wed Jan 04, 2012 11:03 pm
Contact: Website

Re: A program to type in, like you used to

Sun Feb 19, 2012 12:15 am

rurwin said:


Backstory:

You fall down a pit into a dangerous dungeon. The dungeon is a grid of identical rooms, some of which contain monsters. It is dark and you start stumbling around. If you can survive long enough you can gather items to help you find your way out, some of the monsters are friendly and will give you stuff and if you can beat the evil ones you can take stuff off them, but as you work your way up and out, the monster become more evil and more difficult to beat.

In the centre of the dungeon is a deep well of healing water, but there is a cost.



Not that I've ever seen it (honest) but this sounds a bit like that TV show: "Dating in the Dark"

radford64
Posts: 2
Joined: Wed Mar 07, 2012 5:17 pm

Re: A program to type in, like you used to

Wed Mar 07, 2012 5:38 pm


@Jongleur : OK.. I"ve not tried it on my Beeb but it should work. It works on the modern BASIC interpreter I have on my MacBook Air (which I think is "Squirrel BASIC"). Main problem for me is I don"t know how to get a BASIC program in text form onto the Beeb; the saved programs are all tokenised. I do have an SD card reader attached to the User port which works well, so getting the actual text file on there is pretty easy, but getting BBC BASIC to actually accept it.. I dunno about that.


If we're talking about BBC BASIC IV or earlier, *EXEC is your friend. Streams a file to the keyboard input buffer, effectively typing it in for you. It probably needs CR as the line endings instead of LF. CR+LF might be okay.

BASIC V and later, you can just use TEXTLOAD.

User avatar
SN
Posts: 1014
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
Contact: Website

Re: A program to type in, like you used to

Wed Mar 07, 2012 6:20 pm

OMG!

If you really want to play with this old stuff, go google for MESS – this is the Home Computer/Games Console equivalent to MAME for Arcade Machines.

You can relive ANY pre PC memory you so desire…

(SDL)MAME is probably going to run really well on the raspi – it would be nice to see MESS ported too
Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?

caulktel
Posts: 17
Joined: Wed Feb 08, 2012 8:59 pm

Re: A program to type in, like you used to

Wed Mar 07, 2012 6:49 pm

I spent a weekend inputting a vignere,(spelling may be wrong) cypher program into my ZX81. It worked real well, you could choose a seed of 4 digits I believe, then type a text document as long as you wanted. When you got finished you told it to scramble it. It was totally unreadable afterword unless you had the 4 digit seed to resemble it. I would then save it to tape and give it to my buddy at school the next day and he would take it home with the seed that he had to remember, (you couldn't have it falling into enemy hands you know), and reassemble it using his ZX81. Fun times.

louisb
Posts: 47
Joined: Wed Mar 07, 2012 7:08 am

Re: A program to type in, like you used to

Wed Mar 07, 2012 6:50 pm

Does the Raspberry Pi have an audio cassette interface? As it is much quicker to load the programs from tape rather than having to type them in by hand.

ADAMPOKE111
Posts: 62
Joined: Wed Mar 07, 2012 6:38 pm

Re: A program to type in, like you used to

Wed Mar 07, 2012 7:01 pm

Does the raspberry pi have a interface like windows?

fireraisr
Posts: 81
Joined: Wed Nov 23, 2011 2:34 am

Re: A program to type in, like you used to

Wed Mar 07, 2012 7:56 pm

ADAMPOKE111 said:


Does the raspberry pi have a interface like windows?


No, it has an interface like a tv. Windows are too clear to do anything on and it's hard to save your work when it's constantly being bombarded with windex viruses.

caulktel
Posts: 17
Joined: Wed Feb 08, 2012 8:59 pm

Re: A program to type in, like you used to

Wed Mar 07, 2012 8:20 pm

fireraisr said:


ADAMPOKE111 said:


Does the raspberry pi have a interface like windows?


No, it has an interface like a tv. Windows are too clear to do anything on and it's hard to save your work when it's constantly being bombarded with windex viruses.


In answer to your question, yes it will have a desktop that looks sort of like Windows that will allow you to click on things, it just won't be running Windows thank god.

Sorry quoted the wrong poster, I meant fireraisr

Return to “General discussion”