#๐Ÿ”’ I need help with an adventure game.

551 messages ยท Page 1 of 1 (latest)

noble mountain
gritty whaleBOT
#

@noble mountain

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

frozen agate
#

as described here

#

alright!

#

lets start from the start

#

tell me what you already know

noble mountain
#

I will start by sending the link of the game

lone tiger
#

can I learn also?

noble mountain
frozen agate
#

please

noble mountain
#

This is the link

frozen agate
lone tiger
#

Ok thanks

frozen agate
#

thanks, but ill be starting from an empty file

noble mountain
#

Now I post what the assignment is.

frozen agate
noble mountain
#

This is what I gotta do.

#

Part 3 More enemies
Once the combat system is finished and working well with an enemy, add different rooms to the game. In the different rooms, the player must be able to fight against different enemies. Different enemies should have different stats.

Example:
Demonic Monkey, 20 HP, 4 + 1-3 in damage
Frenzied Lizard, 30 HP, 8 + 1-5 in damage
Abyssal Horror, 50 HP, 13 + 1-6 in damage

Part 4 Inventory system and items
Add an inventory system to the game. The player starts with the following items:

2 pcs Cheesecake. Heals 4 + 1-3 HP.
1 Deluxe Cheesecake. Heals 8 + 1-5 HP.
1 bomb. Do 10 + 2-8 in damage.

Add a new option to the combat menu: โ€œUse Itemโ€. The player then gets to choose an item to use.

When the player kills an enemy, the enemy should leave behind an item that the player can pick up.

Example:
Demonic Monkey, Cheesecake
Frenzied Lizard, Bomb
Abyssal Horror, Deluxe Cheesecake

frozen agate
#

share part1 and 2 please

noble mountain
#

Ok

#

Part 2 is only reflection tho

frozen agate
#

i dont mind to know aboout it

noble mountain
#

Alr

#

Its to big to send here

frozen agate
#

!paste

gritty whaleBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

noble mountain
#

I can probaly just send the link to the asignment

frozen agate
#

yes that works

noble mountain
#

assignment

#

I will just make a private document

#

I will just translate everything

#

one second

#

How do I translate fast?

frozen agate
#

no need, you can just share it and ill understand it

noble mountain
#

You got the link

lone tiger
#

It is asking for approval

noble mountain
frozen agate
#

i also have luch.. let me know when you are back

noble mountain
#

Im back

#

@frozen agate

frozen agate
#

hey

#

extended lunch for me!

noble mountain
#

oh alright!

frozen agate
#

so ready to unpack some details about this topic?

noble mountain
#

Give me like 10 minutes and I be back. I will just do another assignment real quick. It will take max 10 minutes

frozen agate
#

sure thing, let me know

noble mountain
#

Im back

#

it took 3 minutes lucky enough

#

@frozen agate

frozen agate
#

alright

noble mountain
#

What's your plan?

frozen agate
#

teaching you some useful things you will need to solve this assignment

#

and showing how these things work

#

such that you can go and do that for your thing

noble mountain
#

Alright thanks, atleast you can teach. My teacher can't

frozen agate
#

when making a game there is one important thing you need to be able to do in code, we have touched a bit on this earlier

#

it is what I like to call, saving internal states

noble mountain
#

He is from Maine, that says a lot of him. But anyways let's talk about my code.

frozen agate
#

states change in a game, and these changes we need to be able to save

#

like the health of a monster

#

or the number of monsters in a room

noble mountain
#

one question.

frozen agate
#

or the number of rooms

#

ask away

noble mountain
#

remember to not talk about something advanced or something new. My teacher will get suspicous if I use python commands that we haven't talk about before.

frozen agate
#

oh no, the correct thing here is to use a class, we will not talk about this

noble mountain
#

I let you know if you would say something I haven't heard of before.

frozen agate
#

please do that

#

also things we need to keep track of, items in our inventory

#

enemy and player attacks

#

and any other things you want to save and use in your game

#

do you have a suggestion of how we can store this data?

noble mountain
#

hmm.. Idk functions? Or I might be very wrong here

frozen agate
#

a function control behaviour, it does not control data

noble mountain
#

right

frozen agate
#

