• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

lupine

[java] assigning values to 8 ints -help-

13 posts in this topic

// Hello, I am still learning JAva //and I have a question about assigning //a random #(1-6) to eight individual (Int) // I was trying to use a method //like where I declared an array and assigned //then assigned it a[1]=Math.Random... // The first(int) one was assigned //a random # but the rest came up ZERO my question is: I know I could declare and assign each individual (int) Declare (int1) (int1)=Math.random... Declare (int2) (int2)=Math.random and so on but there must be a more elegant or "tight" way to accomplish this in Java. Perhaps a For-loop or perhaps an array method if you have time please post sample code along with your response. Thanks gang
0

Share this post


Link to post
Share on other sites
hi.

here you go :

        

int myArray[];
//init array in the main method/constructor/init() or before

//using

myArray = new int[8];

for(int i = 0; i < myArray.length; i++) {
myArray[ i ] = (int)(1 + Math.random() * 6);
}


The other numbers where zero 'cause that's what ints are initialized to .

JP.

==============================================
I feel like a kid in some kind of store...
==============================================
www.thejpsystem.com



Edited by - loserkid on November 16, 2000 3:52:48 PM
0

Share this post


Link to post
Share on other sites
Wouldn''t that be...

1 + Math.Random() * 5

Otherwise you could get 7 as a result.
0

Share this post


Link to post
Share on other sites
JD in the clutch! thats why you wear the "C" JD
(hockey jargon)
no offense Anon but I think you might be off base there

btw Anon is not me!

-----------------------------------------------------------------
elf shot the food!!!!!!!!



Edited by - lupine on November 16, 2000 4:33:53 PM
0

Share this post


Link to post
Share on other sites
If you will bear with me I need a little
moe help. I am trying to run that code as a method but
I''m getting all zero''s
does this have to do with scope?
I get no error messages.
I can put up my embarrassing code if need be

thx if you can

-----------------------------------------------------------------
elf shot the fooooood!
0

Share this post


Link to post
Share on other sites
you probably should put up the code, everybody has to start some where....

JP.

==============================================
I feel like a kid in some kind of store...
==============================================
www.thejpsystem.com
0

Share this post


Link to post
Share on other sites
//here it is
/*
this is a program for me to try out
commands and API''s as I learn Java
-robert corrina Nov. 2000-
*/
import java.awt.*;



//my attempt at a method(a.k.a. subroutine)
//this should assign a rondom # to any value
//passed...it works! but only assigns one variable
class TrivialApplication {
//method but outputd only one number
public void gran(int stats[])
{
stats[1]=(int)(1+ Math.random ()*6);}


//as opposed to gran, this method generates
//eight numbers,(the for-loop) I plan to compare
//the two for reference
//***OUTPUT is all zero''s***nov17
static void myArray(int y[]) {
//init array,y, in the main method/constructor/init() //
// or before
//using
y = new int[8];//y is allocated 8 ints
for(int i = 0; i < y.length; i++) {
y = (int)(1 + Math.random() * 6);
}}


//print to screen
static public void main(String argv[]) {
System.out.println( "Hello World!" );
//generate a random number using Math.
//Math. , system. and more are part of
//java.lang which is automatically imported
//-------------------------------------------
//int ranum = (int)(1+ Math.random ()*6);
//
// System.out.println(ranum);
//------------------------------------------

/// static void genstat(ranum[]) {
///
//example of a for loop
// int i;
//// for (i = 0;i < 8; i++)
//System.out.println("Random# =" + (int)(1+ Math.random ()*6))
// ranum[i]=(int)(1+ Math.random ()*6);
// }

//nov 15, 2000
// pass array variable y to gran()
//need to figure out how arrays work

//nov 17, now trying myAray
//getting all ZEROS
int att[];
att=new int[8];
myArray(att);
System.out.println("strength : " + att[1]);

System.out.println("endurance : " + att[2]);
System.out.println("intelligence : " + att[3]);
System.out.println("leadership : " + att[4]);



}}


//thx ang GOOD LUCK!


0

Share this post


Link to post
Share on other sites
oh I see, you must be familiar with C or some other language like that. I know mainly java but I''m taking C and I was surprised at how strange arrays are in C. So for starters forget all that old stuff. Arrays are objects. Apparently they are implemented differently but from your point of view treat them exactly like all other objects. So if I say a = new int[5] it is like making a class with the following members:

class intArray
{
int 0;
int 1;
int 2;
int 3;
int 4;
} //keeping in mind that you can''t name things 0,1,2,etc..

and instead of writing a.2 you write a[2] ok on to your code

public void gran(int stats[])
{
stats[1]=(int)(1+ Math.random ()*6);
}

ok what you are doing here is getting a reference to an array and returning nothing, but you don''t need to. The first and only line generates a random integer and assigns it to the second variable of stats. The other ones aren''t mentioned in your code so they aren''t altered.

static void myArray(int y[])
{
y = new int[8];//y is allocated 8 ints
//anon: well, not exactly, a new object is made with 8 members
//don''t think of this being low level memory management

for(int i = 0; i < y.length; i++)
{
y = (int)(1 + Math.random() * 6);
}
//does this even compile? It shouldn''t.
//y holds a reference to an object that can hold 8 ints
//y is not the address to y[0] so the only thing that can
//legally be assigned to y is an int[] object, not a primitive int.
//If you want to assign an int to an index you have to assign it to that index.

}

The following should take an array and assign a different random int to each index:

public void assignInts(int[] y)
{
for (int i=0; i{
y=(int)(1 + Math.random()*6);
}
}

not sure if that is what you are asking for.
0

Share this post


Link to post
Share on other sites
oh wait let me try that again

public void assignInts(int[] y)
{
for (int i=0; i{
y=(int)(1 + Math.random()*6);
}
}

0

Share this post


Link to post
Share on other sites
yes it compiles.
and it runs-i get all zero's-
I can assign variables in
a FOR-loop.
I want a method (or class?)
I can call on from anywhere
and say
"assign every int in this array
a random number(1-6)"
----------------------------------
wait a minute i tried that "public void"
and i got a "cannot call a static/public"
something something


Edited by - lupine on November 22, 2000 8:25:26 PM
0

Share this post


Link to post
Share on other sites
what??? it is deleting parts of my code, probably yours too. Ok instead of brackets I am going to use B, and I am going to leave the for loop empty, just fill in the standard incrementing system with the i plus plus.

public void assignInts(int[] y)
{
for ()
{
yBiB=(int)(1 + Math.random()*6);
}
}

0

Share this post


Link to post
Share on other sites