#๐ I need help with an adventure game.
551 messages ยท Page 1 of 1 (latest)
@noble mountain
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.
as described here
alright!
lets start from the start
tell me what you already know
I will start by sending the link of the game
can I learn also?
please
This is the link
yes
Ok thanks
thanks, but ill be starting from an empty file
Now I post what the assignment is.
yes please
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
share part1 and 2 please
i dont mind to know aboout it
!paste
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.
I can probaly just send the link to the asignment
yes that works
assignment
I will just make a private document
I will just translate everything
one second
How do I translate fast?
no need, you can just share it and ill understand it
You got the link
It is asking for approval
I have lunch now. But take your time. Imma go offline for now
i also have luch.. let me know when you are back
oh alright!
so ready to unpack some details about this topic?
Give me like 10 minutes and I be back. I will just do another assignment real quick. It will take max 10 minutes
sure thing, let me know
alright
What's your plan?
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
Alright thanks, atleast you can teach. My teacher can't
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
He is from Maine, that says a lot of him. But anyways let's talk about my code.
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
one question.
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.
oh no, the correct thing here is to use a class, we will not talk about this
I let you know if you would say something I haven't heard of before.
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?
hmm.. Idk functions? Or I might be very wrong here
a function control behaviour, it does not control data
right
you have already used a thing to store data
() ?
No, please tell me.
it is a data structure that lets you save data as key and value pairs
and you can lookup the data with the key
Oh so it can be like def_main ():?
like a sweedish to english book of all words
yes, it makes a lot of sense to do that with a dict
๐
swedish_to_english = {
"hej": "hello",
"tack": "thanks",
"ja": "yes",
"nej": "no",
}
this is a dict of a few words
!e
swedish_to_english = {
"hej": "hello",
"tack": "thanks",
"ja": "yes",
"nej": "no",
}
print(swedish_to_english['hej'])
@frozen agate :white_check_mark: Your 3.12 eval job has completed with return code 0.
hello
notice that i use the key to get the value
ask away
Have you tried my code? If you did, did you found something confusing or something bad?
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
ah
lets figure out what data we need
Are we on part 3 of the game right now?
we are on part 0
Right my bad.
yes, we need to be able to save the important data
No we do need it
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
You just wrote data as an example right? Like you could write anything there?
yes, but DATA is a good name for your game data
Yes correct.
it is the name of the dict
Question.
ask away
You wrote attack 10, does that means that player does 10 damange always?
in this contex, yes thats what it means
Alr but you could use something like ranrange if you wanted random damange?
Just wondering.
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
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?
you call a random function called randrange
well, randint and randrange both works, you just have to know what the result is when you use it
oh alright.
!d random.randrange
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.
!d random.randint
random.randint(a, b)```
Return a random integer *N* such that `a <= N <= b`. Alias for `randrange(a, b+1)`.
Is something of these "better"?
share your code again with me
yes, randrange is better
user_health = 50 so this is player health
Yep!
damage_to_enemy = random.randint(5, 15) this is the damage you do to an enemy
Yes correct, between these numbers.
damage_to_user = random.randint(3, 8) this is the damage an enemy does to the player
correct
and is that all you want your game to do?
Well this is part one of the game so I don't really need anything more of that.
do you want to add defence into this, and do you want to add weapons that give you more damage?
I actually already got defence
Inventory will be added later
You can choose, 1 attack 2 defend, 3 runaway
yes, but how you plan the data is done now, not later
data is done now?
no, far from it
no no, but like what do you mean? I didn't really understand.
do you want the player to be less affected based on how much defence the player has?
Oh, yes!
DATA = {
'player': {
'name': 'Isac',
'HP': 100,
'attack': 10,
'defense': 5,
},
}
so it makes sense for the player to have defence rating
i see, and hence take less damage
yes
the player needs to have an inventory as well
correct.
lets add this
๐
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?
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?
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
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?
try to imagine a pokemon fight with only one pokemon.
Yes, after a victory, you are going to move over to a new room. The big boss should be at this room
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?
right
what do we need to know about a room?
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.
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
Should I add that in the story?
it would be a poor game if you could not tell the player where he is standing
Can I add it here?
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
Well you get to choose what enemy that are going to be in that room
you mean if you choose runaway?
lets start with empty rooms at first
i mean to other rooms
Is it good to use print to descripe the room?
yes
Ok should I add it now?
will the rooms have objects to pick up?
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
enter
no, its something like entred
you enter the Hallway
okay.
you have entered the Hallway
so lets focus on the part that is the most important first
that is to create the place where the data is saved
you are also learning english with coding๐
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': []
},
],
}
correct
oh damn
the tricky part is how you would get this into my code
or how I would do that
dont worry about it
lets figure out all the data you need to save for your game
What data would that be?
why inventory has nothing?
well, what more are missing?
because we have not picked up anything
inventory maybe?
oh ok
we have a place to save the inventory
maybe we should add enemies
there are not a single enemy in the data
there 2 enemies one in entrance hall and one in kitchen
yes, you have, but im talking about the DATA we are creating right now
am i right?
so lets add enemeies to the data
Yeah okay. I do understand don't get me wrong but why do we need to create this data? Like what is it for? Because we got a decent working game. I'm not trying to be rude, you are a very good teacher so don't get me wrong!
the key to a game you can expand is to control two things
behaviour and data
with functions you can only control behaviour
That's why we are creating this data, alr. Now I get it!
with class you can control behaviour data and many many many other things
but class is an advavanced topic
eivl, why do we need to control multiple things? What would you use that for? Is that for inventory
so to make it similar to what you have done, we are now putting the data into a dict
it is the nature of games to have mutiple moving parts
and since functions only control behaviour, you will end up with a spagetti mess if you try to force functions to controll everything
oh ok
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,
},
],
}
isn't it better to have the same stats on the first two enemies?
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
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
well, i find it more interesting to have more options, you can however do it with one fixed boss if you want to
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
the thing is we don't need more bosses rn. Like the bosses should be in the other room
well add one then, the number does not really matter that much
you only fight against one enemy tho? like you dont need to play against everyone?
that is something you can controll
the behaviour of the fight is a function that decides the logic
Ok you get to fight against 2 enemies, one normal and one boss
this are just the available data for the game in one place
then you get to choose against multiple
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
the data should be the first thing after imports
do I need to replace something?
no, you should write everything again, always write everything twice
or WET
what more is missing from the enemies?
I added the bad dragon as a new enemy
but
you cant choose him when you are starting the gaame
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
dang
I fixed it
this is from my editor
so.. what more is missing from the enemies?
yes, that is true, i was thinking about the requirements from the assignment now
no, there is one thing missing from the enemy
A big thing?
do you know Swedish?
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
right...
you are very right
how the heck did I miss that
got any idea?
๐ค
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,
},
],
}
it would probaly be good if each enemy had a specific item, the bad demon could have hp and so one
on*
here each enemy has no item
isnt it interesting to know that before you have written any game logic for the "new game system" you have to worry about all this
the item should help you in some way, agree?
yes it is
Yes correct
so it could be everything from helath to a weapon
so you can give more HP, attack or defence
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
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?
yes, it should
the sword should have these attributes
{'name': 'sword', 'attack': 5, 'defense': 0, 'hp': 0} explain why?
because the sword should only do damange, it shouldn't defend you or heal you.
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
if the player got two swords, he would have +10 attack
ye
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,
},
],
}
we should probaly do an inventory with more than one space
yes a list is good!
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
yep yep
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
i just made a copy of the sword for all enemies, but you have to create your own items later
yes, that is why we start with the easiest and most important, the data
even the easiest is hard for me
programming is hard
correct, sadly i dont like it. But I don't have another choice. I'm glad that you are helping me
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
yeah okay
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,
},
],
}
Jeez im getting kinda slow now
i think its good enough, the values can be changed later
That looks very good
well what do you say, we should maybe take a break for today. Im getting tierd
sure
and in the main.py file i have from constants import DATA
did you import data?
yes, we need the data in our main file, i just dont want a wall of text to clutter the code
which editor are you using?
this is pycharm
oh alright
It is for python only
it is, part of jetbrains. it is not a good editor for beginners
I dont wanna get off track but eivl is this your job?
Vs code is good for beginners?
i am a python developer yes
yes
Well you are a good teacher for sure
thank y ou
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
we use the random function we talked about
hmm what was it
randint?
randrange?
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
right, but we dont need a number
entrance hall
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
well... i got it from your code, do you not know what it does?
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
yeah correct
sometimes we want to control exactly what lines of code we run, but now we just run everrything as it is written
there is one thing i hate with python, to choose room 1 you have to write 0. that is confusing
python is zero indexed
just remember that and you will be fine
it is confusing yes, but it makes math easier
yea
it is better to be confused for a short amount of time, compared to having to think when doing math every time
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?
add elements as a variable
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
ye
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?
so how many enemies do we want to add to this room?
3
or what about, 1, 2 or 3?
0-3
nah. cant have 0 enemies, then we dont get weapons to fight the boss
alright, to do things two times, what type of code do we need?
like a loop?
I do know what while loop is btw
we can use a for loop or just write the same line of code twice
you can use something like append.list
yes, but its mylist.append(...)
we do want to choose one enemy randomly
DATA['enemies'] are all the enemies
we want to choose one of them at random
we use the random commando
yes, lets use random.choice
random.choice(DATA['enemies'])
this will choose one random enemy
ye
it will choose one enemy yes
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
my class is done btw..
no worries
my irl class if you wondering
not your class
your class is god
good
i see, but i think its enough for now, we can continue later
tomorrow evening yes
and we will add behviours we need, select monsters, attack, defend, run away
๐
these behaviours will be almost identical to the ones you have already made
at least so far as i remember them
yes
but they will use the DATA instead
Good Bye
Goodbye
later!
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.