• 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

    • Stardock Start11 v2.5.3.1 by Razvan Serea Stardock Start11 is a Windows 11 customization tool designed to bring back the classic Start menu and enhance users' desktop experience. It offers a range of features and options that allow users to personalize their Start menu and taskbar to suit their preferences. Make Your Desktop Yours Take complete control of your desktop with Start11. With Windows 11, Microsoft chose form over functionality and removed many different features that were available in Windows 10. With Start11, you can customize the experience to fit your personality. Features You Expect Windows 11 removed many features that were present in Windows 10, Start11 brings them back. From the basics like returning the right-click menu on the taskbar to ungrouping of windows on the taskbar. You can also choose to have your icons centered on the taskbar with your Start menu left aligned. One Desktop to Rule Them All When working with multiple devices across various versions of Windows, Start11 can help you create a common desktop experience. Make Windows 10 look like Windows 11, or 11 look like Windows 10. Or how about making both Windows 10 and 11 look like Windows 7? The choice is yours. Remove Unwanted Content Windows 11 brings with it a new design language but also more advertisements and content that you can’t remove. Take back complete control with Start11 and remove unwanted outside content and sections of the Start menu that you don’t want to see. Start11 v2.5.3.1 changelog: All the changes from 2.52 that were went to beta but never was not released Resolves issue with not always releasing reserved space when closing an app which reserved space on the side such as Multiplicity KVM switch bar. Resolved issue with enhanced taskbar not showing status indicators correctly for some running apps Tweaks to start button sizing with vertical taskbars on Windows 11 especially when using small icon mode Tweaks to drag & drop in Win10/Win11/App/Pro/Launcher menus to make creating folders easier and less like playing chase the item around :) Resolved issue with dragging out of a group in Win11/App/Pro/Launcher menus where you couldn't always drag out of a folder to a group below Resolved issue with taskbar texture not refreshing when the OS accent colour changes. Resolved issue with on top taskbar not in enhanced mode and clicking on the taskbar search field which would make the search window appear off the top of the screen incorrectly Apps flagged as 'new' in Win10/11/App/Pro/Launcher menus will now not have the flag once run once or right clicked on Improved removal of 'new' indicator on newly installed apps so it goes away in a day or so. The apps will still be considered 'new' for the recently installed apps list Improved sorting of child items in sub folders in all apps list Start10 style search no longer shows control panel results which are duplicates of the results in the Control Panel section. Enabled sort A-Z option for Folders and Fences groups too on Win11/App/Pro/Launcher menus Small tweaks to icon & tile image loading for Universal apps on Windows 10/11/App/Pro/Launcher menus Fixes setting pins to only show on a secondary not working for some apps. Users will need to reset the show only on a secondary setting on the pins which were not working. Start11 is only $7.40 For more information about Start11, please visit Start11 website. Disclaimer: Neowin's relationship to Stardock. Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Brave 1.80.113 by Razvan Serea Brave Browser is a lightning-fast, secure web browser that stands out from the competition with its focus on privacy, security, and speed. With features like HTTPS Everywhere and built-in tracker blocking, Brave keeps your online activities safe from prying eyes. Brave is one of the safest browsers on the market today. It blocks third-party data storage. It protects from browser fingerprinting. And it does all this by default. Speed - Brave is built on Chromium, the same technology that powers Google Chrome, and is optimized for speed, providing a fast and responsive browsing experience. Brave Browser also features Brave Rewards, a system that rewards users with Basic Attention Tokens (BAT) for viewing opt-in ads. This innovative system provides an alternative revenue model for content creators and a way to support the Brave community. Brave 1.80.113 changelog: Web3 Implemented stricter wallet routing and added a 404 page for an invalid route. (#45684) Updated opt-in screen for Meld to fit on small screen sizes. (#44318) Removed the “Edit” gas button for Zcash transactions. (#45748) Fixed crash which occurred when trying to render Brave Wallet image in certain cases. (#46828) Fixed “Search” icon being cut off on the “Explore” page. (#44950) Leo Added support for automatic default model. (#45954) Added loading spinner to display when uploading image attachments. (#45889) Improved image attachment UI. (#45672) Removed Mixtral from the default Leo model list. (#46406) Fixed attachment thumbnail image not being displayed correctly. (#45916) Rewards Updated dark mode color theme for Rewards UI. (#45741) General Added the ability to open Progressive Web Apps (PWAs) in a tabbed window. (#45435) Updated extension import to warn the user to close Chrome if opened during import attempt. (#44945) Updated extension import to import both “IndexedDB” and “Local Extension Storage” when present for an extension. (#44946) Updated buttons on interstitial pages to use Brave theme. (#45666) Removed the password check box from brave://settings/importData dialog when importing from Chrome. (#46206) Fixed crash which occurred when moving a tab across monitors. (#46066) Fixed issue with “:matches-path” being used at the beginning of a filter rule. (#46220) Fixed display of long keyboard shortcuts on brave://settings/system/shortcuts. (#41873) Fixed “Toggle Vertical Tabs Expanded” keyboard shortcut not working when “Expand Vertical Tabs Independently per Window” is enabled. (#41074) Upgraded Chromium to 138.0.7204.49. (#47094) Download: Brave Browser 64-bit | 1.2 MB (Freeware) Download: Brave Browser 32-bit View: Brave Homepage | Offline Installers | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Google releases Gemma 3n, a new AI model built for mobile devices by David Uzondu Google has announced Gemma 3n, the next generation of its open AI models, and it is a significant step up from what we saw before. After a preview last month at Google I/O, the full version is now here and ready to run directly on your hardware. For those of you who are not aware, Gemma is a family of open AI models. It is different from Gemini in that it is designed for developers to download and modify, whereas Gemini is Google's closed, proprietary powerhouse. The model can now natively process inputs like images, audio, and video to generate text, a leap from just being a text-based model. It can also run on hardware with as little as 2GB of memory, and is supposedly better at tasks like coding and reasoning. Here's the full list of improvements as outlined by Google: Multimodal by design: Gemma 3n natively supports image, audio, video, and text inputs and text outputs. Optimized for on-device: Engineered with a focus on efficiency, Gemma 3n models are available in two sizes based on effective parameters: E2B and E4B. While their raw parameter count is 5B and 8B respectively, architectural innovations allow them to run with a memory footprint comparable to traditional 2B and 4B models, operating with as little as 2GB (E2B) and 3GB (E4B) of memory. Groundbreaking architecture: At its core, Gemma 3n features novel components like the MatFormer architecture for compute flexibility, Per Layer Embeddings (PLE) for memory efficiency, and new audio and MobileNet-v5 based vision encoders optimized for on-device use cases. Enhanced quality: Gemma 3n delivers quality improvements across multilinguality (supporting 140 languages for text and multimodal understanding of 35 languages), math, coding, and reasoning. The core of its efficiency is a new architecture Google calls MatFormer. Google uses the analogy of a Russian Matryoshka doll to describe it: a larger model contains a smaller, fully functional version inside. This allows a single model to run at different sizes for different tasks. And as for benchmarks, the larger E4B model is the first model under 10B parameters to break a LMArena score of 1300. The model's audio capabilities now support on-device speech-to-text and translation, using an encoder that can process speech in fine detail. The vision side of things is powered by a new encoder called MobileNet-V5, which is much faster and more efficient than its predecessor. It can process video at up to 60FPS on a Google Pixel device. If you're interested, you can start playing with it immediately as the models are available through familiar platforms like Hugging Face and Kaggle, and you can even experiment with them directly in Google AI Studio. More details can be found in the official announcement post.
    • Bitdefender Antivirus Free 27.0.53.265 by Razvan Serea Bitdefender Antivirus Free is a free antivirus software especially designed to protect your Windows PC. Quick to install and light on computer resources, it is good for gaming, image and video editing, and resource-intensive applications. Once you have installed Bitdefender Antivirus Free, your device is protected against all kinds of threats (such as malware, spyware, ransomware, exploits, botnets and trojans) and internet threats (such as hackers, phishing and spam). The app uses the Photon technology to enhance the speed and performance of the threat scanning process. It works by learning the usage patterns of your system apps to know what and when to scan, thus minimizing the impact on system performance. Many free antivirus solutions are as intrusive and resource-heavy as the viruses they’re supposed to stop. Only Bitdefender Antivirus Free is designed from the ground up to keep you safe without disrupting your workflow and focus. Free antivirus protection that stops even the fastest-evolving attacks Runs silently in the background and stays out of your way Impossibly light on CPU (will not slow down your computer) Live customer support included (unlike other free antivirus software) Bitdefender Antivirus 27.0.53.265 changelog: Updated Safepay version Fixed blank page issue when loading www.chewy.com in Safepay Fixed login errors on www.pcfinancial.ca in Safepay Fixed issue where websites failed to load with Encrypted Web Scan enabled Fixed issue where Search Advisor checkmarks appeared upside down Fixed duplicate notifications from Alert Mode Operating systems: Windows 7 with Service Pack 1, Windows 8.1, Windows 10 and Windows 11 Download: Bitdefender Antivirus Free 27.0.53.265 | 18.0 MB (Freeware) View: Bitdefender Antivirus Free Homepage | Release Notes | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • i built my own, all ya need is a pc with two network cards and i used operwrt as the os
  • Recent Achievements

    • One Month Later
      jfam earned a badge
      One Month Later
    • First Post
      TheRingmaster earned a badge
      First Post
    • Conversation Starter
      Kavin25 earned a badge
      Conversation Starter
    • One Month Later
      Leonard grant earned a badge
      One Month Later
    • Week One Done
      pcdoctorsnet earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      541
    2. 2
      ATLien_0
      200
    3. 3
      +FloatingFatMan
      176
    4. 4
      Michael Scrip
      145
    5. 5
      snowy owl
      113
  • Tell a friend

    Love Neowin? Tell a friend!