#Classes (basic)

72 messages · Page 1 of 1 (latest)

elder grotto
#

I can send the assignment and the code I'm working with for clarification if needed. But the main issue and what I need help is a class and some funtionality in the code. So basically I have creates a class and objects with acids (from a file of 20 acids) and some of its attributes, in total 4 attributes. It's code, name, weight, something. What I want to do is to is be able to, from an input statement, get a sequences (like CAAC) which are the acid codes, so C, A, A, C and make both an object out of it as well as being able to calculate the weights from all sequnces of acids (every acids has a specific weight)

rotund dawn
# elder grotto I can send the assignment and the code I'm working with for clarification if nee...

your problem is, that you dont know what you want to do.

Thats a beginner problem in programming.
If someone asks you how to make a fried egg, you would think:

- grab eggs
- place them in a pan
- fry till its like i want it

But in programming you need to think smaller, much smaller steps.

just to break down the first point here:

- go to fridge
- open fridge
- search for eggs
- grab eggs
- close fridge
- go to pan
- open egg carton
- grab egg
- break egg over pan
...

and even that can be made smaller.

Basically a program is dumb and cant do shit.
Based on how high the language is you use, you can do more easyer.

You need to think smaller about what you want and what you need for it.
A good help is explaining that to someone, who has no idea about PCs/coding and explain it, like they can follow you.
Because then you have made the steps so simple, you can follow them too 😉

elder grotto
#

Well yes

#

That’s programming 101

#

I need some advice and help

past wing
#

I don't see the question in your original post

lunar crater
elder grotto
#

I’m done with that code

#

Just to answer his reply

#

Tho I could use some help in my current project

#

What would be the best course of action for a single player battleships game where you have 10 textfiles with ships done

#

@lunar crater @past wing

#

Would it be to just print out an empty board and then make a list for the board you open to get coordinates

#

I can go into detail if needed

#

This may be super vague and horribly explained

#

It’s a battleships project anyway without randomized ship placements and no user interface

lunar crater
#

Why do you need text files?

#

@elder grotto

elder grotto
#

So I have already made 10 textfiles for the ship placements and the board

lunar crater
#

Why are you using text files?

elder grotto
#
s - - - S -
- - - - S -
- - S - - - 
- - S - - - 
- - S - - - 
- S - - - - 
#

isnt it ""py ""

lunar crater
#

?

elder grotto
#

3 ` and py

#

to format it as a code

lunar crater
#

Yeah

elder grotto
#

regardless its useless here

#

the text i sent it how the files look

#

the "-" is empty water spaces, and S are part of a ships

#

and I have 10 of those, and I will randomize and pick 1 each game to make it less predictable

#

question is it this is a good course of action to take given the circumstances:

#

to create an empty board for the player, to make a 2d list out of the radomized file, and somehow set it to, if the koordinate picked = S in the 2d file list, then replace that coordinate with X, otherwise O

#

or should I use classes or something

lunar crater
#

You could use a class

#

I get it depends on how you design the game and the classes

#

Like, you could do everything your class does with functions

#

Because you don't really need class instances

elder grotto
#

Yeah, there should be a ton pf ways to do this project

#

But as a 2 week old progrsmmer

#

I’m asking what the best course of action would be

#

Or a good one anyway

#

I dont want to start something stupid then get stuck mid way thru

lunar crater
#

I don't think you should get caught up on these trivial things so early on

#

Just make something that works and worry about how good it is later

elder grotto
#

Not how good, for instance I dont want to create a class for the ship or board

#

Then get stuck on functionality later on

lunar crater
#

Okay, let's start from the beginning

#

What classes are you planning to make?

elder grotto
#

Unsure

#

I’ve seen ppl with the same project use classes for ships and board tho

#

Never really understood why

lunar crater
#

I don't see a reason why you need to

#

I usually use classes for two reasons:

  1. As some sort of way to store data that isn't really nice to do with built in datatypes
  2. Some thing has relevant methods attached to it
#

Could have both

#

But in this case for your battlefield game, there isn't really a reason to use classes except maybe the board?

#

But then there's no reason to not use a 2d list and functions

#

Others might disagree tho wolfshrug

elder grotto
#

What would we gain by assigning it a class?

#

We can access coordinates easily via 2d lists

lunar crater
#

Use a 2d list and functions

#

And then when you realise you need classes (which I doubt you do) you can refactor the code

elder grotto
#

bet

elder grotto
#

I’ll do as much as I can

#

I’ll come back if I have further questions

lunar crater
#

ez

elder grotto
#

@lunar crater

lunar crater
#

What

elder grotto
#

!close

#

@lunar crater can you close this channel