Quick screen grab from my first big project, more details coming soon!
Follow the learning and progress of a waiter who wants to make games. Java, Android and Game Development. Includes code snippets, book reviews and recommendations, game analysis and concept sketches!
Tuesday, 12 January 2016
Monday, 14 September 2015
Making Audio go private
Today I have been working on getting my Audio system implemented, mostly in order to keep the Activity Lifecycle happy- ie ensuring that media is paused, resumed and released appropriately. The initial implementation I made was an Audio class which was built up of static methods, each able to do a specific function, and if necessary call each other to use pre-existing functionality. The class worked, and is in a small project not a bad model, but I have been reading up on ways to setup a game View and it seems that the Audio class needs to be less public.
Honestly, my first reason for making methods static was that I read that using getters and setters was potentially heavy on resources, but in further reading I have found that for my audio needs this won't be an issue.
The main root of my game framework is now a base activity which is able to create and switch between views, the views themselves after a little experimentation are now extensions of the SurfaceView, and are able to take a pre-initialised Audio instance as a parameter. What this does is allow the main activity to set up the audio environment in one place, passing in itself for context rather than having the Audio being setup in the beginning of a new "screen".
The audio environment is now also much more encapsulated, and as such should only be passed to one screen and any reference will be lost as that screen dies. The activity itself can also ensure that the correct settings are in place for the audio-stream, should the app framework be used for other app types.
The project I have been working on is a soundboard which emulates the character select screen of Mortal Kombat 3, a childhood favourite of mine. So far I have been able to load the 15 game characters names and corresponding "introduction" speech files from the game, and I have it set up to play a random one from this list and display the name on each touch event.
The names themselves exist in an array which is organised in the order that the game presents them on the screen, however it may be necessary at a later date to have them sorted alphabetically- which we will do if needed. One string array (in the strings.xml resource) holds these names, and another array holds the filenames for the audio files in the same order. The reason I have kept the two seperate instead of trying to parse one array into an audio filename, is that I am able to localize the name strings and they will still line up with the sound files whose names are written in english. While the game characters names are the same in any language, it may not be the same in character based languages, and if I ever work on supporting those it would be great to not have to rewrite my audio file loading.
There are probably many other ways to link the names in an array to specific sound files but for now this seems to be the simplest and works well for this project.
The next step will be to load in a music track to loop in the background and then I can begin working on graphics!
Monday, 7 September 2015
MediaPlayer experiments
My experiments with the media player began with finding a question on the learnandroid subreddit, which asked about pausing media with a touchevent. From my reading I could see that the poster had not prepared the media track after stopping it, something which is unique to that circumstance but not the pause method. The poster also had a bit of confusion about the touch event itself and where to trigger the media playing. After posting a quick suggestion I decided that I should try to implement a music player in a test app too to get to grips with the little things that might be confusing for a beginner.
Following on from my blank screen SurfaceView test, I used VLC to convert a ripped mp3 into the OGGVorbis format with reduced sound quality (to save on memory) and added that into a new assets folder. From my previous experiemnts with Soundpool (An app with pikachu on it that says pikachu when you touch the screen, and plays a computer booting up sfx from pokemon firered on launch), I knew that sound files can be retrieved using the AssetManager in android. I made the first mistake in not putting the new directory in the right place in the file structure, but that didn't become apparent until it was fully set up.
My first set up was to have all of the media player implemented in the SurfaceView class itself, which is a Runnable in a class called Screen. The implementation included instantiating an asset manager, trying to get the file i wanted an AssetFileDescriptor which I could pass into a new instance of MediaPlayer. The process itself was all set up and the data source set and media started, but the app itself didn't work. After adding some Log notes and an exception message for the try-catch block I found that the asset manager wasn't retrieving the files in the folder, and looked back to my original pikachu app to find the structure difference.
Once the file was able to load and play I ran the app and lo and behold, the music played, (Nine Inchnails- Satellites for those who need to know!). I was elated, then I closed the app and hmm.. still music.
I knew this had something to do with releasing the resources and the activity life cycle so I started to look there for ways to control my music. I started with onStop, onPause and onResume methods inside my SurfaceView which were called from the main activity, and implemented checks for if the media player was valid and playing etc, and stopped the music and restarted it as I expected. This did not work. The app was happy enough to stop the music but not to restart it when the app was loaded up again. I understood that the app was saved in temporary memory when the app was minimized or obscured, so the app was going through the onPause method, but I didn't realize the onStop method was being called also!
Going back I was able to debug my app and place appropriate boolean flags to control the music playing. In the onPause method, the music is (if it is not already) paused, and on resume the music is (if not null such as on initial bootup of the app) started again. The call to onStop was moved into an if block which checked that the app was not being closed fully (isFinishing()) and if so, stopped playback and also released the media player.
With my experiment finally performing the way I wanted it to, I was finally able to begin abstracting the audio into a seperate class. I created an Audio class that could handle music using static methods, which would mean it is accessible throughout my app. Instead of using a default constructor to set up the Audio environment, I opted instead to use static methods that only initialize variables if they are going to be used. I currently have a method that is needed to pass in a context for use in attaining the assets, but later on I will access this statically from a core class that handles the game.
The Audio class also has onPause, onResume and onStop methods which can be called to ensure that any active media, be it sound FX from the soundPool or music from MediaPlayer are paused and resumed correctly, and destroyed on closing the app.
I am really quite happy with the progress I am making in understanding these (albeit simple) aspects of app development. I want to be able to say not only that I understand the theory, but that I can put code on paper to describe the processes and show that I understand the way these systems work together on a more holistic level.
The code for my Audio and Screen app are linked below for viewing.
MainActivity Class
Audio Class
SurfaceView Class
Thursday, 27 August 2015
Return to Game Development
While working through the examples, I have been playing around with the code and finding out the OTHER methods that some of the classes do. While I had made a game on Android following a "For Dummies" book in the past, this time I actually understand the process, the effect that the Activity Life Cycle has, and can see where the ideas I have fit into the code.
To help me keep notes and have an "in my own words" reference, I have been typing up notes into Google Keep, an app I have had on my phone for a long time and rarely used. Being able to type quickly has always prevented me from note-taking on my phone. I am a terrible touch screen typist! Using the in-browser version of Google Keep has been a lifesaver- actual keyboard typing, and sync to my phone for on the go note revision. I have found myself memorizing key concepts quicker with these notes, and can now comfortably say that an extremely basic framework in a regular View can flow pretty quickly from my fingers. I do enjoy making notes and even updating them to make them more precise, but I can't always be at my laptop- for this reason I have contemplated buying a bluetooth for a while. (I have planned to buy a tablet for myself for quite a while now and really wanted a keyboard for it- so I have been watching Amazon and Bestbuy for a deal daily!) I finally ordered myself a keyboard last night, and hopefully that gives me more opportunities to be productive- either in writing up ideas, taking notes or coding when I am not limited by the amount of time I can comfortably sit at the computer.
As an example of the notes I have been keeping, here is my first entry!
Soundpool is a RAM based storage for small soundFX files, ideally in .ogg format and shorter than about 5 seconds. Setting up a SoundPool requires the parameters indicating how many sounds can play simultaneously (20 is a good default), which sound stream is being used (AudioManager.STREAM_MUSIC for media of any type), and a final unused parameter, default 0.
SoundPool sp = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
The SoundPool default constructor has been deprecated with the release of Lollipop, and now utilises a Builder for instantiating a SoundPool object.
SoundPool sp = SoundPool.Builder()
.setUsage(audioAttributes)
.setStream()
.build();
To load a soundFX file to the Pool, you have to get an AssetFileDescriptor from the Asset file.
AssetManager assetManager = context.getAssets();
AssetFileDescriptor asset1 = assetManager.openFD("dir/filename.extension");
When adding the descriptor to the soundpool, it will return an integer which identifies the sound loaded, which can be used as a parameter later. It is vital therefore that any files loaded be done so in an integer expression. the load method itself will take in the AssetFileDescriptor and a sound priority int as parameters. The sound priority is currently unused as is default as 1 (similar I guess to the weight attribute in xml layouts, having them all at 1 gives uniform importance).
int asset1IdNum = sp.load(asset1, 1);
This asset can later be played using the SoundPool instance, by referencing the identifier for the resource, as well as some other parameters.
sp.play(identifierInt, float leftChannelVolume, float rightChannelVolume, int priority, int looping, float playbackSpeed)
The channelVolume parameters allow a sound to be set on one ear or the other. The priority again is unused and is defaulted to 0. Looping is often not a good idea for a sound effect and is thus set to 0, and playback speed will be 1 by default, less for slow play and more for fast playback.
When all use of the SoundPool is done, it is best practice to release the resources directly by using either specific calls to soundPool.unload(identifierInt) or to all resources using soundPool.release();
I have made notes on MusicStream, working with the View and onDraw() method (invalidating as a method of continuous graphics rendering), setting the application to keep the screen on, go fullscreen and hide the notification bar and working in SurfaceView and Threads.
I'm hoping that my notes will not only enable me to retain information better, but also that they may help me to guide others if they ask me for advice on starting on a similar path!
There are notes I have to include after todays coding to describe how to set a listener for loading files, as I wanted to have a specific sound effect play as my testing app opens (computer booting up sound effect from a monster catching game you may have heard of!)
Friday, 21 August 2015
Update to R2-D2 print
Monday, 27 July 2015
Checkboxes and scrollviews
Sunday, 12 July 2015
Review: Android Development for Beginners on Udacity
Monday, 29 June 2015
Android and Java
Before learning Java more comprehensibly through the Head First Java book, I studied via a web series from developer John Purcell. The course is available on Udemy and I highly recommend it for anyone looking to get a grip on Java while seeing someone type and run code into the Eclipse IDE.
There is also an Android course available by John Purcell which I hope to take in once I have a handle of the basics. My experience so far has been that studying from one source and then getting that second look from another really helps to solidify my understanding. Seeing one example of a new concept compared to another is often the deciding factor on whether I "get it" or need to go to bed because I am too tired.
My current understanding of Android is of the Manifest and how to add activities, the use of a few basic View's, some simple touch handling and basic drawing to a Canvas. I am working on an activity that takes in multiple touches (pointers) and assigns them to a new or incomplete pair. For each pointer, if it belongs to a pair but has no other pointer, it draws a circle, and for complete pairs (both pointers still touching the screen) it draws smaller circles and a line to connect them. My code for this has gone through a few iterations as I figure out the pointers for each MotionEvent that is fired and handle it, but the drawing aspect has me stuck right now. My program may just be over complicated (using a class instance for each PointerPair) and I may have to go back to simple arrays to keep track of each pointer and its relationship. for now though my code looks like this.
There are a few Log.d debugging lines in there for when I test on my phone. It took a while for me to realize that my code was not functioning and cloned my initial PointerPair instance to all slots of the array because I didn't exit the for loop when I should have. I understand my code isn't pretty and probably makes some ridiculous optimization choices but its main objective is to help me learn so I'm not too precious yet :P
(I used hilite.me for code formatting)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | package ***********; import java.util.ArrayList; import java.util.Random; import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.os.Build; import android.os.Bundle; import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.Window; import android.view.WindowManager; public class DrawLinesTest extends Activity implements OnTouchListener{ private final int MAX_PAIRS = 5; PointerPair[] pairs = new PointerPair[MAX_PAIRS]; Random rng; PointerPair openPair = null; ArrayList<PointerPair> drawables = new ArrayList<PointerPair>(); public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); RenderView v = new RenderView(this); v.setOnTouchListener(this); setContentView(v); rng = new Random(); } public void onResume(){ super.onResume(); for(int i = 0; i < pairs.length; i++){ pairs[i] = null; } } @TargetApi(Build.VERSION_CODES.FROYO) public boolean onTouch(View v, MotionEvent e){ //Log.d("PointerPair", "Screen Touched"); int action = e.getActionMasked(); int pointerIndex = e.getActionIndex(); int pointerId = e.getPointerId(pointerIndex); switch(action){ case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: if(openPair != null){ openPair.setPointer2Id(pointerId); openPair.setCoords(1, e.getX(), e.getY()); Log.d("PointerPair", "Pairs: An pointer partner has been found! "); openPair = null; } else { boolean pairCreated = false; for(int i = 0; i < pairs.length; i++){ if(!pairCreated){ if(pairs[i] == null){ Log.d("PointerPair", "Pairs: Creating new pair at index " + i); pairs[i] = new PointerPair(pointerId, e.getX(), e.getY()); drawables.add(pairs[i]); Log.d("PointerPair", "Pairs: An pointer needs a partner! "); openPair = pairs[i]; pairCreated = true; } } } } break; case MotionEvent.ACTION_MOVE: for(int i = 0; i < pairs.length; i++){ if(pairs[i] != null){ if(pointerId == pairs[i].pointer1Id){ pairs[i].setCoords(0, e.getX(), e.getY()); } else if(pointerId == pairs[i].pointer2Id){ Log.d("PointerPair", "Painting - updating second pointer coords"); pairs[i].setCoords(1, e.getX(), e.getY()); } } } break; case MotionEvent.ACTION_POINTER_UP: for(int i = 0; i < pairs.length; i++){ if(pairs[i] != null){ if(pointerId == pairs[i].pointer1Id){ //Log.d("PointerPair", "Pairs: Lifted Pointer matches pointer 1 in pair ID:" + i); pairs[i].pointer1Id = -1; } else if(pointerId == pairs[i].pointer2Id){ //Log.d("PointerPair", "Pairs: Lifted Pointer matches pointer 2 in pair ID:" + i); pairs[i].pointer2Id = -1; } } } break; case MotionEvent.ACTION_UP: for(int i = 0; i < pairs.length; i++){ pairs[i] = null; drawables.clear(); } openPair = null; break; } cleanPairs(); v.invalidate(); return true; } private void cleanPairs(){ for(int j = 0; j < pairs.length; j++){ if(pairs[j] != null){ pairs[j].update(); } } // Clean out dead pairs for(int i= 0; i < pairs.length; i++){ if(pairs[i] != null){ if(pairs[i].pairDead()){ drawables.remove(pairs[i]); //Log.d("PointerPair", "Pairs: Nulling a pair at position" + i); pairs[i] = null; } } } } class PointerPair{ private int pointer1Id, pointer2Id; private boolean needsPair, isPointer1Dead, isPointer2Dead, isPairDead; private int p1x, p1y, p2x, p2y; Paint paint; public PointerPair(int pointer1Id){ this.pointer1Id = pointer1Id; pointer2Id = -1; needsPair = true; paint = new Paint(); paint.setARGB(255, rng.nextInt(255), rng.nextInt(255), rng.nextInt(255)); } public PointerPair(int pointer1Id, float x, float y){ this(pointer1Id); setCoords(0, x, y); } public void setCoords(int pointerIndex, float x, float y){ if(pointerIndex == 0){ p1x = (int) x; p1y = (int) y; } else if(pointerIndex == 1){ p2x = (int) x; p2y = (int) y; } } public void update(){ if(pointer1Id == -1){ isPointer1Dead = true; } if (pointer2Id == -1){ isPointer2Dead = true; } if(isPointer1Dead && isPointer2Dead){ isPairDead = true; } else if (isPointer1Dead && needsPair){ isPairDead = true; } } public boolean needsPair(){ return needsPair; } public void setPointer2Id(int pointer2Id){ this.pointer2Id = pointer2Id; needsPair = false; } public boolean pairDead(){ return isPairDead; } public Paint getPaint(){ return paint; } } class RenderView extends View{ Paint paint; public void onDraw(Canvas canvas){ clear(canvas); for(int i = 0; i < pairs.length; i++){ for(PointerPair p: drawables){ Paint paint1 = p.getPaint(); if(p.pointer1Id != -1 && p.pointer2Id != -1){ Log.d("PointerPairPaint", "Painting a pair, 2 circles baby!s"); canvas.drawCircle(p.p1x, p.p1y, getWidth() / 15, paint1); canvas.drawCircle(p.p2x, p.p2y, getWidth() / 15, paint1); return; } if(p.needsPair() || p.isPointer2Dead){ Log.d("PointerPairPaint", "Painting lonely first pointer, " + p.p1x + ", " + p.p1y); canvas.drawCircle(p.p1x, p.p1y, getWidth() / 10, paint1); return; } else if(p.isPointer1Dead){ Log.d("PointerPairPaint", "Painting lonely second pointer, " + p.p2x + ", " + p.p2y); canvas.drawCircle(p.p2x, p.p2y, getWidth() / 10, paint1); return; } } } //invalidate(); } public RenderView(Context context){ super(context); paint = new Paint(); } private void clear(Canvas c){ paint.setColor(Color.GRAY); c.drawRect(0, 0, getWidth() - 1, getHeight() - 1, paint); } } } |
Sunday, 28 June 2015
3 Way Battle Simulation
Mob Class (Parent for the three rpg-classes)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | package saving; import java.io.Serializable; @SuppressWarnings("serial") public class Mob implements Serializable{ int maxHealth; int health; String name; int attack; double defence; double accuracy; double dodge; String type; private String battleReport = null; private String attackReport = null; private boolean isAlive; public Mob(){ isAlive = true; } public void takeDamage(int damage){ int absorb = (int) (damage * defence); if(damage - absorb >= 1){ health -= (damage - absorb); } battleReport = name + " absorbs " + absorb + " damage.\n" + name + " takes " + (damage - absorb) + " damage\nHealth remaining: " + health + "\n"; if(health <= 0) { health = 0; isAlive = false; } } public void attack(Mob enemy){ attackReport = null; battleReport = null; enemy.attackReport = null; enemy.battleReport = null; attackReport = (name + " is attacking " + enemy.name); if(Math.random() > accuracy){ // Missed attackReport += "\nAttack missed. End of attack."; enemy.battleReport = enemy.name + " is unharmed\n"; return; } if(Math.random() < enemy.dodge){ // Dodged attackReport += "\n" + enemy.name + " dodged the attack. End of attack.\n"; enemy.battleReport = enemy.name + " is unharmed\n"; return; } int attackDamage = attack; if ((type.equals("Orc") && enemy.type.equals("Elf")) || (type.equals("Human") && enemy.type.equals("Orc")) || (type.equals("Elf") && enemy.type.equals("Human"))){ attackDamage *= 1.2; attackDamage -= Math.random() * attackDamage; } else if((type.equals("Orc") && enemy.type.equals("Human")) || (type.equals("Human") && enemy.type.equals("Elf")) || (type.equals("Elf") && enemy.type.equals("Orc"))){ attackDamage *= 0.8; attackDamage -= Math.random() * attackDamage + 1; } enemy.takeDamage(attackDamage); } public void heal(int hpUp){ health += hpUp; if(health > maxHealth) health = maxHealth; } public String toString(){ return "MOB: " + this.hashCode() + "\nHealth: " + health +"\nAlive: " + isAlive; } public boolean isAlive(){ return isAlive; } public String getBattleReport(){ return battleReport; } public String getAttackReport(){ return attackReport; } }
|
Main Class - Barracks.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | package saving; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; public class Barracks { private final int COMBATANTS = 500; // exceed 100,000 at your own risk. private int skirmishes; @SuppressWarnings("rawtypes") private ArrayList<ArrayList> mobs; public static void main(String[] args) { Barracks b = new Barracks(); b.go(); } public void go(){ long startTime = System.currentTimeMillis(); System.out.println("Starting simulation: Number of Combatants per army = " + COMBATANTS); // Armies of Mobs ArrayList<Orc> orcs = new ArrayList<Orc>(); ArrayList<Elf> elves = new ArrayList<Elf>(); ArrayList<Human> humans = new ArrayList<Human>(); // Populate armies for(int i = 0; i < COMBATANTS; i++){ orcs.add(new Orc("Warrior" + i)); elves.add(new Elf("Ranger" + i)); humans.add(new Human("Mage" + i)); } // Armies added to array list mobs = new ArrayList<>(); mobs.add(orcs); mobs.add(elves); mobs.add(humans); try { // Create text report FileWriter fw = new FileWriter("BattleReport.rep"); BufferedWriter bw = new BufferedWriter(fw); // Report title bw.write("Battle between " + COMBATANTS + " orcs, elves and Humans:"); // Main simulation loop while(!orcs.isEmpty() && !elves.isEmpty() && !humans.isEmpty()){ // While all armies have combatants, select to opposite faction mobs int class1 = (int) (Math.random() * 3); int mobNum = (int) (Math.random() * mobs.get(class1).size()); Mob fighter1 = (Mob) mobs.get(class1).get(mobNum); // Prevent same faction skirmish int class2 = (int) (Math.random() * 3); while(class2 == class1){ class2 = (int) (Math.random() * 3); } int mob2Num = (int)(Math.random() * mobs.get(class2).size()); Mob fighter2 = (Mob) mobs.get(class2).get(mob2Num); // Actual skirmish fighter1.attack(fighter2); // Get report on actions taken bw.write("\n" + fighter1.getAttackReport()); // Get report on hits taken and damage mitigation bw.write("\n" + fighter2.getBattleReport()); // If damage is taken, increment skirmishes counter if(fighter2.getBattleReport().contains("takes")){ skirmishes++; } if(!((Mob) mobs.get(class1).get(mobNum)).isAlive()){ mobs.get(class1).remove(mobNum); } else if(!((Mob) mobs.get(class2).get(mob2Num)).isAlive()){ mobs.get(class2).remove(mob2Num); } } long delta = System.currentTimeMillis() - startTime; double elapsedTime = delta / 1000.0; System.out.println("Ending simulation: Number of Skirmishes = " + skirmishes + "\nTime taken: " + elapsedTime + "sec"); // Write out summary of battles bw.write(battleReport()); bw.close(); }catch (IOException e){ } } public String battleReport(){ String report = null; // Find defeated army and display remaining enemies and total skirmishes if(mobs.get(0).isEmpty()){ report = "\nOrcs are defeated" + "\n" + mobs.get(1).size() + " Elves remain" + "\n" + mobs.get(2).size() + " Humans remain"; } else if (mobs.get(1).isEmpty()){ report = "\nElves are defeated" + "\n" + mobs.get(0).size() + " Orcs remain" + "\n" + mobs.get(2).size() + " Humans remain"; }else if (mobs.get(2).isEmpty()){ report = "\nHumans are defeated" + "\n" + mobs.get(0).size() + " Orcs remain" + "\n" + mobs.get(1).size() + " Elves remain"; } return (report + "\n" + skirmishes + " total Skirmishes"); } } |
Elf.java - The Ranger class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | package saving; @SuppressWarnings("serial") public class Elf extends Mob{ public Elf(String name){ super(); this.name = name; maxHealth = 180; health = maxHealth; type = "Elf"; attack = 16; defence = 0.15; accuracy = 0.95; dodge = 0.06; } } |
Orc.java - The Warrior class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | package saving; @SuppressWarnings("serial") public class Orc extends Mob{ public Orc(String name){ super(); this.name = name; maxHealth = 150; health = maxHealth; type = "Orc"; attack = 20; defence = 0.30; accuracy = 0.85; dodge = 0.1; } } |
Mage.java - The Mage class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | package saving; @SuppressWarnings("serial") public class Human extends Mob{ public Human(String name){ super(); this.name = name; maxHealth = 140; health = maxHealth; type = "Human"; attack = 30; defence = 0.12; accuracy = 0.90; dodge = 0.05; } } |

