Designing DoomGame

wanting an opinion on my program's design

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 2433 Views - Last Post: 21 March 2012 - 04:39 PM Rate Topic: -----

#16 Zekorov   User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 226
  • Joined: 16-May 10

Re: Designing DoomGame

Posted 18 December 2010 - 08:27 PM

the only thing i can think of to do, is like when i'm in DoomControl, is to make the variables private.. but then use a method that makes them usable like this:
public class DoomControl
{
   private int monsterhealth, etc;
   
   public DoomControl()
   {
     monsterhealth = 0;
     etc = 0;
   }
   
   public void DoomControl(int mh, int e)
   {
     monsterhealth = mh;
     etc = e;
   }
}


if i'm on the right track, please tell me. I have no idea though. and from here i really don't know what i should do. :\ lol
Was This Post Helpful? 0
  • +
  • -

#17 SenhorOfuscado   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 18-December 10

Re: Designing DoomGame

Posted 18 December 2010 - 08:30 PM

In order to make those private attributes accessible to other classes, you should create getter methods. Let me show you an example:

public class Hello {
	private int var;

	public void setVar(int var) {
		this.var = var;
	}

	public int getVar() {
		return var;
	}

}



By calling getVar(), another class can get var's value and by calling setVar() they can set its value.

BTW, according to Java naming convention method names should start with a lower case. Stick to the conventions in order to make your code more readable. ;)

This post has been edited by SenhorOfuscado: 18 December 2010 - 08:39 PM

Was This Post Helpful? 1
  • +
  • -

#18 Zekorov   User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 226
  • Joined: 16-May 10

Re: Designing DoomGame

Posted 18 December 2010 - 09:11 PM

Well thanks dude. I actually basically had a setter class without even realizing it. I just needed a getter class. and i should rename my methods. :) thanks though. I knew i was missing something that seemed so within my grasp haha
Was This Post Helpful? 0
  • +
  • -

#19 Zekorov   User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 226
  • Joined: 16-May 10

Re: Designing DoomGame

Posted 19 December 2010 - 10:57 AM

View PostDogstopper, on 16 December 2010 - 02:55 PM, said:

Main (contains the main and the random other startup things)
Controller (Sends signals from input and output to each part of the program)
DoomInput (Sends keyboard input to the Controller)
DoomOutput (Takes signals from Controller and displays them - either on a Console screen or in a GUI - it shouldn't matter)
DoomGame (This could utilize signals from Controller and use other minor objects to perform the logic and send it back to the Controller)


Ok, I was thinking that i could merge the Input and Output classes together because it just seems easier that way..... or would that be a bad idea due to long run problems if i wanted to convert to GUI?
Was This Post Helpful? 0
  • +
  • -

#20 Zekorov   User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 226
  • Joined: 16-May 10

Re: Designing DoomGame

Posted 19 December 2010 - 11:37 AM

actually, scratch that because i found a use for the two separated classes. :D i think it's working out fine now. so far i have my difficulty set up again. and my whole game does run, though all it does for now is ask you what you want to do. :P
Was This Post Helpful? 0
  • +
  • -

#21 Zekorov   User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 226
  • Joined: 16-May 10

Re: Designing DoomGame

Posted 19 December 2010 - 02:20 PM

Ok i'm doing my difficulty right now... and i'm not sure if i did it the correct way according to the suggested design pattern. Actually.... Here is the code i have now. I think it's right actually. :)
//in DoomControl

//reads in the difficulty selected and gets ready to send out to DoomOutput
public void DoomDiffReader()
{
	input.DoomDifficulty();
	input.getDiffChoice();
	out.println("You have chosen the difficulty level " + input.getDiffChoice() + ".");
}

//outputs your selected difficulty (is sent here from DoomOutput to keep it in Control
public void DoomDiffOutput()
{
	output.DoomDifficultyO();
}

//this is in my DoomInput class
//the next two methods cover selecting and returning the value for difficulty
    public void DoomDifficulty()
    {
    	DoomControl statmods = new DoomControl();

		Scanner scanner = new Scanner(in);

		out.println("Choose your difficulty: 1, 2, or 3");
		difficulty = scanner.nextInt();
    }

    public int getDiffChoice()
    {
    	return difficulty;
    }

//and now this is what's in DoomOutput
//simply prints out everything from the input in DoomController
    public void DoomDifficultyO()
    {
    	DoomControl outtie = new DoomControl();

    	outtie.DoomDiffReader();
    }



Ok that's it. I think i'm getting it now. All i need to do is go through what is modified after the user selects a difficulty. I'm just making sure i am setting it up correctly. :)
Was This Post Helpful? 0
  • +
  • -

#22 Zekorov   User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 226
  • Joined: 16-May 10

Re: Designing DoomGame

Posted 19 December 2010 - 07:19 PM

ok.... so that last little bit i posted to set the difficulty and stats the way i thought it would work, actually doesn't work.... ugh.... so... here's what i have at the moment....
//inside DoomGame class and in addition to what i have posted from my last post with difficulty

	public void BattleSequence()
	{
		DoomControl game = new DoomControl();

		Random generator = new Random( );
		Scanner scanner = new Scanner(in);

		game.DoomDiffOutput();

		out.println("You must press 2 to battle.");
		play = scanner.nextInt();

		while(play == 2)
		{
			//you attack the monster
			game.setRandomAttack(generator.nextInt(4));

			if(game.getRandomAttack() != 3)
			{
				game.setMonsterHealth(game.getMonsterHealth() - game.getUserAttack());
				out.println(game.getMonsterHealth());
			}

			//now monster attacks you
			game.setRandomAttack(generator.nextInt(2));

			if(game.getRandomAttack() == 1)
			{
				game.setUserHealth(game.getUserHealth() - game.getMonsterAttack());
				out.println(game.getUserHealth());
			}

			out.println("Would you like to battle again? (2 for yes)");
			play = scanner.nextInt();

		}

	}



The problem is, it's not keeping my variables in getMonsterHealth() and such the same as they are when they are modified in the game.DoomDiffOutput(). When that method activates, it says the monsters health is 10 at first, and its attack is 2.
but then right outside of that, in the BattleSequence method, it prints out to be 0 for both. I know it's because they are first declared as 0 in my DoomControl constructor class. But how do i fix this?
Was This Post Helpful? 0
  • +
  • -

#23 diek   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 06-November 11

Re: Designing DoomGame

Posted 21 March 2012 - 04:39 PM

Did you ever get this resolved?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2