1tilføjet af

Mod nye rekorder

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
public class piluda extends Applet implements MouseListener {
Image buffer;
Graphics billed;
Font spilNavn, regler, andetTekst, knapTekst;
Color farve;
int oplaegsNr, traek, nuller, score, aktuel, tal, slut, begynd, linje;
int slutscore, okay;
int felt[] = new int[144];
int år, måned, dato, time, minut, sekund, tid, sluttid, resttid;
double deci;
String regel;
String gang[] = new String[25];
public void init() {
buffer = createImage(750, 500);
billed = buffer.getGraphics();
traek = nuller = score = 0;
vaelgOplaeg();
indlæsDagsDato();
sluttid = tid + 1800;
tegnBrat();
addMouseListener(this);
}
public void destroy() {
rensBrat();
removeMouseListener(this);
}
public void paint(Graphics plade) {
update(plade);
}
public void update(Graphics brat) {
brat.drawImage(buffer, 0, 0, this);
}
public void vaelgOplaeg() {
oplaegsNr = (int) (Math.random() * 1000000);
deci = (double) (oplaegsNr * 16 + 388615) / 16777216;
int num = 0;
while (num < 143) {
beregnTal(144);
if (felt[tal] == 0) {
felt[tal] = num / 11 + 1;
num++;
}
}
for (int f = 0; f < 144; f++) {
if (felt[f] == 0) {
aktuel = f;
}
}
for (int n = 0; n < 24; n++) {
gang[n] = " ";
}
}
public void beregnTal(int max) {
int faktor;
do {
faktor = max;
if (faktor%2 == 0) {
faktor++;
}
deci = deci * faktor;
tal = (int) deci;
deci = deci - tal;
} while (tal == max);
}
public void rensBrat() {
for (int slet = 0; slet < 144; slet++) {
felt[slet] = 0;
}
}
public void tegnBrat() {
tegnRamme();
int kol, linje, num;
int r = 0, g = 0, b = 0;
knapTekst = new Font("Serif", 1, 18);
for (int x = 0; x < 12; x++) {
for (int y = 0; y < 12; y++) {
num = x + y * 12;
tal = felt[num];
if (aktuel == num) {
r = 0;
g = 192;
b = 0;
} else if (tal == 0) {
r = 255;
g = 255;
b = 0;
} else if ((x + y) % 2 == 0) {
r = 255;
g = 0;
b = 0;
} else {
r = 0;
g = 128;
b = 255;
}
tegnKnap(r, g, b, x * 40 + 10, y * 40 + 10, 40, 40);
linje = y * 40 + 36;
if (tal < 10) {
kol = x * 40 + 26;
} else {
kol = x * 40 + 21;
}
if (aktuel == num || tal == 0) {
billed.setColor(Color.black);
} else {
billed.setColor(Color.white);
}
billed.setFont(knapTekst);
billed.drawString("" + tal, kol, linje);
}
}
tekster();
repaint();
}
public void tegnRamme() {
int f, r, g, b;
farve = new Color(128, 160, 192);
billed.setColor(farve);
billed.fillRect(0, 0, 750, 500);
for (int a = 0; a < 10; a++) {
f = Math.abs(a - 5);
r = 200 - f * 10;
g = 100 - f * 5;
b = 0;
farve = new Color(r, g, b);
billed.setColor(farve);
billed.drawLine(a, a, 749 - a, a);
billed.drawLine(a, a, a, 499 - a);
billed.drawLine(a, 499 - a, 749 - a, 499 - a);
billed.drawLine(749 - a, a, 749 - a, 499 - a);
}
for (int a = 0; a < 10; a++) {
f = Math.abs(a - 5);
r = 200 - f * 10;
g = 100 - f * 5;
b = 0;
farve = new Color(r, g, b);
billed.setColor(farve);
billed.drawLine(490 + a, 5 + f, 490 + a, 495 - f);
}
}
public void tekster() {
indlæsDagsDato();
resttid = sluttid - tid;
if (resttid <= 0) {
slut = 1;
okay = 0;
} else if (resttid == 1799) {
resttid = 1800;
}
spilNavn = new Font("Verdana", 1, 36);
billed.setFont(spilNavn);
billed.setColor(Color.black);
billed.drawString("PILUDA", 554, 60);
andetTekst = new Font("Times New Roman", 1, 14);
billed.setFont(andetTekst);
billed.setColor(Color.black);
billed.drawString("Board number: " + oplaegsNr, 547, 120);
billed.drawString("Move number: " + traek, 570, 180);
billed.drawString("Zero number: " + nuller, 570, 220);
billed.drawString("Calculation:", 570, 260);
billed.drawString(nuller + " * " + nuller + " * 100", 575, 290);
billed.drawString("" + traek, 610, 305);
billed.drawString("Points: " + score, 570, 340);
billed.drawString("Time remain: " + resttid, 570, 380);
tegnRektangel(0, 0, 0, 570, 292, 100, 1);
if (begynd == 0) {
tegnKnap(192, 192, 192, 580, 420, 80, 30);
billed.setColor(Color.black);
billed.drawString("START", 600, 440);
}
if (slut == 1) {
if (okay == 0) {
score = score / 2;
}
score += resttid / 18;
billed.drawString("Game finished", 570, 420);
billed.drawString("Endscore: " + score, 570, 460);
andetTekst = new Font("Times New Roman", 1, 10);
billed.setFont(andetTekst);
billed.drawString("Svendborg games", 646, 486);
}
}
public void tegnRektangel
(int rod, int gron, int blaa, int x, int y, int brd, int hjd) {
Color farve = new Color(rod, gron, blaa);
billed.setColor(farve);
billed.fillRect(x, y, brd, hjd);
}
public void tegnKnap
(int rod, int gron, int blaa, int x, int y, int b, int h) {
Color f1 = new Color(rod, gron, blaa);
billed.setColor(f1);
billed.fillRect(x+2, y+2, b-4, h-4);
Color f2 = new Color(rod*5/6, gron*5/6, blaa*5/6);
billed.setColor(f2);
billed.drawRect(x+1, y+h-2, b-2, 1);
billed.drawRect(x+b-2, y+1, 1, h-2);
Color f3 = new Color(rod*2/3, gron*2/3, blaa*2/3);
billed.setColor(f3);
billed.drawRect(x, y+h-1, b, 1);
billed.drawRect(x+b-1, y, 1, h);
Color f4 = new Color
(rod+(255-rod)/6, gron+(255-gron)/6, blaa+(255-blaa)/6);
billed.setColor(f4);
billed.drawRect(x+1, y+1, b-3, 1);
billed.drawRect(x+1, y+1, 1, h-3);
Color f5 = new Color
(rod+(255-rod)/3, gron+(255-gron)/3, blaa+(255-blaa)/3);
billed.setColor(f5);
billed.drawRect(x, y, b-1, 1);
billed.drawRect(x, y, 1, h-1);
}
void indlæsDagsDato() {
double GT = 1, sommertid = 0;
Date dagsDato = new Date();
SimpleDateFormat formatter =
new SimpleDateFormat("yyyy",Locale.getDefault());
år = Integer.parseInt(formatter.format(dagsDato));
formatter = new SimpleDateFormat("MM",Locale.getDefault());
måned = Integer.parseInt(formatter.format(dagsDato));
formatter = new SimpleDateFormat("dd",Locale.getDefault());
dato = Integer.parseInt(formatter.format(dagsDato));
formatter = new SimpleDateFormat("HH",Locale.getDefault());
time = Integer.parseInt(formatter.format(dagsDato));
formatter = new SimpleDateFormat("mm",Locale.getDefault());
minut = Integer.parseInt(formatter.format(dagsDato));
formatter = new SimpleDateFormat("ss",Locale.getDefault());
sekund = Integer.parseInt(formatter.format(dagsDato));
TimeZone tz = TimeZone.getDefault();
tid = sekund + 60 * minut + 3600 * time + 86400 * dato;
}
public void mouseReleased(MouseEvent sted) {
int px = sted.getX() - 10;
int py = sted.getY() - 10;
int fx = px / 40;
int fy = py / 40;
String vej;
if (fx >= 0 && fx < 12 && fy >= 0 && fy < 12 && begynd == 1
&& slut == 0) {
int nytSted = fx + fy * 12;
int tal1 = felt[nytSted];
int tal2 = felt[aktuel];
int ax = aktuel % 12;
int ay = aktuel / 12;
int dx = Math.abs(fx - ax);
int dy = Math.abs(fy - ay);
if (dx < 2 && dy < 2 && (dx != 0 || dy != 0) && tal1 != 0) {
if (tal1 > tal2) {
tal1 = tal1 - tal2;
tal2 = tal2 * 2;
} else {
tal2 = tal2 - tal1;
tal1 = tal1 * 2;
}
felt[nytSted] = tal1;
felt[aktuel] = tal2;
aktuel = nytSted;
traek++;
if (tal2 == 0) {
nuller++;
}
score = nuller * nuller * 100 / traek;
slut = 1;
okay = 1;
for (int tx = -1; tx < 2; tx++) {
for (int ty = -1; ty < 2; ty++) {
ax = tx + fx;
ay = ty + fy;
if (ax > -1 && ax < 12 && ay > -1 && ay < 12) {
tal1 = felt[ax + ay * 12];
if ((tx != 0 || ty != 0) && tal1 != 0) {
slut = 0;
}
}
}
tegnBrat();
}
}
} else if (px > 580 && px < 660 && py > 420 && py < 450 && begynd==0) {
begynd = 1;
indlæsDagsDato();
sluttid = tid + 1800;
tegnBrat();
repaint();
}
}
public void mousePressed(MouseEvent sted) {
}
public void mouseClicked(MouseEvent sted) {
}
public void mouseEntered(MouseEvent sted) {
}
public void mouseExited(MouseEvent sted) {
}
}
tilføjet af

er det længden

eller almen interessen du mener?
SuperDebat.dk er det tidligere debatforum på SOL.dk, som nu er skilt ud separat.