Archive for the ‘JAVA WORLD’ Category

Game RPG yang sederhana

karna saya suka bermain game terutama game rpg..eh tiba2 game ini mengimaginasi saya untuk iseng buat game sendiri walaupun sederhana…hahahah….cuma berantemnya doang….

 

import java.io.*;
class rpg
{
public int att;
public int hp;

public static void main(String args[]) throws IOException
{
rpg Human = new rpg();
rpg Monster = new rpg();
Human.att = 90;
Human.hp= 1000;
Monster.att = 100;
Monster.hp= 500;
int n =1;

System.out.println(“Pilih karakter : “);
System.out.println(“1. Human”);
System.out.println(“2. Monster”);
System.out.print(“Pilih : “);
int input=(new Integer((new BufferedReader(new InputStreamReader(System.in))).readLine()).intValue());
switch(input)
{
case 1 : System.out.println(“Human”);
System.out.println(“Serangan : “+Human.att);
System.out.println(“Darah    : “+Human.hp);
break;
case 2 : System.out.println(“Monster”);
System.out.println(“Serangan : “+Monster.att);
System.out.println(“Darah    : “+Monster.hp);
break;
default : System.out.println(“Salah”);
System.exit(0);
break;
}
if(input ==1 )
{
System.out.println(“You VS Monster”);
do
{
if( Human.hp <= 0)
{
System.out.println(“You are the Loser”);
System.exit(0);
}
else if( Monster.hp <= 0)
{
System.out.println(“You are the Winner”);
System.exit(0);
}

System.out.println(“===========Turn “+n+”==================”);
System.out.println(“Musuh : Monster”);
System.out.println(“hp : “+Monster.hp+” Serangan : “+Monster.att);
System.out.println(“You : Human”);
System.out.println(“hp : “+Human.hp+” Serangan : “+Human.att);
System.out.println(“1. Attack”);
System.out.println(“2. Kabur”);
System.out.print(“Pilih Mode : “);
int pilih = (new Integer((new BufferedReader(new InputStreamReader(System.in))).readLine()).intValue());
switch(pilih)
{
case 1 : Monster.hp = Monster.hp – Human.att;
Human.hp = Human.hp – Monster.att;
break;
case 2 : System.out.println(“GAME OVER”);
System.exit(0);
break;
default : System.out.println(“Salah”);
System.exit(0);
break;

}
System.out.println(“Human Attack Monster with “+Human.att+” Damage”);
System.out.println(“Monster Attack u with “+Monster.att+” Damage”);
System.out.println(“\n”);
n++;
}while(n<10);
}else
{
System.out.println(“You VS Human”);
do
{
if( Human.hp <= 0)
{
System.out.println(“You are the winner”);
System.exit(0);
}
else if( Monster.hp <= 0)
{
System.out.println(“You are the loser”);
System.exit(0);
}

System.out.println(“===========Turn “+n+”==================”);
System.out.println(“Musuh : Human”);
System.out.println(“hp : “+Human.hp+” Serangan : “+Human.att);
System.out.println(“You : Monster”);
System.out.println(“hp : “+Monster.hp+” Serangan : “+Monster.att);
System.out.println(“1. Attack”);
System.out.println(“2. Kabur”);
System.out.print(“Pilih Mode : “);
int pilih = (new Integer((new BufferedReader(new InputStreamReader(System.in))).readLine()).intValue());
switch(pilih)
{
case 1 : Human.hp = Human.hp – Monster.att;
Monster.hp = Monster.hp – Human.att;
break;
case 2 : System.out.println(“GAME OVER”);
System.exit(0);
break;
default : System.out.println(“Salah”);
System.exit(0);
break;

}
System.out.println(“Monster Attack Human with “+Monster.att+” Damage”);
System.out.println(“Human Attack u with “+Human.att+” Damage”);
System.out.println(“\n”);
n++;
}while(n<10);

}
}
}

Advertisements

Program menampilkan waktu sekarang

pertama kita buat program class untuk memanggil waktu yang akan kita panggil pada class kedua..sebut saja ini adalah Waktu.java berikut source codenya :

 

import java.util.Calendar;

public class Waktu {

private Calendar calendar = Calendar.getInstance();

public String getHari() {

if (calendar.get(Calendar.DAY_OF_WEEK) == 1) {
return “Minggu”;
} else if (calendar.get(Calendar.DAY_OF_WEEK) == 2) {
return “Senin”;
} else if (calendar.get(Calendar.DAY_OF_WEEK) == 3) {
return “Selasa”;
} else if (calendar.get(Calendar.DAY_OF_WEEK) == 4) {
return “Rabu”;
} else if (calendar.get(Calendar.DAY_OF_WEEK) == 5) {
return “Kamis”;
} else if (calendar.get(Calendar.DAY_OF_WEEK) == 6) {
return “Jumat”;
} else {
return “Sabtu”;
}
}

public String getBulan() {

if (calendar.get(Calendar.MONTH) == 0) {
return “Januari”;
} else if (calendar.get(Calendar.MONTH) == 1) {
return “Februari”;
} else if (calendar.get(Calendar.MONTH) == 2) {
return “Maret”;
} else if (calendar.get(Calendar.MONTH) == 3) {
return “April”;
} else if (calendar.get(Calendar.MONTH) == 4) {
return “Mei”;
} else if (calendar.get(Calendar.MONTH) == 5) {
return “Juni”;
} else if (calendar.get(Calendar.MONTH) == 6) {
return “Juli”;
} else if (calendar.get(Calendar.MONTH) == 7) {
return “Agustus”;
} else if (calendar.get(Calendar.MONTH) == 8) {
return “September”;
} else if (calendar.get(Calendar.MONTH) == 9) {
return “Oktober”;
} else if (calendar.get(Calendar.MONTH) == 10) {
return “November”;
} else {
return “Desember”;
}
}

public String getWaktu() {

String hari;
String tanggal;
String bulan;
String tahun;
hari = getHari();
tanggal = String.valueOf(calendar.get(Calendar.DAY_OF_MONTH));
bulan = getBulan();
tahun = String.valueOf(calendar.get(Calendar.YEAR));
return (hari + “, ” + tanggal + ” ” + bulan + ” ” + tahun);

}
}

==============================================================================

kemudian kita buat satu class lagi yaitu test waktu untuk menampilkan waktu sekarang…kita sebut testwaktu.java berikut source code nya :

 

public class TestWaktu {

public static void main(String[] args) {
Waktu waktu = new Waktu();
System.out.println(“Hari dan tanggal sekarang : ” + waktu.getWaktu());
}
}

 

Mudah kan…….

HalloWorld

public class HalloWorld
{
public static void main(String[]args)
{
System.out.println(“Hallo Mahasiswa”);
System.out.println(“Program pertama dengan Java”);
}

}