Hey guys, I wrote the first game today, it generates a random number from 1 to 8 and then print that number and that number of circles. Once I've finished the other ones I'll pretty it up :) If you have any ideas for games you'd like me to include just comment on this post or text message me and I'll see what I can do :)
On a personal note I hadn't thrown images into Java before, this was definitely a learning experience, and there's some parts that were directly copied from forums, but when I have the time I'll change them to fit how I program, enjoy!
import java.util.Random;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
public final class RunMe {
public static final void main(String... aArgs){
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(8);
if (randomInt==0){
randomInt=8;
}
System.out.println("Number of Circles:" + randomInt);
String path = "C:/Users/Shaun/Pictures/BlueCircle"+randomInt+".jpg";
BufferedImage image = null;
try {
image = ImageIO.read(new File(path));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
LoadAndShow test = new LoadAndShow(image);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new JScrollPane(test));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int height = screenSize.height;
int width = screenSize.width;
f.setSize(623,443);
f.setLocation(623,443);
f.setLocationRelativeTo(null);
f.setVisible(true);
randomInt=randomInt-1;
}
private static void setBounds(int i, int j, int k, int l) {
// TODO Auto-generated method stub
}
}
I'll post a screen-captured video later because you guys won't be able to run it without having the right files or directories.
-Shaun
Hey guys, just letting you know that this code's old now, new stuff has a text box and plays a sound when the player answers the question right/wrong. I'll link it when I upload the next one.
ReplyDelete