• 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

    • Wikipedia has become hot molasses with mostly filth masquerading as truth. Most of it is the imagination of few writers who think of themselves as above god. The narrative setup is mind boggling.
    • he donates it all to his foundation to launder, trying to avoid inheritance tax while buying up africa
    • No. 1/10th the cost of a Mac? The Mini starts at 599. What mini-pc costs 1/10th of that? The OS is nothing like macOS. Sure you can make it look like it, but it won’t work anything like it. Applications won’t install, or remove the same. Application compatibility will be different. Managing the OS is completely dissimilar, the biggest common ground will be a few CLI utilities. You can definitely get yourself an inexpensive little setup that has a good Linux distro and be happy. It won’t be 1/10th the cost or essentially a Mac though.
    • Vivaldi 7.4.3684.50 by Razvan Serea Vivaldi is a cross-platform web browser built for – and with – the web. A browser based on the Blink engine (same in Chrome and Chromium) that is fast, but also a browser that is rich in functionality, highly flexible and puts the user first. A browser that is made for you. Vivaldi is produced with love by a founding team of browser pioneers, including former CEO Jon Stephenson von Tetzchner, who co-founded and led Opera Software. Vivaldi’s interface is very customizable. Vivaldi combines simplicity and fashion to create a basic, highly customizable interface that provides everything a internet user could need. The browser allows users to customize the appearance of UI elements such as background color, overall theme, address bar and tab positioning, and start pages. Vivaldi features the ability to "stack" and "tile" tabs, annotate web pages, add notes to bookmarks and much more. Vivaldi 7.4.3684.50 changelog: [Chromium] Update to 136.0.7103.170 [Crash][Mail][JSError] RangeError: Maximum call stack size exceeded (VB-115288) Download: Vivaldi 64-bit | 125.0 MB (Freeware) Download: Vivaldi 32-bit | ARM64 View: Vivaldi Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • I must be doing something right because I feel like I don’t really come across that many cheaters. I’m not saying you don’t, I just must be really lucky.
  • Recent Achievements

    • Apprentice
      Adrian Williams went up a rank
      Apprentice
    • Reacting Well
      BashOrgRu earned a badge
      Reacting Well
    • Collaborator
      CHUNWEI earned a badge
      Collaborator
    • Apprentice
      Cole Multipass went up a rank
      Apprentice
    • Posting Machine
      David Uzondu earned a badge
      Posting Machine
  • Popular Contributors

    1. 1
      +primortal
      519
    2. 2
      ATLien_0
      260
    3. 3
      +Edouard
      192
    4. 4
      +FloatingFatMan
      178
    5. 5
      snowy owl
      135
  • Tell a friend

    Love Neowin? Tell a friend!