PROGRAMLAR SCRIPTLER KODLAR HABERLER İLETİŞİM
Arşivimde ara Program Script Hazırkod
Ara
ÜYELİK AKTİVASYONU HABERLER WEBMASTER ARAÇLARI SİTENE EKLE REKLAM VER İLETİŞİM
    Program : 12788 Adet  |  Script : 5 Adet  |  Hazırkod : 2748 Adet  |  Haber : 211 Adet
HAZIR KODLAR
ADO.NET - ADO
ASP
ASP.NET
C #
C ++
CGI
COMPONENT
DATABASE
DELPHI
FLASH
HTML
JAVA - JSP
JAVA SCRIPT
PASCAL
PERL
PHP
VISUAL BASIC
VISUAL BASIC.NET
WML
XML
 
İNTERNET PAKETLERİ
ADSL BAŞVURU
SMİLE BAŞVURU
TURK.NET BAŞVURU
TELLCOM İNTERNET PAKETİ
SUPERONLİNE BAŞVURU
TTNET İŞYERİM PAKETİ
TTNET VİTAMİN PAKETİ
 
SCRIPTLER
AJAX SCRIPTLERI
ASP SCRIPTLERI
ASP.NET SCRIPTLERI
C # SCRIPTLERI
C ++ SCRIPTLERI
DELPHI SCRIPTLERI
JAVA - JSP SCRIPTLERI
JAVA SCRIPT SCRIPTLERI
MIRC - IRC SCRIPTLERI
PERL SCRIPTLERI
PHP SCRIPTLERI
VISUAL BASIC SCRIPTLERI
 
İSTATİSTİK
Tekil [Bugün] : 66  
Çoğul [Bugün] : 375  
Tekil [Genel] : 232.420  
Çoğul [Genel] : 2.601.841  
 


Hangman
Açıklama :
oyunu asmaca Adam
 
ARKADAŞINA GÖNDER HEPSİNİ SEÇ

