Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7993489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:51:48+00:00 2026-06-04T13:51:48+00:00

I am creating a game for my school project, so I am not here

  • 0

I am creating a game for my school project, so I am not here for any kind of code, just a global idea on how to do what I am trying to do…

I have Pieces and each piece as is own color and Type like this :
Piece 1 – Yellow – Simple
Piece 2 – Yellow – Explosive
….
Piece 10 – Blue – ChangeColor

At start the game will be field with random pieces from this list (a list created earlier with just one kind of each piece), if we have 3 or more in a row the game as to remove them and count the points, but if one of the 3 (or more) has any “power effect” than the pieces arround must react to that power (hard to explain with my low english level but I think you got it :S..)

For now my game only had simple pieces, and for that I used and enum like this :

public enum CorPeca 
{    
     AMARELO,
     AZUL,
     VERMELHO;
}

On the board class I was doing this :

    this.arrayPecas = new ArrayList<Peca>();

    for (CorPeca corPeca : CorPeca.values())
        this.arrayPecas.add(new Peca(corPeca));

and on the Pieces class i was doing this

public Peca(CorPeca tipoPeca)
{
    this.definirPeca(tipoPeca);
}

public CorPeca getCorPeca() { return this.corPeca; }
public char getCharPeca() { return this.charPeca; }

public void definirPeca(CorPeca tipoPeca)
{
    switch (tipoPeca)
    {
        case AMARELO:
            this.charPeca = 'a';
            this.corPeca = CorPeca.AMARELO;
            break;
        case AZUL:
            this.charPeca = 'u';
            this.corPeca = CorPeca.AZUL;
            break;
        case VERMELHO:
            this.charPeca = 'e';
            this.corPeca = CorPeca.VERMELHO;
            break;                
    }
}

But I was thinking of a good method to easily add those “Power Pieces”, but more than that, being able to add more colors and more “Powers” in the future…

I was thinking about creating subclasses and using extend, but the whole idea just don’t fill in my mind since we can’t extends several classes…

So can anyone give me a global idea on how I can archive that ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:51:50+00:00Added an answer on June 4, 2026 at 1:51 pm

    The classic OOP way to do this would be to define an abstract base class that represents all pieces and contains common functionality (such as a list of powers):

    public abstract class Piece {
        // put in fields that every piece has, e.g. x and y co-ordinate here
    
        // array of powers
        protected ArrayList<Power> powers=new ArrayList<Power>();
    
        // method to add new powers to the piece
        public void addPower(Power power) {
            powers.add(power);
        }
    
        // power method - optionally overriden by specififc pieces
        public void applyPowers() {
            for (Power power:powers) {
                power.methodToActivatePower();
            }
        }
    
        // abstract char method
        public abstract char getChar();
    
    }
    

    Note that abstract means that you can’t directly instantiate this class – you can only make instances of concrete subclasses.

    Then extend this class to implement each specific piece:

    public class YellowPiece extends Piece {
    
        // override applyPowers for yellow piece (if needed)
        @Override
        public void applyPowers() {
            // code for yellow piece power handling goes here
        }
    
        // override char - required
        @Override
        public char getChar() {
            return 'y';
        }
    
    }
    

    You can still create an ArrayList<Piece> and populate it with something like:

    ArrayList<Piece> pieces = new ArrayList<Piece>();
    pieces.add (new YellowPiece());
    pieces.add (new GreenPiece());
    // etc....
    

    Then if you want to apply the power of a specific piece, just do:

    pieces.get(pieceNumber).applyPower();
    

    You’ll obviously need to customise this code a lot to make it work in your game, but hopefully it gives you the general idea. Note that there are lots of other ways of achieving the same goals – I’ve just described the “classic” OOP way.

    P.S. Apologies for all code being in English, but your English is far better than my Portugese 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started creating a game, and I added a second project, it's the
I have a school project I'm not supposed to be starting til monday, and
I'm the network programmer on a school game project. We want to have up
I have just finished creating a game of life simulation for c# and found
I am creating a simple Mahjong game for a final project at school and
As a school project I am creating a browser game in Java, for the
I'm creating a simple JavaScript multiple choice game. Here is a sample question: p
I am developing a game, well have an idea for a game and have
I'm creating a game in Java for fun and I'm trying to decide how
I'm creating a game in which I have a somewhat complex method for creating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.