Results 1 to 20 of 23
Thread: Jump N Run
- 08-05-2011, 11:03 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 71
- Rep Power
- 0
Jump N Run
Hey guys,
i have been programming for some time at school with java and now i started a project:
a simple Jump N Run game. I already managed to build a simple Map editor, but there is a Problem..
My plan was to do it with squares.. which i can color how i want... i wanted to do it REALLY simple :P
now i did a class Editor with a atribute squares[200][20] but there should only always be [40][20] on the screen.. so i have to delete the first row and get the next row in, if i want to see the field [1-41][1-21] and do this again so i can see [2-42][2-42] ... i hope you know what i mean..
ill post a picture here so you will see.. i hope
these ill see at start:

these ill see later:

but at the same position..
i hope you can help me
The .jar file where you can get my idea
this is the .jar file, so you might have an idea what i mean.. you can draw with a and pick a color with number 0-9 .. and i wanted to code, that if you go to the left and right border, there will come more squares ... i hope you know what i mean... like in mario games... :D
thanks for you help already.. im open for any ideas! please!
edit: you also might be interested in the system my program works right now..
i have a class Editor which has int pickedX and int PickedY as position marks for the curser, where im drawing right now.
the squares have int xWert and int yWert as atributes so i can see their position in the whole [200][20] database..Last edited by Coold0wn; 08-05-2011 at 11:08 PM.
-
- 08-05-2011, 11:17 PM #3
Member
- Join Date
- Aug 2011
- Posts
- 71
- Rep Power
- 0
my question is: how can i do this? :P
i mean.. how can i make the [40][20] array walk to the left and right over the [200][20]..
i dont know how i should explain that...
i just ... wrote the answer.... i need a second arrylist.... omg
i hope that will work... xD
well my problem was that i only wanted to show a part of the [200][20] array.. and this part should be flexible..
i hope it will work with a second array... if not, ill be back soon :)
- 08-05-2011, 11:37 PM #4
Member
- Join Date
- Aug 2011
- Posts
- 71
- Rep Power
- 0
doesnt work doggammit... some ideas? :/
- 08-06-2011, 01:49 AM #5
Member
- Join Date
- Aug 2011
- Posts
- 71
- Rep Power
- 0
okay.. i have now an arraylist: Quadrat[100][20] => felder[][]
and one: Quadrat[40][20] => anzeige[][]
my anzeige[][] should get a part of the list felder[][] and show it to us.
by moving to the right border it should show the next row and delete the first,
if you then go back to the left border, it shows the previous row and deletes the last one.
but .. i have some trouble..
whats wrong here? ... :/ do you know?public void anzeigeNachLinks() // should delete the last row and put in the previous
{
for(int x = 0; x < 40; x++)
{
for(int y = 0; y < 20; y++)
{
anzeige[x][y] = felder[x+linksoben-1][y];
}
}
linksoben--; // links oben = integer which tells you the number of the first row shown in the felder[][]
for(int x = 0; x < 40; x++)
{
for(int y = 0; y < 20; y++)
{
anzeige[x][y].nachRechtsBewegen(); // moves all squares 10px to the right
}
}
}
public void anzeigeNachRechts() // should delete the first one, and but in the next row
{
for(int x = 0; x < 39; x++) // 40?
{
for(int y = 0; y < 20; y++)
{
anzeige[x+1][y] = anzeige[x][y];
}
}
for(int y = 0; y < 20; y++)
{
anzeige[linksoben+39][y] = felder[linksoben+40][y];
}
linksoben++;
for(int x = 0; x < 40; x++)
{
for(int y = 0; y < 20; y++)
{
anzeige[x][y].nachLinksBewegen();
}
}
}Last edited by Coold0wn; 08-06-2011 at 01:51 AM.
- 08-06-2011, 02:33 AM #6
Please explain. Are there error messages?i have some trouble..
Or are the results incorrect? Show how you know that the results are incorrect. Print the variables and add an explanation.
Too many "magic" numbers. Your code has too many hardcoded literals like 20 and 40. These should either be variables or properties of the arrays the code is working on.whats wrong here?
Please edit you code and wrap it in code tags to preserve the formatting. See:http://www.java-forums.org/misc.php?do=bbcode#codeLast edited by Norm; 08-06-2011 at 02:36 AM.
- 08-06-2011, 02:14 PM #7
Member
- Join Date
- Aug 2011
- Posts
- 71
- Rep Power
- 0
i made it... after about 15 hours work , the editor is finished :D
File-Upload.net - Jump-N-Run-Editor-.jar
here you can see my awsome pixel-editor :DDDD
- 08-06-2011, 06:14 PM #8
Member
- Join Date
- Aug 2011
- Posts
- 71
- Rep Power
- 0
hi, i have another problem to be solved..
this would be my code to safe a String in a .txtJava Code:import java.io.*; public class SchreibeInDatei { public void speichern() throws IOException{ String text = " 1 1 14 0 -2 3 1 \n 1 0 2 3 4 5 24 111 -24 \n 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"; String dateiName = "Welt1.txt"; FileOutputStream schreibeStrom = new FileOutputStream(dateiName); for (int i=0; i < text.length(); i++){ schreibeStrom.write((byte)text.charAt(i)); } schreibeStrom.close(); } }
but offortunatly i cant do the method "speichern" from another classobject.
it says: cannot find symbol - method speichern();Java Code:public class schreiben { private SchreibeInDatei d; public schreiben() { d = new SchreibeInDatei(); d.speichern(); // => cannot find symbol - method speichern(); } }
you have some idea? i think its because of this 'throws IOException'
i got that from the internet.. and if i delete it, theres another failure-message..
edit: i wanted to make the class which wants to safe sth, to give the SchreibeInDatei class a string by speichern(String s)... but that is the easiest problem..Last edited by Coold0wn; 08-06-2011 at 06:31 PM.
- 08-06-2011, 06:17 PM #9
it says: cannot find symbol - method speichern();Is the speichern() method defined in the DateiLesen class? The compiler can not find it there.Java Code:d = new DateiLesen(); d.speichern(); // => cannot find symbol - method speichern();
- 08-06-2011, 06:20 PM #10
Member
- Join Date
- Aug 2011
- Posts
- 71
- Rep Power
- 0
sure:
public void speichern() throws IOException
or does the throws IOException change something to that?
- 08-06-2011, 06:25 PM #11
The throws clause does not make it so the compiler can not see it.
- 08-06-2011, 06:26 PM #12
Member
- Join Date
- Aug 2011
- Posts
- 71
- Rep Power
- 0
oh.. okay.... and how can i now open that one with another class? Oo
impossible? .. :/
- 08-06-2011, 06:28 PM #13
Please explain and show an example in java code of what you are trying to do.how can i now open that one with another class
- 08-06-2011, 06:31 PM #14
Member
- Join Date
- Aug 2011
- Posts
- 71
- Rep Power
- 0
oh i messed sth up in this example..
thats what it should look like..Java Code:public class schreiben { private SchreibeInDatei d; public schreiben() { d = new SchreibeInDatei(); d.speichern(); <== ureported exception java.io.IOException; must be caught or declared to be thrown } }
and now the mistake is the same as what i had befor..:
ureported exception java.io.IOException; must be caught or declared to be thrown
- 08-06-2011, 06:32 PM #15
Member
- Join Date
- Aug 2011
- Posts
- 71
- Rep Power
- 0
i want to open the speicher() method from the class "SchreibeInDatei" with my class "schreiben"
- 08-06-2011, 06:34 PM #16
Wrap the line(s) of code where that error message is with a try{}catch() block.ureported exception java.io.IOException; must be caught or declared to be thrown
Read in the java tutorial about exceptions: The Really Big Index
Go to the site and find Extensions in the Essential classes section.
- 08-06-2011, 06:35 PM #17
Get a reference to an instance of the SchreibeInDatei class and use that to call the method:i want to open the speicher() method from the class "SchreibeInDatei" with my class "schreiben"
<reference to SchreibeInDatei>.speicher();
- 08-06-2011, 06:38 PM #18
Member
- Join Date
- Aug 2011
- Posts
- 71
- Rep Power
- 0
that wouldnt be the problem :P
the speichern() method throws IOExceptions which makes it impossible to a reference..
it should work with some try catch stuff... i dont know what that is..
- 08-06-2011, 06:46 PM #19
See my post #16try catch stuff... i dont know what that is..
- 08-06-2011, 06:56 PM #20
Member
- Join Date
- Aug 2011
- Posts
- 71
- Rep Power
- 0
Similar Threads
-
how to loop through an array and jump back to beginning
By drhinri in forum New To JavaReplies: 4Last Post: 02-21-2011, 03:52 AM -
jump to args-field in Main method
By argus in forum New To JavaReplies: 7Last Post: 10-07-2010, 04:14 PM -
creating a jump
By pizzadude223 in forum Java 2DReplies: 6Last Post: 07-21-2010, 05:01 PM -
Eclipse- jump to method definition
By Java Tip in forum Java TipReplies: 0Last Post: 11-07-2007, 03:34 PM -
To truncate jump of line in jsp
By Eric in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 06-09-2007, 03:58 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks