Unit 22 Task 3-4

Developing a Game on Java

Game Linkhttps://www.greenfoot.org/scenarios/25745

The game that I decided to develop, is about cars and traffic. It is a simple game, and for this game there are many ideas that could improve the game, like adding different cars with different characteristics. But the game that I did is still raw, I need to work on it in my opinion, but it is playable and it got some physics.

So, the code for MyWorld, contains whatever you can see in the pictures below. It has some if statements that have the role to spawn a random number of Cars and Trees on the map while you will drive, and the numbers after there mean the place where the objects will be spawned and their density- will there be many cars or trees, or not really. And in public MyWorld you can see that I have added the newLine, it is the road, where most of cars will be spawned. This is all that you could see in the code of MyWorld.

Let’s see the actors, and the first one will be the main one, the Ambulance. In this source of code you can see again some if statements. They have the role to move the Ambulance to the left, right and other directions when you will press “W” “A” “S” “D”.

In the next rows of the Ambulance code you will see “checkCollision()” and “checkCollision1()”. These ones are for the case when the Ambulance will hit a car or a tree, the game will stop, and you will lose. Also you can see again some stuff connected to the moves of the Ambulance to different directions, I’ve indicated here the direction where the Ambulance will move, X means horizontal direction and Y vertical, so for Left and Right I’ve added for X -2 and +2, then I did the same for moves Up and Down, but I’ve did the same for Y instead of X.

Here you can see again checkCollision(), I’ve indicated here it to stop the game when the Ambulance hits a car and I did the same for the trees.

Next Actor classes will be together, because they got the same code and function. This is the Car.class, and how you can see I wrote here that it must move down, so the Ambulance is being controlled by the player and he must avoid the cars and trees.

And here is another Actor class, Line. As I said it is the road where the cars appear. And I mentioned that all the actors have the same code except one, but it has a very little change, how you can see the road just got +1 instead +2 in the public void moveDown().

Narrative

In the game that I’ve developed you are driving an Ambulance, and you are trying to get your patient with COVID-19 to the hospital as fast as possible and you need to do it carefully to not hit any cars or other stuff that you can find in your world.

Pseudo Code

If statements – If key “W” is down you can move up or when key “A” is pressed you can move to the left, and the same with other buttons.

Spawning Items randomly – When everything is moving in the game, inclusive you. You will be able to see cars and trees, they has the function to appear randomly everywhere and to stop the game if you hit any of them.

Action List

Start Button – It will start the game and you will be able to move on the map and avoid trees and cars.

Ambulance hits a car/tree – In this case the game will just stop and you will need to restart it.

W/A/S/D – Player will move up/left/back/right after pressing each of these buttons.

M1

Program Design – If you will look at my game design, you will see only default textures and actors that are included in greenfoot, with time I can change them to better ones, but now I didn’t do that because I didn’t find any special textures.

Purpose – The purpose of my design was just to create a simple game design that will understand anyone.

Modularity – Modularity is one of the most important methodologies
in developing any kind of software and particularly computer games.


Systematic approach – This is a principal that details that before a
program can be solved it must be designed. One cannot simply write
a start writing a program without proper analysis, design,
implementation, testing and then further evaluation.


Data dictionary – The data dictionary refers to a collection of
descriptions of what items can be found in the program with their
purpose.


Data types/structures – These refer to how specifc data will be
stored, for example using true or false with a boolean or a string for a
collection of characters.


Methods/procedures – A method or procedure is a set of instruction
that run when called by the program.

Parameters passed – This refers to information being manipulates
and transported between different parts of the program that
ultimately allow it to function properly.

Return values – These are values that the program created and gives
back based on whatever was done to it. So in a calculation of 1+2 the
answer 3 would be the return value.


Scope – Scope refers to where in the program an object or can access
data.


Visibility – Code visibility refers to where the contents of the code can
be seen. Usually publicly or privately.

Private – Private data means that it can only be access in that specifc
part of the program in which it is declared in.

Public – Public data is data that can be accessed from anywhere in the
program.

Static – A static variable refers to it being allocated statically and runs
for the entire duration of the program.

Friend – A friend function has the same access as methods to private
and protected data.

