Assalamualaikum.WR.WB
baiklah di sini saya septian miswanto akan mencoba untuk mengshare apa yg telah saya buat, yaitu program sederhana gama TIC-TAC-TOE :)
I.
Tujuan
1. Meningkatkan
kemampuan berpikir logis
2. Mengetahui
kegunaan PictureBox di SharpDevelop
3. Dapat
mengunakan PictureBox dalam aplikasi windows Sederhana
II.
Dasar
Teori
Control PictureBox digunakan untuk menampilkan gambar dan memanipulasinya.
PictureBox dapat menangani berbagai macam format file gambar. Dalam praktikum
ini kita menggunakan PNG. Untuk mengisi PictureBox dengan gambar, kita tinggal load
gambarnya dengan menge-klik Properties Image-nya. Kemudian sesuaikan ukuran
Width dan Height nya sehingga gambar tidak terpotong.
III.
Praktikum
Gambar pada PictureBox bisa saling dicopy. Artinya gambar pada
instance pictureBox1 dapat kita copy-kan ke instance pictureBox2. Di sini kita
akan membuat permainan TicTacToe. Kita susun terlebih dahulu gambar kotak kosong
sebanyak 3x3 sebagai papan permainan. Kemudian tambahkan gambar lingkaran dan
gambar silang sebagai pemainnya. Gambar ini kita set properties Visible-nya
menjadi false. Semua gambar kita letakkan di PictureBox.
Inti
dari program ini adalah menunggu pemain untuk menempatkan pilihannya. Tiap
PictureBox kita tambahkan event onClick. Apabila salah satu di-klik, akan dicek
terlebih dahulu, apakah masih kosong atau tidak. Apabila kosong, maka pemain
boleh memilih kotak tersebut, artinya kita copy-kan simbol silang ke kotak
tersebut. Kemudian tinggal
di-cek,
apakah sudah ada yang berhasil membuat 3 segaris atau belum. Lalu giliran
komputer. Komputer akan memilih secara acak kotak yang kosong, kemudian
copy-kan simbol lingkaran ke kotak tersebut. Demikian terus bergantian antara
pemain dan komputer sampai semuanya terisi. Tapi apabila ada yang berhasil
membuat 3 segaris,
maka
dia dinyatakan sebagai pemenang.
IV.
Tugas
Tambahkan
kemampuan pada program tersebut sehingga komputer lebih sulit untuk dikalahkan.
Komputer tidak lagi memilih kotak kosong secara acak, namun terlebih dahulu mengecek
apakah dia ada peluang untuk membentuk 3 segaris (=menang) atau tidak. Apabila
tidak ada peluang tersebut, maka komputer harus menge-blok kemungkinan user
menang. Program untuk komputer yang sedikit lebih pandai, dapat anda ambil di learning
polibatam.
Dan inilah
praktikum dan tugas yang saya jadikan menjaji satu.
Ini adalah
tampilan awal/ tampilan form 1 :
Ini adalah
form loading sebelum memulai permainan. Format programnya :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void
timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value < 100)
{
progressBar1.Value += 2;
}
else if
(progressBar1.Value == 100)
{
timer1.Stop();
Form2 Form1 = new Form2();
Form1.Show();
this.Hide();
}
}
}
}
Ini adalah
tampilan form2:
Ini adalah
form untuk kita memaikan gamenya. Format programnya :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
string a, b, c;
private bool
playerTurn = false;
private Image x =
Properties.Resources.x;
private Image o =
Properties.Resources.o;
#region cek
kemenangan
private void
checkwin()//berbagai kemungkinan untuk menang dari
sebuah garis
{
// kemungkinan menang untuk X
if (pictureBox1.BackgroundImage == x &&
pictureBox5.BackgroundImage == x && pictureBox9.BackgroundImage == x)
{
MessageBox.Show("X WIN !!!");
New_Game();
return;
}
if (pictureBox1.BackgroundImage == x &&
pictureBox4.BackgroundImage == x && pictureBox7.BackgroundImage == x)
{
MessageBox.Show("X WIN !!!");
New_Game();
return;
}
if (pictureBox1.BackgroundImage == x &&
pictureBox2.BackgroundImage == x && pictureBox3.BackgroundImage == x)
{
MessageBox.Show("X WIN !!!");
New_Game();
return;
}
if (pictureBox3.BackgroundImage == x &&
pictureBox5.BackgroundImage == x && pictureBox7.BackgroundImage == x)
{
MessageBox.Show("X WIN !!!");
New_Game();
return;
}
if (pictureBox4.BackgroundImage == x &&
pictureBox5.BackgroundImage == x && pictureBox6.BackgroundImage == x)
{
MessageBox.Show("X WIN !!!");
New_Game();
return;
}
if (pictureBox7.BackgroundImage == x &&
pictureBox8.BackgroundImage == x && pictureBox9.BackgroundImage == x)
{
MessageBox.Show("X WIN !!!");
New_Game();
return;
}
if (pictureBox2.BackgroundImage == x &&
pictureBox5.BackgroundImage == x && pictureBox8.BackgroundImage == x)
{
MessageBox.Show("X WIN !!!");
New_Game();
return;
}
if (pictureBox3.BackgroundImage == x &&
pictureBox6.BackgroundImage == x && pictureBox9.BackgroundImage == x)
{
MessageBox.Show("X WIN !!!");
New_Game();
return;
}
// kemungkinan mengang untuk O
if (pictureBox1.BackgroundImage == o &&
pictureBox5.BackgroundImage == o && pictureBox9.BackgroundImage == o)
{
MessageBox.Show("O WIN
!!!");
New_Game();
return;
}
if (pictureBox1.BackgroundImage == o &&
pictureBox4.BackgroundImage == o && pictureBox7.BackgroundImage == o)
{
MessageBox.Show("O WIN
!!!");
New_Game();
return;
}
if (pictureBox1.BackgroundImage == o &&
pictureBox2.BackgroundImage == o && pictureBox3.BackgroundImage == o)
{
MessageBox.Show("O WIN
!!!");
New_Game();
return;
}
if (pictureBox3.BackgroundImage == o &&
pictureBox5.BackgroundImage == o && pictureBox7.BackgroundImage == o)
{
MessageBox.Show("O WIN
!!!");
New_Game();
return;
}
if (pictureBox4.BackgroundImage == o &&
pictureBox5.BackgroundImage == o && pictureBox6.BackgroundImage == o)
{
MessageBox.Show("O WIN
!!!");
New_Game();
return;
}
if (pictureBox7.BackgroundImage == o &&
pictureBox8.BackgroundImage == o && pictureBox9.BackgroundImage == o)
{
MessageBox.Show("O WIN
!!!");
New_Game();
return;
}
if (pictureBox2.BackgroundImage == o &&
pictureBox5.BackgroundImage == o && pictureBox8.BackgroundImage == o)
{
MessageBox.Show("O WIN
!!!");
New_Game();
return;
}
if (pictureBox3.BackgroundImage == o &&
pictureBox6.BackgroundImage == o && pictureBox9.BackgroundImage == o)
{
MessageBox.Show("O WIN
!!!");
New_Game();
return;
}
// jika tidak ada yang menang(Draw)
if (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)
{
MessageBox.Show("X and O DRAW
!!!");// jika tidak ada yang menang akan
menampilkan message ini
New_Game();
return;
}
}
#endregion
#region vs
computer hard
private void
comhard()// giliran computer bermain atau kemungkinan
computer menang dan menghalang kita untuk menang
{
if (pictureBox1.BackgroundImage == o &&
pictureBox2.BackgroundImage == o)
{
if (pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();//fungsi untuk mengecek kemenangan
return;
}
}
if (pictureBox2.BackgroundImage == o &&
pictureBox3.BackgroundImage == o)
{
if (pictureBox1.BackgroundImage == null)
{
pictureBox1.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == o &&
pictureBox3.BackgroundImage == o)
{
if (pictureBox2.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == o &&
pictureBox7.BackgroundImage == o)
{
if (pictureBox4.BackgroundImage == null)
{
pictureBox4.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == o &&
pictureBox4.BackgroundImage == o)
{
if (pictureBox7.BackgroundImage == null)
{
pictureBox7.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox4.BackgroundImage == o &&
pictureBox7.BackgroundImage == o)
{
if (pictureBox1.BackgroundImage == null)
{
pictureBox1.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == o &&
pictureBox9.BackgroundImage == o)
{
if (pictureBox8.BackgroundImage == null)
{
pictureBox8.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == o &&
pictureBox5.BackgroundImage == o)
{
if (pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == o &&
pictureBox9.BackgroundImage == o)
{
if (pictureBox1.BackgroundImage == null)
{
pictureBox1.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == o &&
pictureBox8.BackgroundImage == o)
{
if (pictureBox2.BackgroundImage == null)
{
pictureBox2.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox2.BackgroundImage == o &&
pictureBox8.BackgroundImage == o)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == o &&
pictureBox8.BackgroundImage == o)
{
if (pictureBox2.BackgroundImage == null)
{
pictureBox2.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == o &&
pictureBox6.BackgroundImage == o)
{
if (pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == o &&
pictureBox9.BackgroundImage == o)
{
if (pictureBox6.BackgroundImage == null)
{
pictureBox6.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox6.BackgroundImage == o &&
pictureBox9.BackgroundImage == o)
{
if (pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox4.BackgroundImage == o &&
pictureBox5.BackgroundImage == o)
{
if (pictureBox6.BackgroundImage == null)
{
pictureBox6.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox4.BackgroundImage == o &&
pictureBox6.BackgroundImage == o)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == o &&
pictureBox6.BackgroundImage == o)
{
if (pictureBox4.BackgroundImage == null)
{
pictureBox4.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox7.BackgroundImage == o &&
pictureBox8.BackgroundImage == o)
{
if (pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox7.BackgroundImage == o &&
pictureBox9.BackgroundImage == o)
{
if (pictureBox8.BackgroundImage == null)
{
pictureBox8.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox8.BackgroundImage == o &&
pictureBox9.BackgroundImage == o)
{
if (pictureBox7.BackgroundImage == null)
{
pictureBox7.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == o &&
pictureBox5.BackgroundImage == o)
{
if (pictureBox7.BackgroundImage == null)
{
pictureBox7.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == o &&
pictureBox7.BackgroundImage == o)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == o &&
pictureBox7.BackgroundImage == o)
{
if (pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == o &&
pictureBox7.BackgroundImage == o)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
}
//
untuk x
if (pictureBox1.BackgroundImage == x &&
pictureBox2.BackgroundImage == x)
{
if (pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox2.BackgroundImage == x &&
pictureBox3.BackgroundImage == x)
{
if (pictureBox1.BackgroundImage == null)
{
pictureBox1.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == x &&
pictureBox3.BackgroundImage == x)
{
if (pictureBox2.BackgroundImage == null)
{
pictureBox2.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == x &&
pictureBox7.BackgroundImage == x)
{
if (pictureBox4.BackgroundImage == null)
{
pictureBox4.BackgroundImage
= o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == x &&
pictureBox4.BackgroundImage == x)
{
if (pictureBox7.BackgroundImage == null)
{
pictureBox7.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox4.BackgroundImage == x &&
pictureBox7.BackgroundImage == x)
{
if (pictureBox1.BackgroundImage == null)
{
pictureBox1.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == x &&
pictureBox9.BackgroundImage == x)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == x &&
pictureBox5.BackgroundImage == x)
{
if
(pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox2.BackgroundImage == x &&
pictureBox5.BackgroundImage == x)
{
if (pictureBox8.BackgroundImage == null)
{
pictureBox8.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == x &&
pictureBox8.BackgroundImage == x)
{
if (pictureBox2.BackgroundImage == null)
{
pictureBox2.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == x &&
pictureBox6.BackgroundImage == x)
{
if (pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == x &&
pictureBox9.BackgroundImage == x)
{
if (pictureBox6.BackgroundImage == null)
{
pictureBox6.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox4.BackgroundImage == x &&
pictureBox5.BackgroundImage == x)
{
if (pictureBox6.BackgroundImage == null)
{
pictureBox6.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox4.BackgroundImage == x &&
pictureBox6.BackgroundImage == x)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == x &&
pictureBox6.BackgroundImage == x)
{
if (pictureBox4.BackgroundImage == null)
{
pictureBox4.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox7.BackgroundImage == x &&
pictureBox8.BackgroundImage == x)
{
if (pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox7.BackgroundImage == x &&
pictureBox9.BackgroundImage == x)
{
if (pictureBox8.BackgroundImage == null)
{
pictureBox8.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox8.BackgroundImage == x &&
pictureBox9.BackgroundImage == x)
{
if (pictureBox7.BackgroundImage == null)
{
pictureBox7.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == x &&
pictureBox5.BackgroundImage == x)
{
if (pictureBox7.BackgroundImage == null)
{
pictureBox7.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == x &&
pictureBox7.BackgroundImage == x)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == x &&
pictureBox7.BackgroundImage == x)
{
if (pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox6.BackgroundImage == x && pictureBox9.BackgroundImage
== x)
{
if (pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
//3
if (pictureBox1.BackgroundImage == x &&
pictureBox9.BackgroundImage == x && pictureBox5.BackgroundImage == o)
{
if (pictureBox2.BackgroundImage == null)
{
pictureBox2.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == x &&
pictureBox7.BackgroundImage == x && pictureBox5.BackgroundImage == o)
{
if (pictureBox2.BackgroundImage == null)
{
pictureBox2.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == o &&
pictureBox8.BackgroundImage == x)
{
if (pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == o &&
pictureBox2.BackgroundImage == x)
{
if (pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox2.BackgroundImage == x &&
pictureBox7.BackgroundImage == x)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == x &&
pictureBox7.BackgroundImage == x)
{
if
(pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == x &&
pictureBox9.BackgroundImage == x)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
//jika tidak ada yg terpilih yg di atas
if (pictureBox1.BackgroundImage == null)
{
pictureBox1.BackgroundImage = o;
checkwin();
return;
}
if (pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
if (pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
if (pictureBox6.BackgroundImage == null)
{
pictureBox6.BackgroundImage = o;
checkwin();
return;
}
}
#endregion
#region
vs computer easy
private void comeasy()
{
if (pictureBox1.BackgroundImage == o &&
pictureBox2.BackgroundImage == o)
{
if (pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox2.BackgroundImage == o &&
pictureBox3.BackgroundImage == o)
{
if (pictureBox8.BackgroundImage == null)
{
pictureBox8.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == o &&
pictureBox3.BackgroundImage == o)
{
if (pictureBox7.BackgroundImage == null)
{
pictureBox7.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == o &&
pictureBox7.BackgroundImage == o)
{
if (pictureBox6.BackgroundImage == null)
{
pictureBox6.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == o &&
pictureBox4.BackgroundImage == o)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox4.BackgroundImage == o &&
pictureBox7.BackgroundImage == o)
{
if (pictureBox1.BackgroundImage == null)
{
pictureBox1.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == o &&
pictureBox9.BackgroundImage == o)
{
if (pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == o &&
pictureBox5.BackgroundImage == o)
{
if (pictureBox2.BackgroundImage == null)
{
pictureBox2.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == o &&
pictureBox9.BackgroundImage == o)
{
if (pictureBox1.BackgroundImage == null)
{
pictureBox1.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == o &&
pictureBox8.BackgroundImage == o)
{
if (pictureBox2.BackgroundImage == null)
{
pictureBox2.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox2.BackgroundImage == o &&
pictureBox8.BackgroundImage == o)
{
if
(pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == o &&
pictureBox8.BackgroundImage == o)
{
if (pictureBox4.BackgroundImage == null)
{
pictureBox4.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == o &&
pictureBox6.BackgroundImage == o)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == o &&
pictureBox9.BackgroundImage == o)
{
if (pictureBox6.BackgroundImage == null)
{
pictureBox6.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox6.BackgroundImage == o &&
pictureBox9.BackgroundImage == o)
{
if (pictureBox7.BackgroundImage == null)
{
pictureBox7.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox4.BackgroundImage == o &&
pictureBox5.BackgroundImage == o)
{
if (pictureBox8.BackgroundImage == null)
{
pictureBox8.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox4.BackgroundImage == o &&
pictureBox6.BackgroundImage == o)
{
if (pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == o &&
pictureBox6.BackgroundImage == o)
{
if
(pictureBox8.BackgroundImage == null)
{
pictureBox8.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox7.BackgroundImage == o &&
pictureBox8.BackgroundImage == o)
{
if (pictureBox6.BackgroundImage == null)
{
pictureBox6.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox7.BackgroundImage == o &&
pictureBox9.BackgroundImage == o)
{
if (pictureBox8.BackgroundImage == null)
{
pictureBox8.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox8.BackgroundImage == o &&
pictureBox9.BackgroundImage == o)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == o &&
pictureBox5.BackgroundImage == o)
{
if (pictureBox4.BackgroundImage == null)
{
pictureBox4.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == o &&
pictureBox7.BackgroundImage == o)
{
if (pictureBox6.BackgroundImage == null)
{
pictureBox6.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == o &&
pictureBox7.BackgroundImage == o)
{
if (pictureBox2.BackgroundImage == null)
{
pictureBox2.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == o &&
pictureBox7.BackgroundImage == o)
{
if
(pictureBox1.BackgroundImage == null)
{
pictureBox1.BackgroundImage = o;
checkwin();
return;
}
}
//
untuk x
if (pictureBox1.BackgroundImage == x &&
pictureBox2.BackgroundImage == x)
{
if (pictureBox4.BackgroundImage == null)
{
pictureBox4.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox2.BackgroundImage == x &&
pictureBox3.BackgroundImage == x)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == x &&
pictureBox3.BackgroundImage == x)
{
if (pictureBox6.BackgroundImage == null)
{
pictureBox6.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == x &&
pictureBox7.BackgroundImage == x)
{
if (pictureBox4.BackgroundImage == null)
{
pictureBox4.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == x &&
pictureBox4.BackgroundImage == x)
{
if (pictureBox8.BackgroundImage == null)
{
pictureBox8.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox4.BackgroundImage == x &&
pictureBox7.BackgroundImage == x)
{
if (pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == x &&
pictureBox9.BackgroundImage == x)
{
if (pictureBox2.BackgroundImage == null)
{
pictureBox2.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox1.BackgroundImage == x &&
pictureBox5.BackgroundImage == x)
{
if (pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox2.BackgroundImage == x &&
pictureBox5.BackgroundImage == x)
{
if (pictureBox8.BackgroundImage == null)
{
pictureBox8.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == x &&
pictureBox8.BackgroundImage == x)
{
if (pictureBox2.BackgroundImage == null)
{
pictureBox2.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == x &&
pictureBox6.BackgroundImage == x)
{
if (pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == x &&
pictureBox9.BackgroundImage == x)
{
if (pictureBox6.BackgroundImage == null)
{
pictureBox6.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox4.BackgroundImage == x &&
pictureBox5.BackgroundImage == x)
{
if (pictureBox6.BackgroundImage == null)
{
pictureBox6.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox4.BackgroundImage == x &&
pictureBox6.BackgroundImage == x)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == x &&
pictureBox6.BackgroundImage == x)
{
if (pictureBox4.BackgroundImage == null)
{
pictureBox4.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox7.BackgroundImage == x &&
pictureBox8.BackgroundImage == x)
{
if (pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox7.BackgroundImage == x &&
pictureBox9.BackgroundImage == x)
{
if (pictureBox2.BackgroundImage == null)
{
pictureBox2.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox8.BackgroundImage == x &&
pictureBox9.BackgroundImage == x)
{
if (pictureBox7.BackgroundImage == null)
{
pictureBox7.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == x &&
pictureBox5.BackgroundImage == x)
{
if (pictureBox6.BackgroundImage == null)
{
pictureBox6.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == x &&
pictureBox7.BackgroundImage == x)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == x &&
pictureBox7.BackgroundImage == x)
{
if (pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox6.BackgroundImage == x &&
pictureBox9.BackgroundImage == x)
{
if (pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage = o;
checkwin();
return;
}
//3
if (pictureBox1.BackgroundImage == x &&
pictureBox9.BackgroundImage == x && pictureBox5.BackgroundImage == o)
{
if (pictureBox2.BackgroundImage == null)
{
pictureBox2.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox3.BackgroundImage == x &&
pictureBox7.BackgroundImage == x && pictureBox5.BackgroundImage == o)
{
if (pictureBox2.BackgroundImage == null)
{
pictureBox2.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == o && pictureBox8.BackgroundImage
== x)
{
if (pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == o &&
pictureBox2.BackgroundImage == x)
{
if (pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox2.BackgroundImage == x &&
pictureBox7.BackgroundImage == x)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox5.BackgroundImage
= o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == x &&
pictureBox7.BackgroundImage == x)
{
if (pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
if (pictureBox5.BackgroundImage == x &&
pictureBox9.BackgroundImage == x)
{
if (pictureBox5.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
}
//jika tidak ada yg terpilih yg di atas
if (pictureBox1.BackgroundImage == null)
{
pictureBox1.BackgroundImage = o;
checkwin();
return;
}
if (pictureBox3.BackgroundImage == null)
{
pictureBox3.BackgroundImage = o;
checkwin();
return;
}
if (pictureBox9.BackgroundImage == null)
{
pictureBox9.BackgroundImage = o;
checkwin();
return;
}
if (pictureBox6.BackgroundImage == null)
{
pictureBox6.BackgroundImage = o;
checkwin();
return;
}
}
#endregion
private void pictureclick(ref PictureBox
thePictureBox)// Tini adalah fungsi event clik untuk
pictureBox
{
if (radioButton1.Checked)//untuk
player vs comhard
{
if (thePictureBox.BackgroundImage == null)
{
thePictureBox.BackgroundImage = x;//X pemain
yg pertama mulai
checkwin();//pengecekan menang
comhard();
}
else
MessageBox.Show(" picture box sudah terisi !!!");//menampilkan pesan apabila pictureBox sudah terisi
}
else if
(radioButton2.Checked) //untuk player vs comeasy
{
if (thePictureBox.BackgroundImage == null)
{
thePictureBox.BackgroundImage = x;
checkwin();
comeasy();
}
else
MessageBox.Show(" picture box sudah terisi !!!");
}
else if
(radioButton3.Checked)//untuk multiplayer
{
if (thePictureBox.BackgroundImage == null)
{
if (playerTurn == false)
{
thePictureBox.BackgroundImage = x;//pemain
pertama yg mulai
playerTurn = true;
checkwin();
}
else
{
thePictureBox.BackgroundImage = o;//pemain
kedua
playerTurn = false;
checkwin();
}
}
else
{
MessageBox.Show("picture box sudah terisi");
}
}
else
{
MessageBox.Show("pilih tipe permainan");
}
}
#region fungsi new game / reset
private void
New_Game()
{
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;
radioButton1.Checked
= false;
radioButton2.Checked = false;
radioButton3.Checked = false;
}
#endregion
private void
button1_Click(object sender, EventArgs e)
{
New_Game();
}
private void timer1_Tick(object sender, EventArgs
e)// format untuk running text
{
a
= label1.Text;
b
= a.Substring(a.Length - 1, 1);
c
= a.Substring(0, a.Length - 1);
label1.Text = b + c;
}
#region picturebox
private void
pictureBox1_Click_1(object sender, EventArgs e)
{
pictureclick(ref pictureBox1);
}
private void
pictureBox2_Click_1(object sender, EventArgs e)
{
pictureclick(ref pictureBox2);
}
private void
pictureBox3_Click_1(object sender, EventArgs e)
{
pictureclick(ref pictureBox3);
}
private void
pictureBox4_Click_1(object sender, EventArgs e)
{
pictureclick(ref pictureBox4);
}
private void
pictureBox5_Click_1(object sender, EventArgs e)
{
pictureclick(ref pictureBox5);
}
private void
pictureBox6_Click_1(object sender, EventArgs e)
{
pictureclick(ref pictureBox6);
}
private void
pictureBox7_Click_1(object sender, EventArgs e)
{
pictureclick(ref pictureBox7);
}
private void
pictureBox8_Click_1(object sender, EventArgs e)
{
pictureclick(ref pictureBox8);
}
private void
pictureBox9_Click_1(object sender, EventArgs e)
{
pictureclick(ref pictureBox9);
}
#endregion
}
}
terimakasih, mungkin hanya ini ya dapat saya share :)




No comments:
Post a Comment