Cov txheej txheem:

Sau Koj Tus Kheej Tic Tac Toe Game hauv Java: 6 Kauj Ruam
Sau Koj Tus Kheej Tic Tac Toe Game hauv Java: 6 Kauj Ruam

Video: Sau Koj Tus Kheej Tic Tac Toe Game hauv Java: 6 Kauj Ruam

Video: Sau Koj Tus Kheej Tic Tac Toe Game hauv Java: 6 Kauj Ruam
Video: Python! Tuples 2024, Hlis ntuj nqeg
Anonim
Sau Koj Tus Kheej Tic Tac Toe Game hauv Java
Sau Koj Tus Kheej Tic Tac Toe Game hauv Java

Kuv paub tseeb tias koj txhua tus paub txog kev ua si classic ntawm Tic Tic Toe. Txij li thaum kuv kawm ntawv theem pib, Tic Tac Toe yog qhov kev ua si nrov uas kuv siv los ua si nrog kuv cov phooj ywg. Kuv ib txwm tau nyiam nrog qhov yooj yim ntawm qhov kev ua si. Hauv kuv lub xyoo tshiab, kuv chav kawm Java xav kom kuv tsim kev ua si, sib tham sib tham. Tic Tac Toe yog thawj tus uas tuaj rau kuv lub siab. Nws coj kuv ob peb lub lis piam los txhim kho txoj haujlwm no thiab kuv xav qhia qhov no nrog koj txhua tus. Vam tias koj txhua tus tau tsim txoj haujlwm no thiab qhia rau kuv paub koj txoj kev taug.

Zoo siab Tic Tac Toeing:)

Nov yog cov kauj ruam yooj yim los sau koj tus kheej tic tac ntiv taw program hauv java.

Kauj Ruam 1: Nkag Siab Qib Siab

Nkag Siab Cov Qib Siab
Nkag Siab Cov Qib Siab

Nov yog teeb tsa:

Tic tac ntiv taw ntiv taw pawg sawv cev los ntawm ob seem cim cim. Muaj 3 kab thiab 3 kab, suav 0 txog 2 txhua txoj kev.

Muaj 2 tus neeg ua si. Tus neeg siv thiab lub computer. Tus neeg ua si muaj ib qho kev nqis tes ua. Xaiv lub xov tooj zoo tshaj tom ntej ntawm lub rooj tsavxwm.

Muaj qhov kev twv txiaj uas tswj hwm cov kauj ruam tom ntej thiab kev txiav txim siab.

Nov yog qhov Tic Tac Toe program ua haujlwm li cas:

1. Pib lub rooj tsavxwm

2. Rov ua cov kauj ruam hauv qab no hauv lub voj:

a Tau txais kev txav los ntawm tus neeg siv (Tus neeg siv yuav tsum nkag mus rau hauv cov qauv ntsuas kab [kab] [kab ntawv])

b. Txheeb xyuas tias qhov kev txav mus los siv tau

c. Kos tus xaiv txav lub rooj tsavxwm

d. Txheeb xyuas qhov xwm txheej game. So ntawm lub voj yog tias qhov kev ua si tau xaus.

e. Tau txav los ntawm Computer

f. Txheeb xyuas qhov xwm txheej game. So ntawm lub voj yog tias qhov kev ua si tau xaus.

3. Tshaj tawm qhov txiaj ntsig game (Tus neeg siv yeej/ Computer Yeej/ Kos)

Cov duab txuas nrog qhia cov qib theem siab no. Thov saib txuas nrog java project rau tag nrho cov cai.

Kauj ruam 2: Rub tawm IDE

Rub tawm IDE
Rub tawm IDE
Rub tawm IDE
Rub tawm IDE

Rub tawm thiab Nruab IDE (Kev Sib Tham Sib Tham Ib puag ncig). Dab noj hnub yog IDE siv hauv qhov kev qhia no thiab tuaj yeem siv qhov txuas hauv qab no:

www.eclipse.org/downloads/

Xaiv cov version uas zoo tshaj rau koj lub operating system thiab teeb tsa.

Txuag dab noj hnub kom xav tau qhov chaw thiab xaiv chaw ua haujlwm.

Kauj Ruam 3: Teeb Teeb Dab Neeg

Teeb Teeb Dab Neeg
Teeb Teeb Dab Neeg
Teeb Teeb Dab Neeg
Teeb Teeb Dab Neeg
Teeb Teeb Dab Neeg
Teeb Teeb Dab Neeg

1) Thaum Eclipse qhib, lub vijtsam khoob yuav tsum tshwm sim.

2) Tsim Tus Txheej Txheem Java Tshiab: Mus rau Cov Ntaub Ntawv> Tshiab> Java Project.

3) Lub Npe Cov Ntaub Ntawv ("Tic_Tac_Toe").

4) Tsim Chav Kawm Java Tshiab Sab hauv tsim Java Project: Mus rau Tic_Tac_Toe> src> Tshiab> Chav Kawm.

5) Ib chav kawm khoob yuav tsum qhib.

Kauj Ruam 4: Tsim Koj Tic_Tac_Toe Class Raws Li Qhia Hauv Qab

Tsim Koj Tic_Tac_Toe Class Raws Li Qhia Hauv Qab
Tsim Koj Tic_Tac_Toe Class Raws Li Qhia Hauv Qab

Pib ntxiv cov cai rau koj chav kawm Tic_Tac_Toe raws li qhia hauv cov ntawv txuas.

Siab yog lub ntsiab lus tseem ceeb ntawm txoj haujlwm thiab yuav npaj chav kawm li cas:

Chav Kawm TicTacToe {

Board board = char tshiab [2] [2];

InitializeBoard ();

thaum (muaj tseeb)

{

Txoj hlua userMove = getUserMove ();

markMoveOnBoard ('X', userMove);

gameStatus = getGameStatus ('X', pawg thawj coj saib);

yog (! gameStatus.equals ("InProgress"))

{

tawg;

}

Txoj hlua computerMove = getComputerMove ();

markMoveOnBoard ('O', computerMove);

gameStatus = getGameStatus ('O', board);

yog (! gameStatus.equals ("InProgress"))

{

tawg;

}

}

}

Kauj ruam 5: Khiav qhov program

Khiav qhov Program
Khiav qhov Program

Khiav qhov program los ntawm txhaj Run -> Run menu (lossis los ntawm Ctrl + F11) thiab pib ua si Tic Tac Toe game.

Koj yuav ua si tawm tsam lub computer. Thaum hais kom tus neeg siv txav mus, muab koj qhov kev txav mus los hauv hom [kab] [kab ntawv]

Piv txwv li: [2] [1] sawv cev rau kab thib peb thiab kab thib ob.

Ua si kom txog thaum qhov kev ua si xaus (Tus Neeg Siv Yeej, Khoos Phis Tawj Yeej lossis Kos).

Kauj Ruam 6: Tso Tawm

Tso zis
Tso zis

Saib daim duab txuas li cas cov zis zoo li thaum koj ua si.

Koj tau kawm tiav yuav ua li cas sau tic tac ntiv taw program hauv java!

Pom zoo: