CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2011
    Posts
    6

    Unhappy having touble with creating a game in c#

    hi i am creating a game at the moment using visual studio where a bike collects medals from moving up down left right ect.. and i have been getting an error in the code which is the following could you please help me solve this as i don't understand why this keeps appearing. i'm trying to make it so that once the bike moves to the medal it will remove the medal from the page.

    Inconsistent accessibility: parameter type 'bikegame.medal' is less accessible than method 'bikegame.MainPage.Addmedal(bikegame.medal)'

    Code:
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Windows.Media.Imaging;
    using bikegame.Web;
    
    namespace bikegame
    {
        public partial class MainPage : UserControl
        {
            bike mybike;
            medal mymedal;
    
            private int medalTimer = 0;
            int medalCount = 0;
            List<medal> medal;
    
            public MainPage()
            {
                InitializeComponent();
                mybike = new bike();
                mymedal = new medal();
    
                InitializeComponent();
                medal = new List<medal>();
                CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
    
                Image myImg = new Image();
                myImg.Source = new BitmapImage(new Uri("bike.png", UriKind.Relative));
                myImg.Width = 80;
                myImg.Height = 60;
                mybike.Content = myImg;
                layoutRoot.Children.Add(mybike);
                Canvas.SetLeft(mybike, 100);
                Canvas.SetTop(mybike, 50);
                layoutRoot.Children.Add(mymedal);
                CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
            }
    
           
    
             public void Addmedal(medal a)
             {
                 medal.Add(a);
                 layoutRoot.Children.Add(a);
             }
    
             public void Removemedal(medal a)
             {
                 medal.Remove(a);
                 layoutRoot.Children.Remove(a);
             }
    Last edited by DataMiser; May 4th, 2012 at 11:27 PM. Reason: added code tags

  2. #2
    Join Date
    Feb 2012
    Location
    Strasbourg, France
    Posts
    116

    Re: having touble with creating a game in c#

    "is less accessible than method"
    You didn't specified the access status of your variables so the compiler doesn't know what to do. If you don't know what to put, set them to public, you won't have any problems (though accessibily requires a bit of pre-thinking before coding )

    Code:
            public bike mybike;
            public medal mymedal;

  3. #3
    Join Date
    May 2012
    Location
    Bonn, Germany
    Posts
    43

    Re: having touble with creating a game in c#

    Just a side note:
    I see your classes are named "bike" or "medal".
    This is inconsistent with the standard naming conventions in C#, where classes start with uppercase letters. I think you should change this.

    _________________________________
    Visit my project: Derivative Calculator

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    Re: having touble with creating a game in c#

    Quote Originally Posted by Erendar View Post
    "is less accessible than method"
    You didn't specified the access status of your variables so the compiler doesn't know what to do. If you don't know what to put, set them to public, you won't have any problems (though accessibily requires a bit of pre-thinking before coding )

    Code:
            public bike mybike;
            public medal mymedal;
    Well, no... the compiler knows what to do; it makes them private, because private is the default access modifier, but that has nothing to do with the compiler error the OP is getting anyway.

    You've got a private type (bikegame.medal) as a parameter to a public method (Addmedal). This obviously won't work as you need the definition of bikegame.medal to call the method. You need to make your bikegame.medial type public.

    Erendar, on a side note, please do not suggest to simply make everything public. Your solution doesn't even solve this problem, but "public by default" is a terrible design choice and there is no reason to make what should be private, instance fields public.
    Last edited by BigEd781; May 7th, 2012 at 05:45 PM.
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

  5. #5
    Join Date
    Feb 2012
    Location
    Strasbourg, France
    Posts
    116

    Re: having touble with creating a game in c#

    Thanks BigEd781, noted and recorded

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured