From f08e4364865fa9e2eaea20fdc04cb8e6ce232746 Mon Sep 17 00:00:00 2001
From: Vlad Oleksiyenko <68962947+vladoleksiyenko@users.noreply.github.com>
Date: Thu, 14 Mar 2024 12:26:26 -0700
Subject: [PATCH] Add files via upload
---
CharacterProtocol.iml | 11 ++
.../CharacterProtocol/CharacterClient.class | Bin 0 -> 2899 bytes
.../CharacterProtocol/CharacterServer.class | Bin 0 -> 1300 bytes
.../CharacterProtocol/CharacterService.class | Bin 0 -> 3159 bytes
out/production/CharacterProtocol/Main.class | Bin 0 -> 355 bytes
.../CharacterProtocol/UserCharacter.class | Bin 0 -> 1968 bytes
.../CharacterProtocol/UserCharacters.class | Bin 0 -> 1369 bytes
src/CharacterClient.java | 88 ++++++++++++++
src/CharacterServer.java | 27 ++++
src/CharacterService.java | 107 ++++++++++++++++
src/Main.java | 5 +
src/UserCharacter.java | 115 ++++++++++++++++++
src/UserCharacters.java | 80 ++++++++++++
13 files changed, 433 insertions(+)
create mode 100644 CharacterProtocol.iml
create mode 100644 out/production/CharacterProtocol/CharacterClient.class
create mode 100644 out/production/CharacterProtocol/CharacterServer.class
create mode 100644 out/production/CharacterProtocol/CharacterService.class
create mode 100644 out/production/CharacterProtocol/Main.class
create mode 100644 out/production/CharacterProtocol/UserCharacter.class
create mode 100644 out/production/CharacterProtocol/UserCharacters.class
create mode 100644 src/CharacterClient.java
create mode 100644 src/CharacterServer.java
create mode 100644 src/CharacterService.java
create mode 100644 src/Main.java
create mode 100644 src/UserCharacter.java
create mode 100644 src/UserCharacters.java
diff --git a/CharacterProtocol.iml b/CharacterProtocol.iml
new file mode 100644
index 0000000..9465dd8
--- /dev/null
+++ b/CharacterProtocol.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/out/production/CharacterProtocol/CharacterClient.class b/out/production/CharacterProtocol/CharacterClient.class
new file mode 100644
index 0000000000000000000000000000000000000000..34d06b98e9a10ada4ff096b3995e2a592965cfc3
GIT binary patch
literal 2899
zcmbtWS!`5Q82)}b?Y$iaN{3Py)`Bb@wt}+Gu(i`d2fNWJgMe5s(@W>l>Al0u9X1zm
z!wpT050V%kOf){Ii5OE17>utZ#)JnGc`z|1#sm_dO^o=RJ5xGcVhqm1x#ygJIsgCt
z+uZv5`b_}4@wOk+P@%yWKqaaKvrZbPji!uY4>ollKWV01LDde+w%lEUipFqKgD$A?
zm~7K+N;s(@)79Y@RA-!&kx4sw*AEQ=rEi9yzOiFWW5Uf@_Fyy~PAZm~0A`_9Fmup!
z<94>-l585og1L?1qLAe@l@X#!Xm$W~m_rjN)Ln4Pq~?`Ll~bY`<_c;(D+;caX-cFF
z+ctB4)FY&jT3zy
zjf|F62xM$pG?mt55Q4CRW>Wy0m6}RVK;3K&V4F&?$`hGFKCQry1Q5jzfo_{;-44q(
z1$Cn_EVnGk3=QkpEr5<@;@R5V*}Si9Dm-<>7|ashy=|=rW94Y;Xd|^GJ&CFS*r&X&
z(h(N~_Ob_xNBDd!
zZRCs;voV&jOq+S)i#Y>?u|}cURTw^Q=K9nVf?$U#&ZLpE)VXx&bJG?Rq_$&%o+uR!
z8y2Hn-*|L#`G%8>nZ^7nR_j=9me(r#0W)`$r~X0yjw=wsH1*2tBDK6YX~LM^va;j-
z%(Q7_+;o4+86Gxlf)t!=A`K*jSr!3(pE+O*8-wPUK;Trta>tJ1VKAYkDGZF@VA{!nOWDO6&lWt24A(9?gtcdC7ePo
zW$v|9nCd1(V!g78eWAs16qZJ|({$6$K)$95&-w8@E@-%@8oJ<(>mxqFDB6XUJ?~
z(X!hXd%|9(iIY1gxKduXCB~xCc7mBP^UFINXQ+^kP6oB?W}IN(xvV(_dpT^yQ4%e0
zJ0%q{Ba=z6p+>r
zqEXhg1y1^hj}@;|6yJXc1$5P3U06~;#UCr%K+rQ3_!-N
z=M&6PG30l8#J4Ww8^OVK-(F?xYvs25goNCYpXC>J{0gX?`3>8-)-WgPP|J~6kGWWg
zdHgpJ!bT3w%{;YW5xTILGD~m-4H(2SI9QH6R^TEzFJl$nVM<&<7$0K|KIa^}iuJh3
zM7_mv_5(HjNIQSUCfvmq{DH0b3)@&=+hqnKQirH4#ZFnp3A+Y+WE*E}D_SJZS=xhE
zIflJrV4v7%m-C#A7qDM0aUQlgjSxKAa16Vl8A$mm4Vu(8(dFe-n
zyK26&7{lE8iRvBLM1y52_xQpozT=bMks~?+m!~!G-KQD+hg%Sh`nV+S^Xn^J@aWxX
se^TJI66f~}4LryFG@QpX{MPaOEbm|R)|b8Y5?&+4&)e7WCf-8mA7%!-*8l(j
literal 0
HcmV?d00001
diff --git a/out/production/CharacterProtocol/CharacterServer.class b/out/production/CharacterProtocol/CharacterServer.class
new file mode 100644
index 0000000000000000000000000000000000000000..17e47719424eea446274850ecd7f8af919e772c7
GIT binary patch
literal 1300
zcmZuxTT|0O7(Gib3o%^E)p{)oS`=IFmx2gZP^3_X6dc9}CxjKkC1KLk(O=}VK2S$y
z`~klEchs|~V(ZY%?)KaL_MG#b-Q@evuipSXLD@hXViIu^2_yx2cI{9F&(7j#+{ZA7m=Y0w&SP+it5XbHFBfUqM|72l0dh1<*x*_nUfe{ZO1lg7hFdfxQr{>tg8Ye
ze^{H4O0CvXgv3~jMU`#3uxTKR>l$WUV5nLAO3m}^jXf2~&mw0cug^764ecP5xJ8{U
zl2pJ$EBc#?3nkZ6OSSzC6;w2YKyS%+?7cNRaCQ7=G9GTbRe@CLKb#2y?b|Nh9L&Bx
z$xZk+W&2o9A!ZX*hv_V5nC*E|Ksi4yeZD)7UK8Vbbm?p#Q
zdwo+}->XWLn(p3w`FMp{mR}1THRo!d`&)`uK~7tQVcg`)sef(Y2_nh-c89%J$da=pi>qhm33>C4m+%yo`+
zbQR*C(cL?6h@o`+5a$aC9S$=*!sYdJV!V#gLh=aN^>nh1YXzB>hq&?a*AK$Rprzz+
zioMCGlTQ~?=*D@z^rPsU
z8$;3jVoh_5an}rsMoPEwhUof{H;unb%67xbrvYDKH$rk7S
L1-3>0Z^P1W?5rlM
literal 0
HcmV?d00001
diff --git a/out/production/CharacterProtocol/CharacterService.class b/out/production/CharacterProtocol/CharacterService.class
new file mode 100644
index 0000000000000000000000000000000000000000..c1e427b3b604b432e52b63f095912ec4af2b1f56
GIT binary patch
literal 3159
zcmaJ@`*R!B75=Vcdu3%EC(6^rq%yIIC8aT~`v4Rmj-w>;i_RT3{TFTGs~Vp=V8mXygLOp4JBr}5J8uQ
zsE*Ch3C~mv*C>0YTQuEet85C0y1=%Aa$}p`aM39*nqFG2+oGcfTLq%!)kTDEElk%<
zx8+dyE;g6ZY$TEi=Pu4ya@>>f(^
zG%RO0G?9*C8*Y%t-7BzXXhVp9&Kq^?!*>MQEL&i^4-8Wx)qYMWCfwtMYuVncYcUv-
z?0y{s7$j5jnrwI>VtYcw!ZTzR#{tP~NTByRvo#o>T2e;}2bmJ5!3^ze9U{bm-Xb`p
zV_2rOYu*VGB&mH*$M>bRqg-|BriLGcPLZF?T_~G1&vNW2M(`sYKbFv*nmk?6Gs=r4
zCft-kyiLdLNDF8cqds9?AQ39$w4Av^$DO!KpxsvH9jgacx?+ATdm$acC;=y@^Q9;<
z$ZE*xIELeEB>pPcTZ5m`e9j2DBeqYegS_mZ*5P}*g~o3*?O-|C)WdnyyzpuECKl?qeU8R#XmW%~61_3w5>**Jg%oDPp^Vy9y
z)$mJ!m?}fXWvXG@hRV)BAeYcZwEntD%<$M5XP&w2DOk2S(O8-@-IBjPR&dHjb;fWl
z`5hSBy^6&E#0srTD<~~l3Wk5*Q3Z`P*BX`LHh7J6nXAjuvAOXP_yIt{mM9Yi)V#!au{%-4H5@qQE^;I|rnCzJGhfr0CJu0-^?0DdNf_gh*zEZo3F#;8_{
zyt;WU{gLe_Gd(qxn<&Noa=AS&B3KETec3AWUj)*vaK-ak8sm?|uUq`mT5t6gPOE^P
zm+dW6HR^Sc~^C^CvB5o7Mp5#@CWaf@ucG$~`e=yC^mh*
zVd`#<-F=BBW|Aa+W(A+5VrMr-7y;ttRII!)!VD0#RBT~mgcTqrQn5va=;!_k#i5C%
zYj_xFq9JWfTv)+@RP3h;wl4(x*)=>ChDmk$@tmVFfdb_}&K^ENjZQL-CvbqxdIVEQ
zqsT;;kjFHCXV{pz(+WXtL(@Bf`KnEhcDTDWlqMJ
zw_a-h4ZO*n)2+ArTW^oH-WdBF+y*b@D?*GWwjZd-ykXa`}=R+&$RKM20wYQ
zl)ijbCHBf7?PZXHkx_VjeH7Z1?02b*FHrUsR_FrNWKsU-T56)h7NbGMgAEIBlSv!i
f!MhxH@cTWI_=9@>Nj?9Jzj7u@>)#lckJ0--YrpEo
literal 0
HcmV?d00001
diff --git a/out/production/CharacterProtocol/Main.class b/out/production/CharacterProtocol/Main.class
new file mode 100644
index 0000000000000000000000000000000000000000..0916c414b6654674099f950a8f6bd384f43a0e0c
GIT binary patch
literal 355
zcmZut!AiqG6r7i)jfvH2E8e}e3g!bU^&ohPdZ^^$X%m;YCEdW9`d^*|4}O3jCC)}c
z5f^rb_ukArcHci<-vFHBAVGj$gm8#H27%Z``Ni{
zow3z?mUFILMg8QTu^?GC8&~Q}#(D#k8G?0EA@r=jkzG5lrZ*I~aCj)?pP(o`=l}o!
literal 0
HcmV?d00001
diff --git a/out/production/CharacterProtocol/UserCharacter.class b/out/production/CharacterProtocol/UserCharacter.class
new file mode 100644
index 0000000000000000000000000000000000000000..48101e69cde97e8a927cb0cb56a2e3fa4668640d
GIT binary patch
literal 1968
zcmbu9+in|G6o&up)717PPTi)(fi!Va8ryB-G?Y`*ld+w~khI87BOwIs#2LlYI%AlO
zDNlfS10-&^%q6Nsr~nBhE_o=#zxIrs1lkmVqU^)k>+r3^_>Vt-{uRJ2+({vVsDYS?
zI1&nDkE}1Oa@TUV%l9@P*==7Taouqp|E5B;P~0$ZVxZLboo=~lxm&%R6bwX@NW(NR
zVqz2-g^~NawpZ;~p4IkkPa)<}RUx~oBOEebib8$$ow&%FIEB*+hHHQ6H(bV!6&l5c
zI6hbUmZ{?4ZDty`O2O0u-Hx*L|~$UPLs{Eo9L
z+DAIDq!2IEYQ+uaA`Nw{?n+p%!M&yn#rKtZWp#b!L9<@FU#&|Qv{}-%pA1YA)=sZ4
z9U5u*R{Qaq^_dQC;D*AfgBe=yc)ce9Y9@5rxLa-3D=oUs)GBM0JM{+#5{WQ`2ww*f
z$!*&oMCT;3`yv@=r&_(f*S41(U6mt=&kGLnoQMcVKF*bs#8X73M(-RGy|dBWA@j@i
z1XwX7xR!bI!7=5&Sb7Fk`US>E&yd_ls#N*`sqEN~IJuAU(>NvP@EAni@0vn0-pC
z2o|`WIPTI?VorIRzeaqu+ds
zw64Y;G9sAUeqX3^fz~C3J)FE2AKr5D-=4BaNrEiu;8*n?)nzLoMcGBZUS{FuF+pjb
zs22!UCXxW&;C`D}QbI`}&r-dsVTnc!DW;sR=~R|@P9ipu{=mTX5oU68n9p9A&qBZ!
z<}=s+clgpz@PAhC0sagp35<{=;206cQR5`ksZqlv?qw_wvBwT!FAT944q+RJSRwSS
zpH~pU%>!DHvj+t
literal 0
HcmV?d00001
diff --git a/out/production/CharacterProtocol/UserCharacters.class b/out/production/CharacterProtocol/UserCharacters.class
new file mode 100644
index 0000000000000000000000000000000000000000..43553d8ccf4dbf526bef167d659b55098e68850b
GIT binary patch
literal 1369
zcmbVKTTc@~7(LV5(z2!86rn}A2(%R_#Vb^Wrdy>+TN4URj1Od~8(1u@>BR?MeDPQK
z=!=iWL?O}05Aa|3H+&G!EK9Y007J5wo%!aR@0^)4KYo8b0oUy+^L(d$@Ui-dg(<@e`yol;SA3$&|NysAfquSeZShQFfhS|
zx3wkhv|sm$U4ndtYO_`{9+}eOKpUt&FCPNN8Ht0z2#!pbGlg?E!W<)9y+aqA{Kun*
z5YgawC|}@pJ_toW!+Z1|)<5(O%F{sv_#L9J@YW$d9RK`8k`qymBk*wa!^QS00vJLc
z>j5la05`ZZMqCdjFpD|MN*wcuu})E9=4d3&c^@3dgz+W&gaCfgx!|i=w0&-|iJP#1
zG!|T3b`8722N;wt9F_}GIS=wUA+{N{l%w=SN=q+*o0gue-NJ1$yLcUUaF;m2bDS-9
zrBiH*^l6ICTtIB}9I;@hSd3x|6pLR#Z0sDdtDRy?6kDcP;sRomxMydU=LO49)RW9|
yvj-Ue*b40AU8Wd-W~s<$LToE6)ecKx?lK|=yUv`|d#bZ{j=l5$-FwM$w)_Wsp1pSf
literal 0
HcmV?d00001
diff --git a/src/CharacterClient.java b/src/CharacterClient.java
new file mode 100644
index 0000000..37970cd
--- /dev/null
+++ b/src/CharacterClient.java
@@ -0,0 +1,88 @@
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.net.Socket;
+import java.util.Scanner;
+
+/**
+ This program tests the character server.
+ */
+public class CharacterClient
+{
+ public static void main(String[] args) throws IOException
+ {
+ final int SBAP_PORT = 8888;
+
+ // localhost means we are connecting to our own device
+ // that we are currently running on (loopback to ourselves)
+ // localhost is a name for IP address 127.0.0.1
+ try (Socket s = new Socket("localhost", SBAP_PORT))
+ {
+ InputStream instream = s.getInputStream();
+ OutputStream outstream = s.getOutputStream();
+ Scanner in = new Scanner(instream);
+ PrintWriter out = new PrintWriter(outstream);
+
+ String health_command = "HEALTH_INCREASE 1 500000.0";
+ System.out.println("Sending: " + health_command);
+ out.print(health_command + "\n");
+ out.flush();
+ String response = in.nextLine();
+ System.out.println("Receiving: " + response);
+
+ System.out.println("");
+
+ String damage_command = "DAMAGE_INCREASE 1 500000.0";
+ System.out.println("Sending: " + damage_command);
+ out.print(damage_command + "\n");
+ out.flush();
+ response = in.nextLine();
+ System.out.println("Receiving: " + response);
+
+ System.out.println("");
+
+ health_command = "HEALTH_REDUCE 1 500000.0";
+ System.out.println("Sending: " + health_command);
+ out.print(health_command + "\n");
+ out.flush();
+ response = in.nextLine();
+ System.out.println("Receiving: " + response);
+
+ System.out.println("");
+
+ damage_command = "DAMAGE_REDUCE 1 500000.0";
+ System.out.println("Sending: " + damage_command);
+ out.print(damage_command + "\n");
+ out.flush();
+ response = in.nextLine();
+ System.out.println("Receiving: " + response);
+
+ System.out.println();
+
+ health_command = "GET_HEALTH 1";
+ System.out.println("Sending: " + health_command);
+ out.print(health_command + "\n");
+ out.flush();
+ response = in.nextLine();
+ System.out.println("Receiving: " + response);
+
+ damage_command = "GET_DAMAGE 1";
+ System.out.println("Sending: " + damage_command);
+ out.print(damage_command + "\n");
+ out.flush();
+ response = in.nextLine();
+ System.out.println("Receiving: " + response);
+
+ damage_command = "INVALID COMMAND";
+ System.out.println("Sending: " + damage_command);
+ out.print(damage_command);
+ out.flush();
+
+ String quit_command = "QUIT";
+ System.out.println("Sending: " + quit_command);
+ out.print(quit_command + "\n");
+ out.flush();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/CharacterServer.java b/src/CharacterServer.java
new file mode 100644
index 0000000..279d4a5
--- /dev/null
+++ b/src/CharacterServer.java
@@ -0,0 +1,27 @@
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+/**
+ A server that executes the Character Access Protocol.
+ */
+public class CharacterServer
+{
+ public static void main(String[] args) throws IOException
+ {
+ final int ACCOUNTS_LENGTH = 10;
+ UserCharacters characters = new UserCharacters(ACCOUNTS_LENGTH);
+ final int SBAP_PORT = 8888;
+ ServerSocket server = new ServerSocket(SBAP_PORT);
+ System.out.println("Waiting for users to connect...");
+
+ while (true)
+ {
+ Socket s = server.accept();
+ System.out.println("User connected.");
+ CharacterService service = new CharacterService(s, characters);
+ Thread t = new Thread(service);
+ t.start();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/CharacterService.java b/src/CharacterService.java
new file mode 100644
index 0000000..8308c10
--- /dev/null
+++ b/src/CharacterService.java
@@ -0,0 +1,107 @@
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.Socket;
+import java.util.Scanner;
+
+/**
+ Executes Character Access Protocol commands
+ from a socket.
+ */
+public class CharacterService implements Runnable
+{
+ private Socket s;
+ private Scanner in;
+ private PrintWriter out;
+ private UserCharacters characters;
+
+ /**
+ Constructs a service object that processes commands
+ from a socket for a character.
+ @param aSocket the socket
+ @param userCharacters the character container
+ */
+ public CharacterService(Socket aSocket, UserCharacters userCharacters)
+ {
+ s = aSocket;
+ characters = userCharacters;
+ }
+
+ public void run()
+ {
+ try
+ {
+ try
+ {
+ in = new Scanner(s.getInputStream());
+ out = new PrintWriter(s.getOutputStream());
+ doService();
+ }
+ finally
+ {
+ s.close();
+ }
+ }
+ catch (IOException exception)
+ {
+ exception.printStackTrace();
+ }
+ }
+
+ /**
+ Executes all commands until the QUIT command or the
+ end of input.
+ */
+ public void doService() throws IOException {
+ while (true) {
+ if (!in.hasNext()) {
+ return;
+ }
+
+ String command = in.next();
+
+ if (command.equals("QUIT")) {
+ return;
+ } else {
+ executeCommand(command);
+ }
+ }
+ }
+
+ /**
+ Executes a single command.
+ @param command the command to execute
+ */
+ public void executeCommand(String command)
+ {
+ int characterID = in.nextInt();
+ if (command.equals("HEALTH_INCREASE")) {
+ double amount = in.nextDouble();
+ characters.HEALTH_INCREASE(characterID, amount);
+ receivingOutput(characterID);
+ } else if (command.equals("HEALTH_REDUCE")) {
+ double amount = in.nextDouble();
+ characters.HEALTH_REDUCE(characterID, amount);
+ receivingOutput(characterID);
+ } else if (command.equals("DAMAGE_INCREASE")) {
+ double amount = in.nextDouble();
+ characters.DAMAGE_INCREASE(characterID, amount);
+ receivingOutput(characterID);
+ } else if (command.equals("DAMAGE_REDUCE")) {
+ double amount = in.nextDouble();
+ characters.DAMAGE_REDUCE(characterID, amount);
+ receivingOutput(characterID);
+ } else if (command.equals("GET_HEALTH")) {
+ out.println("CURRENT HEALTH: " + characters.getHealth(characterID));
+ out.flush();
+ } else if (command.equals("GET_DAMAGE")) {
+ out.println("CURRENT DAMAGE: " + characters.getDamage(characterID));
+ out.flush();
+ }
+ }
+
+ public void receivingOutput(int characterID) {
+ out.println("Character ID: " + characterID + " | Character Health: " + characters.getHealth(characterID)
+ + " | Character Damage: " + characters.getDamage(characterID));
+ out.flush();
+ }
+}
\ No newline at end of file
diff --git a/src/Main.java b/src/Main.java
new file mode 100644
index 0000000..f5858db
--- /dev/null
+++ b/src/Main.java
@@ -0,0 +1,5 @@
+public class Main {
+ public static void main(String[] args) {
+
+ }
+}
\ No newline at end of file
diff --git a/src/UserCharacter.java b/src/UserCharacter.java
new file mode 100644
index 0000000..c86a97c
--- /dev/null
+++ b/src/UserCharacter.java
@@ -0,0 +1,115 @@
+import java.util.Random;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ A character has health and damage fields, which can be altered
+ by using included methods
+ */
+public class UserCharacter {
+ private int characterID;
+ private double health;
+ private double damage;
+ private Lock characterLock;
+
+ /**
+ Constructs a character with 0 health, 0 damage and a random id
+ */
+ Random rand = new Random();
+ public UserCharacter() {
+ this.characterID = rand.nextInt(99999); // Not a great way to create unique id's, this is just temporary
+ this.health = 0;
+ this.damage = 0;
+ characterLock = new ReentrantLock();
+ }
+
+ /**
+ Constructs a character with a given health amount and damage amount.
+ @param initialHealth the amount of health the character is created with
+ @param initialDamage the amount of damage the character is created with
+ */
+ public UserCharacter(double initialHealth, double initialDamage) {
+ this.characterID = rand.nextInt(99999); // Not a great way to create unique id's, this is just temporary
+ this.health = initialHealth;
+ this.damage = initialDamage;
+ characterLock = new ReentrantLock();
+ }
+
+ /**
+ Reduces the health of the character by given amount
+ @param amount the amount of health that is reduced
+ */
+ public void HEALTH_REDUCE(double amount) {
+ characterLock.lock();
+ try {
+ if (health == 0) {
+ health = 0;
+ } else {
+ double newHealth = health - amount;
+ health = newHealth;
+ }
+ }
+ finally {
+ characterLock.unlock();
+ }
+ }
+
+ /**
+ Increases the health by given amount
+ @param amount the amount the health is increased by
+ */
+ public void HEALTH_INCREASE(double amount) {
+ characterLock.lock();
+ try {
+ double newHealth = health + amount;
+ health = newHealth;
+ }
+ finally {
+ characterLock.unlock();
+ }
+ }
+
+ /**
+ * Increases the damage by given amount
+ * @param amount the amount that damage is increased by
+ */
+ public void DAMAGE_INCREASE(double amount) {
+ characterLock.lock();
+ try {
+ double newDamage = damage + amount;
+ damage = newDamage;
+ } finally {
+ characterLock.unlock();
+ }
+ }
+
+ /**
+ * Reduces the damage by given amount
+ * @param amount the amount that damage is reduces by
+ */
+ public void DAMAGE_REDUCE(double amount) {
+ characterLock.lock();
+ try {
+ double newDamage = damage - amount;
+ damage = newDamage;
+ } finally {
+ characterLock.unlock();
+ }
+ }
+
+ /**
+ Gets the current health amount of a character.
+ @return the current amount
+ */
+ public double getHealth() {
+ return health;
+ }
+
+ /**
+ Gets the current damage amount of a character.
+ @return the current amount
+ */
+ public double getDamage() {
+ return damage;
+ }
+}
\ No newline at end of file
diff --git a/src/UserCharacters.java b/src/UserCharacters.java
new file mode 100644
index 0000000..f8cd04b
--- /dev/null
+++ b/src/UserCharacters.java
@@ -0,0 +1,80 @@
+/**
+ An array that contains characters
+ */
+public class UserCharacters
+{
+ private UserCharacter[] userCharacters;
+
+ /**
+ Creates a user character array that contains user characters
+ @param size the array size (how many characters it'll contain)
+ */
+ public UserCharacters(int size)
+ {
+ userCharacters = new UserCharacter[size];
+ for (int i = 0; i < userCharacters.length; i++)
+ {
+ userCharacters[i] = new UserCharacter(500.0, 500.0);
+ }
+ }
+
+ /**
+ Increases the health amount of a character
+ @param characterID the character id
+ @param amount the amount of increase to the health
+ */
+ public void HEALTH_INCREASE(int characterID, double amount) {
+ UserCharacter character = userCharacters[characterID];
+ character.HEALTH_INCREASE(amount);
+ }
+
+ /**
+ Increases the health amount of a character
+ @param characterID the character id
+ @param amount the amount of reduction to the health
+ */
+ public void HEALTH_REDUCE(int characterID, double amount) {
+ UserCharacter character = userCharacters[characterID];
+ character.HEALTH_REDUCE(amount);
+ }
+
+ /**
+ Increases the damage amount of a character
+ @param characterID the character id
+ @param amount the amount of increase to the damage
+ */
+ public void DAMAGE_INCREASE(int characterID, double amount) {
+ UserCharacter character = userCharacters[characterID];
+ character.DAMAGE_INCREASE(amount);
+ }
+
+ /**
+ Reduces the damage amount of a character
+ @param characterID the character id
+ @param amount the amount of reduction to the damage
+ */
+ public void DAMAGE_REDUCE(int characterID, double amount) {
+ UserCharacter character = userCharacters[characterID];
+ character.DAMAGE_REDUCE(amount);
+ }
+
+ /**
+ Returns the health for given character id
+ @param characterID the character id
+ @param characterID the character id that is used to return health
+ */
+ public double getHealth(int characterID) {
+ UserCharacter character = userCharacters[characterID];
+ return character.getHealth();
+ }
+
+ /**
+ Returns the damage for given character id
+ @param characterID the character id
+ @param characterID the character id that is used to return damage
+ */
+ public double getDamage(int characterID) {
+ UserCharacter character = userCharacters[characterID];
+ return character.getDamage();
+ }
+}
\ No newline at end of file