Objects – Objects are pieces of code that do a specifc thing in a
program.

Instantiation algorithm design – Instantiation is the creation of a real
instance of an abstraction such as a class of objects or a computer
processes.

Develop – To develop a program refers to the design and visualisation.

Choice of language eg object oriented or procedural – In my case I have chosen Object Oriented Programming, thanks to it I am able to reuse any parts of my code.

Development Facilities – I developed this game on a laptop, using Greenfoot.

Menu – The game that I’ve created doesn’t have a menu yet, but I am thinking about creating one as I want to extend my game.

Editing techniques – Editing techniques include things like graphical
elements that I can change later that isn’t affected by code.

Saving Files – Usually I am saving files on my laptop, sometimes I can do it on my USB, but not now, now I will do like usually, it is more secure and I will save everything in one folder.

Building or compiling code – This is a step where the compiler
automatically check the code for errors and if there are none prepared the
code to be run.

Built-In Help Facilities – Greenfoot has built in help. This is good because when you get stuck you can just look for an answer there, most of times you will find it there.

Small unitary code blocks – Each small blocks of code have a specifc
task and run entirely on their own and can be deleted and duplicated
accordingly.


Invocation – This refers to calling up a function or starting a function.

Consistent indentation – It is good practice to code neatly and indent
relevant code together.

Descriptive identifiers – While any variable name will work, they
should be descriptive enough to avoid confusion.

Coding – good use of program structures – The program should be
well organised and grouped well avoiding randomly written code and
irrelevant code together.

Syntax rules for the language – For the program to work, we must
follow the syntax rules of the program so in Java’s case each line must
end in a semi colon.

Assigning values – Assigning values is giving specific variables actual
information to represent.


Operators input/output statements – This refers to taking in
information, processing it then outputting it in an understandable form.

Selection methods (calls to external procedures) – Calls from the
program can happen anywhere and start a function very quickly and
efficiently using a single line of code.

Iteration loops (pre-conditioned) – A precondition is a condition
that must be met before running the rest of the code in a method.

Post-conditioned – A postcondition is a condition that is true after
running the code in a method.

Fixed – A fxed loop is a set of instructions that runs a specifc number
of times that is continually repeated until a certain condition is met.

Data representation: types (integers) – An integer is a whole number
with a positive or negative value.

Real numbers – Real numbers include all rational numbers.

Booleans – A statement that is true or false.

Characters – These are values that can be inputted by a keyboard.

Strings – A collection of characters. Usually a word or a phrase.

Declaring, assigning constants – These are a form of variables or
placeholders that have one fixed value.

Variables – Variables are placeholders in the code that represent
certain data and can be changed many times. They can be private or
public.

Test 1 – To see if the game stops when hits a car or a tree

When the player hits a car or a tree the game must instantly stop. After the tests I made sure that all is working properly, you can see it as well in the screenshots below:

Car_Test
Tree_Test

Test 2 – To see if everything is moving down except the background and the ambulance.

For this test we just need to start the game and to see if the cars and trees move down, and after the test all was working how it should.

Test 3 – To see if everything is spawning randomly

How you could see on each screenshot all the trees and cars were in absolutely different positions and none of them got an algorithm of spawning on the map.

Test 4 – To make sure that Ambulance will move correctly

The Ambulance must move to the left/right/up/down by pressing W/A/S/D. I think all the screenshots that you can see on the top are a good evidence of it because in all these screenshots you can see that car is in different positions, this mean that all is working.

Here is the link for my game: https://www.greenfoot.org/scenarios/25745 . You can use it to visit the page with my game and test it if you want.

Suggest Improvements

As I said my game is still raw, but I want to extend it. Some of my friends have tested it and they told me what could I add to it.

  1. Scoreboard – A scoreboard will keep the players interests to this game and they will want after each lose to play again and again to beat their best score.
  2. Car Speed – Someone told me that I should add a boost for the car. For example, each 30 seconds it will load a super speed, and it will help you to get faster a higher score.
  3. Diversity of Actors and Sounds – It will be great to add other textures, not the default ones that are in greenfoot, and maybe to add 2 or 3 types of cars that will have different speed or functions. Sounds are also important in a game, my game has no sounds because I could not find any good sounds for me, same with textures, before quarantine I had some textures on the college computer but I lost them after this and couldn’t find again.
  4. Diversity of Modes – I have some ideas for gameplay, to do one for surviving and getting a high score and other for playing per 3 minutes for example, and to get how many points possible.

