 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Thoxay How do I cheat?
Reputation: 0
Joined: 15 Jul 2007 Posts: 3
|
Posted: Sun Jul 15, 2007 6:24 am Post subject: I need help in Java . |
|
|
| Quote: | import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class project
{
Button b,b1,b2,b3;
Frame f;
TextField tf;
TextArea ta;
Panel p,p1,p2;
int[] num = new int[7];
int i;
public void createFrame()
{
f = new Frame();
f.setTitle("Client");
f.setLayout(new BorderLayout());
p=new Panel();
p.setLayout(new GridLayout(2,2));
p1=new Panel();
p2=new Panel();
tf = new TextField(59);
p2.add(tf);
ta = new TextArea();
p1.add(ta);
b=new Button("Start");
p.add(b);
b1=new Button("Exit");
p.add(b1);
b2=new Button("Higher");
p.add(b2);
b3=new Button("Lower");
p.add(b3);
f.add(p,BorderLayout.SOUTH);
f.add(p1,BorderLayout.NORTH);
f.add(p2,BorderLayout.CENTER);
f.setVisible(true);
f.pack();
WindowHandler wh= new WindowHandler();
f.addWindowListener(wh);
MouseHandler mh = new MouseHandler();
b.addMouseListener(mh);
b1.addMouseListener(mh);
b2.addMouseListener(mh);
b3.addMouseListener(mh);
}
public static void main(String args[])
{
project fw= new project();
fw.createFrame();
}
public class WindowHandler extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
public class MouseHandler extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
Button bclick =(Button)e.getSource();
if (bclick == b)
{
Random r = new Random();
int result1 = r.nextInt(10);
int result2 = r.nextInt(10);
int result3 = r.nextInt(10);
int result4 = r.nextInt(10);
int result5 = r.nextInt(10);
num[1]= result1;
num[2]= result2;
num[3]= result3;
num[4]= result4;
num[5]= result5;
num[0] = 5;
for (i=0;i<num.length;i++)
{
if(num[1] == 5)
{
num[1] = result1;
}
{
ta.append(num[1]+"");
}
}
}
if (bclick == b1)
{
System.exit(0);
}
if (bclick == b2)
{
//button clicked
}
if (bclick == b3)
{
//button clicked
}
}
}
}
|
I need to make sure that num[1] to num[5] is all different numbers and the numbers can't be 5. Anyone knows how to check that ?
Thanks in advance people.
|
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Sun Jul 15, 2007 2:37 pm Post subject: |
|
|
Make an array of boolean the size of your largest random number, 11 in your case. Then every time the integer is generated, check in the boolean array if that index is set to true: if true, generate a new one, else set the boolean as true and make your num[index] as the integer generated. To prevent the numbers from becoming 5, just set in the boolean array's index 5 as true.
Example:
| Code: |
final int SIZE = 4;
final int MAX = 11;
int num[] = new int[SIZE];
boolean set[] = new boolean[SIZE];
int buff;
set[5] = true;
Note,
for (int i = 0; i < SIZE ; i++){
do{
buff = (int)(Math.random()*(MAX+1));
}while (set[buff]);
num[i]=buff;
}
|
Note, this is only good for generating within a small range. For generating within a large range, it will be more memory efficient to make an array the same size as your array of numbers, then put in all of the generated numbers into the array. Now every time you want to generate a number, you would have to check through the whole array to see if the number was previously used. Of course, this will be much slower as you have to loop through the whole array.
There are other methods, such as adding all possible elements into a Vector and deleting the element every time you generate one.
_________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
Thoxay How do I cheat?
Reputation: 0
Joined: 15 Jul 2007 Posts: 3
|
Posted: Mon Jul 16, 2007 4:16 am Post subject: |
|
|
Thanks alot bro. Haha. My final year project is giving me headaches
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|