#Trying to add Polymorphism to my 'Turn base Snake Game"

19 messages · Page 1 of 1 (latest)

grizzled egret
#

Good Morning! I am currently having issues on a project I am doing for school. It is a spin on the 90's game, snake. The only difference is that it is turn based. I am currently trying to add BonusItems, or superPowers to my game. Right now I want to add a bonus item that doubles the score, but for some reason it is not working. ANY help will be grately appreciated

The files for powerup are:
PowerUp
DoubleScore
GitHub Link:
https://github.com/WardRiverPlease/COSC/tree/main

GitHub

Contribute to WardRiverPlease/COSC development by creating an account on GitHub.

paper dewBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

remote obsidian
#

I think @odd plinth would be interested

grizzled egret
#

!!

remote obsidian
odd plinth
#

no way

#

(what does?)

plush girder
#

in applyPower(int score) the score is a local variable.
You probably meant that to be int&

remote obsidian
odd plinth
#

ah

boreal igloo
grizzled egret
plush girder
grizzled egret
#

umm. Okay, so as of now I am just lost on the state of polymorphism and the intersection of my code, how would this change enact the power up to work ?

odd plinth
grizzled egret
plush girder
#

what you want is probably this:

    if (gameBoard.checkCollisionWithFood())
    {
        int score = 100;
        
        if (activePowerUp != nullptr && activePowerUp->isActive())
        {
           activePowerUp->applyPower(score);
        }

        LevelManager.increaseScore(score);
    }

applyPower(int& score) expects a variable that can be altered (called l-value in c++ speak)