Produce user documentation for a computer game and
produce technical documentation for a computer game.

Specified game applications – My game is a browser game, so everyone can play it, you do not need a good PC for it. You can also download it and launch on your greenfoot app.

Purpose of Game – It was to demonstrate my skills and to see what can I do.

Operation of game – My game involves the players to drive and to survive on the road as much time as possible, they must not hit any cars or trees.

FAQ

How do I play? It is very simple for now, you just need to use W/A/S/D to move, with time I will update it and add other controls.

How do I lose? To lose you must just hit a car or a tree.

How do I restart? For this you have a “Restart” button, or you could reload the page if you are playing in browser.

Technical Documentation

Data Dictionary – A data dictionary allows us to store a list of
proposed field names and their respective types for the
program we are going to build.

Algorithm designs including control methods – A control
variable is a variable that always has the same value. It will not
change throughout the code.

Selection – This is for the times when you only want to run code
if conditions are met otherwise skip over that portion of code.

Iteration – This is for the times when you want the program to
run the same lines of code many times.

User interface method design – An example of it is the design that I’ve done for my game that I have demonstrated.

Action Charts and Tables – It is another thing that I’ve shown above, through them you can see the actions available for you in the game.

Data flow diagrams – This simply shows the flow of information
in any process or system.

Class and instance diagrams – These diagrams show how
classes relate to objects then instance variables and class
variables to methods.

Explain how the structure and design of a game can assist in
maintenance and capacity for extension.

Code Commenting

These comments are included in the code, but they are not compiled and displayed into the game. They are useful more for those who create the game. Some programmers use them but others don’t do that. An example of using the for programmers is when they write a part of code, and leave it for some time, it can become much more time than they expected, and before it the left a comment there, about what is doing that part of code, it is useful if you have a bad visual memory. In the code of my game you are not gonna see any comments like these, because it is not a big project for which I should leave comments in the code, I can remember what are responding for most of the parts of the code. There were even games where programmers left comments for the users that would like to see the code of the game, when the player saw the code they also could read the comments where they can find something interesting.

Variable Names and Naming Conventions

A well named variable name or function can save a lot of time and effort when coding as it is more obvious as to what the program is doing. A good variable name should describe what the variable is actually stored. For my game I’ve also used variables and classes with good names, I have chosen a name for each one that will remind me about what is this variable about. In my opinion it is better than commenting the code, you just need to name your variables so you will never forget what are those about. I prefer to name my variables correctly, with names that will remind me about the functions of the code, than to comment each part of the code.

Indenting and Layout

To help with the code visibility for making future extension a lot easier to day we use techniques such as indenting code to show how things work together and also to spot smaller and simpler mistakes to fox such as if there were missing brackets or semicolons.

Modularisation

Modularity refers to the concept of making multiple modules first and then linking and combining them to form a complete system. Modularity is also a feature of object oriented programming. When you break code up into small chunks, it’s easy to tell what each of those small chunks does, and then see how they all fit together. With regards to OOP, you can create classes and objects that would allow your code to be better organized.

Syntax and Semantics

In Java the syntax refers to how a line of code is structured or written. Each line must end with a semi colon for it to compile. If it doesn’t the entire program will not work. This is why to make improvements down the line understand the syntax becomes very important so that effective changed can be made.

Conclusion

In conclusion I can be sure that I’ve improved my skills in coding on Java, now I can develop a game, a simple one but with time I will be able to do something greater. About users feedback I can say that they are right and I was thinking to do the same, a scoreboard, sounds, textures. All of them liked the game but said that a scoreboard for this type of game is the thing that must be here. It was interesting to develop a game, to look for how to do some parts of the code, and fix the bugs, especially the moments when you don’t know what to do much time but finally you get the answer. Overall I feel like I have done a game that will help beginners to start their own game, they can take my idea or my game to see how have I done it and to try to modify it.