you have already used a thing to store data

noble mountain
#

I did sadly forget what you call it

#

Yes right

#

I need to open my code

frozen agate
#

you saved enemy health

#

what did you use to do that?

noble mountain
#

() ?

frozen agate
#

you use a dict

#

do you know what a dict is?

noble mountain
#

No, please tell me.

frozen agate
#

it is a data structure that lets you save data as key and value pairs

#

and you can lookup the data with the key

noble mountain
#

Oh so it can be like def_main ():?

frozen agate
#

like a sweedish to english book of all words

noble mountain
#

it's that something you use to store data with?

#

is*

frozen agate
#

yes, it makes a lot of sense to do that with a dict

noble mountain
#

๐Ÿ‘

frozen agate
#
swedish_to_english = {
    "hej": "hello",
    "tack": "thanks",
    "ja": "yes",
    "nej": "no",
}
#

this is a dict of a few words

noble mountain
#

ah

#

It's nice seeing how you use pictures. it makes it easier to understand.

frozen agate
#

!e

swedish_to_english = {
    "hej": "hello",
    "tack": "thanks",
    "ja": "yes",
    "nej": "no",
}

print(swedish_to_english['hej'])
gritty whaleBOT
#

@frozen agate :white_check_mark: Your 3.12 eval job has completed with return code 0.

hello
frozen agate
#

notice that i use the key to get the value

noble mountain
#

right

#

Can I ask you another question?

frozen agate
#

ask away

noble mountain
#

Have you tried my code? If you did, did you found something confusing or something bad?

frozen agate
#

i have not tried it, we will unpack some best practises while we talk, and you will see that when you write your game again you will write it in a different way

noble mountain
#

ah

frozen agate
#

lets figure out what data we need

noble mountain
#

Are we on part 3 of the game right now?

frozen agate
#

we are on part 0

noble mountain
#

Right my bad.

frozen agate
#

no worries

#

we need player to save all the data on the player needs

#

agree?

noble mountain
#

Agree

#

Or do we?

frozen agate
#

yes, we need to be able to save the important data

noble mountain
#

No we do need it

frozen agate
#

that way, when we write functioon that control behaviour, the functions can use the data for calculations

#
DATA = {
    'player': {
        'name': 'Player',
        'HP': 100,
        'MP': 100,
        'attack': 10,
        'defense': 5,
    }
}
#

so im not sure what you actually need for the player

#

this is just a guess

noble mountain
#

You just wrote data as an example right? Like you could write anything there?

frozen agate
#

yes, but DATA is a good name for your game data

noble mountain
#

Yes correct.

frozen agate
#

it is the name of the dict

noble mountain
#

Question.

frozen agate
#

ask away

noble mountain
#

You wrote attack 10, does that means that player does 10 damange always?

frozen agate
#

in this contex, yes thats what it means

noble mountain
#

Alr but you could use something like ranrange if you wanted random damange?

#

Just wondering.

frozen agate
#

yes, we can use randomness to add more variance to the calculations

#

but the DATA is static, so the random behaviour needs to be done in functions

noble mountain
#

oh that's something new. My teacher did not teach that sadly.

#

What do you write in python if you want to chose something between 1-10?

frozen agate
#

you call a random function called randrange

noble mountain
#

we used random.randint

#

that might be wrong

frozen agate
#

well, randint and randrange both works, you just have to know what the result is when you use it

noble mountain
#

oh alright.

frozen agate
#

!d random.randrange

gritty whaleBOT
#

random.randrange(stop)``````py

random.randrange(start, stop[, step])```
Return a randomly selected element from `range(start, stop, step)`.

This is roughly equivalent to `choice(range(start, stop, step))` but supports arbitrarily large ranges and is optimized for common cases.

The positional argument pattern matches the [`range()`](https://docs.python.org/3/library/stdtypes.html#range) function.

Keyword arguments should not be used because they can be interpreted in unexpected ways. For example `randrange(start=100)` is interpreted as `randrange(0, 100, 1)`.

Changed in version 3.2: [`randrange()`](https://docs.python.org/3/library/random.html#random.randrange) is more sophisticated about producing equally distributed values. Formerly it used a style like `int(random()*n)` which could produce slightly uneven distributions.
frozen agate
#

!d random.randint

gritty whaleBOT
#

random.randint(a, b)```
Return a random integer *N* such that `a <= N <= b`. Alias for `randrange(a, b+1)`.
noble mountain
#

