Diablicolic Posted September 25, 2003 Posted September 25, 2003 **URGENT** Multiple Projects 1 DLL Problem!! AAHH!! This program game is due the 26th, and I've come across a crazy problem! Ok I'll try to give enough information so you guys can help me out. Ok this is the overview of what's going on: Overview: Ok I've got 2 projects. One is a DLL and the other is like the main menu and the place where the character moves. The DLL project is for the Battle, Game Over, and Battle Over. DLL Project: -Battle Form --when you're battling -Game Over Form --when you die you go here -Battle Over Form --where you receive your experience PROBLEM Main Project: -Main Menu --where you choose to go to a new game, load game, or exit -WORLD --this is where you walk around with your character PROBLEM Ok first go to Main Menu, so you click on New Game, there you go to the WORLD. Then Bam! You go into a battle! So I hide the WORLD form and send all of the stuff I need to the Battle form on the DLL. So you kill the demon! Then all of the information goes to the Battle Over form. Now, here's the problem: How am I suppose to send all of the data from Battle Over to a class in the WORLD if I can't reference to it?! (because I can't create a reference to a project that is not a DLL) Quote "Reality is fake, Dreams are for real"
wyrd Posted September 25, 2003 Posted September 25, 2003 (edited) Create an information object that can be passed back and forth between the two objects. ie; public class Info { public int Score = 0; } public class SomeDllClass { private Info _info; public Info ClassInfo { get { return _info; } set { _info = value; } } } Edited September 25, 2003 by wyrd Quote Gamer extraordinaire. Programmer wannabe.
Diablicolic Posted September 25, 2003 Author Posted September 25, 2003 This is my first time with get and set. All of the information I'm moving from form to form is: Level CurrExperience NextLevelExp CurrHP CurrMP MaxHP MaxMP Strike Defense Wisdom Courage Swordlvl Armorlvl enemyPower item1 item2 item3 item4 item5 item6 item7 item8 item9 item10 item11 item12 item13 item14 item15 Now I'm transferring this stuff from WORLD to Battle to Battle Over and then back to WORLD. But that example that you made, that class called SomeDllClass, I would refer to that when the Battle Over is done with right? (when I move back to WORLD) I'm sorry for the bold, is it easier to read? Quote "Reality is fake, Dreams are for real"
Diablicolic Posted September 25, 2003 Author Posted September 25, 2003 Create an information object that can be passed back and forth between the two objects. ie; public class Info { public int Score = 0; } public class SomeDllClass { private Info _info; [color=red]<-- But I can't refer to a class that's not a DLL and not a Reference. It wouldn't know what Info is.[/color] public Info ClassInfo { get { return _info; } set { _info = value; } } } Quote "Reality is fake, Dreams are for real"
wyrd Posted September 25, 2003 Posted September 25, 2003 Okay, so it's set up like this; Project World .dll Battle You have a reference from World to Battle (obviously), correct? From your explanation I'm assuming this is true, otherwise you couldn't of passed info. to it in the first place. There are two easy solutions; 1) Pass a Form object into the Battle's constructor, which would allow Battle to reference World. 2) Create an Event inside Battle that is triggered when something happens. This will allow you to register the event over on the World (you can do it dynamically at run-time when you create a Battle). Obviously this would allow you to send info. from Battle to World using your EventArgs. Whatever solution you choose, you'll still want to use an object (like I described above) to pass in and out information. It looks like those properties you listed above all belong to a Player, so you should have a Player object that you pass around (btw, Get and Set are used to Get and Set a property); public class Player { // To simplify things and save myself typing, I'll just // make all the member variables public. In your actual // application you should make these private and then // create properties for each so you can have control // on what info is being passed around. public int Level; public int Experience; public int ExpNeeded; public int HP; public int MP; public int MaxHP; public int MaxMP; public int Strike; public int Defense; public int Wisdom; public int Courage; public int SwordLevel; public int ArmorLevel; public Item[] Items = new Item[15]; } Quote Gamer extraordinaire. Programmer wannabe.
Diablicolic Posted September 25, 2003 Author Posted September 25, 2003 Well I did send the form WORLD to Battle but...when you know you type something like this in a class, let's say the Battle Class: //So here I Imported the World form into Battle public void Imported(System.Windows.Forms.Form MyWorld) { //Ok so now I have the WORLD reference //Buuuut when I go like this: MyWorld. //And get the list of public subs and whatnot, I can't find the //Public sub that has to do with the character stats //That is located in the form WORLD } Quote "Reality is fake, Dreams are for real"
wyrd Posted September 25, 2003 Posted September 25, 2003 There are tons of ways to allow communication between forms. You just need remember that a form is a class. When you realize this, it becomes clear, and you can finally start treating it like one in your code. public class MyWorld : Form { public Info WorldInfo { // Get/Set... } } public class Battle : Form { private MyWorld _world; public Battle(MyWorld world) { _world = world; } public void FinishBattle() { _world.WorldInfo = ... // Whatever... } } Quote Gamer extraordinaire. Programmer wannabe.
Diablicolic Posted September 26, 2003 Author Posted September 26, 2003 (edited) 1) Pass a Form object into the Battle's constructor, which would allow Battle to reference World. Ok how would I create a reference to the World by using the Form Object by using this? System.Windows.Forms.Form myWorld ------Edit------- This is how I transfer the information from WORLD to Battle: Event: Dim mySounds As New Splash_Screen.MySounds() mySounds.Play("Data/Sounds/Battle-Start.wav", SND_ASYNC) System.Threading.Thread.Sleep(5000) imgAvatar.Image = Nothing lblTalk.Text = "" timDialog.Enabled = False BackgroundMusic = BackgroundMusic.FromFile("Data/Music/Opening II.mp3") BackgroundMusic.Stop() BackgroundMusic.CurrentPosition = 0 Me.Hide() '//Dim myBattles As New Battles() '//myBattles.Initialize() Dim mySound As New Splash_Screen.MySounds() mySound.StopPlay() Dim newBattle As New Splash_Screen.Form1() newBattle.Show() TransfertoBattle(newBattle) timDialog.Enabled = False Transfer all the data to the Battle using this class in the WORLD Public Sub TransfertoBattle(ByVal theform As Splash_Screen.Form1) Randomize() Dim myRando As Integer myRando = CInt(Int((5 * Rnd()) + 1)) theform.transfertoBattle(Convert.ToInt32(lblLevel.Text), Convert.ToInt32(lblCurrentExp.Text), Convert.ToInt32(lblNextLevel.Text), Convert.ToInt32(lblHPCurrent.Text), Convert.ToInt32(lblMPCurrent.Text), Convert.ToInt32(lblHPMax.Text), Convert.ToInt32(lblMPMax.Text), Convert.ToInt32(lblStrike.Text), Convert.ToInt32(lblDefense.Text), Convert.ToInt32(lblWisdom.Text), Convert.ToInt32(lblCourage.Text), mySwordlvl, myArmorlvl, myRando, myItem1, myItem2, myItem3, myItem4, myItem5, myItem6, myItem7, myItem8, myItem9, myItem10, myItem11, myItem12, myItem13, myItem14, myItem15, COPYOFMYWORLD) End Sub If you look at the very end of the information movement, you'll see COPYOFMYWORLD. At the top of this form this is what it looks like: Private COPYOFMYWORLD As The_Final_Fantasy.World Note that the DLL is in C# and the Project with the WORLD and Main Menu are in Visual Basic .NET Edited September 26, 2003 by Diablicolic Quote "Reality is fake, Dreams are for real"
Diablicolic Posted September 26, 2003 Author Posted September 26, 2003 Here's a large picture (sorry for it being so large :-\ ) of everything! I'm still trying to work with what you're saying Wyrd. But like they say, frustration is part of learning. Quote "Reality is fake, Dreams are for real"
wyrd Posted September 26, 2003 Posted September 26, 2003 *scratches head* Ah, I had a bad feeling this is what you actually ment. I was hoping you were refering to "reference" as in referencing an object via code, not the actual class library. The only way I know of (maybe someone else can chime in here, I've never actually tried to reference a project before) to solve your problem, would be to create an Interface that is stored in a seperate class library, then have your form inherit that interface and also use it in your .dll. public interface IWorld { public Info GetWorldInfo(); } public class World : Form, IWorld { public Info GetWorldInfo() { return _info; } } public class Battle { public Battle(IWorld world) { world.GetWorldInfo(); } } I'm not going to rag on about bad design decisions (god knows I make a ton of those myself), but what I would of done is seperated the game logic into a self containing class library, and then had your forms all within the same game project. Quote Gamer extraordinaire. Programmer wannabe.
Diablicolic Posted September 26, 2003 Author Posted September 26, 2003 LOL, yeah that would've been the smart way. You see when I was thinking about a Battle part in the project for the World and Main Menu...I tried an example on a different project in C# (why...I do not know lol), to see if I could do it. Well I did it! But it looked so good that I didn't want to move it over to Visual Basic, because if I did that then people would start to think: "Visual Basic? Gah that's like HTML." So now I got myself into this mess! lol, oh well I'll try out what you said. But I'll give it time because I'm going to make it so that they don't go: World --> Battle --> Battle Over --> World I'm going to MAKE them go: World --> Battle --> Game Over rofl It's the only way for now :rolleyes: Thank you for your help a lot Wyrd! I know we didn't exactly see each other eye to eye lol, but just the fact that you tried to help a lot is very nice of you. Quote "Reality is fake, Dreams are for real"
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.