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

  • Home
  • SEARCH
  • 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 3401772
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:03:23+00:00 2026-05-18T05:03:23+00:00

I am trying to write a program to simulate a card game. I have

  • 0

I am trying to write a program to simulate a card game. I have class called MagicCard, and a variety of classes that extend card, like card1, card2… I want to find a way to store a list/array of different cards (a deck). Each card1, card2… has a “special” effect that they trigger when they are played, so the need a unique function, which is why i need all the different subclasses. A lot of the cards have a similar properties. How can I store the deck in a reasonable and accessible manner? (I want the deck to easily be manipulated so I can add a card, or remove a card from it when I want).

Currently this is what I have:

//My Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mtgDeckSimulator
{

    //General properties of a magic card, extended by individual classes
    class cardProperties
    {
        private String cardName;
        /*Mana Array Aranged in the following Order:
         * [Colorless,White,Blue,Black,Red,Green] */
        private int[] manaCost;
        /* Card Type int definitions:
         * 0-Artifact
         * 1-Creature
         * 2-Enchantment
         * 3-Instant
         * 4-Land
         * 5-Planeswalker
         * 6-Sorcery
         * 7-Tribal */
        private int cardType;
        public int attack;
        public int defense;
        private bool permBool;
        private bool isLegen; //Or is restricted to one copy
        public cardProperties(String cardName,int[] manaCostIn,int cardTypeIn,int attack,int defense,bool permBoolIn,bool isLegenIn)
        {
            this.cardName = cardName;
            manaCost = manaCostIn;
            cardType = cardTypeIn;
            permBool = permBoolIn;
            isLegen = isLegenIn;
        }
        //Get Variables
        public String getCardName()
        {
            return cardName;
        }
        public int[] getManaCost()
        {
            return manaCost;
        }
        public int getCardType()
        {
            return cardType;
        }
        public bool getPermBool()
        {
            return permBool;
        }
        public bool getIsLegen()
        {
            return isLegen;
        }
        //Other Methods
    }

    //Interface for magic cards
    interface MagicCard
    {
        int SpecialEffect();
    }
    #region Magic Card List
    class WallOfOmens : cardProperties, MagicCard
    {
        public WallOfOmens()
            : base("Wall of Omens", new int[6] { 1, 1, 0, 0, 0, 0 }, 1, 0, 4, true, false)
        {
            ;
        }
        public int SpecialEfect()
        {
            return 1;
            //throw new NotImplementedException();
        }
    }
    class Card2 : cardProperties, MagicCard
    {
        public int SpecialEfect()
        {
            return 2;
            //throw new NotImplementedException();
        }
    }
    #endregion
}

Is there a better way to implement this? Also the code does not work as it tells me WallOfOmens and Card2 do not implement SpecialEffect(), why is that happening?

  • 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-05-18T05:03:23+00:00Added an answer on May 18, 2026 at 5:03 am

    I would consider an alternative, use composition instead of inheritance. Composition is more flexible than inheritance, it allows you to combine different aspects more freely than inheritance.

    Instead of creating

    abstract class BaseCard{abstract int SpecialEffect();}
    class Card1 : BaseCard{override int SpecialEffect(){return 1;}}
    class Card2 : BaseCard{override int SpecialEffect(){return 2;}}
    ...
    

    you create different SpecialEffect-classes

    abstract class SpecialEffectBase{abstract int SpecialEffect();}
    class SpecialEffect1 : SpecialEffectBase{override int SpecialEffect(){return 1;}}
    class SpecialEffect2 : SpecialEffectBase{override int SpecialEffect(){return 2;}}
    ...
    

    and assemble the different cards in a factory

    Card card1 = new Card(new SpecialEffect1());
    Card card2 = new Card(new SpecialEffect2());
    

    This might sound like just another step of indirection, but if you reuse several some effects in different cards, and have other properties that differ between cards, like Rules or something you can assemble them like this

    Card card1 = new Card(new SpecialEffect1(), new Rule1());
    Card card2 = new Card(new SpecialEffect1(), new Rule2());
    Card card3 = new Card(new SpecialEffect2(), new Rule1());
    Card card4 = new Card(new SpecialEffect2(), new Rule2());
    ...
    

    Another benefit is that it forces you to encapsulate the SpecialEffect-rules in the SpecialEffect-classes, the Rule-rules in the Rule-classes, etc. instead of having them all over the place in your Card class.

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

Sidebar

Related Questions

For my data structure class, I am trying to write a program that simulates
I'm trying to write a program that uses sockets to connect with other instances
I'm trying to write a program in C (on Linux) that loops until the
I am trying to write a C++ program that takes the following inputs from
I am trying to write a fragment program that will take a texture and
Imagine we have a program trying to write to a particular file, but failing.
I trying to write a program that navigates the local file system using a
I'm trying to write a program to process the BSD-style process accounting file under
I'm trying to write a simple program in VC++ which will just initialize the
I'm trying to write a C# program, where when a user enters some data

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.