• 0

Stuck on simple Visual Basic C# game


Question

I am making a simple 5- a side text based football game for uni, problem is i suck at programming and have really messed it up so now im stuck as to what to do. The task description is only really to think of a simple 5 a-side game with goalkeeper (who can save), defenders (who can tackle) and attackers (who can shoot).  All players have a Name, a position and can pass, dribble and run. This includes a hasball feature which will check if a particular player has the ball. So far i have a basic code i made to work off for my classes, i can think of what i need to do exactly but i just don't know how to express it in code.

 

So far i only need to build off classes for the interfaces below but i cant seem to get any arrays working with it, i don't know how to implement the shoot, tackle run actions, its my first time programming this semester and im still getting used to everything i don't want to fall behind or possibly fail because of one module. What i have to work off is follows:

 

interface IFootballPlayer

    {

        string Name { get; set; }

        bool HasBall { get; set; }

        int XPos { get; set; }

        int YPos { get; set; }

 

        void Pass(FootballPlayer receiver);

        void Dribble(int x, int y);

        void Run(int x, int y);

        string ToString();

    }

 

    interface IGoalKeeper

    {

        int SaveSkill { get; set; }

        void Save(Attacker attacker);

    }

 

    interface IDefender

    {

        int TackleSkill { get; set; }

        void Tackle(Attacker attacker);

    }

 

    interface IAttacker

    {

        int ShootSkill { get; set; }

        void Shoot(GoalKeeper goalKeeper);

    }

 

If i can get this sorted ill be able to scrape a pass hopefully

I would be grateful for any advice, C# still looks like a alien language to me

Link to comment
https://www.neowin.net/forum/topic/1356538-stuck-on-simple-visual-basic-c-game/
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Show us what you've come up with so far (not just what the assignment provides you) and we can assist in aiming you in the right direction.

  • Like 1
  • 0

Hi i currently have a failed attempt at trying to get close to what ive been asked. Im sure it probably makes no sense. I have 2 classes so far 1 for all the players as asked e.g. defender attacker goalkeeper which is below.

class FootballPlayer
    {
        interface IFootballPlayer
        {
            string Name { get; set; }
            bool HasBall { get; set; }
            int XPos { get; set; }
            int YPos { get; set; }

            void Pass(FootballPlayer receiver);
            void Dribble(int x, int y);
            void Run(int x, int y);
            string ToString();
        }

       


        public class Attacker : FootballPlayer
        {
            Attacker[] playerArray = new Attacker[4];
            String[] attackerames = new String[] { "james", "edward", "tyson", "billy" };

            int ShootSkill { get; set; }
            void Shoot(Goalkeeper goalkeeper);
        }
        public class Defender: FootballPlayer
        {
           Defender[] playerArray = new Defender[4];
            String[] defenderNames = new String[] { "connor", "kyle", "darren", "daniel" };
            int TackleSkill { get; set; }
            void Tackle(Attacker attacker);
        }
        public class Goalkeeper : FootballPlayer
        {
            Goalkeeper[] playerArray = new Goalkeeper[2];
            String[] goalkeeperNames = new String[] { "jacob", "anton" };
            int SaveSkill { get; set; }
            void Save(Attacker attacker);
        }
        public interface IMovement
        {
            void Dribble(int dribbleSpeed);
            void Run(int runSpeed);
        }

    }
The main program is largely untouched as im trying to get in each players name and skill level before i try to make them shoot goals or anything. All in all i just need to make sure there are 5 players on each team who can follow the ball and shoot. If i can figure out how to name and give each player a skill level i can have it so if the attacker has a higher skill than the keeper he scores. And if the defender has higher skill he tackles.

Edited by pinacallada1
  • 0

This is an assignment on Object-Oriented Programming, the point is to see if you can come up with a class hierarchy. Some tips:

 

  • First of all don't nest your classes and interfaces like that. Declare each class and interface separately rather than one inside the other.
  • Pay attention to the wording and base your design off of that, it's a fairly 1-1 translation. For example, "All players have properties x, y, z" tells you quite clearly that these properties should be on a common base class.
  • Your individual classes should not be holding instances of themselves like that (your `playerArray` fields). The code using the class (your actual program) will instantiate the players it needs.
  • Same thing for the player names, the code using these classes will assign names. It seems like it's not clear to you how you're doing to use these classes.

 

Oh and by the way there is no such thing as "Visual Basic C#" :laugh:. "Visual Basic" and "C#" are two different programming languages. It's possible you meant to say "Visual C#", which refers to the C# integration in Visual Studio. Just say "C#".

 

