Compare commits

..

12 Commits

227 changed files with 347 additions and 5367 deletions

1
.idea/compiler.xml generated
View File

@@ -34,7 +34,6 @@
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.38/lombok-1.18.38.jar" />
</processorPath>
<module name="game (1)" />
<module name="game" />
</profile>
</annotationProcessing>
</component>

View File

@@ -1,6 +0,0 @@
<component name="CopyrightManager">
<copyright>
<option name="notice" value="Copyright (C) &amp;#36;today.year Jakub Žitník&#10;&#10;This program is free software: you can redistribute it and/or modify&#10;it under the terms of the GNU General Public License as published by&#10;the Free Software Foundation, either version 3 of the License, or&#10;(at your option) any later version&#10;&#10;This program is distributed in the hope that it will be useful,&#10;but WITHOUT ANY WARRANTY; without even the implied warranty of&#10;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the&#10;GNU General Public License for more details.&#10;&#10;You should have received a copy of the GNU General Public License&#10;along with this program. If not, see &lt;https://www.gnu.org/licenses/&gt;." />
<option name="myName" value="GPL 3.0" />
</copyright>
</component>

View File

@@ -1,3 +0,0 @@
<component name="CopyrightManager">
<settings default="GPL 3.0" />
</component>

674
COPYING
View File

@@ -1,674 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View File

@@ -1,37 +0,0 @@
# Lost in a cave
A multiplayer terminal-based game built with Java, utilizing WebSockets for communication and Lanterna for the text-based user interface.
## Project Structure
* **game**: Client application (TUI).
* **server**: WebSocket server.
* **common**: Shared libraries and logic.
## Requirements
* Java 25
* Maven
## How to Run
1. Build the project:
```bash
mvn clean install
```
2. Start the server:
```bash
mvn compile exec:java -pl server -am
```
3. Start the client (in a new terminal):
```bash
mvn compile exec:java -pl game -am
```
## Controls
* **Left Click**: Interact with objects and fight.
* **WASD**: Move the character.
* **CTRL**: Hold to run (sprint).

View File

@@ -59,11 +59,5 @@
<version>2.0.17</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -1,10 +1,5 @@
package cz.jzitnik.common;
/**
* Configuration constants for the common module.
*
* @author Jakub Žitník (jzitnik)
*/
public class Config {
public static final int WORLD_PASSWORD_LENGTH = 5;
}

View File