Is something of these "better"?

frozen agate
#

share your code again with me

frozen agate
noble mountain
frozen agate
#

user_health = 50 so this is player health

noble mountain
#

Yep!

frozen agate
#

damage_to_enemy = random.randint(5, 15) this is the damage you do to an enemy

noble mountain
#

Yes correct, between these numbers.

frozen agate
#

damage_to_user = random.randint(3, 8) this is the damage an enemy does to the player

noble mountain
#

correct

frozen agate
#

and is that all you want your game to do?

noble mountain
#

Well this is part one of the game so I don't really need anything more of that.

frozen agate
#

do you want to add defence into this, and do you want to add weapons that give you more damage?

noble mountain
#

I actually already got defence

#

Inventory will be added later

#

You can choose, 1 attack 2 defend, 3 runaway

frozen agate
#

yes, but how you plan the data is done now, not later

noble mountain
#

data is done now?

frozen agate
#

no, far from it

noble mountain
#

no no, but like what do you mean? I didn't really understand.

frozen agate
#

i see.. im asking you, i dont have any answers

#

it is your game

noble mountain
#

Ok and the question was?

#

I'm a little slow sometimes

frozen agate
#

do you want the player to be less affected based on how much defence the player has?

noble mountain
#

Oh, yes!

frozen agate
#
DATA = {
    'player': {
        'name': 'Isac',
        'HP': 100,
        'attack': 10,
        'defense': 5,
    },
}
#

so it makes sense for the player to have defence rating

noble mountain
#

ye

#

When you choose defend the player won't cause any damange to the enemy

frozen agate
#

i see, and hence take less damage

noble mountain
#

yes

frozen agate
#

the player needs to have an inventory as well

noble mountain
#

correct.

frozen agate
#

lets add this

noble mountain
#

๐Ÿ‘

frozen agate
#
DATA = {
    'player': {
        'name': 'Isac',
        'HP': 100,
        'attack': 10,
        'defense': 5,
    },
    'inventory': [],
}
#

the inventory is a list

#

it is here empty, because ... well... the player does not have any items

#

are you planning on having more then one inventory?

noble mountain
#

yep, we have actually talked about list before which is great!

#

No, one inventory is enough. You get to choose one thing. Or do you think it would be better with 2?

frozen agate
#

the decision is to put the inventory inside the player or have it as part of the DATA (like i have done above)

#

if it is inside the player, you can add a second player, with its own inventory

noble mountain
#

ah

#

Well we don't really need a second player, it's a 1v1 game

frozen agate
#

then we will use it as it is, notice that im thinking about everything that can happen at this point in time

#

so what more data do we need, do you need to navigate between rooms?

noble mountain
#

try to imagine a pokemon fight with only one pokemon.

noble mountain
frozen agate
#

alright, so we need to save rooms to our data

#

lets do that

noble mountain
#

If you are defeated, you won't respawn, its game over then

#

I believe that we need a smilar code under the old code? Or is this to complicated?

frozen agate
#

lets tacle those things when we get there

#

this is just the design part

noble mountain
#

right

frozen agate
#

what do we need to know about a room?

noble mountain
#

we don't really need to know anything about it, We don't need to know how it looks. Let's say, "You defetaed the first enemy, you are now going to fight against the boss in the castle" Let's just say it's a castle.

frozen agate
#

ok, lets say we are in a castle, that is a good place

#

the first room is the entrance hall

#

this room has a name

#

"Entrance Hall" would its name be

noble mountain
#

Should I add that in the story?

frozen agate
noble mountain
#

Can I add it here?

frozen agate
#

and we need a description for the room

#

we need to know if there are enemies in this room

#

and if there are multiple exits in a room, we might have to tell about that as well

noble mountain
#

Well you get to choose what enemy that are going to be in that room

noble mountain
frozen agate
#

lets start with empty rooms at first

frozen agate
noble mountain
#

Is it good to use print to descripe the room?

