Skip to content

Commit

Permalink
Merge pull request #120 from StenAL/features
Browse files Browse the repository at this point in the history
Client: Use ArrayLists instead of Vectors
  • Loading branch information
PhilippvK authored Sep 18, 2024
2 parents 73cc7db + 6080b26 commit b14125d
Show file tree
Hide file tree
Showing 27 changed files with 368 additions and 384 deletions.
37 changes: 19 additions & 18 deletions client/src/main/java/agolf/game/GameCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;

public class GameCanvas extends GameBackgroundCanvas implements Runnable, MouseMotionListener, MouseListener, KeyListener {

Expand Down Expand Up @@ -48,8 +49,8 @@ public class GameCanvas extends GameBackgroundCanvas implements Runnable, MouseM
private double somethingSpeedThing;
private double[] resetPositionX;
private double[] resetPositionY;
private Vector<double[]>[] teleportStarts;
private Vector<double[]>[] teleportExists;
private List<double[]>[] teleportStarts;
private List<double[]>[] teleportExists;
private short[][][] magnetMap;
private double[] playerX;
private double[] playerY;
Expand Down Expand Up @@ -704,17 +705,17 @@ protected boolean init(String commandLines, String playerStatuses, int gameId) {
}
}

Vector<double[]> startPositions = new Vector<>();
List<double[]> startPositions = new ArrayList<>();
this.resetPositionX = new double[4];
this.resetPositionY = new double[4];
this.teleportExists = new Vector[4];
this.teleportStarts = new Vector[4];
Vector<int[]> magnetVec = new Vector<>();
this.teleportExists = new ArrayList[4];
this.teleportStarts = new ArrayList[4];
List<int[]> magnets = new ArrayList<>();

for (int i = 0; i < 4; ++i) {
this.resetPositionX[i] = this.resetPositionY[i] = -1.0D;
this.teleportExists[i] = new Vector<>();
this.teleportStarts[i] = new Vector<>();
this.teleportExists[i] = new ArrayList<>();
this.teleportStarts[i] = new ArrayList<>();
}

