Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 18:42

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C# interfaces making me feel extra dumb

Discussion on C# interfaces making me feel extra dumb within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
C# interfaces making me feel extra dumb

Ok so I've obviously seen the simple interface examples used before... I kinda understand how they work.. yet for some reason I seem to be unable to use them in my case atm :S


So what I'm doing is messing around with an existing quad tree example. My hopes is I'll be able to adapt it for use on my server (I HAVE looked through the example and understand it fairly well so far.. it's not that complicated, just like having something working with as a template to start)

The problem I'm having is this....

The example I have uses interfaces to pull x/y dimensions for the objects being stored in the quad (allows for collision detection simply using xna framework to determine what needs to be spawned/removed)... yet for some reason I can't figure out for the life of me how to go about doing this.


Sample code;

Code:
 public interface HasRect
    {
        Rectangle Rect { get; }
    }
    public class Quad<T> where T : HasRect
    {....
So Has rect is being used to get a rectangle from the objects being added to the quad... this is then used for coord and dimension information through the rest of the code..

So to add anything to this quad obviously, I need to add this to my Entity information.
Code:
public class GameClient : Calculation.HasRect
    {....
Now I need to find a way to implement this interface member... which is where I'm stuck.

Doing public Rectangle Rect = new Rectangle(X, Y, Height, Width); obviously works but does not allow me to do anything because it's not implementing the interface...

Some generic examples of things I've tried (I'm well aware they are not the right way.. just listing some things I've done..

HasRect(Rect); (where rect is a defined rectangle already created)

HasRect A = new HasRect(); //cannot create instance of the abstract class or interface blablabla

asRect A;
A.Rect = new Rectangle(1,2,3 ,4);

//cannot be assigned to, it's read only... I can add set; to the code and it will then tell me that A is an unassigned local variable obviously


Forget what else I tried... Basically I've tried every way I know to setup values and interface seems to just keep kicking my ass... I KNOW it's something simple but I can't seem to find any valid information on google about this type of thing. It's all calling functions and stuff through interfaces and inheritance.
pro4never is offline  
Old 09/17/2010, 01:53   #2
 
Nullable's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 390
Received Thanks: 321
From my understanding of your post you want to implement HasRect's members in the GameClient class, so you tried having a field in the class which may look like this
Code:
public class GameClient : HasRect
{
    public Rectangle Rect = new Rectangle(X, Y, width, height);
}
If this is the case then it won't work, you cannot declare fields in interfaces, thus you cannot declare a field in the inheriting class and expect it to satisfy the case.

What you declared in HasRect interface is a get only property, thus you have to implement it in GameClient class the same way, as a get only property
Code:
public class GameClient : HasRect
{
	private Rectangle m_Rect; // private member to be able to work around with the rectangle within class
	public Rectangle Rect // the declaration of the get only property
	{
		get { return this.m_Rect; }
	}
}
This piece of code shall work.
Nullable is offline  
Thanks
1 User
Old 09/17/2010, 05:10   #3
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
yahh I knew it was something to do with me just being a complete moron.

Never really used interfaces before so this is good learning experience. it was driving me crazy though cause I'm so used to other ways of doing things so that's just how my mind tends to work now.

I'll test it out tomorrow when I have some free time and get back w/ any issues I run into w/ quadtree. The example code I have now makes theoretical sense to me. Thinking I'm going to test out its actual usage and then see if I can write a fully custom quad system myself using it as reference (cause theoretical understanding and practical/usable knowledge != same lol)


<edit>

yah got it all working code wise but C# hates trying to use .xna so I'm writing all my geometry from scratch.

yayy for math I haven't had to do in ages! xD
pro4never is offline  
Reply


Similar Threads Similar Threads
[Quote]Are you Dumb ? You are Dumb ?
06/15/2009 - Quotes - 8 Replies
Ich weiß ist nicht so lustig aber das soll es auch nicht sein. Hier geht es nur darum wie schlecht die Deutschen Kinder English können.Ich weiß mein English ist auch nicht grade so der knüller.
can someone help me in making extra slot in weapons?
06/06/2009 - RF Online - 8 Replies
meron b marunong kung pno mglagay ng extra slot sa weapon?
Dumb question, dumb answer game!
04/25/2008 - Off Topic - 3 Replies
Thought that this forum could use some chatting games: Sooo lt's goo i will give a totally pointless question and you will give a more pointless answer! :D Soo why am I so cool?



All times are GMT +1. The time now is 18:42.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.