This topic is now closed to further replies.
  • Posts

    • Microsoft lets you have extra year of Windows 10 updates for free by Taras Buria The end of Windows 10 support is quickly approaching, which means users are facing a tough choice: leave Windows 10 behind and update to Windows 11 or stay and either accept the risk of using unsupported software or enroll in the extended security update program. If you plan to go with the latter option, Microsoft has some important details and good news for you. Microsoft finally announced program enrollment details for Windows 10 users. Starting today, Windows 10 Insiders can access a new enrollment wizard through the Settings app and push notifications to set up their systems for the Extended Security Update program (ESU). More importantly, Microsoft is introducing free enrollment options, allowing Windows 10 users to remain supported for one more year without paying Microsoft a single dollar. Now, you can get 12 more months of security updates using one of the following three options: Use the Windows Backup app to sync your settings to the cloud Pay 1,000 Microsoft Rewards points Pay $30 (local prices may vary) This is the first time that Microsoft has made the Extended Security Update program available for consumers. Previously, this program was reserved for commercial customers only. However, four years after the release of Windows 11, Windows 10 remains the dominant desktop operating system. At this scope, Microsoft cannot just drop hundreds of millions of users behind. Microsoft's initial plan was to give customers 12 months of extra updates for $30, but now, the company is seemingly giving up on that. While the $30 option is still available, the program is pretty much free for every consumer, which addresses some of the concerns I expressed earlier. 1,000 Microsoft Reward points is a pretty small price to pay, and the Windows Backup option is entirely free. With these two new options, Microsoft makes security updates more accessible to users (governments are already warning users about the end of Windows 10 support), giving them more time to plan their migration to Windows 11 without sending their computers to the landfill and generating thousands of tons of e-waste. The enrollment wizard is now available to Windows 10 Insiders. Next month, it will be available outside the Insider program as part of the July non-security updates. Broad availability is expected by mid-August. Commercial organizations can also enroll their devices today using the Microsoft Volume Licensing Program. The price is $61 per device for one year. For Windows 365, these Cloud PCs are eligible for extended security updates at no extra cost. It is worth noting that the program only grants one year of security updates, from October 15, 2025, to October 13, 2026. However, those who need more support can opt for third-party solutions like 0patch, which promises five more years of security updates. The end of mainstream Windows 10 support means that the company will stop providing technical support and feature/security updates outside the ESU program. As such, many developers will start dropping Windows 10 support in their products, reduce available functionality, and more. However, Windows 10 PCs will not stop working overnight. Moreover, some of Microsoft-made services will continue receiving support. Those include Microsoft 365 and Microsoft Defender updates. Microsoft 365 apps will be getting new features until August 2026 and security updates until October 10, 2028. For many users, the biggest problem with Windows 11 is not its controversial taskbar or Start menu (which is getting a big redesign, mind you). Steeper hardware requirements prevent many users from updating their still-capable computers to a supported release. To mitigate this, Microsoft is willing to offer free security updates for one year instead of lowering Windows 11's hardware requirements. Several months ago, Microsoft doubled down on those and stressed that Windows 11's minimum hardware requirements would not be lowered.
    • When the rich steal, it's business, when the poor steal, it's a crime. Typical systematic injustice in the US. From broad daylight corruption being legal (a.k.a. lobbying), to deporting "illegal immigrants" from a land that was stolen to begin with. Alas, can't ever expect true justice from a land built from the ground up with injustice...
    • A little older than that really since it was originally Keyhole from 2001.
    • A lifetime subscription to AI MagicX (Rune Plan) drops to lowest price by Steven Parker Today's highlighted deal comes via our Apps + Software section of the Neowin Deals store, where for only a limited time, you can save 93% on a lifetime subscription to AI MagicX (Rune Plan). Transform Your Vision with AI-Driven Creativity AI MagicX is your ultimate creative companion, offering a suite of AI-powered tools designed to elevate your content creation process. From generating unique logos to crafting stunning art, AI MagicX empowers you to bring your ideas to life effortlessly. Enhance user engagement with our smart AI Chatbots, generate compelling articles with our AI Article Generator, and create captivating stories with our AI Story Generator. Streamline your document editing with the AI MagicX Editor. Perfect for entrepreneurs and small business owners, AI MagicX provides customizable solutions that leverage cutting-edge AI technology to make your creative process seamless and efficient. Special AI-powered features for your services AI Logo Designer Craft unique brand identities effortlessly Generate personalized logos instantly, avoiding generic stock logos MagicX Art Generator Turn simple descriptions into breathtaking visuals No artistic skills needed to create stunning art AI Chatbots Boost user interaction and engagement Experience the power of our smart chatbots for free AI Article Generator Create high-quality articles in minutes Generate well-researched and engaging content effortlessly AI Story Generator Develop captivating stories with ease Transform your ideas into compelling narratives quickly Document Editor Enhance your document editing process Increase productivity, creativity, and efficiency with the AI Magicx Editor What is AI MagicX? AI Magicx is a comprehensive platform offering advanced AI tools for content creation. Whether you need a unique logo, captivating art, engaging articles, or interactive chatbots, AI Magicx has you covered. How AI MagicX works Start using AI MagicX to automatically enhance your creative process. Our tools are designed to be intuitive and user-friendly, making content creation simple. AI Magicx leverages advanced AI technology to deliver high-quality results quickly and efficiently. What's included in the Rune Plan per month? Unlimited MagicX words 250 MagicX Images 250 MagicX Logos Private Generations Commercial license 100 Premium Chatbots Messages Good to know Length of access: lifetime Redemption deadline: redeem your code within 30 days of purchase Access options: desktop or mobile Max number of device(s): 999 Version: 3+ Updates included A lifetime subscription to AI MagicX (Rune Plan) normally costs $972, but you can pick it up for just $59.97 for a limited time - that represents a saving of $912. For a full description, specs, and license info, click the link below. There are two other discounted plans available. Get this lifetime deal for just $59.97, or learn more Although priced in U.S. dollars, this deal is available for digital purchase worldwide. We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
    • AI can read everything it wants. It cannot comprehend like a human. Everyone is being sold a steaming pile of lies.
  • Recent Achievements

    • Week One Done
      DrRonSr earned a badge
      Week One Done
    • Week One Done
      Sharon dixon earned a badge
      Week One Done
    • Dedicated
      Parallax Abstraction earned a badge
      Dedicated
    • First Post
      956400 earned a badge
      First Post
    • Week One Done
      davidfegan earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      604
    2. 2
      ATLien_0
      226
    3. 3
      Michael Scrip
      169
    4. 4
      +FloatingFatMan
      154
    5. 5
      Som
      136
  • Tell a friend

    Love Neowin? Tell a friend!