// Iterates over the 49*25 map
Expand All @@ -727,7 +728,7 @@ protected boolean init(String commandLines, String playerStatuses, int gameId) {
//24 Start Position Common
if (tile == 24) {
double[] startPosition = new double[]{screenX, screenY};
startPositions.addElement(startPosition);
startPositions.add(startPosition);
}
//48 Start Position Blue
//49 Start Position Red
Expand All @@ -746,7 +747,7 @@ protected boolean init(String commandLines, String playerStatuses, int gameId) {
if (tile == 33 || tile == 35 || tile == 37 || tile == 39) {
teleportIndex = (tile - 33) / 2;
double[] teleporter = new double[]{screenX, screenY};
this.teleportExists[teleportIndex].addElement(teleporter);
this.teleportExists[teleportIndex].add(teleporter);
}

//33 Teleport Start Blue
Expand All @@ -756,14 +757,14 @@ protected boolean init(String commandLines, String playerStatuses, int gameId) {
if (tile == 32 || tile == 34 || tile == 36 || tile == 38) {
teleportIndex = (tile - 32) / 2;
double[] teleporter = new double[]{screenX, screenY};
this.teleportStarts[teleportIndex].addElement(teleporter);
this.teleportStarts[teleportIndex].add(teleporter);
}

//44 magnet attract
//45 magnet repel
if (tile == 44 || tile == 45) {
int[] magnet = new int[]{(int) (screenX + 0.5D), (int) (screenY + 0.5D), tile};
magnetVec.addElement(magnet);
magnets.add(magnet);
}
}
}
Expand All @@ -773,12 +774,12 @@ protected boolean init(String commandLines, String playerStatuses, int gameId) {
if (startPositionsCount == 0) {
this.startPositionX = this.startPositionY = -1.0D;
} else {
double[] startPosition = startPositions.elementAt(gameId % startPositionsCount);
double[] startPosition = startPositions.get(gameId % startPositionsCount);
this.startPositionX = startPosition[0];
this.startPositionY = startPosition[1];
}

int magnetVecLen = magnetVec.size();
int magnetVecLen = magnets.size();
if (magnetVecLen == 0) {
this.magnetMap = null;
} else {
Expand All @@ -792,7 +793,7 @@ protected boolean init(String commandLines, String playerStatuses, int gameId) {

for (int magnetIndex = 0; magnetIndex < magnetVecLen; ++magnetIndex) {
// [ x, y, blockid ]
int[] magnet = magnetVec.elementAt(magnetIndex);
int[] magnet = magnets.get(magnetIndex);
double forceTemp2X = magnet[0] - magnetLoopX;
double forcetemp2Y = magnet[1] - magnetLoopY;
double force = Math.sqrt(forceTemp2X * forceTemp2X + forcetemp2Y * forcetemp2Y);
Expand Down Expand Up @@ -1401,7 +1402,7 @@ private void handleTeleport(int teleportId, int playerId, int x, int y) {
do {
i = startLen - 1;
random = this.rngSeed.next() % (i + 1);
teleportPos = this.teleportStarts[teleportId].elementAt(random);
teleportPos = this.teleportStarts[teleportId].get(random);
if (Math.abs(teleportPos[0] - (double) x) >= 15.0D || Math.abs(teleportPos[1] - (double) y) >= 15.0D) {
this.playerX[playerId] = teleportPos[0];
this.playerY[playerId] = teleportPos[1];
Expand Down Expand Up @@ -1436,7 +1437,7 @@ private void handleTeleport(int teleportId, int playerId, int x, int y) {
}

//finally move player to exit position
teleportPos = this.teleportExists[var13].elementAt(random);
teleportPos = this.teleportExists[var13].get(random);
this.playerX[playerId] = teleportPos[0];
this.playerY[playerId] = teleportPos[1];
}
Expand Down
26 changes: 13 additions & 13 deletions client/src/main/java/agolf/game/HackedShot.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.aapeli.tools.Tools;

import java.util.Arrays;
import java.util.Vector;
import java.util.List;

/**
* mmmkay children.
Expand All @@ -28,8 +28,8 @@ public class HackedShot implements Runnable {
private double aDouble2820;
private double[] aDoubleArray2821;
private double[] aDoubleArray2822;
private Vector<double[]>[] aVectorArray2823;
private Vector<double[]>[] aVectorArray2824;
private List<double[]>[] teleportStarts;
private List<double[]>[] teleportExits;
private short[][][] aShortArrayArrayArray2825;
private double[] playerX;
private double[] playerY;
Expand Down Expand Up @@ -60,8 +60,8 @@ public HackedShot(int anInt2809,
double aDouble2820,
double[] aDoubleArray2821,
double[] aDoubleArray2822,
Vector<double[]>[] aVectorArray2823,
Vector<double[]>[] aVectorArray2824,
List<double[]>[] teleportStarts,
List<double[]>[] teleportExits,
short[][][] aShortArrayArrayArray2825,
double[] playerX,
double[] playerY,
Expand All @@ -88,8 +88,8 @@ public HackedShot(int anInt2809,
this.aDouble2820 = aDouble2820;
this.aDoubleArray2821 = Arrays.copyOf(aDoubleArray2821, aDoubleArray2821.length);
this.aDoubleArray2822 = Arrays.copyOf(aDoubleArray2822, aDoubleArray2822.length);
this.aVectorArray2823 = Arrays.copyOf(aVectorArray2823, aVectorArray2823.length);
this.aVectorArray2824 = Arrays.copyOf(aVectorArray2824, aVectorArray2824.length);
this.teleportStarts = Arrays.copyOf(teleportStarts, teleportStarts.length);
this.teleportExits = Arrays.copyOf(teleportExits, teleportExits.length);
if (aShortArrayArrayArray2825 != null) {
this.aShortArrayArrayArray2825 = Arrays.copyOf(aShortArrayArrayArray2825, aShortArrayArrayArray2825.length);
} else {
Expand Down Expand Up @@ -497,7 +497,7 @@ public double[] getHackedCoordintes() {

private void method154(int var1, int var2, int var3, int var4) {
boolean var5 = true;
int var6 = this.aVectorArray2824[var1].size();
int var6 = this.teleportExits[var1].size();
int var7;
int var8;
double[] var11;
Expand All @@ -507,15 +507,15 @@ private void method154(int var1, int var2, int var3, int var4) {
var7 = var6 - 1;
var8 = this.aSeed_2836.next() % (var7 + 1);
} else {
var7 = this.aVectorArray2823[var1].size();
var7 = this.teleportStarts[var1].size();
int var10;
if (var7 >= 2) {
int var14 = 0;

do {
var10 = var7 - 1;
var8 = this.aSeed_2836.next() % (var10 + 1);
var11 = this.aVectorArray2823[var1].elementAt(var8);
var11 = this.teleportStarts[var1].get(var8);
if (Math.abs(var11[0] - (double) var3) >= 15.0D || Math.abs(var11[1] - (double) var4) >= 15.0D) {
this.playerX[var2] = var11[0];
this.playerY[var2] = var11[1];
Expand All @@ -531,7 +531,7 @@ private void method154(int var1, int var2, int var3, int var4) {
boolean var9 = false;

for (var10 = 0; var10 < 4 && !var9; ++var10) {
if (this.aVectorArray2824[var10].size() > 0) {
if (this.teleportExits[var10].size() > 0) {
var9 = true;
}
}
Expand All @@ -542,14 +542,14 @@ private void method154(int var1, int var2, int var3, int var4) {

do {
var13 = this.aSeed_2836.next() % 4;
var6 = this.aVectorArray2824[var13].size();
var6 = this.teleportExits[var13].size();
} while (var6 == 0);

int var12 = var6 - 1;
var8 = this.aSeed_2836.next() % (var12 + 1);
}

var11 = this.aVectorArray2824[var13].elementAt(var8);
var11 = this.teleportExits[var13].get(var8);
this.playerX[var2] = var11[0];
this.playerY[var2] = var11[1];
}
Expand Down
17 changes: 9 additions & 8 deletions client/src/main/java/com/aapeli/applet/AdCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.net.URL;
import java.util.Vector;
import java.util.ArrayList;
import java.util.List;

class AdCanvas extends Canvas implements MouseListener {

private static final String linkTarget = "_blank";
private AApplet gameApplet;
private LoadingPanel loadingPanel;
private URL anURL117;
private Vector<AdCanvasText> aVector118;
private List<AdCanvasText> texts;
private URL anURL119;
private String aString120;
private int anInt121;
Expand All @@ -31,10 +32,10 @@ class AdCanvas extends Canvas implements MouseListener {
private long aLong126;


private AdCanvas(AApplet var1, URL var2, Vector<AdCanvasText> var3, URL var4, String var5, int var6) {
private AdCanvas(AApplet var1, URL var2, List<AdCanvasText> var3, URL var4, String var5, int var6) {
this.gameApplet = var1;
this.anURL117 = var2;
this.aVector118 = var3;
this.texts = var3;
this.anURL119 = var4;
this.aString120 = var5;
this.anInt121 = var6;
Expand All @@ -60,10 +61,10 @@ public void update(Graphics var1) {
}

var1.drawImage(this.anImage122, 0, 0, null);
int var5 = this.aVector118.size();
int var5 = this.texts.size();

for (int var6 = 0; var6 < var5; ++var6) {
AdCanvasText var4 = this.aVector118.elementAt(var6);
AdCanvasText var4 = this.texts.get(var6);
var4.method1548(var1);
}
} else {
Expand Down Expand Up @@ -98,13 +99,13 @@ protected static AdCanvas create(AApplet applet, Parameters parameters) {
try {
String var2 = parameters.getParameter("ad_image");
URL var3 = new URL(applet.getCodeBase(), var2);
Vector<AdCanvasText> var4 = new Vector<>();
List<AdCanvasText> var4 = new ArrayList<>();

String var6;
for (int var5 = 1; (var6 = parameters.getParameter("ad_text-" + var5)) != null; ++var5) {
AdCanvasText var7 = AdCanvasText.method1547(var6);
if (var7 != null) {
var4.addElement(var7);
var4.add(var7);
}
}

Expand Down
21 changes: 10 additions & 11 deletions client/src/main/java/com/aapeli/client/HtmlLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import java.awt.Font;
import java.awt.Graphics;
import java.util.Vector;
import java.util.ArrayList;
import java.util.List;

class HtmlLine {

private int anInt1366;
private boolean aBoolean1367;
private Vector<HtmlWord> words;
private List<HtmlWord> words;
private int nextWordStart;
private int height;
private final HtmlText aHtmlText1371;
Expand All @@ -18,7 +19,7 @@ protected HtmlLine(HtmlText htmlText, Graphics graphics, int var3, boolean var4)
this.aHtmlText1371 = htmlText;
this.anInt1366 = var3;
this.aBoolean1367 = var4;
this.words = new Vector<>();
this.words = new ArrayList<>();
this.nextWordStart = 0;
this.height = graphics.getFont().getSize();
}
Expand All @@ -27,8 +28,8 @@ public String toString() {
int wordsLength = this.words.size();
String s = "[HtmlLine: words.size=" + wordsLength + "\n";

for (int i = 0; i < wordsLength; ++i) {
s = s + " " + this.words.elementAt(i).toString() + "\n";
for (HtmlWord word : this.words) {
s = s + " " + word.toString() + "\n";
}

s = s + "'relatx'=" + this.nextWordStart + " 'height'=" + this.height + "]";
Expand All @@ -42,7 +43,7 @@ protected boolean method1604(int var1) {
protected void addWord(String text, Font font, int length) {
if (!this.isEmpty() || text.trim().length() != 0) {
HtmlWord word = new HtmlWord(this, text, font, this.nextWordStart, length);
this.words.addElement(word);
this.words.add(word);
this.nextWordStart += length;
int fontSize = font.getSize();
if (fontSize > this.height) {
Expand All @@ -62,21 +63,19 @@ protected int getHeight() {

protected void draw(Graphics graphics, int x, int y) {
int wordsCount = this.words.size();
HtmlWord word;
int wordsLength;
if (this.aBoolean1367) {
wordsLength = 0;

for (int i = 0; i < wordsCount; ++i) {
word = this.words.elementAt(i);
wordsLength += word.getLength();
for (HtmlWord htmlWord : this.words) {
wordsLength += htmlWord.getLength();
}

x += (this.anInt1366 - wordsLength) / 2;
}

for (wordsLength = 0; wordsLength < wordsCount; ++wordsLength) {
word = this.words.elementAt(wordsLength);
HtmlWord word = this.words.get(wordsLength);
word.draw(graphics, x, y);
}

Expand Down
Loading

0 comments on commit b14125d

Please sign in to comment.