Judul : Source Code Game Hang Man Sederhana manggunakan JAVA
link : Source Code Game Hang Man Sederhana manggunakan JAVA
Source Code Game Hang Man Sederhana manggunakan JAVA
Sahabat Bloggers, ini aku ngepostin materi kuliahku sob, siapa tau ada yang membutuhkannya.hehe
Ini adalah source code dari game Hang Man, versi yang sederhana banget untuk memenuhi tugas dari dosen Pemrograman Lanjut Materi Object Oriented Programming.
ada dua class dalam source code saya ini, mulai dari Class Main, Class untuk gambar, dan untuk Gamenya sendiri.
1. Class Main
package hangmanpemrogramanlanjut;
/**
*
* @author Hermawan Kusuma
* @nama HermawanKusuma
* @nim 125150200111094
*/
import java.io.*;
import java.util.*;
public class Main {
static int pilih;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
String apa;
Scanner a = new Scanner(System.in);
System.out.println(" ||---Selamat Datang dalam Permainan HangMan---|| ");
boolean loop = true;
PertanyaanHangMan coba = new PertanyaanHangMan();
coba.nama();
while (loop == true) {
coba.Pilih();
coba.Rule();
coba.Jawaban();
coba.Pertanyaan();
System.out.println("Masih mau lanjut ? (Tekan N/n untuk mengakhiri game) : ");
apa = a.nextLine();
if (apa.contains("n") || apa.contains("N")) {
break;
}
}
}
}
2. Class untuk game, pertanyaan, gambar, dan rulenya
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hangmanpemrogramanlanjut;
/**
*
* @author Hermawan Kusuma
*/
import java.util.*;
import java.io.*;
public class PertanyaanHangMan extends Main {
static String nama;
public static int Pilih() {
pilih = (int) (Math.random() * 29);
return pilih;
}
public static String nama() {
Scanner input = new Scanner(System.in);
System.out.println("Masukkan Nama user : ");
nama = input.nextLine();
return nama;
}
public void Rule() throws IOException {
int armor = 3;
Scanner input = new Scanner(System.in);
String gambarAwal = HangMan(0);
String gambarKalah = HangMan(1);
String gambarMenang = HangMan(2);
String kuis;
String kunci = Jawaban();
String blank = "";
for (int i = 0; i < kunci.length(); i++) {
blank += "*";
}
char[] ubahblank = blank.toCharArray();
char[] ubahtanya = kunci.toCharArray();
do {
if (armor == 0) {
System.out.println();
System.out.println(gambarKalah);
System.out.println(nama + ",You Lose");
System.out.println("Correct Answer : " + Jawaban());
break;
} else {
System.out.println(gambarAwal);
System.out.println();
System.out.println("Armor tersisa = " + armor);
}
System.out.println("Pertanyaan = " + Pertanyaan());
for (int a = 0; a < blank.length(); a++) {
System.out.print(ubahblank[a] + " ");
}
System.out.println("");
System.out.println(nama + " Coba Tebak hurufnya =");
kuis = input.next();
char letter = kuis.charAt(0);
if (kunci.contains(kuis)) {
for (int i = 0; i < kunci.length(); i++) {
if (ubahtanya[i] == letter) {
ubahblank[i] = letter;
}
}
} else {
armor -= 1;
}
String lihat = new String(ubahblank);
if (lihat.contains(kunci)) {
System.out.println();
System.out.println("Jawaban Anda Benar = "+ Jawaban());
System.out.println(gambarMenang);
System.out.println("Congratulations " + nama + " You Win");
break;
}
} while (armor <= 3);
}
public static String Jawaban() throws IOException {
BufferedReader input = null;
StringBuffer in = new StringBuffer();
try {
String tugas = null;
input = new BufferedReader(new FileReader("Kunci.txt"));
} catch (FileNotFoundException ea) {
System.out.println("File tidak ditemukan");
}
String Jawaban[] = new String[29];
for (int i = 0; i < Jawaban.length; i++) {
Jawaban[i] = input.readLine();
}
input.close();
return Jawaban[pilih];
}
public static String Pertanyaan() throws IOException {
BufferedReader input = null;
StringBuffer in = new StringBuffer();
try {
String tugas = null;
input = new BufferedReader(new FileReader("Soal.txt"));
} catch (FileNotFoundException ea) {
System.out.println("File tidak ditemukan");
}
String Pertanyaan[] = new String[29];
for (int i = 0; i < Pertanyaan.length; i++) {
Pertanyaan[i] = input.readLine();
}
input.close();
return Pertanyaan[pilih];
}
public static String HangMan(int a) {
String gambar[] = new String[3];
gambar[0] = "=====================\n[]\t \t[]\n[]\tO \t[]\n[] /|\\\t[]\n[] / \\\t[]"; //awal
gambar[1] = "=====================\n[]\t| \t[]\n[]\tO \t[]\n[] /|\\\t[]\n[] / \\\t[]\n[]\t\t []"; //kalah
gambar[2] = "======================\n[]\t \t[]\n[]\t\\O/\t[]\n[] | \t[]\n[] / \\\t[]"; //menang
return gambar[a];
}
}
Terimakasih, semoga bermanfaat bagi anda :)
Ini adalah source code dari game Hang Man, versi yang sederhana banget untuk memenuhi tugas dari dosen Pemrograman Lanjut Materi Object Oriented Programming.
ada dua class dalam source code saya ini, mulai dari Class Main, Class untuk gambar, dan untuk Gamenya sendiri.
1. Class Main
package hangmanpemrogramanlanjut;
/**
*
* @author Hermawan Kusuma
* @nama HermawanKusuma
* @nim 125150200111094
*/
import java.io.*;
import java.util.*;
public class Main {
static int pilih;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
String apa;
Scanner a = new Scanner(System.in);
System.out.println(" ||---Selamat Datang dalam Permainan HangMan---|| ");
boolean loop = true;
PertanyaanHangMan coba = new PertanyaanHangMan();
coba.nama();
while (loop == true) {
coba.Pilih();
coba.Rule();
coba.Jawaban();
coba.Pertanyaan();
System.out.println("Masih mau lanjut ? (Tekan N/n untuk mengakhiri game) : ");
apa = a.nextLine();
if (apa.contains("n") || apa.contains("N")) {
break;
}
}
}
}
2. Class untuk game, pertanyaan, gambar, dan rulenya
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hangmanpemrogramanlanjut;
/**
*
* @author Hermawan Kusuma
*/
import java.util.*;
import java.io.*;
public class PertanyaanHangMan extends Main {
static String nama;
public static int Pilih() {
pilih = (int) (Math.random() * 29);
return pilih;
}
public static String nama() {
Scanner input = new Scanner(System.in);
System.out.println("Masukkan Nama user : ");
nama = input.nextLine();
return nama;
}
public void Rule() throws IOException {
int armor = 3;
Scanner input = new Scanner(System.in);
String gambarAwal = HangMan(0);
String gambarKalah = HangMan(1);
String gambarMenang = HangMan(2);
String kuis;
String kunci = Jawaban();
String blank = "";
for (int i = 0; i < kunci.length(); i++) {
blank += "*";
}
char[] ubahblank = blank.toCharArray();
char[] ubahtanya = kunci.toCharArray();
do {
if (armor == 0) {
System.out.println();
System.out.println(gambarKalah);
System.out.println(nama + ",You Lose");
System.out.println("Correct Answer : " + Jawaban());
break;
} else {
System.out.println(gambarAwal);
System.out.println();
System.out.println("Armor tersisa = " + armor);
}
System.out.println("Pertanyaan = " + Pertanyaan());
for (int a = 0; a < blank.length(); a++) {
System.out.print(ubahblank[a] + " ");
}
System.out.println("");
System.out.println(nama + " Coba Tebak hurufnya =");
kuis = input.next();
char letter = kuis.charAt(0);
if (kunci.contains(kuis)) {
for (int i = 0; i < kunci.length(); i++) {
if (ubahtanya[i] == letter) {
ubahblank[i] = letter;
}
}
} else {
armor -= 1;
}
String lihat = new String(ubahblank);
if (lihat.contains(kunci)) {
System.out.println();
System.out.println("Jawaban Anda Benar = "+ Jawaban());
System.out.println(gambarMenang);
System.out.println("Congratulations " + nama + " You Win");
break;
}
} while (armor <= 3);
}
public static String Jawaban() throws IOException {
BufferedReader input = null;
StringBuffer in = new StringBuffer();
try {
String tugas = null;
input = new BufferedReader(new FileReader("Kunci.txt"));
} catch (FileNotFoundException ea) {
System.out.println("File tidak ditemukan");
}
String Jawaban[] = new String[29];
for (int i = 0; i < Jawaban.length; i++) {
Jawaban[i] = input.readLine();
}
input.close();
return Jawaban[pilih];
}
public static String Pertanyaan() throws IOException {
BufferedReader input = null;
StringBuffer in = new StringBuffer();
try {
String tugas = null;
input = new BufferedReader(new FileReader("Soal.txt"));
} catch (FileNotFoundException ea) {
System.out.println("File tidak ditemukan");
}
String Pertanyaan[] = new String[29];
for (int i = 0; i < Pertanyaan.length; i++) {
Pertanyaan[i] = input.readLine();
}
input.close();
return Pertanyaan[pilih];
}
public static String HangMan(int a) {
String gambar[] = new String[3];
gambar[0] = "=====================\n[]\t \t[]\n[]\tO \t[]\n[] /|\\\t[]\n[] / \\\t[]"; //awal
gambar[1] = "=====================\n[]\t| \t[]\n[]\tO \t[]\n[] /|\\\t[]\n[] / \\\t[]\n[]\t\t []"; //kalah
gambar[2] = "======================\n[]\t \t[]\n[]\t\\O/\t[]\n[] | \t[]\n[] / \\\t[]"; //menang
return gambar[a];
}
}
Terimakasih, semoga bermanfaat bagi anda :)
Ainsi l'article Source Code Game Hang Man Sederhana manggunakan JAVA
C'est l'article Source Code Game Hang Man Sederhana manggunakan JAVA cette fois, j'espère que cela pourra vous être bénéfique à tous. eh bien, à bientôt dans un autre article post.
Vous lisez maintenant l'article Source Code Game Hang Man Sederhana manggunakan JAVA avec l'adresse du lien https://indonesianne.blogspot.com/2013/04/source-code-game-hang-man-sederhana.html
0 Response to "Source Code Game Hang Man Sederhana manggunakan JAVA"
Posting Komentar