noble mountain
#

Ok should I add it now?

frozen agate
#

will the rooms have objects to pick up?

noble mountain
#

Nope.

#

The castle might have, but not the first room

#

Ok let me add it

#

How do you say enter on english? Like if you have enter something

#

its grammar

frozen agate
#

enter

noble mountain
#

no, its something like entred

frozen agate
#

you enter the Hallway

noble mountain
#

okay.

frozen agate
#

you have entered the Hallway

noble mountain
#

there it is

#

now you know what room you're in

frozen agate
#

so lets focus on the part that is the most important first

#

that is to create the place where the data is saved

lone tiger
#

you are also learning english with coding๐Ÿ˜…

frozen agate
#
DATA = {
    'player': {
        'name': 'Isac',
        'HP': 100,
        'attack': 10,
        'defense': 5,
    },
    'inventory': [],
    'rooms': [
        {
            'name': 'entrance hall',
            'description': 'You are standing in a grand entrance hall.',
            'exits': ['north', 'east', 'west', 'south'],
            'enemies': []
        },
        {
            'name': 'kitchen',
            'description': 'You are in a cozy kitchen.',
            'exits': ['south'],
            'enemies': []
        },
    ],
}
noble mountain
#

correct

#

oh damn

#

the tricky part is how you would get this into my code

#

or how I would do that

frozen agate
#

dont worry about it

noble mountain
#

with help ofcourse

#

you are a coding god

frozen agate
#

lets figure out all the data you need to save for your game

noble mountain
lone tiger
#

why inventory has nothing?

frozen agate
frozen agate
noble mountain
lone tiger
frozen agate
#

maybe we should add enemies

noble mountain
#

so we need data to save the room

#

but we have enemies right?

#

Or atleast 2

frozen agate
#

there are not a single enemy in the data

noble mountain
#

hm

#

there isn't?

frozen agate
#

take a look

noble mountain
#

But I got this data tho

lone tiger
#

there 2 enemies one in entrance hall and one in kitchen

frozen agate
lone tiger
#

am i right?

frozen agate
#

so lets add enemeies to the data

noble mountain
frozen agate
#

behaviour and data

#

with functions you can only control behaviour

noble mountain
#

That's why we are creating this data, alr. Now I get it!

frozen agate
#

with class you can control behaviour data and many many many other things

#

but class is an advavanced topic

noble mountain
#

eivl, why do we need to control multiple things? What would you use that for? Is that for inventory

frozen agate
#

so to make it similar to what you have done, we are now putting the data into a dict

frozen agate
#

and since functions only control behaviour, you will end up with a spagetti mess if you try to force functions to controll everything

frozen agate
#

lets look at a few enemies, and lets change this to some more real values

#
DATA = {
    'player': {
        'name': 'Isac',
        'HP': 100,
        'attack': 10,
        'defense': 5,
    },
    'inventory': [],
    'rooms': [
        {
            'name': 'entrance hall',
            'description': 'You are standing in a grand entrance hall.',
            'exits': ['north', 'east', 'west', 'south'],
            'enemies': []
        },
        {
            'name': 'kitchen',
            'description': 'You are in a cozy kitchen.',
            'exits': ['south'],
            'enemies': []
        },
    ],
    'enemies': [
        {
          'name': 'goblin',
          'health': 10,
          'attack': 5,
        },
        {
          'name': 'dragon',
          'health': 50,
          'attack': 20,
        },
    ],
}

noble mountain
#

isn't it better to have the same stats on the first two enemies?

frozen agate
#

you decide that

#

create and change it so it fits your needs

noble mountain
#

The boss might have more hp and attack but the first two you get to choose about is probaly better with the same stas, this was only an example tho

frozen agate
#

i would suggest you have many enemies, and you can randomly select between all enemies when you enter a room

#

and you would have a selection of a few boss enemies, and pick one of the bosses for the final room

noble mountain
#

okay

#

so not only one boss?

frozen agate
#

well, i find it more interesting to have more options, you can however do it with one fixed boss if you want to

noble mountain
#

Alright!

#

So what do you think?

#

what should be improved?

frozen agate
#

i would like you to add more enemeies and bosses, and add them to the dict i have started

