How To Introduce Pokemon Moves As Objects

Mar 6, 2015

I'm building a pokemon battle simulator, as I mentioned in my previous post, and I'm starting from simplest game form and then adding complexities. right now I'm trying to give my pokemon multiple moves to randomly(for now) choose from. and I started with an int[] array that holds the magnitude of each move. But then it occurred to me that moves need to have multiple attributes like name, type, damage.. etc.. and also they can be acquired by more than one pokemon, and having them as an array would mean literally that I would have to make multiple arrays and it would involve a lot of repetitiveness.

So I settled on Objects, however the first challenge that faced me was, how to introduced the different types of moves? one one hand, I have healing moves,which acts on the pokemon's own health. on the other hand, I have attacking moves,which acts on the other pokemon's health. Given that both types of moves need to be in the same object array, I thought of polymorphism and created a superclass "Moves", which has HealingMoves and FightingMoves as subclasses, so both can be sent to the Moves[]. but since these moves have different effects, I had to make an new if statement that checks for class of move selected and based on that does different things. How the game's logic is going so far? is this the right way to introduce moves?

This is somewhat out of topic, but what is the difference between these two statements:

1-System.out.println(user.moveList[2].getClass().equals(HealingMoves.class)
2-System.out.println(user.moveList[2].equals(HealingMoves.class)

statement two always evaluated to false for some reason...

GameClass
public class OutPut {
static Monster user=new Monster("Me");
static Monster playerOne;
static Monster playerTwo;
static Monster android=new Monster("android");
static Scanner userFeed=new Scanner(System.in);
public static void turnSelection()

[Code] ....

View Replies


ADVERTISEMENT

Generic Methods Introduce Their Own Type Parameters

Apr 10, 2014

Generic methods are methods that introduce their own type parameters. This is similar to declaring a generic type, but the type parameter's scope is limited to the method where it is declared. Static and non-static generic methods are allowed, as well as generic class constructors.

1. The method is only exclusively to be used for the declared argument parameter? For example given a generic method:public static <String, Integer> boolean method(Pair<K, V> p1) {}I could only invoke the method if Pair argument parameter is <String, Integer>?

2. Or, it will return a <String, Integer> value?

View Replies View Related

Control Rectangle And Determine Where It Moves - Key Presses

Mar 11, 2014

I am writing a program where i am trying to control a rectangle and determine where it moves, everything is working fine it is moving but i am trying to figure out how to change direction using the "WASD" keys. This is what I have and I am not sure why its not working.

Java Code:

addKeyListener( new KeyAdapter() {
public void keyReleased(KeyEvent event) {
for (MoveableShape creature : creatures) {
if (((Creature)creature).isPlayer()) {
if (event.getKeyCode() == KeyEvent.VK_W) //up

[Code] ....

View Replies View Related

Type Mismatch For RL Method Which Moves Rows To Left

Feb 16, 2014

I'm trying to make a puzzle that gets the user input and moves the rows either to the left or right, the columns move either up or down depending on what the user wants. The problem I'm getting is a type mismatch for my RL method which moves the rows to the left.

import java.util.*;
import java.io.*;
public class Numbrosia {
static int [][] board = new int [5][5];
public static void main(String[]args){
Scanner scan = null;
try{

[code]....

View Replies View Related

Creating Cursor For A Game That Moves Square By Square - Removing Trailing Images

Aug 31, 2014

I'm trying to create a cursor for a game that moves square by square. While it will move to the next square, though, it leaves the image of the previous cursor on the last square it was on.

As a visual explanation, this is what the program looks like on launch:

This is what it's suppose to look like after you press the right arrow key once (made by forcibly changing launch coordinates):

And this is what it actually looks like after you press the right arrow key once:

Here is the code for the program:

package cursortest;
import javax.swing.*;
import java.awt.*;
import javax.imageio.*;
import java.io.*;
import java.awt.event.*;
public class CursorTest extends JPanel implements KeyListener{

[Code] ......

I'm fully aware that I could just use g.clearRect on the area and remove it for sure, but I know for a fact I shouldn't have to as I have another program I made a long time ago that tried to do something similar without needing to resort to that.

View Replies View Related

Copying Data Objects To Serializable Objects

Jul 27, 2014

I am currently working on a project where I need to return data from a database over RMI to a client who requests it. Some of the fields in the Data Object can not be seen by the client so I need to create another object to send over the network instead. The method I use is this...

public static SerializableObject createSerializableObjectFromDataObject(DataObject dataObject){
SerializableObject serializableObject = new SerializableObject();
serializableObject.setField(dataObject.getField());
serializableObject.setAnotherField(dataObject.getAnotherField());
return serializableObject;
}

Is there a better way of doing this? I am creating many subclasses DataObject which all require this static method to be implemented and I can't push it into the superclass because each one needs custom behaviour.

View Replies View Related

How String Objects Are Different From Other Objects

Jan 23, 2015

how String objects are different from other objects

part 1:

// creating two objects
Dog mydog1 = new Dog();
Dog mydog2 = new Dog();
// comparing the reference variables
if( mydog1 == mydog2){
System.out.println(" The reference variables refer the same object ");
}
else {
System.out.println(" They refer to different objects ");
}

The above code works as I understand objects , it prints "They refer to different objects " to the screen.

Part - 2

// creating two objects ( I beleive, pls correct me if i am wrong )
String a = "haai";
String b = "haai";
 
if( a == b){
System.out.println(" Reference variables refer to same object");

When i run the above code it prints that a and b refer same object , I don't understand how they refer to same object when i didn't assign " String b = a; ". My question is did java just create one object and stored the same reference values to a and b .

View Replies View Related

Update XML Using DOM Objects

Sep 29, 2014

I have a requirement to insert the data into xml file . I have used DOM class for doing this. Below is my xml file

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<deployments>
<applications>
<application>
<name> PCMH</name>

[Code] ....

The thing is if SITA is the name then I have to insert component to the particular envi tabs , if DEVB is the component I have to insert the component there. How can I do this I have done some code its inserting the data at the bottom og the XML .

View Replies View Related

How To Get Two Classes To Get Objects From Each Other

Oct 18, 2014

I'm quite new to Java. I have some trouble with understanding how to get two classes to get objects from each other (if that is the correct term).

Lets say I have a login class, in which I have a method checking what the user has entered into the console (I have not displayed the whole code, but this class works as it should and give the user an option to enter username and password and return it true if entered correct).

public static boolean validateUserPass(String userName, String password) {
String[] user = {"admin"};
String[] passwords = {"firkanten"};
boolean check = false;
for (int i = 0; i < user.length; i++) {
if (userName.equals(user[i])) {
if (password.equals(passwords[i])) {
check = true;

Now, in another class I want a display box to appear on the screen and give the user three options: Click yes, no or cancel. I get this to run perfectly alone, this is not the hard part for me. I want the display box only to appear when the correct username and password is given, but I can't seem to figure out how to do this probably.

View Replies View Related

Getting Names Of Objects?

Jan 22, 2015

In my project I had to create 2 classes, Room and Animal.

Room had to have an array (NOT arrayList-I know theyre better and easier but I need to use an array, for now) This array must be able to be populated by 10 "Animals", and the Room class needs two methods, a method to add animal a to the room (rooms array) and a toString() that returns the name of the room and the names of the animals in the room. The teacher added a hint saying that this toString() should reference the animal classes toString()

Here is my code thus far:

public class Room {
private String name;
Animal[] inRoom = new Animal[10];
public Room(String roomName){
name = roomName;
} public void addAnimal(Animal a){
for(int i = 0; i < 10; i++){

[code].....

View Replies View Related

XML Editing Using DOM Objects?

Sep 29, 2014

I have a requirement to insert the data into xml file . I have used DOM class for doing this.

Below is my xml file

<code>
-<deployments>
-<applications>
-<application>
<name> PCMH</name>
-<envs>
-<env>
<name> DEVA</name>
<version>1.0.0 </version>

[code]....

The thing is if SITA is the name then I have to insert component to the particular envi tabs , if DEVB is the component I have to insert the component there. How can I do this I have done some code its inserting the data at the bottom og the XML.

View Replies View Related

Objects Being Displayed On Top Of One Another?

Dec 15, 2014

I am making a game in java and for the game board i want to fill the screen with blocks. to do this i stored objects of a class that displays squares into an array list and displayed the array list. however, when i do this all of the squares are drawn on top of anther at the final squares coordinates and i dont know why.

here is the code

// code for adding the squares into the array
nt x = 0;
int y = 0;
int size = 10;
static ArrayList<Map> map = new ArrayList<Map>();
//static ArrayList<Items> items = new ArrayList<Items>();

[code]....

View Replies View Related

Can't Create New Die Objects?

Apr 2, 2015

I'm having trouble creating two new die objects for the PairofDie class. I'm trying to run two separate die and print the face value and then add both numbers up and print those values as well.
 
public class Die {
private final int MAX = 6;
private int faceValue;
//private int faceValue2;
public Die(){
faceValue = 1;
 
[Code] .....

Exception in thread "main" java.lang.Error: Unresolved compilation problems:

The method Die() is undefined for the type PairofDice
The method Die() is undefined for the type PairofDice
at PairofDice.main(PairofDice.java:6)

View Replies View Related

Iterate Through Objects

Feb 27, 2015

I would like to know how I can iterate through objects . I have a manually created linked list (without using the built-in method one). So in the memory my object looks like this(attachment).I would like to do a for loop or while loop to get each element under the test3.head.

View Replies View Related

Array Of Objects

Mar 28, 2014

Exercise the Coin class using a driver class in which 5 coins are flipped, as a group, 1024 times. Display the number of times exactly 4 tails are obtained. Display the number of times exactly 5 tails are obtained. Use an array of Coin.

how to put an object into an array?I know how to make a coin class with a Heads and Tails, but I dont know how to make 5 coins all at once.

View Replies View Related

How To Compare Objects With Another

Feb 3, 2014

I have the following method stubs to complete:

public class Item{
private int myId;
private int myInv;
public Item(int id, int inv){
myId = id;
myInv = inv;

[Code] .....

I do not understand how to complete the compareTo() method and the equals() method. I understand that the compareTo() to should return 1 if the argument is smaller -1 if its bigger and 0 if they are the same, but I do not understand how it's possible to compare the current object with the object passed in as the parameter.

This is what I tried for the compareTo():

public int compareTo(Item other){
return this.compareTo(other);
}

But my compiler tells me its a recursive call so I am not sure if I am doing this correctly.

Basically I am supposed to compare an object to another but I am not sure how to access the object that is not passed in as a parameter and compare it. Same goes for the equals(). This is what I tried for that (compiler also says its a recursive call):

public boolean equals(Item other){
return this.equals(other);
}

View Replies View Related

How Many Objects Are Created

Jan 19, 2014

String s= new String ("Hello");
String a = new String ("Hello");

As per my understanding the first line creates 2 objects : 1 for the heap memory and 1 for String pool

2nd line : new object created and no new object created in the String pool as the keyword already exists in the pool.

So the total number of objects created after the execution of 2 lines are : 3

View Replies View Related

Unwanted Changes In Objects

Nov 22, 2014

I can't come up with a simple scenario so I'll use my actual code to explain the problem, and it's going to be related to java.awt.Color, but my problem is general, not awt dependent. Although I will shorten my code to show only what I think is relevant to the problem.

Java Code:

public class GameColor {
public abstract class Effect {
public int strength;
public Effect(int strength) {
this.strength = strength;
}
public abstract Color get(Color color);

[Code] ....

I have my reasons for having a SetHue inner class and a setHue method that practically do the same thing. The inner abstract class Effect and inner class SetHue was static but I changed it when I testing what could cause this problem, later I will need them to be static, but since they don't affect the problem I don't think it matters if they're static or not.

So down to the problem, I create three new GameColor instances which all are 255, 0, 0, basically red. Then I do setHue(0) method on the first one, setHue(20) on the second one, and setHue(40) on the last one. And for some reason all of them have a hue of 40, whereas the last one should've had this, so basically the last time I call setHue on the instances of GameColor, changes the hue of all of these colours to that hue. I want it to be individually affected, but all of them are affected. This is where I apply these changes:

Java Code:

colo1.setHue(0);
colo2.setHue(20);
colo3.setHue(40); mh_sh_highlight_all('java');

And how I initialise the colors:

Java Code:

public GameColor colo1 = GameColor.RED;
public GameColor colo2 = GameColor.RED;
public GameColor colo3 = GameColor.RED; mh_sh_highlight_all('java');

View Replies View Related

Using Objects In HashMaps

Mar 21, 2014

I am currently trying to implement a hashmap from a class i currently have that is called 'Paper'

My paper class consists of:

String Title;
String[] author;

What I am wondering, is if there is anyway I can call these seperate attributes to be both the key and the value of the hashmap. Currently I cannot see a way to call individual values, only the class itself.

View Replies View Related

Compare All Objects In ArrayList To All Others But Not Self

Mar 15, 2015

I have a ArrayList of objects of class called HockeyPlayer (ArrayList<HockeyPlayer>). A HockeyPlayer has a String name and int number of goals.

This is my current work for comparing each object in the list to every other and printing them to screen:

Iterator<HockeyPlayer> it = hockeyPlayersList.iterator();
while (it.hasNext()) {
HockeyPlayer singleHockeyPlayer = it.next(); //the first one encountered
// HockeyPlayer nextHockeyPlayer = it.next(); //the next one encountered

[Code]...

This of course produces some duplication in the print-out: These are the equal hockey players: Who Ever wears jersey. This type of employee is paid: true. This employee has post-secondary education: false. This employee's work is to play. This hockey player has scored 0 goals.

Jason Harrison wears jersey. This type of employee is paid: true. This employee has post-secondary education: false. This employee's work is to play. This hockey player has scored 0 goals.

These are the equal hockey players: Jason Harrison wears jersey. This type of employee is paid: true. This employee has post-secondary education: false. This employee's work is to play. This hockey player has scored 0 goals.

Who Ever wears jersey. This type of employee is paid: true. This employee has post-secondary education: false. This employee's work is to play. This hockey player has scored 0 goals.

How do I remove the duplication in the print-out?

View Replies View Related

How To Find Particular Objects In HashMap

Dec 25, 2014

Suppose i have a hashMap which includes instances of class Employees and instances of class Customers.

How can i get the employees objects only?

And would it be possible to find the oldest staff by comparing the ages stored in the age fields of the staff objects.

View Replies View Related

Accessing Objects From Other Packages

Dec 7, 2014

I have GameConsole class with gamePlay(). There are two objects in this class that I want to access from a class in another package.

package blackjackControls;
public class GameConsole {
Player dealer; //both of these objects I am trying to bring over into the blackjackGUI package
Deck playingDeck;
public void gamePlay(){

[code].....

The dealer and playingDeck objects are giving me an error of unresolved. the way it is written I also get a static error on line 37. I know that I have not yet written in the actionEvent statement in the button constructor.

View Replies View Related

JSP :: ForEach ArrayList Of Objects

Feb 11, 2014

I am trying to access an array of "Movie" objects in my jsp. The array is loaded via

org.springframework.web.servlet.ModelAndView.addObject().

Here is my jsp code:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

[Code] .....

The System.out.println("jsp page: .... &> results in the output: "jsp page: movielist - [Title: Die Hard; Budget: 20000000, Title: two days in paris; Budget: 1000000]" so I am confident the objects are being loaded into the ModelAndView correctly. However the output of the block is "${movie.name}" instead of the list of movies. My movie object has a getName() method to return a string (and a setName() method). I am not sure why the System.out.println statement can find the movielist attribute, but ${movie.name} is being treated a plain text. There are no execptions thrown or other indications of errors.

View Replies View Related

How To Clone ArrayList Objects

Jun 20, 2014

I want to clone some Arraylist, but the compiler apparently are just referencing the values to it's original ArrayList. I don't know what should it be:

package projetoteste;
import java.util.ArrayList;
import java.util.List;
public class TestFood {
public static void main(String[] args) {
List food=new ArrayList();

[code]....

Notice that ArrayList dailyMeal should be untouchable, but it return the changes that I made in local for-loop iteration although I didn't added nothing to it, just to it's clone.

Output:

[[[Suco, 1 , 2], [Suco, 1 , 2]], [[Suco, 1 , 2], [Suco, 1 , 2]]]
[[[►, ►, Suco, 1 , 2], [►, ►, Suco, 1 , 2]], [[►, ►, Suco, 1 , 2], [►, ►, Suco, 1 , 2]]]

View Replies View Related

Accessing Objects Within GCompound?

Sep 19, 2014

Given the class MyExample below:

public class MyExample extends GCompound {
//instance variables
public GRect R1 = new GRect(0, 0, 20, 20);
public GRect R2 = new GRect(0, 0, 5, 5); //R2 is in front of R1, but its coordinates are all "inside" of R1's coordinates
//constructor
public MyExample() {
add(R1);
add(R2);
}
}

1) Suppose I'm in a GraphicsProgram and declare:

MyExample myex = new MyExample();

Suppose I have coordinates (x1, y1), and want to find out whether this is the myex object defined in the previous line. I would use:

obj = getElementAt(x, y);
if (obj == myex) (...and so on)

Now suppose I want to test whether the object is the GRect object R1 within myex. Why doesn't the following work?

if(obj ==myex.R1) (...and so on);

Here is the full code that shows my question; it outputs "myex", none of the other outputs come out...

public void run() {
GObject obj1, obj2;
MyExample myex = new MyExample();
add(myex);
obj1 = getElementAt(1, 1);
obj2 = getElementAt(19, 19);
if (obj1 == myex) System.out.println("myex");
if(obj1 == myex.R1) System.out.println("R1");
if(obj1 == myex.R2) System.out.println("R2");
if(obj2 == myex.R1) System.out.println("R11");
if(obj2 == myex.R2) System.out.println("R22");
}

View Replies View Related

How To Refer To Objects In Die Class

Apr 4, 2015

how to refer to objects die1 and die2 in the PairofDie class from the SnakeEyes class and what to do.

public class Die {
 
private final int MAX = 6;
private int faceValue;
private int sum;
//private int faceValue2;
 
public Die(){
faceValue = 1;

[code]....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved