# Everyday Game Coding

I am a simply game-addicted guy
a little bit special about me is that I start learning ‘Java coding’
so here I am, start coding a simple game step by step everyday for you ❤ :) (Using Java of cause)

Requirements

### Day 1 : Let’s play “Hangman”!

Everybody love hangman, then why not let it be our first game !

#### Game’s rules

This Hangman will be a bit different with the others, no drawing head, leg,..
We will just set how many turns can the player guess, and they will lose when they spend all their turns.

Remember, every programs are not gonna pop out of nowhere. All comes from your head!

• We are going to need 2 Strings Arrays. The Strings we use as key words, and the String of underscores (_ _ _ _ _) we use to show the player during the game.
• We are going to use lots of ‘for’ loops.
so let me explain for you a bit.
Example : ‘for loop command’
for(int x = 0;x<10;x++){…}
means we set integer x ,values it zero, then do command in the {…}
plus x = 1 when end of command then start doing all the command
in the {…}again until x<10
(until x = 9 in this case because the highest integer below 10 = 9)
• we will show the player with underscore (_) and replace it with the correct character they input. If they input the wrong one then remain underscore.

#### Here goes the program!

• package everydaygames is your folder name the file is located in.
• import java.util.*;
You have to import some data for this game ,I will tell you more about it later.

Now comes to the body part, the heart of the program!

• the word I choose for today is “Java”
• this two Strings is the part you have to customize before you play the game.
• the quantity of the underscores in hangman2[] and quantity of the characters in hangman[] has to be the same
• for(String s : hangman2)
is the new way to use ‘for’
this means the command in the for loop will run for every Strings there are in the hangman2 Array.
• I set the command to print underscore
• “\t” is for tab, try running the program without it and see what happens
• now we should get _ _ _ _ on the Output screen
• let’s make another for loop here
for(int count=1; count<=quantity; count++)
the quantity is for how many times you allow the player to try to input
in this case I values it 10.
• I create ‘quantity’ variable because it is easier for the programmer to customize the data later ,the programmer can customize three variable on the top.
• Scanner reader = new Scanner(System.in)
This “reader” is our new function ‘Scanner’ to make an input command
this where we need ‘import java.util.*; in the header
is the command where the player input String into y
the number refer to how many times the player input the letter
then the player can input the letter
this will run for a loop for 10(quantity) times
• “\n” is for the new line
• hangman.length
is the length of hangman Array
• for in a for ! The program will run the inner for first until it’s done then the outter for.
• the inner for is for comparing the player’s answer and the keyword if it’s correct then…
• hangman2[b]=y;
this mean now the String number ‘b’ in hangman2 Array now keep the value of ‘y’ variable
• ** int x [] ={1,2,3,4,5}
x[0] = 1
x[1] = 2
x[2] = 3
x[3] = 4
x[4] = 5
• x++ means x=x+1
x is for counting how many characters the player answer correctly
if x=hangman’s length then it means the player correct it all
that make the player win
• equals in programming is not “=” but “==”
• break;
command that break out of every loop
• now we creating the condition for winning and losing
• for(String s2 : hangman2)

{System.out.print(s2+”\t”);}

is for print out every members of hangman2[] after player input a character
so this has to be in the
for(int count=1;count<=quantity;count++}

• what if the player put the same character! He will ruin our program!!
• create String z to keep the value of y at the end of the loop to compare with the new value of y
if they are the same then means the player input the same character
count = count -1 // this make the program will not count the same character as a new one
x = x-1 // if the player put 4 same correct character then he can not win
(ex. j j j j)

#### What you can improve

• Decorate the program,
give the instruction
• Try to use easier way than mine.
Keep it in mind, there are various ways to code!
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.