Please read Instructions.md to better understand project requirements.
- Install a recent version of IntelliJ IDEA. Kotlin is bundled with IntelliJ IDEA starting from version 15.
- You can download the free Community Edition from JetBrains.
- Download the project as zip file.
- Unzip the downloaded file.
- Open the project folder from from Intellij IDEA.
- Run!
The project has 3 main components.
main.kt
: Main Kotlin file where the application starts its life.controllers
: The package contains logic and engine related files. It consists of 2 objects: --Data
: For data handling jobs like, reading, writing and mapping. --Simulation
: Process the valuable information and make the simulation happen.models
: The package contains the classes. It consists of 5 classes: --Creature
: Main class holds the main and common variables, other living creatures like Hero" and "Enemy" will be inherited from this main class, --Enemy
: Class for enemies, inherits from the "Creature" class. --Hero
: Class for hero, inherits from the "Creature" class. --Resource
: Class for resource. --MappedData
: Class for the data that we read from the "input.txt" file.
This project has developed in Andorid’s official and JVM language “Kotlin”. The general flow of the application is as it follows.
- Define the variable
readFileName
, default value isinput.txt
- Call the
readFile()
function fromData
object by passing the valuereadFileName
as an input parameter to read the input file and assign its return value which is an instance ofMappedData
class to themappedData
variable. readFile()
function reads theinput.txt
line by line and adds it toinputLines
list which stores each line of the given input text file as an item. This function returns the instance ofMappedData
class by passing the variableinputLines
as an input parameter todataMapper()
function.dataMapper()
function is actually do the data mining job by extracting the valuable information from theinputLines
list which is equal to the information ininput.txt
file. After organising the necessary information and assigning them to relateed variables, returns it as an instance ofMappedData
class by executingreturn MappedData(resource, hero, enemyList)
.- We red the file
input.txt
and stored the necessary information for simulation in themappedData
variable which is an instance ofMappedData
class. Now we can call thestart()
function fromSimulation
object by passing themappedData
variable as a parameter by executingSimulation.start(mappedData)
. start()
function initialises to simulation by extracting the wrapped information frommappedData
variable and assigning the values to the related variables and then starts thewhile()
loop which represents our hero's movement.while()
loop continues till thehero
reaches to theposition
of theresource
or until he/she dies. Inside thewhile()
loop there is afor()
loop that loops through theenemies
and calls thefight()
function each time by passing thePair(hero, enemy)
variable as a parameter if theirpositions
meets.fight()
function simulates the fight between the hero and the enemy. The parameterpair
holds the instances ofHero
and, enemyEnemy
classes. And returnsBoolean
that represents if thehero
won the fight or not.- In the end we reach to the end of
start()
function where we callwriteFile()
function by passing thejourneyLog
variable as a parameter. writeFile()
loops throughjourneyLog
variable and writes it line by line to the text file calledoutput.txt
. If the file exists with the same name it numbers the file name starting from1
. For exampleoutput1.txt
,output2.txt
,output3.txt
...
MIT License
Copyright (c) 2017 Arda Özceviz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.