• C# XNA Code Problem
    14 replies, posted
*****ANSWERED So I have some code i've written for a final project and I am putting this out there that I am a newbie to C# & XNA so bear with me. I know this is a newbie mistake but I can't solve it between my understanding of the language and google. My problem is that I am trying to pass some info between the Game1.cs and Soldier.Cs and it seems to be encountering an error with two of my lists. I have three files zipped; screenshot of error, and the two cs files in the dropbox link. It has to deal with is an " ' ----' is less accessible than field '-----'. Any help is great and warning it is noob code so I apologize for any pain felt to you more experienced coders out there. [URL]https://www.dropbox.com/sh/1rjehq4ee2xippg/Q0ROUaM14M[/URL] *****UNANSWERED I need to draw each rectangle created for each soldier and I am wondering where it would be best to draw it? In the Soldier Class and call it in game1 or just do it in the Game1.cs draw method. Also I have included a newer version of the code in this link ---> [URL]https://www.dropbox.com/s/ej5wg7pntmneiaz/Final1.zip[/URL]. Any suggestions on how best to do this?
Just post the code here. I don't want to dl your poop. [editline]1st June 2012[/editline] remove the "protected" on your lists.
[QUOTE=Mr_Razzums;36164906]Just post the code here. I don't want to dl your poop. [editline]1st June 2012[/editline] remove the "protected" on your lists.[/QUOTE] That didn't really work as I need to define that lists in a way that I can pass info through them. One of my coding buddies had told me that out need the protected but I think I have something wrong with the way I set up my class. I still could be wrong though.
[QUOTE=MJdaminer;36168587]That didn't really work as I need to define that lists in a way that I can pass info through them. One of my coding buddies had told me that out need the protected but I think I have something wrong with the way I set up my class. I still could be wrong though.[/QUOTE] Use public instead of protected
[QUOTE=Mr_Razzums;36168825]Use public instead of protected[/QUOTE] Again that doesn't fix the situation. Thats why im like WTH!?!?!?! That should fix it but it something with the way i have my soldier class structured must be causing the problem. Also i have tried private to for shits and giggles but that didn't work either. I have also tried declaring variables differently in my class and that didn't help. Question: Should I create a handler class? then reference that in my game1.cs? I would prefer not cause it just adds a bunch of code but if it works then maybe....
Jesus H. Christ why are you making soldier inherit Game1?
[QUOTE=Perl;36168978]Jesus H. Christ why are you making soldier inherit Game1?[/QUOTE] I am going of some buddies who are pretty good at this stuff and that's what they directed me to do. I think creating a handler class may help with the problems.
[QUOTE=MJdaminer;36169003]I am going of some buddies who are pretty good at this stuff and that's what they directed me to do. I think creating a handler class may help with the problems.[/QUOTE] You never inherit your main class. Especially in XNA. Stuff are bound to fuck up, believe me.
[QUOTE=Perl;36169653]You never inherit your main class. Especially in XNA. Stuff are bound to fuck up, believe me.[/QUOTE] Indeed - you use inheritance for an is-kind-of relationship. Like a Car class that inherits from a Vehicle class. A Soldier is an object you'll have in your Game1 but it's not a type of Game1, so it doesn't make sense to make it a subclass of Game1.
try to edit the code [code] class Soldier : Game1 { private double speed; private int health; private Texture2D img; private int type; private int attackingpower; public int expense; private int attackingDistance; public bool moving; public Vector2 position; public Rectangle rect; private Soldier() { } private Soldier(ref Texture2D _img, int Type) { [/code] to: [code] public class Soldier : Game1 { private double speed; private int health; private Texture2D img; private int type; private int attackingpower; public int expense; private int attackingDistance; public bool moving; public Vector2 position; public Rectangle rect; public Soldier() { } public Soldier(ref Texture2D _img, int Type) { [/code]
Thanks for all the help guys. And yes i am a scrub; my understanding is a bit lower than id like. Ill try changing it in the morning and we will see what happens.
[QUOTE='Crabman [HUN];36173998']try to edit the code [code] class Soldier : Game1 { private double speed; private int health; private Texture2D img; private int type; private int attackingpower; public int expense; private int attackingDistance; public bool moving; public Vector2 position; public Rectangle rect; private Soldier() { } private Soldier(ref Texture2D _img, int Type) { [/code] to: [code] public class Soldier : Game1 { private double speed; private int health; private Texture2D img; private int type; private int attackingpower; public int expense; private int attackingDistance; public bool moving; public Vector2 position; public Rectangle rect; public Soldier() { } public Soldier(ref Texture2D _img, int Type) { [/code][/QUOTE] That kinda of worked but now I have to redo a bunch of code.
just start over again and make soldier inherit from player or something like that...
[QUOTE=HeatPipe;36183061]just start over again and make soldier inherit from player or something like that...[/QUOTE] like a completely separate player class? nvm, got it working somewhat. Thanks again for everyone's help
--Snip--
Sorry, you need to Log In to post a reply to this thread.