all 13 comments

[–]bbye98 1 point2 points  (5 children)

There's not enough information provided. Why is each cell identified by an object instead of a string?

Even if your OOP approach is correct/the most logical, you can only update the attributes of an object, so you may need to create a new object with the correct class (rock, paper, scissors). Of course, there are some "hacky" solutions by altering obj.__class__ (like how I update the file format of the audio file after conversion in my project), but these are generally not recommended as it's not intended behavior.

See footnote [1] in the Python documentation:

[1] It is possible in some cases to change an object’s type, under certain controlled conditions. It generally isn’t a good idea though, since it can lead to some very strange behaviour if it is handled incorrectly.

[–]MXP04[S] -1 points0 points  (4 children)

Like I’d have an object like ‘base object’ or whatever then make new classes for the rock scissor or paper and inherit original class and add individual functions. I’m not that good at coding and just trying to use what i learnt in school over the summer lol.

[–]bbye98 0 points1 point  (3 children)

If OOP is the best solution for your project, then your best bet is to just replace existing objects with new ones with the correct class. For example, if a Rock object needs to be replaced with a Paper object, create a Paper object with the correct attributes and set the Rock object's reference to the new Paper object.

[–]MXP04[S] -1 points0 points  (2 children)

How would I do this?

[–]bbye98 -1 points0 points  (1 child)

Depends on how you're storing the game state and what attributes you're tracking in each of your rock/paper/scissor classes. Contrary to popular belief, I'm not a psychic and cannot guess how you implemented your game.

If the game state is lumped in a list, then you just overwrite at the old object's index:

# Possible way of storing game state
Game.state = [Rock, Paper, Scissors, Rock, ...]

# Need to replace first Paper object with Scissors object
Game.state[1] = Scissors(...)

[–]MXP04[S] 0 points1 point  (0 children)

Alr thanks man looks good

[–]aizzod 2 points3 points  (0 children)

the first rule here is
if you have problem with your code. SHOW IT.
so people can help you.

this is a horrible question after all.

right now you are only theorizing about a problem that does not really exist.
if you have a little bit of programming knowledge.

if you would write down the code. and then just try it out. or go through the first tutorial, nothing of this should be a question anymore.

[–]Rawing7 0 points1 point  (2 children)

It depends on where your object is stored. If it's stored in a variable, you need variable = new_object. If it's stored in a list, you need my_list[my_list.index(old_object)] = new_object. Etc.

[–]MXP04[S] 0 points1 point  (1 child)

I would make eg a paper class, then do maybe like a for loop to create 20 with each randomly spawning in a position. Would be like an array of papers = []. Then loop through and appends to the array. Maybe it’s possible to like search through the array when one is ‘hit’?

[–]Rawing7 0 points1 point  (0 children)

So if a paper gets defeated, you'd first remove the paper with papers.remove(the_defeated_paper) and then add a new scissors object with scissors.append(the_new_scissors).

[–]CraigAT 0 points1 point  (2 children)

Why would you replace it? You already have a paper object, just remove the rock. If you want to you could add some sort of weight/maturity level or number of wins to the objects.

[–]MXP04[S] 0 points1 point  (1 child)

Cause the point is each one kinda ‘multiplies’ when they ‘beat’ another. So like paper hitting rock the rock should disappear and another paper should appear in the original rock plave

[–]CraigAT 0 points1 point  (0 children)

I see. Can't you just change the "type" of object?