Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: Help with Simple java application. on: 2009-02-21 03:49:40
You need to pass the player and enemy into the Battle...
For example, in the Battles constructor

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public class Battle
{

Player player;
Enemy enemy;

public Battle(Player p, Enemy e)
{

  player = p;
  enemy = e;
}

}


now you can use player, and enemy in the Battle class.


Thank you. It worked nicely.
2  Game Development / Newbie & Debugging Questions / Help with Simple java application. on: 2009-02-21 02:59:02
Hello, I am practicing on what ive learned so far in Java. (Which isnt very much). This is just for simple practice. In Battle.java I'm trying to calculate and attack between user1 and and Ene1. But I do not know how to call their variables from within Battle.java.  I tried to type in user1.attack or ene1.defence. But nothing comes up unless i'm under the RPG.java (Main class).

I know this is probably horribly put together. but I'm still learning the basics.

Thanks

~Ty

RPG:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
import java.util.Scanner;


public class RPG {

 public static void main(String[] args){



Scanner myScan = new Scanner(System.in);
Player user1 = new Player(100,100,50,50);
Enemy  Ene1 = new Enemy(5, 100,100);
Battle testbat = new Battle();



while(true){
System.out.println("Please Select what you want to do:");
System.out.println("1. Move");
System.out.println("2. Rest");
int input = myScan.nextInt();
if (input == 1){
   user1.moveX();
   user1.moveY();
   
} else {
   System.out.println("You rest and gain your strength");
   user1.HP += 10;
}



if(testbat.checkBattle()) {
 testbat.enterBattle();
 }

 } // end while

 } // End main

}  // end class RPG




Battle
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
import java.util.Random;
import java.util.Scanner;


public class Battle  {
 
 Random generator = new Random();
 Scanner myScan = new Scanner(System.in);
 public Battle (){

 
 }
 
public boolean checkBattle(){
 int ranNum = generator.nextInt(10);
 System.out.println(ranNum);
 
 if (ranNum <4) {
  return false;
 } else {
  return true;
 }

}// end check battle

public void enterBattle(){
 int ranNum = generator.nextInt(10);
 //check to see who attacks first
if (ranNum < 7 ){
  System.out.println("You sneak upon the enemy");
 Fight();    
 
 } else if (ranNum >8){
  System.out.println("The enemy sneak attacks you");
 Fight();
 }
 
 } // end enterBattle

public void Fight(){
boolean endFight = true;
while (endFight){
System.out.println("What do you want to do?");
System.out.println("1. Attack");
System.out.println("2. Deffend");
int input = myScan.nextInt();

if (input == 1) {
 System.out.println("You Attack");
 //**NEED TO FIGURE OUT WHAT TO PUT HERE TO ATTACK

}


 
}



   
} // end fight



}
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (20 views)
2014-08-19 09:29:53

Tekkerue (21 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (55 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (27 views)
2014-08-08 02:01:56

Norakomi (35 views)
2014-08-06 19:49:38

BurntPizza (64 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!