/*
* Created on 19.Eki.2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author ZURGUN
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

// the class hangman extends JApplet and implements ActionListener
public class Hangman extends JApplet implements ActionListener {

final int WON = 0, LOST = 1, CONTINUE = 2; // the variables are used in defining the game status

boolean no1Gate = false; // these variables are used to make sure that the if statement that
boolean no2Gate = false; // checks the random number enters the if statemenet only once.
boolean no3Gate = false; // In other words these variables are used to make sure that the
boolean no4Gate = false; // won counter is incremented only once even if it enters the "if" more than once

int gameStatus = CONTINUE; // game status declaration

int limbCounter = 5; // limb counter that'll be decremented if the player makes a wrong guess

int correctCounter = 0; // correct counter will be incremented if the player makes a correct guess

int randomNumber = 0; // initialization of the random number

int number1 ; // initialization of digits of the number to be guessed
int number2 ;
int number3 ;
int number4 ;

// GUI components that will be used
JLabel limbCount, randomLabel;
JTextField no1Field, no2Field, no3Field, no4Field, limbCountField, randomField;
JButton guessButton;


//set up GUI components and generate the random number that'll be guessed
public void init()
{
// obtain content pane and change its layout to Flowlayout
Container container = getContentPane();
container.setLayout(new FlowLayout());

// create label and text field for the GUI


no1Field = new JTextField(5);
no1Field.setEditable(false);
container.add(no1Field);
no1Field.setText("*");

no2Field = new JTextField(5);
no2Field.setEditable(false);
container.add(no2Field);
no2Field.setText("*");

no3Field = new JTextField(5);
no3Field.setEditable(false);
container.add(no3Field);
no3Field.setText("*");

no4Field = new JTextField(5);
no4Field.setEditable(false);
container.add(no4Field);
no4Field.setText("*");

guessButton = new JButton(" Guess Next Digit Randomly");
guessButton.addActionListener(this);
container.add(guessButton);

limbCount = new JLabel(" Limb Counter");
container.add(limbCount);
limbCountField = new JTextField(5);
limbCountField.setEditable(false);
limbCountField.setText(Integer.toString(5));
container.add(limbCountField);

randomLabel = new JLabel(" Your guess is:");
container.add(randomLabel);
randomField = new JTextField(5);
randomField.setEditable(false);
container.add(randomField);
randomField.setText("");

// generation of random numbers
number1 = 1 + (int)(Math.random()*9);
number2 = (int)(Math.random()*10);
number3 = (int)(Math.random()*10);
number4 = (int)(Math.random()*10);

// System.out.println("" + number1 + number2 + number3 + number4); ==> this can be used to trace the corecctness of the code from the execution console

} //end method init

// process one guess
public void actionPerformed(ActionEvent hangmanEvent){



randomNumber = randomGuess(); // call to the method randomGuess that generates a random number
// System.out.println("" + randomNumber); ==> this can be used to trace the correctness of the code


// check if the guess is correct and check if it is entered before. increment as needed

if (randomNumber == number1 || randomNumber == number2 || randomNumber == number3 || randomNumber == number4){

if(randomNumber == number1 && no1Gate == false){
gameStatus = CONTINUE;
no1Field.setText(Integer.toString(number1));
no1Gate = true;
correctCounter ++;
}

if(randomNumber == number2 && no2Gate == false){
gameStatus = CONTINUE;
no2Field.setText(Integer.toString(number2));
no2Gate = true;
correctCounter ++;
}

if(randomNumber == number3 && no3Gate == false){
gameStatus = CONTINUE;
no3Field.setText(Integer.toString(number3));
no3Gate = true;
correctCounter ++;
}

if(randomNumber == number4 && no4Gate == false){
gameStatus = CONTINUE;
no4Field.setText(Integer.toString(number4));
no4Gate = true;
correctCounter ++;
}}

// if a wrong guess is made decrement the limb counter.
else{
gameStatus = CONTINUE;
limbCounter --;
limbCountField.setText(Integer.toString(limbCounter));
}

// if limbcounter is zero game status is LOST
if(limbCounter == 0){
gameStatus = LOST;
}

// if correct counter is 4 game status is WON
if (correctCounter >= 4){
gameStatus = WON;
}

displayMessage(); // call method displayMessage


} //end of action performed

// display the according message looking at the game status
public void displayMessage(){
if(gameStatus == CONTINUE)
showStatus("Click 'Guess Next Digit Randomly' again to make a guess");
else{
if (gameStatus == WON){
showStatus("You won the game. Click 'Guess Next Digit Randomly' to play again");
restart(); // call to the method restart
}
else{
showStatus("You lost the game. Click 'Guess Next Digit Randomly' to play again");
restart(); // call to the method restart
}
}

} // end of display message

// the method rendomGuess generates a random number for the guess of the user
public int randomGuess(){

int x = (int) (Math.random()*10);
randomField.setText(Integer.toString(x)); // user sees what he guessed by the randomGuess
return x;
}// end of method randomGuess


// the method restart, restarts the game
public void restart(){

randomField.setText("");

no1Field.setText("*");
no2Field.setText("*");
no3Field.setText("*");
no4Field.setText("*");

correctCounter = 0;

limbCounter = 5;
limbCountField.setText(Integer.toString(5));

number1 = 1 + (int)(Math.random()*9);
number2 = (int)(Math.random()*10);
number3 = (int)(Math.random()*10);
number4 = (int)(Math.random()*10);

no1Gate = false;
no2Gate = false;
no3Gate = false;
no4Gate = false;

}

} // end of class Hangman




Hazırkod Tanıtımı
oyunu asmaca Adam
İzlenme  84 Kez
Hit  0 Adet
HAZIRKOD HAKKINDA YAPILAN YORUMLAR
Yorum eklemek için tıklayınız
 
Bu hazırkod hakkında herhangi bir yorum yapılmamış!
 
KULLANICI GİRİŞİ
   
GİRİŞ
   
Yeni Kayıt
Yardım
 
GOOGLE REKLAMLARI
 
ETİKETLER
20917
ssk prim sorgulama
562953
Morphyre
Ehliyet Sınav Sonuçları
trabzonemlak
1011599
Sayısal Loto Sonuçları
42/01/49149
1301190
1139963
Açık Öğretim Sınav Sonuçları
6770
hotkey driver for sony vg...
CINAR SiTESi
1020924
T.C. Kimlik No Sorgulama
1058847
SELiN
phped 5.9 serial
1014016
314515
SSK Prim Sorgulama
is KOLU
220229
 
Sitede yayınlanan dosya ve dökümanların kullanımları sonucu oluşabilecek zararlardan duzenle.com sorumlu değildir.
duzenle.com sitesinde yayınlanan tüm program, script ve benzeri dökümanları kurmadan yada çalıştırmadan önce virüs taramasından geçiriniz.

PROGRAMLAR SCRIPTLER KODLAR HABERLER İLETİŞİM