#

share it here when you are done

#

five enemies and three bosses maybe. just to have some to pick from

noble mountain
#

the thing is we don't need more bosses rn. Like the bosses should be in the other room

frozen agate
#

well add one then, the number does not really matter that much

noble mountain
#

you only fight against one enemy tho? like you dont need to play against everyone?

frozen agate
#

that is something you can controll

#

the behaviour of the fight is a function that decides the logic

noble mountain
#

Ok you get to fight against 2 enemies, one normal and one boss

frozen agate
#

this are just the available data for the game in one place

noble mountain
#

then you get to choose against multiple

frozen agate
#
DATA = {
    'player': {
        'name': 'Isac',
        'HP': 100,
        'attack': 10,
        'defense': 5,
    },
    'inventory': [],
    'rooms': [
        {
            'name': 'entrance hall',
            'description': 'You are standing in a grand entrance hall.',
            'exits': ['north', 'east', 'west', 'south'],
            'enemies': []
        },
        {
            'name': 'kitchen',
            'description': 'You are in a cozy kitchen.',
            'exits': ['south'],
            'enemies': []
        },
    ],
    'enemies': [
         {
             'name':  'goblin',
             'health': 10,
             'attack': 5,
         },
         {
             'name':  'dragon',
             'health': 50,
             'attack': 12,
         },
         {
             'name':  'troll',
             'health': 30,
             'attack': 15,
         },
         {
             'name':  'vampire',
             'health': 40,
             'attack': 11,
         },
         {
             'name':  'werewolf',
             'health': 50,
             'attack': 14,
         },
    ],
    'bosses': [
         {
             'name':  'Morgana the Witch Queen',
             'health': 100,
             'attack': 80,
         },
         {
             'name':  'Gorthok the Unyielding',
             'health': 150,
             'attack': 70,
         },
         {
             'name':  'The Dark Lord Xarath',
             'health': 200,
             'attack': 50,
         },
    ],
}

#

here are my suggestion

noble mountain
#

where should it be added?

frozen agate
#

the data should be the first thing after imports

noble mountain
#

do I need to replace something?

frozen agate
#

no, you should write everything again, always write everything twice

#

or WET

#

what more is missing from the enemies?

noble mountain
#

one sec

#

something went wrong

frozen agate
#

what do you mean?

#

im just asking what more is missing from the enemies

noble mountain
#

I added the bad dragon as a new enemy

#

but

#

you cant choose him when you are starting the gaame

frozen agate
#

you are missing something important

#

you are not suppose to change your code now

#

you are not suppose to do anthing with your code

#

if you want to make a new file, you can do that and use the dict we have been discussing instead

noble mountain
#

dang

frozen agate
#

i did say this when we started

noble mountain
#

I fixed it

frozen agate
#

this is from my editor

noble mountain
#

Don't worry

#

its restored

frozen agate
#

so.. what more is missing from the enemies?

noble mountain
#

a description?

#

they already got a status

frozen agate
#

yes, that is true, i was thinking about the requirements from the assignment now

noble mountain
#

Well let me read it rq

#

well I got all requirements

frozen agate
#

no, there is one thing missing from the enemy

noble mountain
#

A big thing?

frozen agate
#

unless my swedish is off

#

yes

noble mountain
#

do you know Swedish?

frozen agate
#

i do

#

Nรคr spelaren dรถdar en fiende ska fienden lรคmna efter sig en item som spelaren kan plocka upp.

#

enemies needs an Item

noble mountain
#

right...

#

you are very right

#

how the heck did I miss that

#

got any idea?

#

๐Ÿค”

frozen agate
#

so each enemy has one item, do you want each enemy to have a prefedined item

#

or do you want to pick an item from a selection of multiple items?

#

like a loot table

