oke gak panjang lebar, kali ini saya akan membuat sebuah tutorial tentang game tictactoe, pasti udah pada tau kan? game yang mirip dengan permainan SOS kok :).
oke pertama-tama kita membutuhkan alat-alat tempur untuk membuat program ini, seperti :
1. Sharp Develop atau Visual Studio berapa aja, disini saya menggunakan Visual Studio 2012.
2. internet (untuk Mencari Referensi)
3. dll .... :D
2. internet (untuk Mencari Referensi)
3. dll .... :D
oke, saat membuka visual studio, pilih Windows Form, dan kasih nama project sesuai keinginan anda .
dan design lah sebuah kotak 3x3 .
disini saya menggunakan PictureBox, dan kalian juga dapat menggunakan Tool yang lain, seperti label, button, dll, sesuai seleera dan perintah dosen aja ....
buat design standar seperti ini :
dan design lah sebuah kotak 3x3 .
disini saya menggunakan PictureBox, dan kalian juga dapat menggunakan Tool yang lain, seperti label, button, dll, sesuai seleera dan perintah dosen aja ....
buat design standar seperti ini :
untuk propertiesnya bisa di lihat di postingan sebelumnya .
cara merubah dan memainkan isi properties.
dan berikut adalah source programnya :
dan jika sudah ini adalah saat Play, dan player1 adalah pemenangnya :
cara merubah dan memainkan isi properties.
dan berikut adalah source programnya :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Games_Tic_Tac_Toe_easy_Vs_Ai
{
public partial class Form1 : Form
{
public bool status = true;
public Form1()
{
InitializeComponent();
}
Image gambarX = Properties.Resources.x;
Image gambarY = Properties.Resources.Orkut_logo;
int pic1 = 0, pic2 = 0, pic3 = 0, pic4 = 0, pic5 = 0,pic6 = 0, pic7 = 0, pic8 = 0, pic9 = 0;// kondisi awal semua program
int score_pic1 = 0, score_pic2 = 0, score_pic3 = 0, score_pic4 = 0,score_pic5 = 0, score_pic6 = 0, score_pic7 = 0, score_pic8 = 0, score_pic9 = 0;//kondisi awal score
private void btnRESET_Click(object sender, EventArgs e)
{
pictureBox1.BackgroundImage = null;
pictureBox2.BackgroundImage = null;
pictureBox3.BackgroundImage = null;
pictureBox4.BackgroundImage = null;
pictureBox5.BackgroundImage = null;
pictureBox6.BackgroundImage = null;
pictureBox7.BackgroundImage = null;
pictureBox8.BackgroundImage = null;
pictureBox9.BackgroundImage = null;
pic1 = pic2 = pic3 = pic4 = pic5 = pic6 = pic7 = pic8 = pic9 = 0;
score_pic1 = score_pic2 = score_pic3 = score_pic4 = score_pic5 = score_pic6 = score_pic7 = score_pic8 = score_pic9 = 0;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
if (pic1 == 0)
{
score_pic1++;
pic1++;
pictureBox1.BackgroundImage = gambarX;
}
else if (pic1 == 2)
{
MessageBox.Show("Maaf Kolom Sudah Terisi :)");
}
proses_program();
scorenya();
}
private void pictureBox2_Click(object sender, EventArgs e)
{
if (pic2 == 0)
{
score_pic2++;
pic2++;
pictureBox2.BackgroundImage = gambarX;
}
else if (pic2 == 2)
{
MessageBox.Show("Maaf Kolom Sudah Terisi :)");
}
proses_program();
scorenya();
}
private void pictureBox3_Click(object sender, EventArgs e)
{
if (pic3 == 0)
{
score_pic3++;
pic3++;
pictureBox3.BackgroundImage = gambarX;
}
else if (pic3 == 2)
{
MessageBox.Show("Maaf Kolom Sudah Terisi :)");
}
proses_program();
scorenya();
}
private void pictureBox4_Click(object sender, EventArgs e)
{
if (pic4 == 0)
{
score_pic4++;
pic4++;
pictureBox4.BackgroundImage = gambarX;
}
else if (pic4 == 2)
{
MessageBox.Show("Maaf Kolom Sudah Terisi :)");
}
proses_program();
scorenya();
}
private void pictureBox5_Click(object sender, EventArgs e)
{
if (pic5 == 0)
{
score_pic5++;
pic5++;
pictureBox5.BackgroundImage = gambarX;
}
else if (pic5 == 2)
{
MessageBox.Show("Maaf Kolom Sudah Terisi :)");
}
proses_program();
scorenya();
}
private void pictureBox6_Click(object sender, EventArgs e)
{
if (pic6 == 0)
{
score_pic6++;
pic6++;
pictureBox6.BackgroundImage = gambarX;
}
else if (pic6 == 2)
{
MessageBox.Show("Maaf Kolom Sudah Terisi :)");
}
proses_program();
scorenya();
}
private void pictureBox7_Click(object sender, EventArgs e)
{
if (pic7 == 0)
{
score_pic7++;
pic7++;
pictureBox7.BackgroundImage = gambarX;
}
else if (pic7 == 2)
{
MessageBox.Show("Maaf Kolom Sudah Terisi :)");
}
proses_program();
scorenya();
}
private void pictureBox8_Click(object sender, EventArgs e)
{
if (pic8 == 0)
{
score_pic8++;
pic8++;
pictureBox8.BackgroundImage = gambarX;
}
else if (pic8 == 2)
{
MessageBox.Show("Maaf Kolom Sudah Terisi :)");
}
proses_program();
scorenya();
}
private void pictureBox9_Click(object sender, EventArgs e)
{
if (pic9 == 0)
{
score_pic9++;
pic9++;
pictureBox9.BackgroundImage = gambarX;
}
else if (pic9 == 2)
{
MessageBox.Show("Maaf Kolom Sudah Terisi :)");
}
proses_program();
scorenya();
}
void proses_program()
{
if (pic1 == 1)
{
inti_program();
pic1++;
}
else if (pic2==1)
{
inti_program();
pic2++;
}
else if (pic3==1)
{
inti_program();
pic3++;
}
else if (pic4==1)
{
inti_program();
pic4++;
}
else if (pic5==1)
{
inti_program();
pic5++;
}
else if (pic6==1)
{
inti_program();
pic6++;
}
else if (pic7 == 1)
{
inti_program();
pic7++;
}
else if (pic8 == 1)
{
inti_program();
pic8++;
}
else if (pic9 == 1)
{
inti_program();
pic9++;
}
}
void inti_program()
{
if (pic1 == 0)
{
pictureBox1.BackgroundImage = gambarY;
pic1 = pic1 + 2;
}
else if (pic2 == 0)
{
pictureBox2.BackgroundImage = gambarY;
pic2 = pic2 + 2;
}
else if (pic3 == 0)
{
pictureBox3.BackgroundImage = gambarY;
pic3 = pic3 + 2;
}
else if (pic4 == 0)
{
pictureBox4.BackgroundImage = gambarY;
pic4 = pic4 + 2;
}
else if (pic5 == 0)
{
pictureBox5.BackgroundImage = gambarY;
pic5 = pic5 + 2;
}
else if (pic6 == 0)
{
pictureBox6.BackgroundImage = gambarY;
pic6 = pic6 + 2;
}
else if (pic7 == 0)
{
pictureBox7.BackgroundImage = gambarY;
pic7 = pic7 + 2;
}
else if (pic8 == 0)
{
pictureBox8.BackgroundImage = gambarY;
pic8 = pic8 + 2;
}
else if (pic9 == 0)
{
pictureBox9.BackgroundImage = gambarY;
pic9 = pic9 + 2;
}
}
void hapus()
{
pictureBox1.BackgroundImage = null;
pictureBox2.BackgroundImage = null;
pictureBox3.BackgroundImage = null;
pictureBox4.BackgroundImage = null;
pictureBox5.BackgroundImage = null;
pictureBox6.BackgroundImage = null;
pictureBox7.BackgroundImage = null;
pictureBox8.BackgroundImage = null;
pictureBox9.BackgroundImage = null;
pic1=pic2=pic3=pic4=pic5=pic6=pic7=pic8=pic9=0;
score_pic1=score_pic2=score_pic3=score_pic4=score_pic5=score_pic6=score_pic7=score_pic8=score_pic9=0;
}
void scorenya()
{
if (score_pic1 == 1 && score_pic2== 1 && score_pic3==1)
{
MessageBox.Show("Player 1 WIN !!");
hapus();
}
if (score_pic4 == 1 && score_pic5== 1 && score_pic6==1)
{
MessageBox.Show("Player 1 WIN !!");
hapus();
}
if (score_pic7 == 1 && score_pic8== 1 && score_pic9==1)
{
MessageBox.Show("Player 1 WIN !!");
hapus();
}
if (score_pic1 == 1 && score_pic5== 1 && score_pic9==1)
{
MessageBox.Show("Player 1 WIN !!");
hapus();
}
if (score_pic3 == 1 && score_pic5== 1 && score_pic7==1)
{
MessageBox.Show("Player 1 WIN !!");
hapus();
}
if (score_pic1 == 1 && score_pic4== 1 && score_pic7==1)
{
MessageBox.Show("Player 1 WIN !!");
hapus();
}
if (score_pic2 == 1 && score_pic5== 1 && score_pic8==1)
{
MessageBox.Show("Player 1 WIN !!");
hapus();
}
if (score_pic3 == 1 && score_pic6== 1 && score_pic9==1)
{
MessageBox.Show("Player 1 WIN !!");
hapus();
}
}
}
}
dan jika sudah ini adalah saat Play, dan player1 adalah pemenangnya :
ini link youtube nya :
http://youtu.be/Q_-rleN2Itk
NB : lagi Proses Penguploadan :D
No comments:
Post a Comment