• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

Stuck on simple Visual Basic C# game

Question

pinacallada1    0

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

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0
Matthew S.    364

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

Share this post


Link to post
Share on other sites
  • 0
pinacallada1    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

Share this post


Link to post
Share on other sites
  • 0
Andre S.    1,923

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#".

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.