#
DATA = {
    'player': {
        'name': 'Isac',
        'HP': 100,
        'attack': 10,
        'defense': 5,
    },
    'inventory': [],
    'rooms': [
        {
            'name': 'entrance hall',
            'description': 'You are standing in a grand entrance hall.',
            'exits': ['north', 'east', 'west', 'south'],
            'enemies': []
        },
        {
            'name': 'kitchen',
            'description': 'You are in a cozy kitchen.',
            'exits': ['south'],
            'enemies': []
        },
    ],
    'enemies': [
         {
             'name':  'goblin',
             'health': 10,
             'attack': 5,
             'item': [],
         },
         {
             'name':  'dragon',
             'health': 50,
             'attack': 12,
             'item': [],
         },
         {
             'name':  'troll',
             'health': 30,
             'attack': 15,
             'item': [],
         },
         {
             'name':  'vampire',
             'health': 40,
             'attack': 11,
             'item': [],
         },
         {
             'name':  'werewolf',
             'health': 50,
             'attack': 14,
             'item': [],
         },
    ],
    'bosses': [
         {
             'name':  'Morgana the Witch Queen',
             'health': 100,
             'attack': 80,
         },
         {
             'name':  'Gorthok the Unyielding',
             'health': 150,
             'attack': 70,
         },
         {
             'name':  'The Dark Lord Xarath',
             'health': 200,
             'attack': 50,
         },
    ],
}

noble mountain
#

it would probaly be good if each enemy had a specific item, the bad demon could have hp and so one

#

on*

frozen agate
#

here each enemy has no item

noble mountain
#

good example

#

then I can just come up with some item

frozen agate
frozen agate
noble mountain
#

so it could be everything from helath to a weapon

frozen agate
#

so you can give more HP, attack or defence

noble mountain
#

I cant spell hp

#

health

frozen agate
#

because those attributes are the ones we have picked for the player

#

if we had more attributes that did different things, we could have made more different items

#

but three attributes is enough for a simple game

noble mountain
#

yep

#

let's pretend that you get a sword from the bad monkey after you have defeated him. This item should then be added into my inventory, correct?

frozen agate
#

yes, it should

#

the sword should have these attributes

#

{'name': 'sword', 'attack': 5, 'defense': 0, 'hp': 0} explain why?

noble mountain
#

because the sword should only do damange, it shouldn't defend you or heal you.

frozen agate
#

yes

#

and we explicit say that hp and defence is 0 because the computer does not really know what a sword is

#

the computer only cares about the value

#

so we will add attack, defence and hp to our player

noble mountain
#

yes

#

I do believe that we already have that tho, which is great!

frozen agate
#

if the player got two swords, he would have +10 attack

noble mountain
#

ye

frozen agate
#
DATA = {
    'player': {
        'name': 'Isac',
        'hp': 100,
        'attack': 10,
        'defense': 5,
    },
    'inventory': [],
    'rooms': [
        {
            'name': 'entrance hall',
            'description': 'You are standing in a grand entrance hall.',
            'exits': ['north', 'east', 'west', 'south'],
            'enemies': []
        },
        {
            'name': 'kitchen',
            'description': 'You are in a cozy kitchen.',
            'exits': ['south'],
            'enemies': []
        },
    ],
    'enemies': [
         {
             'name':  'goblin',
             'health': 10,
             'attack': 5,
             'item': {'name': 'sword', 'attack': 5, 'defense': 0, 'hp': 0},
         },
         {
             'name':  'dragon',
             'health': 50,
             'attack': 12,
             'item': [],
         },
         {
             'name':  'troll',
             'health': 30,
             'attack': 15,
             'item': [],
         },
         {
             'name':  'vampire',
             'health': 40,
             'attack': 11,
             'item': [],
         },
         {
             'name':  'werewolf',
             'health': 50,
             'attack': 14,
             'item': [],
         },
    ],
    'bosses': [
         {
             'name':  'Morgana the Witch Queen',
             'health': 100,
             'attack': 80,
         },
         {
             'name':  'Gorthok the Unyielding',
             'health': 150,
             'attack': 70,
         },
         {
             'name':  'The Dark Lord Xarath',
             'health': 200,
             'attack': 50,
         },
    ],
}

noble mountain
#

we should probaly do an inventory with more than one space

frozen agate
#

yes, a list can have as many as we want

#

that is why the inventory is a list

noble mountain
#

yes a list is good!

frozen agate
#

and since the assignment says that the enemy drops one item, well, we dont need a list for that, so we just drop the one item it has

noble mountain
#

yep yep

frozen agate
noble mountain
#