@@ -6,15 +6,9 @@ import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import java.awt.image.BufferedImage;
import java.io.Serializable;
import java.util.List;
/**
* Represents coordinates in a room.
*
* @author Jakub Žitník (jzitnik)
*/
@Slf4j
@ToString
@Getter
@@ -22,25 +16,6 @@ public class RoomCords implements Cloneable, Serializable {
private int x;
private int y;
/**
* Calculates the center coordinate based on a texture's dimensions.
*
* @param texture The texture to calculate the center for
* @return A new RoomCords instance representing the center
*/
public RoomCords calculateCenter(BufferedImage texture) {
return new RoomCords(
x + texture.getWidth() / 2,
y + texture.getHeight() / 2
);
}
/**
* Constructs RoomCords with specified x and y values.
*
* @param x The x coordinate
* @param y The y coordinate
*/
@JsonCreator
public RoomCords(
@JsonProperty("x") int x,
@@ -49,34 +24,15 @@ public class RoomCords implements Cloneable, Serializable {
updateCords(x, y);
}
/**
* Updates the coordinates with new x and y values.
*
* @param x The new x coordinate
* @param y The new y coordinate
*/
public void updateCords(int x, int y) {
this.x = x;
this.y = y;
}
/**
* Updates the coordinates using another RoomCords instance.
*
* @param roomCords The RoomCords instance to copy values from
*/
public void updateCords(RoomCords roomCords) {
updateCords(roomCords.getX(), roomCords.getY());
}
/**
* Updates the coordinates only if the new position does not collide with specified colliders.
*
* @param colliders The list of colliders in the room
* @param x The target x coordinate
* @param y The target y coordinate
* @param playerCollider The collider of the player
*/
public void updateCordsWithColliders(List<RoomPart> colliders, int x, int y, RoomPart playerCollider) {
var normalizedPlayerCollider = new RoomPart(
new RoomCords(playerCollider.getStart().getX() + x, playerCollider.getStart().getY() + y),
@@ -89,11 +45,6 @@ public class RoomCords implements Cloneable, Serializable {
updateCords(x, y);
}
/**
* Creates and returns a copy of this object.
*
* @return A clone of this instance
*/
@Override
public RoomCords clone() {
try {

View File

@@ -7,23 +7,12 @@ import lombok.ToString;
import java.io.Serializable;
/**
* Represents a rectangular part of a room, defined by start and end coordinates.
*
* @author Jakub Žitník (jzitnik)
*/
@Data
@ToString
public class RoomPart implements Serializable {
private RoomCords start;
private RoomCords end;
/**
* Constructs a RoomPart with specified start and end coordinates.
*
* @param start The start coordinates (top-left)
* @param end The end coordinates (bottom-right)
*/
@JsonCreator
public RoomPart(
@JsonProperty("start") RoomCords start,
@@ -33,12 +22,6 @@ public class RoomPart implements Serializable {
this.end = end;
}
/**
* Checks if the given coordinates are within this room part.
*
* @param cords The coordinates to check
* @return true if the coordinates are within this part, false otherwise
*/
public boolean isWithin(RoomCords cords) {
return cords.getX() >= start.getX() &&
cords.getX() <= end.getX() &&
@@ -47,10 +30,7 @@ public class RoomPart implements Serializable {
}
/**
* Checks if this RoomPart overlaps with another.
*
* @param other The other RoomPart to check for overlap
* @return true if it overlaps, false otherwise
* Checks if this GameRoomPart overlaps with another.
*/
public boolean isOverlapping(RoomPart other) {
return start.getX() <= other.getEnd().getX() &&

View File

@@ -9,11 +9,6 @@ import lombok.Setter;
import java.io.Serializable;
/**
* Data required for player creation.
*
* @author Jakub Žitník (jzitnik)
*/
@Getter
public final class PlayerCreation implements Serializable {
@Setter
@@ -21,12 +16,6 @@ public final class PlayerCreation implements Serializable {
private final RoomCords playerCords;
private final RoomPart collider;
/**
* Constructs a PlayerCreation instance.
*
* @param playerCords The player's initial coordinates
* @param collider The player's collider
*/
@JsonCreator
public PlayerCreation(
@JsonProperty("playerCords") RoomCords playerCords,

View File

@@ -2,10 +2,5 @@ package cz.jzitnik.common.socket;
import java.io.Serializable;
/**
* Base interface for all messages sent over the socket.
*
* @author Jakub Žitník (jzitnik)
*/
public interface SocketMessage extends Serializable {
}

View File

@@ -0,0 +1,6 @@
package cz.jzitnik.common.socket.messages;
import cz.jzitnik.common.socket.SocketMessage;
public class Test implements SocketMessage {
}

View File

@@ -1,11 +0,0 @@
package cz.jzitnik.common.socket.messages.game;
import cz.jzitnik.common.socket.SocketMessage;
/**
* Message indicating that the game has been won.
*
* @author Jakub Žitník (jzitnik)
*/
public record GameWin() implements SocketMessage {
}

View File

@@ -1,12 +0,0 @@
package cz.jzitnik.common.socket.messages.game;
import cz.jzitnik.common.socket.SocketMessage;
/**
* Message indicating that a player has died.
*
* @param playerId The ID of the player who died.
* @author Jakub Žitník (jzitnik)
*/
public record PlayerDeath(int playerId) implements SocketMessage {
}

View File

@@ -2,11 +2,5 @@ package cz.jzitnik.common.socket.messages.game.connection;
import cz.jzitnik.common.socket.SocketMessage;
/**
* Message sent to request connection to a game.
*
* @param gamePass The password of the game to connect to.
* @author Jakub Žitník (jzitnik)
*/
public record ConnectToAGame(String gamePass) implements SocketMessage {
}

View File

@@ -5,45 +5,20 @@ import cz.jzitnik.common.socket.SocketMessage;
import java.util.List;
/**
* Response message sent after a connection request to a game.
*
* @param responseType The type of response (SUCCESS or GAME_DOES_NOT_EXIST).
* @param playerCreation Information about the player being created.
* @param existingPlayers List of existing players in the game.
* @author Jakub Žitník (jzitnik)
*/
public record ConnectToAGameResponse(ResponseType responseType, PlayerCreation playerCreation, List<PlayerCreation> existingPlayers) implements SocketMessage {
/**
* Enum representing the possible response types for game connection.
*/
private enum ResponseType {
GAME_DOES_NOT_EXIST,
SUCCESS
}
/**
* Default constructor representing a failed connection (game does not exist).
*/
public ConnectToAGameResponse() {
this(ResponseType.GAME_DOES_NOT_EXIST, null, null);
}
/**
* Constructor for a successful connection.
*
* @param playerCreation Information about the player being created.
* @param existingPlayers List of existing players in the game.
*/
public ConnectToAGameResponse(PlayerCreation playerCreation, List<PlayerCreation> existingPlayers) {
this(ResponseType.SUCCESS, playerCreation, existingPlayers);
}
/**
* Checks if the connection was successful.
*
* @return true if successful, false otherwise.
*/
public boolean success() {
return responseType == ResponseType.SUCCESS;
}

View File

@@ -2,10 +2,5 @@ package cz.jzitnik.common.socket.messages.game.creation;
import cz.jzitnik.common.socket.SocketMessage;
/**
* Message sent to request game creation.
*
* @author Jakub Žitník (jzitnik)
*/
public class CreateGame implements SocketMessage {
}

View File

@@ -5,11 +5,6 @@ import cz.jzitnik.common.socket.SocketMessage;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* Response message sent after a game is created.
*
* @author Jakub Žitník (jzitnik)
*/
@Getter
@AllArgsConstructor
public class CreateGameResponse implements SocketMessage {

View File

@@ -2,13 +2,6 @@ package cz.jzitnik.common.socket.messages.items;
import cz.jzitnik.common.socket.SocketMessage;
/**
* Message indicating that an item was taken from a chest.
*
* @param roomId The ID of the room where the chest is located.
* @param id The ID of the item taken.
* @author Jakub Žitník (jzitnik)
*/
public record ItemTookFromChest(
String roomId, // For faster lookup i guess
int id

View File

@@ -3,16 +3,6 @@ package cz.jzitnik.common.socket.messages.player;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.common.socket.SocketMessage;
/**
* Message sent when a player's arrival status in a room changes.
*
* @param id The ID of the player.
* @param playerCords The current coordinates of the player.
* @param playerRotation The current rotation of the player.
* @param arrived Whether the player has arrived or departed.
* @param rerender Whether a rerender is requested.
* @author Jakub Žitník (jzitnik)
*/
public record PlayerArrivalChange(int id, RoomCords playerCords, PlayerRotation playerRotation,
boolean arrived, boolean rerender) implements SocketMessage {
}

View File

@@ -2,11 +2,5 @@ package cz.jzitnik.common.socket.messages.player;
import cz.jzitnik.common.socket.SocketMessage;
/**
* Message indicating that a player has disconnected.
*
* @param playerId The ID of the player who disconnected.
* @author Jakub Žitník (jzitnik)
*/
public record PlayerDisconnected(int playerId) implements SocketMessage {
}

View File

@@ -3,11 +3,5 @@ package cz.jzitnik.common.socket.messages.player;
import cz.jzitnik.common.models.player.PlayerCreation;
import cz.jzitnik.common.socket.SocketMessage;
/**
* Message indicating that a new player has joined the game.
*
* @param playerCreation Information about the player who joined.
* @author Jakub Žitník (jzitnik)
*/
public record PlayerJoined(PlayerCreation playerCreation) implements SocketMessage {
}

View File

@@ -3,12 +3,5 @@ package cz.jzitnik.common.socket.messages.player;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.common.socket.SocketMessage;
/**
* Message sent when a player moves.
*
* @param newCords The new coordinates of the player.
* @param playerRotation The rotation of the player.
* @author Jakub Žitník (jzitnik)
*/
public record PlayerMove(RoomCords newCords, PlayerRotation playerRotation) implements SocketMessage {
}

View File

@@ -5,11 +5,6 @@ import cz.jzitnik.common.socket.SocketMessage;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* Message sent when another player moves within the same room.
*
* @author Jakub Žitník (jzitnik)
*/
@Getter
@AllArgsConstructor
public class PlayerMovedInUrRoom implements SocketMessage {

View File

@@ -1,10 +1,5 @@
package cz.jzitnik.common.socket.messages.player;
/**
* Enum representing the possible rotations of a player.
*
* @author Jakub Žitník (jzitnik)
*/
public enum PlayerRotation {
FRONT, BACK, LEFT, RIGHT
}

View File

@@ -3,14 +3,6 @@ package cz.jzitnik.common.socket.messages.room;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.common.socket.SocketMessage;
/**
* Message sent to request moving a player to a new room.
*
* @param newRoomId The ID of the room to move to.
* @param oldCords The coordinates in the old room.
* @param newCords The initial coordinates in the new room.
* @author Jakub Žitník (jzitnik)
*/
public record MovePlayerRoom(String newRoomId, RoomCords oldCords, RoomCords newCords) implements SocketMessage {
}

View File

@@ -9,37 +9,13 @@ import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Response message sent after a player moves to a different room.
*
* @param players Set of players currently in the new room.
* @author Jakub Žitník (jzitnik)
*/
public record MovePlayerRoomResponse(Set<Registry> players) implements SocketMessage {
/**
* Represents a registry of a player in a room.
*
* @param id The ID of the player.
* @param cords The coordinates of the player.
* @param playerRotation The rotation of the player.
*/
public record Registry(int id, RoomCords cords, PlayerRotation playerRotation) implements Serializable {}
/**
* Gets a player's registry by their ID.
*
* @param id The ID of the player to find.
* @return An Optional containing the registry if found, otherwise empty.
*/
public Optional<Registry> getById(int id) {
return players.stream().filter(registry -> registry.id == id).findFirst();
}
/**
* Gets the set of IDs of all players in the response.
*
* @return A Set of player IDs.
*/
public Set<Integer> getIds() {
return players.stream().map(Registry::id).collect(Collectors.toSet());
}

View File

@@ -1,76 +0,0 @@
package cz.jzitnik.common.models.coordinates;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import static org.junit.jupiter.api.Assertions.*;
class RoomCordsTest {
@Test
void testConstructor() {
RoomCords cords = new RoomCords(10, 20);
assertEquals(10, cords.getX());
assertEquals(20, cords.getY());
}
@Test
void testUpdateCordsWithInts() {
RoomCords cords = new RoomCords(0, 0);
cords.updateCords(5, 10);
assertEquals(5, cords.getX());
assertEquals(10, cords.getY());
}
@Test
void testUpdateCordsWithRoomCords() {
RoomCords cords = new RoomCords(0, 0);
RoomCords newCords = new RoomCords(15, 25);
cords.updateCords(newCords);
assertEquals(15, cords.getX());
assertEquals(25, cords.getY());
}
@Test
void testCalculateDistance() {
RoomCords cords1 = new RoomCords(0, 0);
RoomCords cords2 = new RoomCords(3, 4);
double distance = cords1.calculateDistance(cords2);
assertEquals(5.0, distance, 0.0001);
}
@Test
void testCalculateDistanceToSelf() {
RoomCords cords = new RoomCords(5, 5);
double distance = cords.calculateDistance(cords);
assertEquals(0.0, distance, 0.0001);
}
@Test
void testCalculateDistanceThrowsOnNull() {
RoomCords cords = new RoomCords(0, 0);
assertThrows(IllegalArgumentException.class, () -> cords.calculateDistance(null));
}
@Test
void testClone() {
RoomCords original = new RoomCords(7, 8);
RoomCords cloned = original.clone();
assertEquals(original.getX(), cloned.getX());
assertEquals(original.getY(), cloned.getY());
assertNotSame(original, cloned);
}
@ParameterizedTest
@CsvSource({
"0, 0, 10, 10",
"5, 5, 15, 15",
"-5, -5, 0, 0"
})
void testUpdateCordsWithValues(int x, int y, int expectedX, int expectedY) {
RoomCords cords = new RoomCords(x, y);
assertEquals(x, cords.getX());
assertEquals(y, cords.getY());
}
}

View File

@@ -1,73 +0,0 @@
package cz.jzitnik.common.models.coordinates;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class RoomPartTest {
@Test
void testConstructor() {
RoomCords start = new RoomCords(0, 0);
RoomCords end = new RoomCords(10, 10);
RoomPart roomPart = new RoomPart(start, end);
assertEquals(start, roomPart.getStart());
assertEquals(end, roomPart.getEnd());
}
@Test
void testIsWithinReturnsTrueForPointInside() {
RoomPart roomPart = new RoomPart(new RoomCords(0, 0), new RoomCords(10, 10));
assertTrue(roomPart.isWithin(new RoomCords(5, 5)));
}
@Test
void testIsWithinReturnsTrueForPointOnEdge() {
RoomPart roomPart = new RoomPart(new RoomCords(0, 0), new RoomCords(10, 10));
assertTrue(roomPart.isWithin(new RoomCords(0, 0)));
assertTrue(roomPart.isWithin(new RoomCords(10, 10)));
}
@Test
void testIsWithinReturnsFalseForPointOutside() {
RoomPart roomPart = new RoomPart(new RoomCords(0, 0), new RoomCords(10, 10));
assertFalse(roomPart.isWithin(new RoomCords(15, 5)));
assertFalse(roomPart.isWithin(new RoomCords(5, 15)));
assertFalse(roomPart.isWithin(new RoomCords(-1, 5)));
}
@Test
void testIsOverlappingReturnsTrueForOverlappingParts() {
RoomPart part1 = new RoomPart(new RoomCords(0, 0), new RoomCords(10, 10));
RoomPart part2 = new RoomPart(new RoomCords(5, 5), new RoomCords(15, 15));
assertTrue(part1.isOverlapping(part2));
}
@Test
void testIsOverlappingReturnsTrueForIdenticalParts() {
RoomPart part1 = new RoomPart(new RoomCords(0, 0), new RoomCords(10, 10));
RoomPart part2 = new RoomPart(new RoomCords(0, 0), new RoomCords(10, 10));
assertTrue(part1.isOverlapping(part2));
}
@Test
void testIsOverlappingReturnsFalseForNonOverlappingParts() {
RoomPart part1 = new RoomPart(new RoomCords(0, 0), new RoomCords(10, 10));
RoomPart part2 = new RoomPart(new RoomCords(20, 20), new RoomCords(30, 30));
assertFalse(part1.isOverlapping(part2));
}
@Test
void testIsOverlappingReturnsTrueForAdjacentParts() {
RoomPart part1 = new RoomPart(new RoomCords(0, 0), new RoomCords(10, 10));
RoomPart part2 = new RoomPart(new RoomCords(10, 0), new RoomCords(20, 10));
assertTrue(part1.isOverlapping(part2));
}
@Test
void testIsOverlappingWithOnePartInsideAnother() {
RoomPart part1 = new RoomPart(new RoomCords(0, 0), new RoomCords(20, 20));
RoomPart part2 = new RoomPart(new RoomCords(5, 5), new RoomCords(15, 15));
assertTrue(part1.isOverlapping(part2));
}
}

View File

@@ -123,6 +123,13 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>6.0.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>6.0.2</version>
<scope>test</scope>
</dependency>

View File

@@ -17,11 +17,6 @@ import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
/**
* Command line interface handler using Lanterna.
*
* @author Jakub Žitník (jzitnik)
*/
@Slf4j
@Dependency
public class Cli implements Runnable {
@@ -34,9 +29,6 @@ public class Cli implements Runnable {
@InjectState
private RunningState runningState;
/**
* Runs the CLI thread, handling terminal input and events.
*/
@Override
public void run() {
// Start event manager thread

View File

@@ -14,11 +14,6 @@ import org.reflections.Reflections;
import java.io.IOException;
/**
* Main game class responsible for initialization and starting the game loop.
*
* @author Jakub Žitník (jzitnik)
*/
public class Game {
private final DependencyManager dependencyManager = new DependencyManager(new Reflections("cz.jzitnik.client"));
@@ -33,13 +28,10 @@ public class Game {
@InjectDependency
private ThreadManager threadManager;
@InjectDependency
private ScheduledTaskManager scheduledTaskManager;
@InjectDependency
private GlobalIOHandlerRepository globalIOHandlerRepository;
/**
* Starts the game by injecting dependencies and initializing managers.
*
* @throws IOException If an I/O error occurs
*/
public void start() throws IOException {
dependencyManager.inject(this);
@@ -47,6 +39,7 @@ public class Game {
socketEventManager.start();
threadManager.startAll();
scheduledTaskManager.startAll();
globalIOHandlerRepository.setup();
gameSetup.setup();

View File

@@ -4,18 +4,7 @@ package cz.jzitnik.client;
import java.io.IOException;
/**
* Main entry point for the client application.
*
* @author Jakub Žitník (jzitnik)
*/
public class Main {
/**
* Main method that starts the game.
*
* @param args Command line arguments
* @throws IOException If an I/O error occurs
*/
public static void main(String[] args) throws IOException {
new Game().start();
}

View File

@@ -5,18 +5,8 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
/**
* Annotation to mark a class as a configuration component loaded from a YAML file.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Config {
/**
* The YAML file name.
*
* @return file name
*/
String value();
}

View File

@@ -5,18 +5,9 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
/**
* Annotation to mark a class as a dependency for the DependencyManager.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Dependency {
/**
* Custom alias for the dependency.
*
* @return Alias class
*/
/** Custom alias **/
Class<?> value() default Object.class;
}

View File

@@ -7,18 +7,8 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
/**
* Annotation to mark a class as an event handler for a specific Event type.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface EventHandler {
/**
* The type of Event this handler handles.
*
* @return Event class
*/
Class<? extends Event> value();
}

View File

@@ -5,11 +5,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
/**
* Annotation to mark a method to be called after dependency injection.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface PostInit {

View File

@@ -6,24 +6,9 @@ import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import java.util.concurrent.TimeUnit;
/**
* Annotation to mark a task for periodic execution.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ScheduledTask {
/**
* Execution rate.
*
* @return rate
*/
long rate();
/**
* Time unit for the rate.
*
* @return rate unit
*/
TimeUnit rateUnit();
}

View File

@@ -7,18 +7,8 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to mark a class as a socket event handler for a specific SocketMessage type.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface SocketEventHandler {
/**
* The type of SocketMessage this handler handles.
*
* @return SocketMessage class
*/
Class<? extends SocketMessage> value();
}

View File

@@ -5,11 +5,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
/**
* Annotation to mark a class as a state component.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface State {

View File

@@ -5,11 +5,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
/**
* Annotation to mark a class for automatic thread registration.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ThreadRegistry {

View File

@@ -5,11 +5,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to inject a configuration component into a field.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface InjectConfig {

View File

@@ -5,11 +5,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to inject a dependency into a field.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface InjectDependency {

View File

@@ -5,11 +5,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to inject a state component into a field.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface InjectState {

View File

@@ -4,25 +4,10 @@ import com.googlecode.lanterna.input.KeyType;
import java.lang.annotation.*;
/**
* Annotation to mark a method as a keyboard press handler.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Repeatable(KeyboardPressHandlers.class)
public @interface KeyboardPressHandler {
/**
* The key type to handle.
*
* @return key type
*/
KeyType keyType() default KeyType.Character;
/**
* The specific character to handle (if keyType is Character).
*
* @return character
*/
char character() default '\0';
}

View File

@@ -5,18 +5,8 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Container annotation for repeatable KeyboardPressHandler.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface KeyboardPressHandlers {
/**
* Array of KeyboardPressHandler annotations.
*
* @return handlers
*/
KeyboardPressHandler[] value();
}

View File

@@ -5,18 +5,8 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
/**
* Annotation to mark a method as a mouse handler.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MouseHandler {
/**
* The type of mouse action to handle.
*
* @return handler type
*/
MouseHandlerType value();
}

View File

@@ -1,10 +1,5 @@
package cz.jzitnik.client.annotations.ui;
/**
* Enum representing types of mouse handlers.
*
* @author Jakub Žitník (jzitnik)
*/
public enum MouseHandlerType {
CLICK,
MOVE,

View File

@@ -5,11 +5,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
/**
* Annotation to mark a method as a rendering method.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Render {

View File

@@ -5,11 +5,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
/**
* Annotation to mark a class as a UI component.
*
* @author Jakub Žitník (jzitnik)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface UI {

View File

@@ -4,19 +4,8 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import cz.jzitnik.client.annotations.Config;
/**
* Configuration for core game logic.
*
* @param itemDropDisappearMinutes Minutes before a dropped item disappears
* @author Jakub Žitník (jzitnik)
*/
@Config("core_logic.yaml")
public record CoreLogic(int itemDropDisappearMinutes) {
/**
* Constructs a CoreLogic configuration instance.
*
* @param itemDropDisappearMinutes Disappear timeout in minutes
*/
@JsonCreator
public CoreLogic(
@JsonProperty("itemDropDisappearMinutes") int itemDropDisappearMinutes

View File

@@ -4,23 +4,8 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import cz.jzitnik.client.annotations.Config;
/**
* Configuration for debugging features.
*
* @param renderColliders Whether to render colliders
* @param renderPlayerCollider Whether to render the player's collider
* @param showPlayerCordsLogs Whether to show player coordinate logs
* @author Jakub Žitník (jzitnik)
*/
@Config("debugging.yaml")
public record Debugging(boolean renderColliders, boolean renderPlayerCollider, boolean showPlayerCordsLogs) {
/**
* Constructs a Debugging configuration instance.
*
* @param renderColliders Whether to render colliders
* @param renderPlayerCollider Whether to render the player's collider
* @param showPlayerCordsLogs Whether to show player coordinate logs
*/
@JsonCreator
public Debugging(
@JsonProperty("renderColliders") boolean renderColliders,

View File

@@ -4,19 +4,8 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import cz.jzitnik.client.annotations.Config;
/**
* Configuration for microphone input.
*
* @param volumeThreshold The volume threshold for activation
* @author Jakub Žitník (jzitnik)
*/
@Config("microphone.yaml")
public record MicrophoneConfig(float volumeThreshold) {
/**
* Constructs a MicrophoneConfig instance.
*
* @param volumeThreshold The volume threshold
*/
@JsonCreator
public MicrophoneConfig(
@JsonProperty("volumeThreshold") float volumeThreshold

View File

@@ -5,18 +5,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import cz.jzitnik.client.annotations.Config;
import cz.jzitnik.client.events.handlers.PlayerMoveEventHandler;
/**
* Configuration for player-related settings.
*
* @param playerReach The distance a player can reach
* @param playerMoveDistance The distance a player moves normally
* @param playerMoveDistanceSprinting The distance a player moves while sprinting
* @param sprintKey The key used for sprinting
* @param swingTimeMs Time in milliseconds for a weapon swing
* @param staminaIncreaseRateMs Rate at which stamina increases
* @param staminaDelayMs Delay before stamina starts increasing
* @author Jakub Žitník (jzitnik)
*/
@Config("player.yaml")
public record PlayerConfig(
double playerReach,
@@ -27,17 +15,6 @@ public record PlayerConfig(
int staminaIncreaseRateMs,
int staminaDelayMs
) {
/**
* Constructs a PlayerConfig instance.
*
* @param playerReach Player reach
* @param playerMoveDistance Move distance
* @param playerMoveDistanceSprinting Sprint move distance
* @param sprintKey Sprint key
* @param swingTimeMs Swing time
* @param staminaIncreaseRateMs Stamina increase rate
* @param staminaDelayMs Stamina delay
*/
@JsonCreator
public PlayerConfig(
@JsonProperty("playerReach") double playerReach,

View File

@@ -4,21 +4,8 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import cz.jzitnik.client.annotations.Config;
/**
* Configuration for thread pool sizes.
*
* @param eventThreadCount Number of threads for events
* @param taskThreadCount Number of threads for tasks
* @author Jakub Žitník (jzitnik)
*/
@Config("threads.yaml")
public record ThreadPoolConfig(int eventThreadCount, int taskThreadCount) {
/**
* Constructs a ThreadPoolConfig instance.
*
* @param eventThreadCount Event thread count
* @param taskThreadCount Task thread count
*/
@JsonCreator
public ThreadPoolConfig(
@JsonProperty("eventThreadCount") int eventThreadCount,

View File

@@ -3,10 +3,5 @@ package cz.jzitnik.client.events;
import cz.jzitnik.client.game.objects.DroppedItem;
import cz.jzitnik.client.utils.events.Event;
/**
* Event triggered when a dropped item in the game world needs to be rerendered.
*
* @param droppedItem the dropped item to rerender
*/
public record DroppedItemRerender(DroppedItem droppedItem) implements Event {
}

View File

@@ -2,10 +2,6 @@ package cz.jzitnik.client.events;
import cz.jzitnik.client.utils.events.Event;
/**
* Event indicating that the application should exit.
*
* @author Jakub Žitník (jzitnik)
*/
/** Custom event without any handler **/
public class ExitEvent implements Event {
}

View File

@@ -2,8 +2,5 @@ package cz.jzitnik.client.events;
import cz.jzitnik.client.utils.events.Event;
/**
* Event triggered when the entire screen needs to be fully redrawn.
*/
public class FullRedrawEvent implements Event {
}

View File

@@ -4,10 +4,6 @@ import cz.jzitnik.client.utils.events.Event;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* Event triggered when the current room needs to be fully drawn.
* Can optionally trigger a full rerender of all elements.
*/
@NoArgsConstructor
@Getter
public class FullRoomDraw implements Event {

View File

@@ -2,8 +2,5 @@ package cz.jzitnik.client.events;
import cz.jzitnik.client.utils.events.Event;
/**
* Event triggered when the player's inventory display needs to be rerendered.
*/
public class InventoryRerender implements Event {
}

View File

@@ -5,11 +5,6 @@ import cz.jzitnik.client.utils.events.Event;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* Event triggered when a key is pressed.
*
* @author Jakub Žitník (jzitnik)
*/
@Getter
@AllArgsConstructor
public class KeyboardPressEvent implements Event {

View File

@@ -4,28 +4,11 @@ import com.googlecode.lanterna.TerminalPosition;
import com.googlecode.lanterna.input.MouseActionType;
import cz.jzitnik.client.utils.events.Event;
/**
* Event triggered by a mouse action.
*
* @author Jakub Žitník (jzitnik)
*/
public class MouseAction extends com.googlecode.lanterna.input.MouseAction implements Event {
/**
* Constructs a MouseAction.
*
* @param actionType The type of action
* @param button The button involved
* @param position The terminal position
*/
public MouseAction(MouseActionType actionType, int button, TerminalPosition position) {
super(actionType, button, position);
}
/**
* Constructs a MouseAction from an existing Lanterna MouseAction.
*
* @param mouseAction The Lanterna mouse action
*/
public MouseAction(com.googlecode.lanterna.input.MouseAction mouseAction) {
this(mouseAction.getActionType(), mouseAction.getButton(), mouseAction.getPosition());
}

View File

@@ -4,11 +4,6 @@ import cz.jzitnik.client.utils.events.Event;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* Event triggered by a mouse movement.
*
* @author Jakub Žitník (jzitnik)
*/
@AllArgsConstructor
@Getter
public class MouseMoveEvent implements Event {

View File

@@ -5,11 +5,6 @@ import cz.jzitnik.client.utils.events.Event;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* Event triggered when a player attempts to move.
*
* @author Jakub Žitník (jzitnik)
*/
@AllArgsConstructor
@Getter
public class PlayerMoveEvent implements Event {

View File

@@ -2,8 +2,5 @@ package cz.jzitnik.client.events;
import cz.jzitnik.client.utils.events.Event;
/**
* Event triggered when the player stats display needs to be rerendered.
*/
public class RenderStats implements Event {
}

View File

@@ -4,11 +4,6 @@ import cz.jzitnik.client.utils.events.Event;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* Event requesting a rerender of a specific part of the screen.
*
* @author Jakub Žitník (jzitnik)
*/
@Getter
@AllArgsConstructor
public class RerenderPart implements Event {

View File

@@ -6,11 +6,6 @@ import cz.jzitnik.client.utils.events.Event;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* Event triggered when specific parts of the screen need to be rerendered.
*
* @param parts the screen parts that need to be rerendered
*/
public record RerenderScreen(ScreenPart[] parts) implements Event {
public RerenderScreen(ScreenPart part) {
this(new ScreenPart[]{part});

View File

@@ -3,10 +3,5 @@ package cz.jzitnik.client.events;
import cz.jzitnik.client.events.handlers.FullRoomDrawHandler;
import cz.jzitnik.client.utils.events.Event;
/**
* Event triggered when the player changes to a different room.
*
* @param door the door position from which the player entered the new room
*/
public record RoomChangeEvent(FullRoomDrawHandler.DoorPosition door) implements Event {
}

View File

@@ -3,10 +3,5 @@ package cz.jzitnik.client.events;
import cz.jzitnik.client.utils.events.Event;
import cz.jzitnik.common.socket.SocketMessage;
/**
* Event triggered when a socket message needs to be sent to the server.
*
* @param message the socket message to send
*/
public record SendSocketMessageEvent(SocketMessage message) implements Event {
}

View File

@@ -5,11 +5,6 @@ import cz.jzitnik.client.utils.events.Event;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* Event triggered when the terminal is resized.
*
* @author Jakub Žitník (jzitnik)
*/
@AllArgsConstructor
@Getter
public class TerminalResizeEvent implements Event {

View File

@@ -2,10 +2,5 @@ package cz.jzitnik.client.events;
import cz.jzitnik.client.utils.events.Event;
/**
* Event triggered when the terminal window is too small to render the game.
*
* @author Jakub Žitník (jzitnik)
*/
public class TerminalTooSmallEvent implements Event {
}

View File

@@ -18,11 +18,6 @@ import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
/**
* Handler for the RerenderScreen event in the CLI.
*
* @author Jakub Žitník (jzitnik)
*/
@Slf4j
@EventHandler(RerenderScreen.class)
public class CliHandler extends AbstractEventHandler<RerenderScreen> {
@@ -35,11 +30,6 @@ public class CliHandler extends AbstractEventHandler<RerenderScreen> {
@InjectState
private RenderState renderState;
/**
* Handles the RerenderScreen event by drawing requested parts of the screen buffer to the terminal.
*
* @param event The RerenderScreen event
*/
@Override
public void handle(RerenderScreen event) {
if (renderState.isTerminalTooSmall()) {
@@ -89,13 +79,6 @@ public class CliHandler extends AbstractEventHandler<RerenderScreen> {
}
}
/**
* Resolves the final pixel color by blending with the global override buffer.
*
* @param buffer The base pixel from the rendered buffer
* @param globalOverride The pixel from the global override buffer
* @return The final pixel to draw
*/
private Pixel getPixel(Pixel buffer, AlphaPixel globalOverride) {
if (globalOverride instanceof Empty) {
return buffer;
@@ -114,14 +97,6 @@ public class CliHandler extends AbstractEventHandler<RerenderScreen> {
return new ColoredPixel(blended);
}
/**
* Blends two colors using an alpha value.
*
* @param base The base color
* @param overlay The overlay color
* @param alpha The alpha transparency of the overlay
* @return The blended color
*/
private TextColor blendColors(TextColor base, TextColor overlay, float alpha) {
int r = blend(base.getRed(), overlay.getRed(), alpha);
int g = blend(base.getGreen(), overlay.getGreen(), alpha);
@@ -130,27 +105,10 @@ public class CliHandler extends AbstractEventHandler<RerenderScreen> {
return new TextColor.RGB(r, g, b);
}
/**
* Internal helper to blend a single color channel.
*
* @param base Base channel value
* @param overlay Overlay channel value
* @param alpha Alpha transparency
* @return Blended channel value
*/
private int blend(int base, int overlay, float alpha) {
return Math.round(base * (1 - alpha) + overlay * alpha);
}
/**
* Draws a "half-pixel" using Unicode character '▄' to achieve higher vertical resolution.
*
* @param tg The TextGraphics context
* @param x X terminal position
* @param y Y terminal position
* @param topColor Color for the top half
* @param bottomColor Color for the bottom half
*/
private void drawHalfPixel(TextGraphics tg, int x, int y,
TextColor topColor,
TextColor bottomColor) {

View File

@@ -7,7 +7,6 @@ import cz.jzitnik.client.annotations.EventHandler;
import cz.jzitnik.client.annotations.injectors.InjectDependency;
import cz.jzitnik.client.annotations.injectors.InjectState;
import cz.jzitnik.client.events.RerenderScreen;
import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.dialog.Dialog;
import cz.jzitnik.client.game.dialog.OnEnd;
import cz.jzitnik.client.states.DialogState;
@@ -23,14 +22,9 @@ import cz.jzitnik.client.utils.events.EventManager;
import lombok.extern.slf4j.Slf4j;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.ArrayList;
/**
* Handler for the Dialog event.
*
* @author Jakub Žitník (jzitnik)
*/
@Slf4j
@EventHandler(Dialog.class)
public class DialogEventHandler extends AbstractEventHandler<Dialog> {
@@ -44,9 +38,6 @@ public class DialogEventHandler extends AbstractEventHandler<Dialog> {
@InjectState
private ScreenBuffer screenBuffer;
@InjectState
private GameState gameState;
@InjectDependency
private EventManager eventManager;
@@ -58,204 +49,98 @@ public class DialogEventHandler extends AbstractEventHandler<Dialog> {
private static final int WIDTH = 350;
private static final int MARGIN_BOTTOM = 15;
/** Padding for the dialog box. */
public static final int PADDING = 7;
private static final int BUTTON_TEXT_PADDING = 4;
private static final int QUESTION_ACTIONS_GAP = 10;
/** Height of a button in the dialog. */
public static final int BUTTON_HEIGHT = 15;
/** Padding for buttons in the dialog. */
public static final int BUTTON_PADDING = 5;
private static final float FONT_SIZE = 15f;
/**
* Calculates the total height required for buttons in a dialog.
*
* @param dialog The dialog
* @param gameState Current game state
* @return Calculated height
*/
public static int calculateButtonHeight(Dialog dialog, GameState gameState) {
if (dialog.getOnEnd() instanceof OnEnd.AskQuestion askQuestion) {
int count = askQuestion.answers(gameState).length;
return count * BUTTON_HEIGHT + Math.max(0, count - 1) * BUTTON_PADDING;
}
public static int calculateButtonHeight(Dialog dialog) {
if (dialog.getOnEnd() instanceof OnEnd.AskQuestion(OnEnd.AskQuestion.Answer[] answers)) {
return answers.length * BUTTON_HEIGHT + (answers.length - 1) * BUTTON_PADDING;
} else {
return 0;
}
}
/**
* Calculates the starting Y coordinate for buttons.
*
* @param textRenderer The text renderer
* @param dialog The dialog
* @return Starting Y coordinate
*/
public static int getYStartButtons(TextRenderer textRenderer, Dialog dialog) {
var textSize = textRenderer.measureText(
dialog.getText(),
WIDTH - PADDING * 2,
FONT_SIZE
);
var textSize = textRenderer.measureText(dialog.getText(), WIDTH - PADDING * 2, FONT_SIZE);
return PADDING + textSize.height + BUTTON_PADDING;
}
/**
* Calculates the overall size of the dialog box.
*
* @param textRenderer The text renderer
* @param dialog The dialog
* @param gameState Current game state
* @return The terminal size
*/
public static TerminalSize getSize(TextRenderer textRenderer, Dialog dialog, GameState gameState) {
var textSize = textRenderer.measureText(
dialog.getText(),
WIDTH - PADDING * 2,
FONT_SIZE
);
public static TerminalSize getSize(TextRenderer textRenderer, Dialog dialog) {
var textSize = textRenderer.measureText(dialog.getText(), WIDTH - PADDING * 2, FONT_SIZE);
int buttonsHeight = 0;
if (dialog.getOnEnd() instanceof OnEnd.AskQuestion) {
buttonsHeight = BUTTON_PADDING + calculateButtonHeight(dialog, gameState);
return new TerminalSize(300, PADDING + textSize.height + (
dialog.getOnEnd() instanceof OnEnd.AskQuestion ? BUTTON_PADDING + calculateButtonHeight(dialog) : 0
) + PADDING);
}
return new TerminalSize(
300,
PADDING + textSize.height + buttonsHeight + PADDING
);
}
/**
* Calculates the starting terminal position for the dialog box.
*
* @param terminalSize Current terminal size
* @param size Size of the dialog box
* @return Starting position
*/
public static TerminalPosition getStart(TerminalSize terminalSize, TerminalSize size) {
int startY = terminalSize.getRows() * 2 - MARGIN_BOTTOM - size.getRows();
int startX = (terminalSize.getColumns() / 2) - (size.getColumns() / 2);
return new TerminalPosition(startX, startY);
}
/**
* Handles the Dialog event by rendering it with typing animation.
*
* @param event The Dialog event
*/
@Override
public void handle(Dialog event) {
boolean onlyLast = dialogState.getCurrentDialog() == event;
dialogState.setCurrentDialog(event);
TerminalSize terminalSize = terminalState.getTerminalScreen().getTerminalSize();
var overrideBuffer = screenBuffer.getGlobalOverrideBuffer();
var size = getSize(textRenderer, event, gameState);
var size = getSize(textRenderer, event);
var start = getStart(terminalSize, size);
var animation = textRenderer.renderTypingAnimation(
event.getText(),
size.getColumns() - PADDING * 2,
size.getRows() - PADDING * 2,
Color.WHITE,
FONT_SIZE
);
var textSize = textRenderer.measureText(
event.getText(),
size.getColumns() - PADDING * 2,
FONT_SIZE
);
var animation = textRenderer.renderTypingAnimation(event.getText(), size.getColumns() - PADDING * 2, size.getRows() - PADDING * 2, Color.WHITE, FONT_SIZE);
var textSize = textRenderer.measureText(event.getText(), size.getColumns() - PADDING * 2, FONT_SIZE);
OnEnd onEnd = event.getOnEnd();
List<AlphaPixel[][]> answersBuf = new ArrayList<>();
OnEnd.AskQuestion askQuestion = null;
if (onEnd instanceof OnEnd.AskQuestion aq) {
askQuestion = aq;
for (OnEnd.AskQuestion.Answer answer : aq.answers(gameState)) {
answersBuf.add(
textRenderer.renderText(
answer.answer(),
size.getColumns() - PADDING * 2,
BUTTON_HEIGHT,
Color.BLACK,
FONT_SIZE,
false
)
);
if (onEnd instanceof OnEnd.AskQuestion(
OnEnd.AskQuestion.Answer[] answers
)) {
for (OnEnd.AskQuestion.Answer answer : answers) {
answersBuf.add(textRenderer.renderText(answer.answer(), size.getColumns() - PADDING * 2, BUTTON_HEIGHT, Color.BLACK, FONT_SIZE, false));
}
}
dialogState.setRenderInProgress(true);
try {
for (int i = onlyLast ? animation.length : 0; i <= animation.length; i++) {
var buf = animation[Math.min(i, animation.length - 1)];
for (int y = 0; y < size.getRows(); y++) {
for (int x = 0; x < size.getColumns(); x++) {
var textPixel = buf[
Math.min(Math.max(0, y - PADDING), buf.length - 1)
][
Math.min(Math.max(0, x - PADDING), buf[0].length - 1)
];
if (textPixel instanceof Empty
|| y < PADDING
|| x < PADDING
|| x >= size.getColumns() - PADDING
|| y >= size.getRows() - PADDING) {
if (i == animation.length
&& askQuestion != null
&& y - 2 > textSize.height + QUESTION_ACTIONS_GAP) {
var answers = askQuestion.answers(gameState);
var textPixel = buf[Math.min(Math.max(0, y - PADDING), buf.length - 1)][Math.min(Math.max(0, x - PADDING), buf[0].length - 1)];
if (textPixel instanceof Empty || y < PADDING || x < PADDING || x >= size.getColumns() - PADDING || y >= size.getRows() - PADDING) {
if (i == animation.length && y - 2 > textSize.height + QUESTION_ACTIONS_GAP && onEnd instanceof OnEnd.AskQuestion(
OnEnd.AskQuestion.Answer[] answers
)) {
int buttonsY = y - textSize.height - QUESTION_ACTIONS_GAP - 2;
int buttonIndex = buttonsY / (BUTTON_HEIGHT + BUTTON_PADDING);
int rest = buttonsY % (BUTTON_HEIGHT + BUTTON_PADDING);
if (buttonIndex < answers.length
&& rest < BUTTON_HEIGHT
&& x >= PADDING
&& x < size.getColumns() - PADDING) {
if (buttonIndex < answers.length && rest < BUTTON_HEIGHT && x >= PADDING && x < size.getColumns() - PADDING) {
int localY = rest - BUTTON_TEXT_PADDING;
int localX = x - PADDING - BUTTON_TEXT_PADDING;
var buttonBuf = answersBuf.get(buttonIndex);
var buttonTextPixel = buttonBuf[
Math.min(Math.max(0, localY), buttonBuf.length - 1)
][
Math.min(Math.max(0, localX), buttonBuf[0].length - 1)
];
var buttonTextPixel = buttonBuf[Math.min(Math.max(0, localY), buttonBuf.length - 1)][Math.min(Math.max(0, localX), buttonBuf[0].length - 1)];
if (buttonTextPixel instanceof Empty
|| localY < 0
|| localX < 0
|| localY >= buttonBuf.length
|| localX >= buttonBuf[0].length) {
overrideBuffer[start.getRow() + y][start.getColumn() + x] =
new ColoredPixel(
new TextColor.RGB(255, 255, 255),
dialogState.getHoveredButtonIndex() == buttonIndex ? 0.8f : 0.6f
);
if (buttonTextPixel instanceof Empty || localY < 0 || localX < 0 || localY >= buttonBuf.length || localX >= buttonBuf[0].length) {
overrideBuffer[start.getRow() + y][start.getColumn() + x] = new ColoredPixel(new TextColor.RGB(255, 255, 255), dialogState.getHoveredButtonIndex() == buttonIndex ? 0.8f : 0.6f);
} else {
overrideBuffer[start.getRow() + y][start.getColumn() + x] =
buttonTextPixel;
overrideBuffer[start.getRow() + y][start.getColumn() + x] = buttonTextPixel;
}
continue;
}
}
overrideBuffer[start.getRow() + y][start.getColumn() + x] =
new ColoredPixel(new TextColor.RGB(0, 0, 0), 0.6f);
overrideBuffer[start.getRow() + y][start.getColumn() + x] = new ColoredPixel(new TextColor.RGB(0, 0, 0), 0.6f);
continue;
}
@@ -267,10 +152,7 @@ public class DialogEventHandler extends AbstractEventHandler<Dialog> {
new RerenderScreen(
new RerenderScreen.ScreenPart(
start,
new TerminalPosition(
start.getColumn() + size.getColumns(),
start.getRow() + size.getRows()
)
new TerminalPosition(start.getColumn() + size.getColumns(), start.getRow() + size.getRows())
)
)
);
@@ -279,6 +161,7 @@ public class DialogEventHandler extends AbstractEventHandler<Dialog> {
}
dialogState.setRenderInProgress(false);
next(onEnd, start, size);
} catch (InterruptedException e) {
@@ -287,39 +170,31 @@ public class DialogEventHandler extends AbstractEventHandler<Dialog> {
}
private void next(OnEnd onEnd, TerminalPosition start, TerminalSize size) throws InterruptedException {
Thread.sleep(1000);
if (onEnd instanceof OnEnd.Continue(Dialog nextDialog)) {
clear(start, size);
eventManager.emitEvent(nextDialog);
} else if (onEnd instanceof OnEnd.RunCode runCode) {
Runnable runnable = runCode.getRunnable();
dependencyManager.inject(runnable);
runnable.run();
next(runCode.getOnEnd(), start, size);
} else if (onEnd instanceof OnEnd.End) {
clear(start, size);
dialogState.setCurrentDialog(null);
eventManager.emitEvent(
new RerenderScreen(
new RerenderScreen.ScreenPart(
start,
new TerminalPosition(
start.getColumn() + size.getColumns(),
start.getRow() + size.getRows()
)
)
)
);
}
}
private void clear(TerminalPosition start, TerminalSize size) {
Thread.sleep(1000);
for (int y = start.getRow(); y < start.getRow() + size.getRows(); y++) {
for (int x = start.getColumn(); x < start.getColumn() + size.getColumns(); x++) {
screenBuffer.getGlobalOverrideBuffer()[y][x] = new Empty();
}
}
if (nextDialog == null) {
dialogState.setCurrentDialog(null);
eventManager.emitEvent(
new RerenderScreen(
new RerenderScreen.ScreenPart(
start,
new TerminalPosition(start.getColumn() + size.getColumns(), start.getRow() + size.getRows())
)
)
);
} else {
eventManager.emitEvent(nextDialog);
}
} else if (onEnd instanceof OnEnd.RunCode(Runnable runnable, OnEnd end)) {
dependencyManager.inject(runnable);
runnable.run();
next(end, start, size);
}
}
}

View File

@@ -10,21 +10,11 @@ import cz.jzitnik.client.utils.events.EventManager;
import java.awt.image.BufferedImage;
/**
* Handler for the DroppedItemRerender event.
*
* @author Jakub Žitník (jzitnik)
*/
@EventHandler(DroppedItemRerender.class)
public class DroppedItemRerenderHandler extends AbstractEventHandler<DroppedItemRerender> {
@InjectDependency
private EventManager eventManager;
/**
* Handles the DroppedItemRerender event by emitting a RerenderPart event.
*
* @param event The DroppedItemRerender event
*/
@Override
public void handle(DroppedItemRerender event) {
RoomCords droppedItemCords = event.droppedItem().getCords();

View File

@@ -10,11 +10,6 @@ import cz.jzitnik.client.utils.ThreadManager;
import cz.jzitnik.client.utils.events.AbstractEventHandler;
import cz.jzitnik.client.utils.roomtasks.RoomTaskScheduler;
/**
* Handler for the ExitEvent.
*
* @author Jakub Žitník (jzitnik)
*/
@EventHandler(ExitEvent.class)
public class ExitEventHandler extends AbstractEventHandler<ExitEvent> {
@InjectDependency
@@ -29,11 +24,6 @@ public class ExitEventHandler extends AbstractEventHandler<ExitEvent> {
@InjectDependency
private ScheduledTaskManager scheduledTaskManager;
/**
* Handles the ExitEvent by shutting down all managers and setting the running state to false.
*
* @param event The ExitEvent
*/
@Override
public void handle(ExitEvent event) {
threadManager.shutdownAll();

View File

@@ -12,11 +12,6 @@ import cz.jzitnik.client.utils.events.EventManager;
import java.io.IOException;
/**
* Handler for the FullRedrawEvent.
*
* @author Jakub Žitník (jzitnik)
*/
@EventHandler(FullRedrawEvent.class)
public class FullRedrawEventHandler extends AbstractEventHandler<FullRedrawEvent> {
@InjectDependency
@@ -25,11 +20,6 @@ public class FullRedrawEventHandler extends AbstractEventHandler<FullRedrawEvent
@InjectState
private TerminalState terminalState;
/**
* Handles the FullRedrawEvent by clearing the terminal and emitting a FullRoomDraw event.
*
* @param event The FullRedrawEvent
*/
@Override
public void handle(FullRedrawEvent event) {
terminalState.getTerminalScreen().clear();

View File

@@ -32,11 +32,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* Handler for the FullRoomDraw event.
*
* @author Jakub Žitník (jzitnik)
*/
@Slf4j
@EventHandler(FullRoomDraw.class)
public class FullRoomDrawHandler extends AbstractEventHandler<FullRoomDraw> {
@@ -60,11 +55,6 @@ public class FullRoomDrawHandler extends AbstractEventHandler<FullRoomDraw> {
@InjectDependency
private GlobalIOHandlerRepository globalIOHandlerRepository;
/**
* Handles the FullRoomDraw event by rendering the entire room and players.
*
* @param event The FullRoomDraw event
*/
@Override
public void handle(FullRoomDraw event) {
try {
@@ -113,9 +103,6 @@ public class FullRoomDrawHandler extends AbstractEventHandler<FullRoomDraw> {
}
}
/**
* Enum representing door positions in a room.
*/
public enum DoorPosition {
TOP,
LEFT,

View File

@@ -9,11 +9,6 @@ import cz.jzitnik.client.ui.Inventory;
import cz.jzitnik.client.utils.events.AbstractEventHandler;
import cz.jzitnik.client.utils.events.EventManager;
/**
* Handler for the InventoryRerender event.
*
* @author Jakub Žitník (jzitnik)
*/
@EventHandler(InventoryRerender.class)
public class InventoryRerenderHandler extends AbstractEventHandler<InventoryRerender> {
@InjectDependency
@@ -22,11 +17,6 @@ public class InventoryRerenderHandler extends AbstractEventHandler<InventoryRere
@InjectDependency
private Inventory inventory;
/**
* Handles the InventoryRerender event by rerendering the inventory UI component.
*
* @param event The InventoryRerender event
*/
@Override
public void handle(InventoryRerender event) {
inventory.renderInventoryRerender();

View File

@@ -8,11 +8,6 @@ import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.utils.GlobalIOHandlerRepository;
import cz.jzitnik.client.utils.events.AbstractEventHandler;
/**
* Handler for the KeyboardPressEvent.
*
* @author Jakub Žitník (jzitnik)
*/
@EventHandler(KeyboardPressEvent.class)
public class KeyboardPressEventHandler extends AbstractEventHandler<KeyboardPressEvent> {
@InjectState
@@ -21,11 +16,6 @@ public class KeyboardPressEventHandler extends AbstractEventHandler<KeyboardPres
@InjectDependency
private GlobalIOHandlerRepository globalIOHandlerRepository;
/**
* Handles the KeyboardPressEvent by delegating to the current screen or the global repository.
*
* @param event The KeyboardPressEvent
*/
@Override
public void handle(KeyboardPressEvent event) {
if (gameState.getScreen() != null) {

View File

@@ -18,11 +18,6 @@ import cz.jzitnik.client.utils.events.EventManager;
import java.util.Optional;
import java.util.stream.Stream;
/**
* Handler for the MouseAction event.
*
* @author Jakub Žitník (jzitnik)
*/
@EventHandler(MouseAction.class)
public class MouseActionEventHandler extends AbstractEventHandler<MouseAction> {
@InjectDependency
@@ -43,11 +38,6 @@ public class MouseActionEventHandler extends AbstractEventHandler<MouseAction> {
@InjectDependency
private DependencyManager dependencyManager;
/**
* Handles the MouseAction event by delegating to screens, repositories, or performing interactions.
*
* @param event The MouseAction event
*/
@Override
public void handle(MouseAction event) {
if (gameState.getScreen() != null) {

View File

@@ -32,11 +32,6 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Handler for the MouseMoveEvent.
*
* @author Jakub Žitník (jzitnik)
*/
@Slf4j
@EventHandler(MouseMoveEvent.class)
public class MouseMoveEventHandler extends AbstractEventHandler<MouseMoveEvent> {
@@ -63,17 +58,6 @@ public class MouseMoveEventHandler extends AbstractEventHandler<MouseMoveEvent>
@InjectConfig
private PlayerConfig playerConfig;
/**
* Calculates the distance from a point to a rectangle.
*
* @param px Point X
* @param py Point Y
* @param rectTopLeftX Rectangle top-left X
* @param rectTopLeftY Rectangle top-left Y
* @param rectBottomRightX Rectangle bottom-right X
* @param rectBottomRightY Rectangle bottom-right Y
* @return Distance as double
*/
private double distancePointToRect(
double px, double py,
double rectTopLeftX, double rectTopLeftY,
@@ -97,11 +81,6 @@ public class MouseMoveEventHandler extends AbstractEventHandler<MouseMoveEvent>
}
}
/**
* Handles the MouseMoveEvent by updating selectable object states based on hover and distance.
*
* @param event The MouseMoveEvent
*/
@Override
public void handle(MouseMoveEvent event) {
if (event.getMouseAction() != null) {

View File

@@ -26,11 +26,6 @@ import lombok.extern.slf4j.Slf4j;
import java.awt.image.BufferedImage;
/**
* Handler for the PlayerMoveEvent.
*
* @author Jakub Žitník (jzitnik)
*/
@Slf4j
@EventHandler(PlayerMoveEvent.class)
public class PlayerMoveEventHandler extends AbstractEventHandler<PlayerMoveEvent> {
@@ -55,11 +50,6 @@ public class PlayerMoveEventHandler extends AbstractEventHandler<PlayerMoveEvent
@InjectDependency
private Stats stats;
/**
* Handles the PlayerMoveEvent by updating player position and triggering rerenders.
*
* @param event The PlayerMoveEvent
*/
@Override
public void handle(PlayerMoveEvent event) {
if (renderState.isTerminalTooSmall()) {
@@ -169,9 +159,6 @@ public class PlayerMoveEventHandler extends AbstractEventHandler<PlayerMoveEvent
});
}
/**
* Enum representing keys that can be used for sprinting.
*/
public static enum SprintKey {
CTRL,
SHIFT,

View File

@@ -9,11 +9,6 @@ import cz.jzitnik.client.ui.Stats;
import cz.jzitnik.client.utils.events.AbstractEventHandler;
import cz.jzitnik.client.utils.events.EventManager;
/**
* Handler for the RenderStats event.
*
* @author Jakub Žitník (jzitnik)
*/
@EventHandler(RenderStats.class)
public class RenderStatsHandler extends AbstractEventHandler<RenderStats> {
@InjectDependency
@@ -22,11 +17,6 @@ public class RenderStatsHandler extends AbstractEventHandler<RenderStats> {
@InjectDependency
private Stats stats;
/**
* Handles the RenderStats event by rerendering the stats UI component.
*
* @param event The RenderStats event
*/
@Override
public void handle(RenderStats event) {
stats.rerender();

View File

@@ -20,11 +20,6 @@ import cz.jzitnik.client.utils.events.EventManager;
import java.awt.image.BufferedImage;
/**
* Handler for the RerenderPart event.
*
* @author Jakub Žitník (jzitnik)
*/
@EventHandler(RerenderPart.class)
public class RerenderPartHandler extends AbstractEventHandler<RerenderPart> {
@InjectState
@@ -45,11 +40,6 @@ public class RerenderPartHandler extends AbstractEventHandler<RerenderPart> {
@InjectDependency
private EventManager eventManager;
/**
* Handles the RerenderPart event by rerendering a portion of the screen.
*
* @param event The RerenderPart event
*/
@Override
public void handle(RerenderPart event) {
int forStartX = event.getForStartX();

View File

@@ -7,25 +7,17 @@ import cz.jzitnik.client.events.RoomChangeEvent;
import cz.jzitnik.client.events.SendSocketMessageEvent;
import cz.jzitnik.client.game.GameRoom;
import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.Requirement;
import cz.jzitnik.common.models.coordinates.RoomCords;
import cz.jzitnik.client.utils.events.AbstractEventHandler;
import cz.jzitnik.client.utils.events.EventManager;
import cz.jzitnik.client.utils.roomtasks.RoomTaskScheduler;
import cz.jzitnik.common.socket.messages.game.GameWin;
import cz.jzitnik.common.socket.messages.room.MovePlayerRoom;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* Handler for the RoomChangeEvent.
*
* @author Jakub Žitník (jzitnik)
*/
@Slf4j
@EventHandler(RoomChangeEvent.class)
public class RoomChangeEventHandler extends AbstractEventHandler<RoomChangeEvent> {
@@ -37,11 +29,6 @@ public class RoomChangeEventHandler extends AbstractEventHandler<RoomChangeEvent
@InjectDependency
private RoomTaskScheduler roomTaskScheduler;
/**
* Handles the RoomChangeEvent by changing the current room and moving the player.
*
* @param event The RoomChangeEvent
*/
@Override
public void handle(RoomChangeEvent event) {
RoomCords playerCords = gameState.getPlayer().getPlayerCords();
@@ -58,20 +45,6 @@ public class RoomChangeEventHandler extends AbstractEventHandler<RoomChangeEvent
return;
}
if (newRoom.getRequirement() != null) {
Requirement requirement = newRoom.getRequirement();
String itemType = requirement.itemType();
if (Arrays.stream(gameState.getPlayer().getInventory()).noneMatch(item -> {
if (item == null) {
return false;
}
return item.getType().getItemType().getSimpleName().equals(itemType);
})) {
return;
}
}
switch (event.door()) {
case LEFT -> playerCords.updateCords(155, playerCords.getY());
case RIGHT -> playerCords.updateCords(30, playerCords.getY());
@@ -82,10 +55,6 @@ public class RoomChangeEventHandler extends AbstractEventHandler<RoomChangeEvent
eventManager.emitEvent(new SendSocketMessageEvent(new MovePlayerRoom(newRoom.getId(), oldCords, playerCords)));
gameState.setCurrentRoom(newRoom);
if (newRoom.isEnd()) {
eventManager.emitEvent(new SendSocketMessageEvent(new GameWin()));
} else {
scheduler.schedule(() -> roomTaskScheduler.setupNewSchedulers(newRoom), 200, TimeUnit.MILLISECONDS);
}
}
}

View File

@@ -8,21 +8,11 @@ import cz.jzitnik.client.utils.events.AbstractEventHandler;
import java.io.IOException;
/**
* Handler for the SendSocketMessageEvent.
*
* @author Jakub Žitník (jzitnik)
*/
@EventHandler(SendSocketMessageEvent.class)
public class SendSocketMessageEventHandler extends AbstractEventHandler<SendSocketMessageEvent> {
@InjectDependency
private Client client;
/**
* Handles the SendSocketMessageEvent by sending the message through the client.
*
* @param event The SendSocketMessageEvent
*/
@Override
public void handle(SendSocketMessageEvent event) {
try {

View File

@@ -15,11 +15,6 @@ import cz.jzitnik.client.utils.events.AbstractEventHandler;
import cz.jzitnik.client.utils.events.EventManager;
import lombok.extern.slf4j.Slf4j;
/**
* Handler for the TerminalResizeEvent.
*
* @author Jakub Žitník (jzitnik)
*/
@Slf4j
@EventHandler(TerminalResizeEvent.class)
public class TerminalResizeEventHandler extends AbstractEventHandler<TerminalResizeEvent> {
@@ -34,11 +29,6 @@ public class TerminalResizeEventHandler extends AbstractEventHandler<TerminalRes
private boolean screenRerendering = false;
/**
* Handles the TerminalResizeEvent by reinitializing buffers and triggering a full redraw.
*
* @param event The TerminalResizeEvent
*/
@Override
public void handle(TerminalResizeEvent event) {
TerminalSize size = event.getNewSize();

View File

@@ -14,21 +14,11 @@ import cz.jzitnik.client.utils.events.AbstractEventHandler;
import java.io.IOException;
import java.util.EnumSet;
/**
* Handler for the TerminalTooSmallEvent.
*
* @author Jakub Žitník (jzitnik)
*/
@EventHandler(TerminalTooSmallEvent.class)
public class TerminalTooSmallEventHandler extends AbstractEventHandler<TerminalTooSmallEvent> {
@InjectState
private TerminalState terminalState;
/**
* Handles the TerminalTooSmallEvent by rendering a warning message directly to the terminal.
*
* @param event The TerminalTooSmallEvent
*/
@Override
public void handle(TerminalTooSmallEvent event) {
// Directly render the message for the user

View File

@@ -2,12 +2,6 @@ package cz.jzitnik.client.game;
import com.googlecode.lanterna.TextColor;
/**
* Global game constants.
*
* @author Jakub Žitník (jzitnik)
*/
public class Constants {
/** The default background color for the game. */
public static final TextColor BACKGROUND_COLOR = new TextColor.RGB(4, 4, 16);
}

View File

@@ -4,24 +4,7 @@ import cz.jzitnik.common.models.coordinates.RoomCords;
import java.awt.image.BufferedImage;
/**
* Interface representing a player-like entity in the game.
*
* @author Jakub Žitník (jzitnik)
*/
public interface GamePlayer {
/**
* Gets the player's coordinates.
*
* @return RoomCords instance
*/
RoomCords getPlayerCords();
/**
* Gets the player's current texture.
*
* @param resourceManager The resource manager to load texture
* @return BufferedImage texture
*/
BufferedImage getTexture(ResourceManager resourceManager);
}

View File

@@ -14,11 +14,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Represents a room in the game.
*
* @author Jakub Žitník (jzitnik)
*/
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id"
@@ -39,26 +34,11 @@ public class GameRoom {
@JsonIgnore
private final List<RoomPart> colliders = new ArrayList<>();
@JsonProperty("requirement")
private Requirement requirement;
@JsonProperty("end")
private boolean end;
private GameRoom left;
private GameRoom right;
private GameRoom up;
private GameRoom down;
/**
* Constructs a GameRoom.
*
* @param id Room ID
* @param objects List of objects in the room
* @param colliders List of colliders
* @param mobs List of mobs
* @param texture Texture resource
*/
@JsonCreator
public GameRoom(
@JsonProperty("id") String id,
@@ -86,41 +66,21 @@ public class GameRoom {
this.overrideBuffer = overrideBuffer;
}
/**
* Sets the room to the west (left).
*
* @param west West room
*/
@JsonSetter("west")
public void setWest(GameRoom west) {
if (west != null) this.left = west;
}
/**
* Sets the room to the east (right).
*
* @param east East room
*/
@JsonSetter("east")
public void setEast(GameRoom east) {
if (east != null) this.right = east;
}
/**
* Sets the room to the north (up).
*
* @param north North room
*/
@JsonSetter("north")
public void setNorth(GameRoom north) {
if (north != null) this.up = north;
}
/**
* Sets the room to the south (down).
*
* @param south South room
*/
@JsonSetter("south")
public void setSouth(GameRoom south) {
if (south != null) this.down = south;

View File

@@ -11,11 +11,6 @@ import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
/**
* Holds the current state of the game.
*
* @author Jakub Žitník (jzitnik)
*/
@RequiredArgsConstructor
@State
public class GameState {
@@ -35,20 +30,10 @@ public class GameState {
private final List<OtherPlayer> otherPlayers = new ArrayList<>();
/**
* Gets a list of visible other players.
*
* @return List of visible other players
*/
public List<OtherPlayer> getOtherPlayers() {
return otherPlayers.stream().filter(OtherPlayer::isVisible).toList();
}
/**
* Gets a list of all other players.
*
* @return List of all other players
*/
public List<OtherPlayer> getAllOtherPlayers() {
return otherPlayers;
}
@@ -60,11 +45,6 @@ public class GameState {
@Getter
private Screen screen;
/**
* Sets the current screen and injects its dependencies.
*
* @param screen The screen to set
*/
public void setScreen(Screen screen) {
if (screen != null) {
dependencyManager.inject(screen);

View File

@@ -9,11 +9,6 @@ import lombok.Setter;
import java.awt.image.BufferedImage;
/**
* Represents another player connected to the same game.
*
* @author Jakub Žitník (jzitnik)
*/
@Getter
public class OtherPlayer implements GamePlayer {
private final int id;
@@ -24,20 +19,11 @@ public class OtherPlayer implements GamePlayer {
@Setter
private boolean visible;
/**
* Constructs an OtherPlayer.
*
* @param playerCreation Player creation data
*/
public OtherPlayer(PlayerCreation playerCreation) {
this.id = playerCreation.getId();
this.playerCords = playerCreation.getPlayerCords();
}
/**
* {@inheritDoc}
*/
@Override
public BufferedImage getTexture(ResourceManager resourceManager) {
BufferedImage resource = resourceManager.getResource(switch (playerRotation) {
case FRONT -> ResourceManager.Resource.PLAYER_FRONT;

View File

@@ -22,20 +22,13 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/**
* Represents the local player.
*
* @author Jakub Žitník (jzitnik)
*/
@Getter
@Slf4j
public class Player implements GamePlayer {
private final int id;
/** Maximum stamina value. */
public static final int MAX_STAMINA = 20;
/** Maximum health value. */
public static final int MAX_HEALTH = 30;
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private final RoomCords playerCords;
private final RoomPart collider;
@@ -50,52 +43,27 @@ public class Player implements GamePlayer {
private boolean hitAnimationOn = false;
private ScheduledFuture<?> currentTimeoutHitAnimation = null;
/**
* Constructs a Player.
*
* @param playerCreation Player creation data
*/
public Player(PlayerCreation playerCreation) {
this.playerCords = playerCreation.getPlayerCords();
this.collider = playerCreation.getCollider();
this.id = playerCreation.getId();
}
/**
* Increases player stamina.
*/
public void increaseStamina() {
stamina++;
}
/**
* Decreases player stamina.
*/
public void decreaseStamina() {
stamina--;
}
/**
* Restores player health.
*
* @param amount Amount to restore
*/
public void addHealth(int amount) {
health = Math.min(MAX_HEALTH, health + amount);
}
/**
* Deals damage to the player.
*
* @param amount Damage amount
* @param dependencyManager Dependency manager
* @return true if player died
*/
public boolean dealDamage(int amount, DependencyManager dependencyManager) {
if (health - amount <= 0) {
health = 0;
EventManager eventManager = dependencyManager.getDependencyOrThrow(EventManager.class);
eventManager.emitEvent(new cz.jzitnik.client.events.SendSocketMessageEvent(new cz.jzitnik.common.socket.messages.game.PlayerDeath(id)));
return true;
}
@@ -118,11 +86,6 @@ public class Player implements GamePlayer {
return false;
}
/**
* Triggers a rerender of the player.
*
* @param dependencyManager Dependency manager
*/
private void rerender(DependencyManager dependencyManager) {
ResourceManager resourceManager = dependencyManager.getDependencyOrThrow(ResourceManager.class);
EventManager eventManager = dependencyManager.getDependencyOrThrow(EventManager.class);
@@ -139,10 +102,6 @@ public class Player implements GamePlayer {
});
}
/**
* {@inheritDoc}
*/
@Override
public BufferedImage getTexture(ResourceManager resourceManager) {
BufferedImage resource = resourceManager.getResource(switch (playerRotation) {
case FRONT -> ResourceManager.Resource.PLAYER_FRONT;
@@ -158,11 +117,6 @@ public class Player implements GamePlayer {
return resource;
}
/**
* Gets the damage dealt by the player with their current weapon.
*
* @return Damage value
*/
public int getDamageDeal() {
int damage = 1;
@@ -175,12 +129,6 @@ public class Player implements GamePlayer {
return damage;
}
/**
* Adds an item to the player's inventory.
*
* @param item Item to add
* @return true if item was added, false if inventory is full
*/
public boolean addItem(GameItem item) {
boolean added = false;
for (int i = 0; i < inventory.length; i++) {
@@ -194,11 +142,6 @@ public class Player implements GamePlayer {
return added;
}
/**
* Triggers a weapon swing animation.
*
* @param delayMs Duration of the swing
*/
public void swing(int delayMs) {
if (swinging) {
return;

View File

@@ -1,24 +0,0 @@
package cz.jzitnik.client.game;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Represents a requirement (e.g. an item) needed to enter a room.
*
* @param itemType The type of item required
* @author Jakub Žitník (jzitnik)
*/
public record Requirement(String itemType) {
/**
* Constructs a Requirement.
*
* @param itemType The type of item required
*/
@JsonCreator
public Requirement(
@JsonProperty("item") String itemType
) {
this.itemType = itemType;
}
}

View File

@@ -11,19 +11,11 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
/**
* Manages loading and caching of game resources (textures, audio).
*
* @author Jakub Žitník (jzitnik)
*/
@Dependency
public class ResourceManager {
@InjectDependency
private ClassLoader classLoader;
/**
* Enum representing available game resources.
*/
@AllArgsConstructor
@Getter
public enum Resource {
@@ -31,14 +23,6 @@ public class ResourceManager {
ROOM2("rooms/2.png"),
ROOM3("rooms/3.png"),
ROOM4("rooms/4.png"),
ROOM5("rooms/5.png"),
ROOM6("rooms/6.png"),
ROOM7("rooms/7.png"),
ROOM8("rooms/8.png"),
ROOM9("rooms/9.png"),
ROOM10("rooms/10.png"),
ROOM11("rooms/11.png"),
ROOM12("rooms/12.png"),
ROOM_FROZEN("rooms/frozen.png"),
PLAYER_FRONT("player/front.png"),
@@ -52,23 +36,8 @@ public class ResourceManager {
APPLE("food/apple.png"),
// TEMP TEXTURES JUST TO GET THE GAME WORKING
OLD_MAN("player/front.png"),
KEY_KEEPER("player/front.png"),
CAVE_BEAST("player/front.png"),
BLIND_HUNTER("player/front.png"),
ZOMBIE("player/front.png"),
RUSTY_SWORD("tools/wooden_sword.png"),
AXE("tools/wooden_sword.png"),
DAGGER("tools/wooden_sword.png"),
BREAD("food/apple.png"),
ROCK("food/apple.png"),
KEY("food/apple.png"),
BOSS_SKIN("tools/wooden_sword.png"),
// UI
DOORS("rooms/doors.png"),
STAMINA("ui/stamina.png"),
HEART("ui/heart.png");
@@ -77,12 +46,6 @@ public class ResourceManager {
private final HashMap<Resource, BufferedImage> resourceCache = new HashMap<>();
/**
* Retrieves a texture resource by its enum key.
*
* @param resource The resource key
* @return The loaded BufferedImage
*/
public BufferedImage getResource(Resource resource) {
if (resourceCache.containsKey(resource)) {
return resourceCache.get(resource);
@@ -102,12 +65,6 @@ public class ResourceManager {
}
}
/**
* Retrieves a texture resource by its path.
*
* @param path The resource path
* @return The loaded BufferedImage
*/
public BufferedImage getResource(String path) {
InputStream is = classLoader.getResourceAsStream(path);
if (is == null) {
@@ -121,12 +78,6 @@ public class ResourceManager {
}
}
/**
* Gets a resource input stream by path.
*
* @param path The resource path
* @return InputStream for the resource
*/
public InputStream getResourceAsStream(String path) {
return classLoader.getResourceAsStream(path);
}

View File

@@ -1,36 +1,18 @@
package cz.jzitnik.client.game.dialog;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import cz.jzitnik.client.utils.events.Event;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/**
* Represents a dialog sequence in the game.
*
* @author Jakub Žitník (jzitnik)
*/
@AllArgsConstructor
@RequiredArgsConstructor
@Getter
public class Dialog implements Event {
/**
* Characters per second
*/
private final int typingSpeed = 10;
private int typingSpeed = 10;
private final String text;
private final OnEnd onEnd;
/**
* Constructs a Dialog.
*
* @param text The dialog text
* @param onEnd Action to perform when dialog ends
*/
@JsonCreator
public Dialog(
@JsonProperty("text") String text,
@JsonProperty("onEnd") OnEnd onEnd
) {
this.text = text;
this.onEnd = onEnd;
}
}

View File

@@ -1,182 +1,13 @@
package cz.jzitnik.client.game.dialog;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import cz.jzitnik.client.annotations.injectors.InjectDependency;
import cz.jzitnik.client.annotations.injectors.InjectState;
import cz.jzitnik.client.events.InventoryRerender;
import cz.jzitnik.client.game.GameState;
import cz.jzitnik.client.game.Player;
import cz.jzitnik.client.game.Requirement;
import cz.jzitnik.client.game.ResourceManager;
import cz.jzitnik.client.game.items.GameItem;
import cz.jzitnik.client.game.mobs.HittableMobDrops;
import cz.jzitnik.client.utils.events.EventManager;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.Arrays;
import java.util.Optional;
/**
* Interface for actions to perform at the end of a dialog.
*
* @author Jakub Žitník (jzitnik)
*/
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type"
)
@JsonSubTypes({
@JsonSubTypes.Type(value = OnEnd.Continue.class, name = "continue"),
@JsonSubTypes.Type(value = OnEnd.AskQuestion.class, name = "ask_question"),
@JsonSubTypes.Type(value = OnEnd.End.class, name = "end"),
@JsonSubTypes.Type(value = OnEnd.GiveItem.class, name = "give_item")
})
public interface OnEnd {
/** Terminal dialog action. */
record End() implements OnEnd {
}
record RunCode(Runnable runnable, OnEnd onEnd) implements OnEnd {}
/** Action that gives an item to the player. */
class GiveItem extends RunCode {
/**
* Constructs a GiveItem action.
*
* @param item Item to give
* @param onEnd Next action
*/
@JsonCreator
public GiveItem(
@JsonProperty("item") GameItem item,
@JsonProperty("then") OnEnd onEnd
) {
super(new Run(item), onEnd);
}
/** Internal runnable to give the item. */
@RequiredArgsConstructor
private static class Run implements Runnable {
private final GameItem item;
@InjectState
private GameState gameState;
@InjectDependency
private EventManager eventManager;
@InjectDependency
private ResourceManager resourceManager;
/**
* {@inheritDoc}
*/
@Override
public void run() {
Player player = gameState.getPlayer();
var playerCords = player.getPlayerCords().calculateCenter(player.getTexture(resourceManager));
boolean addedIntoInventory = player.addItem(item);
if (!addedIntoInventory) {
eventManager.emitEvent(HittableMobDrops.dropItem(playerCords.getX(), playerCords.getY(), gameState.getCurrentRoom(), item));
} else {
eventManager.emitEvent(new InventoryRerender());
}
}
}
}
/** Action that runs arbitrary code. */
@Getter
@RequiredArgsConstructor
class RunCode implements OnEnd {
private final Runnable runnable;
private final OnEnd onEnd;
}
/** Action that continues to another dialog. */
record Continue(Dialog nextDialog) implements OnEnd {
/**
* Constructs a Continue action.
*
* @param nextDialog The next dialog
*/
@JsonCreator
public Continue(@JsonProperty("nextDialog") Dialog nextDialog) {
this.nextDialog = nextDialog;
}
}
/** Action that asks the player a question with multiple answers. */
record AskQuestion(Answer[] answers) implements OnEnd {
/**
* Constructs an AskQuestion action.
*
* @param answers Possible answers
*/
@JsonCreator
public AskQuestion(@JsonProperty("answers") Answer[] answers) {
this.answers = answers;
}
/** Represents a single answer to a question. */
public record Answer(
String answer,
Dialog dialog,
Optional<Requirement> requirement
) {
/**
* Constructs an Answer.
*
* @param answer Answer text
* @param dialog Resulting dialog
* @param requirement Requirement to see this answer
*/
@JsonCreator
public Answer(
@JsonProperty("answer") String answer,
@JsonProperty("dialog") Dialog dialog,
@JsonProperty("requirement") Requirement requirement
) {
this(answer, dialog, Optional.ofNullable(requirement));
}
/**
* Checks if the answer is valid for the current state.
*/
private boolean isValid(GameState gameState) {
if (requirement.isPresent()) {
Requirement requirement = requirement().get();
if (requirement.itemType() != null) {
return Arrays.stream(gameState.getPlayer().getInventory()).anyMatch(item -> {
if (item == null) {
return false;
}
return item.getType().getItemType().getSimpleName().equals(requirement.itemType());
});
}
return true;
}
return true;
}
}
/**
* Gets valid answers for the current game state.
*
* @param gameState Current game state
* @return Array of valid answers
*/
public Answer[] answers(GameState gameState) {
return Arrays.stream(answers)
.filter(answer -> answer.isValid(gameState))
.toArray(Answer[]::new);
public record Answer(String answer, Dialog dialog) {
}
}
}

View File

@@ -1,23 +1,10 @@
package cz.jzitnik.client.game.exceptions;
/**
* Exception thrown when coordinates are invalid.
*
* @author Jakub Žitník (jzitnik)
*/
public class InvalidCoordinatesException extends RuntimeException {
/**
* Constructs an InvalidCoordinatesException with message.
*
* @param message The error message
*/
public InvalidCoordinatesException(String message) {
super(message);
}
/**
* Constructs an InvalidCoordinatesException.
*/
public InvalidCoordinatesException() {
super();
}

View File

@@ -8,11 +8,6 @@ import lombok.Getter;
import java.awt.image.BufferedImage;
/**
* Represents an item in the game.
*
* @author Jakub Žitník (jzitnik)
*/
@Getter
public class GameItem implements Renderable {
private final ItemType<?> type;
@@ -21,15 +16,6 @@ public class GameItem implements Renderable {
private final String name;
private final int id;
/**
* Constructs a GameItem.
*
* @param id Item ID
* @param name Item name
* @param type Item type
* @param resource Texture resource
* @param resourceManager Resource manager
*/
@JsonCreator
public GameItem(
@JsonProperty("id") int id,

Some files were not shown because too many files have changed in this diff Show More