it's kinda easy to understand what you should add and not, its very hard to get the logic where it should be added to the code

frozen agate
#

i just made a copy of the sword for all enemies, but you have to create your own items later

frozen agate
noble mountain
#

even the easiest is hard for me

frozen agate
#

programming is hard

noble mountain
#

correct, sadly i dont like it. But I don't have another choice. I'm glad that you are helping me

frozen agate
#

it looks like the player can only use one item from the inventory at the time. im not sure that is a good choice, but lets keep that in mind

noble mountain
#

yeah okay

frozen agate
#

alright.. lets take a final look at the data

#
DATA = {
    'player': {
        'name': 'Isac',
        'hp': 100,
        'attack': 10,
        'defense': 5,
    },
    'inventory': [],
    'rooms': [
        {
            'name': 'entrance hall',
            'description': 'You are standing in a grand entrance hall.',
            'exits': ['north', 'east', 'west', 'south'],
            'enemies': []
        },
        {
            'name': 'kitchen',
            'description': 'You are in a cozy kitchen.',
            'exits': ['south'],
            'enemies': []
        },
    ],
    'enemies': [
         {
             'name':  'goblin',
             'health': 10,
             'attack': 5,
             'item': {'name': 'sword', 'attack': 5, 'defense': 0, 'hp': 0},
         },
         {
             'name':  'dragon',
             'health': 50,
             'attack': 12,
             'item': {'name': 'sword', 'attack': 5, 'defense': 0, 'hp': 0},
         },
         {
             'name':  'troll',
             'health': 30,
             'attack': 15,
             'item': {'name': 'sword', 'attack': 5, 'defense': 0, 'hp': 0},
         },
         {
             'name':  'vampire',
             'health': 40,
             'attack': 11,
             'item': {'name': 'sword', 'attack': 5, 'defense': 0, 'hp': 0},
         },
         {
             'name':  'werewolf',
             'health': 50,
             'attack': 14,
             'item': {'name': 'sword', 'attack': 5, 'defense': 0, 'hp': 0},
         },
    ],
    'bosses': [
         {
             'name':  'Morgana the Witch Queen',
             'health': 100,
             'attack': 80,
         },
         {
             'name':  'Gorthok the Unyielding',
             'health': 150,
             'attack': 70,
         },
         {
             'name':  'The Dark Lord Xarath',
             'health': 200,
             'attack': 50,
         },
    ],
}
noble mountain
#

Jeez im getting kinda slow now

frozen agate
#

i think its good enough, the values can be changed later

noble mountain
#

That looks very good

frozen agate
#

im making a new file called constants.py

#

and im moving the data there

noble mountain
#

well what do you say, we should maybe take a break for today. Im getting tierd

frozen agate
#

yes, lets jkust finish the last part of this please

#

10 min?

noble mountain
#

sure

frozen agate
#

and in the main.py file i have from constants import DATA

noble mountain
#

did you import data?

frozen agate
#

yes, we need the data in our main file, i just dont want a wall of text to clutter the code

lone tiger
frozen agate
noble mountain
#

oh alright

lone tiger
#

It is for python only

frozen agate
#

it is, part of jetbrains. it is not a good editor for beginners

noble mountain
#

I dont wanna get off track but eivl is this your job?

lone tiger
#

Vs code is good for beginners?

frozen agate
frozen agate
noble mountain
frozen agate
#

thank y ou

noble mountain
#

my real teacher is from USA

#

Maine

frozen agate
#

lets see how we can pick a random enemy from the first room, and prrint the messages about the monster. and then we will leave the rest for later

noble mountain
#

we use the random function we talked about

#

hmm what was it

#

randint?

#

randrange?

frozen agate
#

if we need a random number, we an use one of those

#

however we dont need a random number, we have all the enemies to choose from already

#

we just have to choose one of them randomly

noble mountain
#

right, but we dont need a number

frozen agate
#

not when using python

#

rooms are in order, so lets pick the first room

noble mountain
#

entrance hall

frozen agate
#
import random

from constants import DATA


def main():
    room = DATA['rooms'][0]
    print(room['name'])
    print(room['description'])


if __name__ == "__main__":
    main()
#

this is just a quick demo of how to get the first room

noble mountain
#

what does the last sentece do?

#

sentence

frozen agate
#

well... i got it from your code, do you not know what it does?

noble mountain
#

No, Ai

#

It dosent happend anything if I remove it tho

#

so idk

frozen agate
#
import random

from constants import DATA


room = DATA['rooms'][0]
print(room['name'])
print(room['description'])
#

so lets look at that part some other time

#

python runs code from top to bottom, so as long as we follow that rule, we are fine

noble mountain
#

yeah correct

frozen agate
#

sometimes we want to control exactly what lines of code we run, but now we just run everrything as it is written

noble mountain
#

there is one thing i hate with python, to choose room 1 you have to write 0. that is confusing

frozen agate
#

just remember that and you will be fine

#

it is confusing yes, but it makes math easier

frozen agate
#

it is better to be confused for a short amount of time, compared to having to think when doing math every time

noble mountain
#

right

#

so now?

frozen agate
#

lets put enemies in the room

#

we have an enemies list in the room we can append monsters to

#

do you know how to append elements to a list?

noble mountain
#

add elements as a variable

frozen agate
#

well yes, but lists have their own append method, we can use this to just add what we want to the list

#

we just need the name of the list and its value

#

name_of_list.append(my_element)

#

it looks like this

noble mountain
#

ye

frozen agate
#

so lets look at the DATA and see what the name of our room[0] ememy list is

#

so we already have room defined from the code above

#

room = DATA['rooms'][0]

#

that means the name of the list for this room is room['enemies']

#

agree?

noble mountain
#

yr

#

ye

frozen agate
#

so how many enemies do we want to add to this room?

noble mountain
#

3

frozen agate
#

or what about, 1, 2 or 3?

noble mountain
#

0-3

frozen agate
#

nah. cant have 0 enemies, then we dont get weapons to fight the boss

noble mountain
#

take 2 enemies

#

cuz that what I have

#

that's

frozen agate
#

alright, to do things two times, what type of code do we need?

noble mountain
#

oh you said that earilier

#

it was something

#

like

#

idk

frozen agate
#

like a loop?

noble mountain
#

I forgot

#

no not to add things

#

loop does just repeat the game

#

or one thing

frozen agate
#

lets tackle that later instead.

#

we need to append two things

noble mountain
#

I do know what while loop is btw

frozen agate
#

we can use a for loop or just write the same line of code twice

noble mountain
#

you can use something like append.list

frozen agate
noble mountain
#

right..

#

my bad

frozen agate
#

we do want to choose one enemy randomly

#

DATA['enemies'] are all the enemies

#

we want to choose one of them at random

noble mountain
#

we use the random commando

frozen agate
#

yes, lets use random.choice

#

random.choice(DATA['enemies'])

#

this will choose one random enemy

noble mountain
#

ye

frozen agate
#

neat, is it not?

#

and we will append that enemy to our room list

noble mountain
#

it will choose one enemy yes

frozen agate
#

room['enemies'].append(random.choice(DATA['enemies']))

#

and we can run this twice for now

#
import random

from constants import DATA


room = DATA['rooms'][0]
print(room['name'])
print(room['description'])

room['enemies'].append(random.choice(DATA['enemies']))
room['enemies'].append(random.choice(DATA['enemies']))

print(room['enemies'])
#

lets end it there

noble mountain
#

my class is done btw..

#

no worries

#

my irl class if you wondering

#

not your class

#

your class is god

#

good

frozen agate
#

i see, but i think its enough for now, we can continue later

noble mountain
#

tomorrow

#

?

frozen agate
#

tomorrow evening yes

noble mountain
#

great

#

see you and thanks for everything

#

have a good day

frozen agate
#

and we will add behviours we need, select monsters, attack, defend, run away

noble mountain
#

๐Ÿ‘

frozen agate
#

these behaviours will be almost identical to the ones you have already made

#

at least so far as i remember them

noble mountain
#

yes

frozen agate
#

but they will use the DATA instead

noble mountain
#

well, goodbye eivl!

#

And thanks again

lone tiger
#

Good Bye

noble mountain
#

Goodbye

frozen agate
#

later!

gritty whaleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.