Using Arduino for some people it is difficult but once you follow the Nine simple steps below you can immediately understand how to use arduino very easily. First, you must have the Arduino board and USB cable. In this tutorial, I assume you are using an Arduino Uno, Arduino Duemilanove, Nano or Diecimila. second, you need to download Software Arduino. Third, Connect Board. Connect the Arduino board with the computer using a USB cable. Green LED (labeled PWR) will live. fourth, Drivers Installation You can verify that the drivers are installed by opening the Windows Device Manager (in the Hardware tab in the Control Panel - System). Search for "USB Serial Port" in the Ports, that's the Arduino board. fifth, Run Application Double click on the Arduino Arduino application (arduino.exe). sixth, Open Blink example. Open LED Blink program example: File> Examples> 1.Basics> Blink. seventh, select your board.You need to choose the option in the Tools menu> Board in accordance with the Arduino board is used. eighth, Select anda.Pilih serial port serial port used by your Arduino board from the Tools menu> Serial Port. Usually this is COM3 or higher (COM1 and COM2 usually reserved for serial port hardware). Finally, Upload upload program If successful there will be a message "Done uploading." which appears on the status bar.
Some time after the upload is complete, you can see the pin 13 (L) LED on the board start flickering (orange). If so, congratulations! You've successfully run the Arduino and its program successfully.
Selasa, 06 Oktober 2015
Senin, 05 Oktober 2015
My room is the best place
I live in small room. It is a room with size about 2,5 m2 with cream covered all the walls. In my room there are about a bed, a chest. in front of chest, there is bed. above the bed, there is towel hanger. at the corner of my room, there are cutlery. right next to cutlery, there are a computer and stick. above the PC, there is a box and on the box there is my equipment of campus.
My room is a clean and comfortable for living. Every morning, i always cleaned before go to campus. the refore my room always becomes the most favorite room for my friend. they are very fond of being in my room because the atmosphare which so comfortable. i know it is a very small room, but it is the best place i have ever seen.
Selasa, 29 September 2015
My room
I live in small room. It is a room with size about 2,5 m2 with cream covered all the walls. In my room there are about a bed, a chest. in front of chest, there is bed. above the bed, there is towel hanger. at the corner of my room, there are cutlery. right next to cutlery, there are a computer and stick. above the PC, there is a box and on the box there is my equipment of campus. indeed it is a small room, but i like living in here for wasting my spare time.
My room is a clean and comfortable for living. Every morning, i always cleaned before go to campus. the refore my room always becomes the most favorite room for my friend. they are very fond of being in my room because the atmosphare which so comfortable. i know it is a very small room, but it is the best place i have ever seen.
My room is a clean and comfortable for living. Every morning, i always cleaned before go to campus. the refore my room always becomes the most favorite room for my friend. they are very fond of being in my room because the atmosphare which so comfortable. i know it is a very small room, but it is the best place i have ever seen.
Minggu, 14 Juni 2015
Pratikum 10 – Komunikasi Ethernet
Assalamualaikum wr.wb ....
kembali lagi di blog saya mengenai pemograman c# pada Ms. visual c# 2010 kali ini saya akan menshare hasil pratikum saya pada minggu lalu mengenai Komunikasi Ethernet. Baik langsung saja kita mulai
kembali lagi di blog saya mengenai pemograman c# pada Ms. visual c# 2010 kali ini saya akan menshare hasil pratikum saya pada minggu lalu mengenai Komunikasi Ethernet. Baik langsung saja kita mulai
Komunikasi Ethernet merupakan salah satu jenis komunikasi yang paling sering ditemui saat ini. Penggunaannya juga beragam, bisa digunakan untuk komunikasi antar PC, PC dengan mikrokontroller, PC dengan PLC, PLC dengan PLC dan sebagainya.
Komunikasi Ethernet dapat menggunakan media berupa kabel maupun nirkabel. Media kabel yang digunakan biasanya berupa kabel UTP yang ditiap ujungnya terdapat konektor RJ45, sedangkan yang nirkabel biasanya memanfaatkan router wireless. Untuk mengenali tujuan pengiriman data, komunikasi ini menggunakan IP address dan port. IP Address dianalogikan sebagai kompleks perumahan, dan port dianalogikan sebagai nomor rumah. Jika IP Address dan port yang digunakan asal-asalan, maka paket data yang dikirimkan juga tidak akan pernah sampai ke device tujuan.
Pada komunikasi Ethernet terdapat 2 jenis protocol pengiriman data, yaitu TCP dan UDP. Kedua protocol tersebut memiliki kelebihan dan kekurangan masing-masing. Pada praktikum kali ini, kita akan membuat sebuah aplikasi chatting teks sederhana menggunakan protocol UDP.
Berikut langkah-langkah program :
1. Tentunya anda harus membuka Microsoft visual C# 2010.
2. Buatlah form desain seperti berikut ini :
3.Buatlah codingan seperti di bawah ini :
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;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace komunikasi_ethernet
{
public partial class Form1 : Form
{
delegate void AddMessage(string Message);
string username;
int port = 11000;
const string broadcastAddress=”192.168.0.255″;
UdpClient receivingClient = new UdpClient(11000);
UdpClient sendingClient;
Thread receivingThread;
{
public partial class Form1 : Form
{
delegate void AddMessage(string Message);
string username;
int port = 11000;
const string broadcastAddress=”192.168.0.255″;
UdpClient receivingClient = new UdpClient(11000);
UdpClient sendingClient;
Thread receivingThread;
public Form1()
{
InitializeComponent();
this.Load += new EventHandler (Form1_Load);
button1.Click += new EventHandler (button1_click);
{
InitializeComponent();
this.Load += new EventHandler (Form1_Load);
button1.Click += new EventHandler (button1_click);
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Focus();
InitializeSender();
InitializeReceive();
{
button1.Focus();
InitializeSender();
InitializeReceive();
}
private void InitializeSender()
{
sendingClient = new UdpClient(broadcastAddress, port);
sendingClient.EnableBroadcast = true;
}
private void InitializeSender()
{
sendingClient = new UdpClient(broadcastAddress, port);
sendingClient.EnableBroadcast = true;
}
private void InitializeReceive()
{
ThreadStart start = new ThreadStart(Receiver) ;
receivingThread = new Thread (start) ;
receivingThread.IsBackground=true;
receivingThread.Start();
}
{
ThreadStart start = new ThreadStart(Receiver) ;
receivingThread = new Thread (start) ;
receivingThread.IsBackground=true;
receivingThread.Start();
}
private void button1_click(object sender, EventArgs e)
{
button1.Text = button1.Text.TrimEnd();
if (!string.IsNullOrEmpty(button1.Text))
{
string toSend = “<” + Environment.MachineName + “>:” + button1.Text;
byte[] data = Encoding.ASCII.GetBytes(toSend);
sendingClient.Send(data, data.Length);
button1.Text = “”;
}
button1.Focus();
}
private void Receiver ()
{
IPEndPoint endpoint = new IPEndPoint (IPAddress.Any,port);
AddMessage messagedelegate= MessageReceived;
while (true)
{
byte[] data = receivingClient.Receive(ref endpoint);
string message = Encoding.ASCII.GetString(data);
Invoke(messagedelegate, message);
System.Console.Beep(1500, 300);
}
}
private void MessageReceived(string message)
{
richTextBox1.Text += message + “\n”;
}
}
}
{
button1.Text = button1.Text.TrimEnd();
if (!string.IsNullOrEmpty(button1.Text))
{
string toSend = “<” + Environment.MachineName + “>:” + button1.Text;
byte[] data = Encoding.ASCII.GetBytes(toSend);
sendingClient.Send(data, data.Length);
button1.Text = “”;
}
button1.Focus();
}
private void Receiver ()
{
IPEndPoint endpoint = new IPEndPoint (IPAddress.Any,port);
AddMessage messagedelegate= MessageReceived;
while (true)
{
byte[] data = receivingClient.Receive(ref endpoint);
string message = Encoding.ASCII.GetString(data);
Invoke(messagedelegate, message);
System.Console.Beep(1500, 300);
}
}
private void MessageReceived(string message)
{
richTextBox1.Text += message + “\n”;
}
}
}
5.lalu jalankan (F5) start debbugging
6.Coba ganti IP address dan port yang digunakan.
7.Compile aplikasi kemudian amati.
terimakasih sudah menyelpatkan diri untuk membaca postingan saya, kritik dan saran anda sangat berguna buat saya dan juga kemajuan blog ini kedepannya
wassalamualaikum wr.wb
Minggu, 31 Mei 2015
Serial Port Communication
Assalammualaikum Wr.Wb
Pada kesempatan kali ini saya ingin berbagi cara koneksi antar serial port, namun tanpa menggunakan hardware(antar aplikasi, dengan menggunakan aplikasi tambahan "Virtual Port"). Dalam kasus ini kita dapat mengirim dan menerima data sederhana(berupa text) antar serial port yang kemudian kita beri fungsi untuk mengontrol beberapa lampu LED, kita cukup menggunakan method Write dengan parameter berupa string yang akan dikirim dan diterima dalam bentuk string juga.
Pertama-tama, teman-teman bisa mengikuti seperti design dibawah ini :
Samakan semua fungsi dan even (source code) anda dengan dibawah ini, dibawah ini adalah versi full Code-nya :
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 Serial_port_communication
{
public partial class Form1 : Form
{
Image ON = Properties.Resources._2;
Image OFF = Properties.Resources._3;
public Form1()
{
InitializeComponent();
foreach (String PortKu in System.IO.Ports.SerialPort.GetPortNames())
{
comboBox1.Items.Add(PortKu);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
if (serialPort1.BytesToRead != 0)
{
textBox2.Text = (serialPort1.ReadExisting());
textBox2.AppendText(serialPort1.ReadExisting());
if (textBox2.Text.ToUpper() == "LAMPU1 ON" || textBox2.Text.ToUpper() == "ON LAMPU1")
{
lampu1.Image = ON;
}
if (textBox2.Text.ToUpper() == "LAMPU2 ON" || textBox2.Text.ToUpper() == "ON LAMPU2")
{
lampu2.Image = ON;
}
if (textBox2.Text.ToUpper() == "LAMPU3 ON" || textBox2.Text.ToUpper() == "ON LAMPU3")
{
lampu3.Image = ON;
}
///...........................................................................................
if (textBox2.Text.ToUpper() == "LAMPU1 OFF" || textBox2.Text.ToUpper() == "OFF LAMPU1")
{
lampu1.Image = OFF;
}
if (textBox2.Text.ToUpper() == "LAMPU2 OFF" || textBox2.Text.ToUpper() == "OFF LAMPU2")
{
lampu2.Image = OFF;
}
if (textBox2.Text.ToUpper() == "LAMPU3 OFF" || textBox2.Text.ToUpper() == "OFF LAMPU3")
{
lampu3.Image = OFF;
}
}
}
else { }
}
private void button_Open_Click(object sender, EventArgs e)
{
serialPort1.PortName = comboBox1.Text;
if (comboBox1.Text == "Port")
{
MessageBox.Show("Pilih Port Terlebih Dahulu", "Alpha System", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if (!serialPort1.IsOpen)
{
button_Open.BackColor = Color.Blue;
button_Open.Enabled = false;
button_Close.BackColor = Color.Red;
button_Close.Enabled = true;
serialPort1.Open();
}
else { }
}
}
private void button_Close_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
button_Close.BackColor = Color.Blue;
button_Close.Enabled = false;
button_Open.BackColor = Color.Red;
button_Open.Enabled = true;
serialPort1.Close();
}
else { }
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
if (serialPort1.IsOpen)
{
serialPort1.Write(textBox1.Text + " ");
}
else { }
}
}
private void textBox1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "Kirim Data")
{
textBox1.Text = "";
}
else { }
textBox1.ForeColor = Color.Maroon;
}
private void All_Lampu_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
PictureBox Pilih = (PictureBox)sender;
if (Pilih.Image == OFF)
{
serialPort1.Write(Pilih.Name + " hidup ");
Pilih.Image = ON;
}
else
{
serialPort1.Write(Pilih.Name + " mati ");
Pilih.Image = OFF;
}
}
else { }
}
private bool LetterOnly(System.Windows.Forms.KeyPressEventArgs e)
{
string strValid = "";
if (strValid.IndexOf(e.KeyChar) < 0 && !(e.KeyChar == Convert.ToChar(Keys.Back)))
{
return true;
}
else
{
return false;
}
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = LetterOnly(e);
}
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show("Maaf..... Output tidak dapat diubah !!!", "Alpha System", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void button1_Click(object sender, EventArgs e)
{
serialPort1.Write(textBox1.Text);
button1.BackColor = Color.Blue;
button1.Enabled = false;
button1.BackColor = Color.Red;
button1.Enabled = true;
}
}
}
Install Virtual Port terlebih dahulu, kemudian buatlah setidaknya satu pasang koneksi(COM1 dan COM2) dengan cara “Add pair”.
lalu jalankan aplikasi HTERM seperti ini, lalu setting COM berlawanan dengan COM yang terdapat pada visual lalu kemudian klik “connect”.
Sekarang jalankan Program……..
Pemahaman Form serial Port
Baiklah…,, Demikian sedeikit penjelasan yang dapat saya sampaikan, jika ada kesalahan saya mohon maaf. semoga ini bermanfaat bagi sahabat2 blogger
Input melalui HTerm “lampu2 on”, maka lampu pada LED akan menyala(orange)
Wassalammualaikum Wr.Wb
Pratikum 9 Serial Transmit data
Assalamualaikum wr.wb ....
kembali lagi di blog saya mengenai pemograman c# pada Ms. visual c# 2010 kali ini saya akan menshare hasil pratikum saya pada minggu lalu mengenai Serial Transmit Data. Baik langsung saja kita mulai
kembali lagi di blog saya mengenai pemograman c# pada Ms. visual c# 2010 kali ini saya akan menshare hasil pratikum saya pada minggu lalu mengenai Serial Transmit Data. Baik langsung saja kita mulai
1. Tentunya anda harus membuka Microsoft visual C# 2010.
2. Buatlah form desain seperti berikut ini :
3. lalu buatlah program dengan kode dibawaj ini :
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;
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 button1_Click(object sender, EventArgs e)
{
serialPort1.Write(textBox1.Text);
}
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
serialPort1.Write(textBox1.Text);
}
private void timer1_Tick(object sender, EventArgs e)
{
if (serialPort1.BytesToRead != 0)
{
textBox2.Text = serialPort1.ReadExisting();
}
}
{
if (serialPort1.BytesToRead != 0)
{
textBox2.Text = serialPort1.ReadExisting();
}
}
private void Form1_Load(object sender, EventArgs e)
{
serialPort1.Open();
}
{
serialPort1.Open();
}
}
}
}
Untuk program di arduino anda dapat ketikkan seperti di bawah ini :
4.Koneksikan Arduino ke computer, pilih port dan tipe Arduino terlebih dahulu.
5. Lalu klik tanda centang pada Arduino setelah itu tunggu samapai done uploading.
6. Jalankan aplikasi anda, dengan mengatur port serial sesuai dengan port Arduino yang terdeteksi pada computer.
7.Buka hyperterminal, kemudian amati data yang tampil pada hyperterminal saat anda mengirim data.
wasaalamualaikum wr.wb ..
Pratikum 8 Serial Receive Port
Assalamualaikum wr.wb ....
kembali lagi di blog saya mengenai pemograman c# pada Ms. visual c# 2010 Express terima kasih sudah kunjungi blog saya, kali ini seperti biasa saya akan membagikan ilmu tentang pemograman C# tentang SERIAL PORT
3.setelah itu Atur properties “Series” pada chart, sehingga muncul window baru
seperti dibawah ini
kembali lagi di blog saya mengenai pemograman c# pada Ms. visual c# 2010 Express terima kasih sudah kunjungi blog saya, kali ini seperti biasa saya akan membagikan ilmu tentang pemograman C# tentang SERIAL PORT
1.buka visual C# 2010
2. buatlah desain form seperti dibawah ini :
3.setelah itu Atur properties “Series” pada chart, sehingga muncul window baru
seperti dibawah ini
4.langsung saja mulai masuk ke pemogramannya
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 seri1
{
public partial class Form1 : Form
{
string rxString;
int[] lokasiY = new int[100];
public Form1()
{
InitializeComponent();
}
private Graphics objGraphic;
private void Form1_Load(object sender, EventArgs e)
{
objGraphic = CreateGraphics();
if (objGraphic == null)
return;
}
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == “Connect”)
{
button1.Text = “Disconnect”;
serialPort1.Open();
//richTextBox1.text = “”;
//a = 0;
}
else
{
button1.Text = “Connect”;
serialPort1.Close();
}
}
void SerialPort1DataReceived(object sender,System.IO.Ports.SerialDataReceivedEventArgs e)
{
rxString = serialPort1.ReadLine();
this.Invoke(new EventHandler(DisplayText));
}
private void DisplayText(object sender, EventArgs e)
{
richTextBox1.Text += rxString;
float tinggi = float.Parse(rxString);
tinggi = 179 – (tinggi / 1023 * 179);
// geser arraynya
for (int i = 0; i < 99; i++)
{
lokasiY[i] = lokasiY[i + 1];
}
lokasiY[99] = (int)tinggi;
}
private void timer1_Tick(object sender, EventArgs e)
{
Pen pena = new Pen(Color.Black);
int awalX = 0;
int titikMulaiX, titikMulaiY, titikAkhirX, titikAkhirY;
// hapus dulu semuanya
objGraphic.Clear(Color.White);
for (int i = 0; i < 99; i++)
{
titikMulaiX = awalX + i * 5;
titikMulaiY = lokasiY[i];
titikAkhirX = awalX + (i + 1) * 5;
titikAkhirY = lokasiY[i + 1];
objGraphic.DrawLine(pena, titikMulaiX, titikMulaiY, titikAkhirX, titikAkhirY);
}
}
}
}
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 seri1
{
public partial class Form1 : Form
{
string rxString;
int[] lokasiY = new int[100];
public Form1()
{
InitializeComponent();
}
private Graphics objGraphic;
private void Form1_Load(object sender, EventArgs e)
{
objGraphic = CreateGraphics();
if (objGraphic == null)
return;
}
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == “Connect”)
{
button1.Text = “Disconnect”;
serialPort1.Open();
//richTextBox1.text = “”;
//a = 0;
}
else
{
button1.Text = “Connect”;
serialPort1.Close();
}
}
void SerialPort1DataReceived(object sender,System.IO.Ports.SerialDataReceivedEventArgs e)
{
rxString = serialPort1.ReadLine();
this.Invoke(new EventHandler(DisplayText));
}
private void DisplayText(object sender, EventArgs e)
{
richTextBox1.Text += rxString;
float tinggi = float.Parse(rxString);
tinggi = 179 – (tinggi / 1023 * 179);
// geser arraynya
for (int i = 0; i < 99; i++)
{
lokasiY[i] = lokasiY[i + 1];
}
lokasiY[99] = (int)tinggi;
}
private void timer1_Tick(object sender, EventArgs e)
{
Pen pena = new Pen(Color.Black);
int awalX = 0;
int titikMulaiX, titikMulaiY, titikAkhirX, titikAkhirY;
// hapus dulu semuanya
objGraphic.Clear(Color.White);
for (int i = 0; i < 99; i++)
{
titikMulaiX = awalX + i * 5;
titikMulaiY = lokasiY[i];
titikAkhirX = awalX + (i + 1) * 5;
titikAkhirY = lokasiY[i + 1];
objGraphic.DrawLine(pena, titikMulaiX, titikMulaiY, titikAkhirX, titikAkhirY);
}
}
}
}
Jika program diatas berhasil dan tidak ada yang eror maka sambungin ARDUINO ke port computer/laptop lalu masuk ke software arduino untuk membuat program nya dan sertai potensio di luar untuk mengatur tegangan input yang diterima oleh C#. berikut program Arduino :
void setup()
{ Serial.begin(9600); }
void loop()
{ int sensorValue = analogRead(A1); delay(500); Serial.println(sensorValue, DEC); }
{ Serial.begin(9600); }
void loop()
{ int sensorValue = analogRead(A1); delay(500); Serial.println(sensorValue, DEC); }
6.jika tidak ada yang eror silahkan runningkan program nya.
Hasil runningan nya bila anda memutar potensio lebih besar nilainya maka grafik akan semakin merapat.
Terima kasih , semoga apa yang saya share ini berguna .
Wassalamualaikum wr.wb
Minggu, 03 Mei 2015
Membuat Game Tic Tac Toe menggunakan Ms. visual c# 2010 Express
Assalamualaikum wr.wb ..
kembali lagi di blog saya mengenai pemograman c# pada Ms. visual c# 2010 Express ..
Setelah Beberapa kali membuat aplikasi berbasis c#, maka kali ini kita akan memcoba membuat sebuah game sederhana berbasis C#. Game tersebut adalah Tic Tac Toe. game ini adalah game yang sangat simple dan termasuk game yang lama
pertama- tama siapkan terlebih dahulu:
1. Microsoft Visual Studio. bisa diganti dengan aplikasi sejenis yang memiliki bahasa pemograman c#.
1. Microsoft Visual Studio. bisa diganti dengan aplikasi sejenis yang memiliki bahasa pemograman c#.
2.Niat dan jangan lupa baca bismillah
langkah – langkah awalnya sama seperti post sebelumnya yaitu membuka aplikasi visual studio dan membuat project baru . setelah itu dapat mengikuti langkah-langkah dibawah ini:
1. Desainlah tampilan form menjadi seperti ini
2.klik kanan lalu klik view code dan buat program seperti dibawah ini tetapi nama properties dari setiap komponen di sesuaikan dengan yang teman-teman buat.
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
{
int play = 0;
int p1 = 0, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0, p7 = 0, p8 = 0, p9 = 0;
int input;
public Form1()
{
InitializeComponent();
}
void com_expert(int masukan)
{
if (masukan == 5) // ketika player memilih pictureBox 5
{
if (p2 == 0) // akan di tahan di pictureBox 2
{
if (play == 1)
{
pictureBox2.BackgroundImage = Properties.Resources.x;
p2 = 2; //tampilan sesuai pilihan
}
else
{
pictureBox2.BackgroundImage = Properties.Resources.o;
p2 = 1;
}
}
else if (p1 == 0)
{
if (play == 1)
{
pictureBox1.BackgroundImage = Properties.Resources.x;
p1 = 2;
}
else
{
pictureBox1.BackgroundImage = Properties.Resources.o;
p1 = 1;
}
}
else if (p3 == 0)
{
if (play == 1)
{
pictureBox3.BackgroundImage = Properties.Resources.x;
p3 = 2;
}
else
{
pictureBox3.BackgroundImage = Properties.Resources.o;
p3 = 1;
}
}
else if (p4 == 0)
{
if (play == 1)
{
pictureBox4.BackgroundImage = Properties.Resources.x;
p4 = 2;
}
else
{
pictureBox4.BackgroundImage = Properties.Resources.o;
p4 = 1;
}
}
else if (p6 == 0)
{
if (play == 1)
{
pictureBox6.BackgroundImage = Properties.Resources.x;
p6 = 2;
}
else
{
pictureBox6.BackgroundImage = Properties.Resources.o;
p6 = 1;
}
}
else if (p7 == 0 && p3 == 1 && p5 == 1)
{
if (play == 1)
{
pictureBox7.BackgroundImage = Properties.Resources.x;
p7 = 2;
}
else
{
pictureBox7.BackgroundImage = Properties.Resources.o;
p7 = 1;
}
}
else if (p8 == 0)
{
if (play == 1)
{
pictureBox8.BackgroundImage = Properties.Resources.x;
p8 = 2;
}
else
{
pictureBox8.BackgroundImage = Properties.Resources.o;
p8 = 1;
}
}
else if (p9 == 0)
{
if (play == 1)
{
pictureBox9.BackgroundImage = Properties.Resources.x;
p9 = 2;
}
else
{
pictureBox9.BackgroundImage = Properties.Resources.o;
p9 = 1;
}
}
}
if (masukan == 1)
{
if (p2 == 0)
{
if (play == 1)
{
pictureBox2.BackgroundImage = Properties.Resources.x;
p2 = 2;
}
else
{
pictureBox2.BackgroundImage = Properties.Resources.o;
p2 = 1;
}
}
}
if (masukan == 2)
{
if (p1 == 0)
{
if (play == 1)
{
pictureBox1.BackgroundImage = Properties.Resources.x;
p1 = 2;
}
else
{
pictureBox1.BackgroundImage = Properties.Resources.o;
p1 = 1;
}
}
else if (p3 == 0)
{
if (play == 1)
{
pictureBox3.BackgroundImage = Properties.Resources.x;
p3 = 2;
}
else
{
pictureBox3.BackgroundImage = Properties.Resources.o;
p3 = 1;
}
}
else if (p5 == 0)
{
if (play == 1)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
}
else if (p8 == 0)
{
if (play == 1)
{
pictureBox8.BackgroundImage = Properties.Resources.x;
p8 = 2;
}
else
{
pictureBox8.BackgroundImage = Properties.Resources.o;
p8 = 1;
}
}
}
if (masukan == 3)
{
if (p2 == 0)
{
if (play == 1)
{
pictureBox2.BackgroundImage = Properties.Resources.x;
p2 = 2;
}
else
{
pictureBox2.BackgroundImage = Properties.Resources.o;
p2 = 1;
}
}
else if (p1 == 0)
{
if (play == 1)
{
pictureBox1.BackgroundImage = Properties.Resources.x;
p1 = 2;
}
else
{
pictureBox1.BackgroundImage = Properties.Resources.o;
p1 = 1;
}
}
else if (p6 == 0)
{
if (play == 1)
{
pictureBox6.BackgroundImage = Properties.Resources.x;
p6 = 2;
}
else
{
pictureBox6.BackgroundImage = Properties.Resources.o;
p6 = 1;
}
}
else if (p5 == 0)
{
if (play == 1)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
}
else if (p7 == 0)
{
if (play == 1)
{
pictureBox7.BackgroundImage = Properties.Resources.x;
p7 = 2;
}
else
{
pictureBox7.BackgroundImage = Properties.Resources.o;
p7 = 1;
}
}
else if (p9 == 0)
{
if (play == 1)
{
pictureBox9.BackgroundImage = Properties.Resources.x;
p9 = 2;
}
else
{
pictureBox9.BackgroundImage = Properties.Resources.o;
p9 = 1;
}
}
}
if (masukan == 4)
{
if (p1 == 0)
{
if (play == 1)
{
pictureBox1.BackgroundImage = Properties.Resources.x;
p1 = 2;
}
else
{
pictureBox1.BackgroundImage = Properties.Resources.o;
p1 = 1;
}
}
else if (p5 == 0)
{
if (play == 1)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
}
else if (p6 == 0)
{
if (play == 1)
{
pictureBox6.BackgroundImage = Properties.Resources.x;
p6 = 2;
}
else
{
pictureBox6.BackgroundImage = Properties.Resources.o;
p6 = 1;
}
}
else if (p7 == 0)
{
if (play == 1)
{
pictureBox7.BackgroundImage = Properties.Resources.x;
p7 = 2;
}
else
{
pictureBox7.BackgroundImage = Properties.Resources.o;
p7 = 1;
}
}
}
if (masukan == 6)
{
if (p3 == 0)
{
if (play == 1)
{
pictureBox3.BackgroundImage = Properties.Resources.x;
p3 = 2;
}
else
{
pictureBox3.BackgroundImage = Properties.Resources.o;
p3 = 1;
}
}
else if (p9 == 0)
{
if (play == 1)
{
pictureBox9.BackgroundImage = Properties.Resources.x;
p9 = 2;
}
else
{
pictureBox9.BackgroundImage = Properties.Resources.o;
p9 = 1;
}
}
else if (p4 == 0)
{
if (play == 1)
{
pictureBox4.BackgroundImage = Properties.Resources.x;
p4 = 2;
}
else
{
pictureBox4.BackgroundImage = Properties.Resources.o;
p4 = 1;
}
}
else if (p5 == 0)
{
if (play == 1)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
}
}
if (masukan == 7)
{
if (p3 == 0)
{
if (play == 1)
{
pictureBox3.BackgroundImage = Properties.Resources.x;
p3 = 2;
}
else
{
pictureBox3.BackgroundImage = Properties.Resources.o;
p3 = 1;
}
}
else if (p5 == 0)
{
if (play == 1)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
}
else if (p1 == 0)
{
if (play == 1)
{
pictureBox1.BackgroundImage = Properties.Resources.x;
p1 = 2;
}
else
{
pictureBox1.BackgroundImage = Properties.Resources.o;
p1 = 1;
}
}
else if (p4 == 0)
{
if (play == 1)
{
pictureBox4.BackgroundImage = Properties.Resources.x;
p4 = 2;
}
else
{
pictureBox4.BackgroundImage = Properties.Resources.o;
p4 = 1;
}
}
else if (p8 == 0)
{
if (play == 1)
{
pictureBox8.BackgroundImage = Properties.Resources.x;
p8 = 2;
}
else
{
pictureBox8.BackgroundImage = Properties.Resources.o;
p8 = 1;
}
}
else if (p9 == 0)
{
if (play == 1)
{
pictureBox9.BackgroundImage = Properties.Resources.x;
p9 = 2;
}
else
{
pictureBox9.BackgroundImage = Properties.Resources.o;
p9 = 1;
}
}
}
if (masukan == 8)
{
if (p2 == 0)
{
if (play == 1)
{
pictureBox2.BackgroundImage = Properties.Resources.x;
p2 = 2;
}
else
{
pictureBox2.BackgroundImage = Properties.Resources.o;
p2 = 1;
}
}
else if (p5 == 0)
{
if (play == 1)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
}
else if (p7 == 0)
{
if (play == 1)
{
pictureBox7.BackgroundImage = Properties.Resources.x;
p7 = 2;
}
else
{
pictureBox7.BackgroundImage = Properties.Resources.o;
p7 = 1;
}
}
else if (p9 == 0)
{
if (play == 1)
{
pictureBox9.BackgroundImage = Properties.Resources.x;
p9 = 2;
}
else
{
pictureBox9.BackgroundImage = Properties.Resources.o;
p9 = 1;
}
}
}
if (masukan == 9)
{
if (p1 == 0)
{
if (play == 1)
{
pictureBox1.BackgroundImage = Properties.Resources.x;
p1 = 2;
}
else
{
pictureBox1.BackgroundImage = Properties.Resources.o;
p1 = 1;
}
}
else if (p3 == 0)
{
if (play == 1)
{
pictureBox3.BackgroundImage = Properties.Resources.x;
p3 = 2;
}
else
{
pictureBox3.BackgroundImage = Properties.Resources.o;
p3 = 1;
}
}
else if (p6 == 0)
{
if (play == 1)
{
pictureBox6.BackgroundImage = Properties.Resources.x;
p6 = 2;
}
else
{
pictureBox6.BackgroundImage = Properties.Resources.o;
p6 = 1;
}
}
else if (p7 == 0)
{
if (play == 1)
{
pictureBox7.BackgroundImage = Properties.Resources.x;
p7 = 2;
}
else
{
pictureBox7.BackgroundImage = Properties.Resources.o;
p7 = 1;
}
}
else if (p8 == 0)
{
if (play == 1)
{
pictureBox8.BackgroundImage = Properties.Resources.x;
p8 = 2;
}
else
{
pictureBox8.BackgroundImage = Properties.Resources.o;
p8 = 1;
}
}
else if (p5 == 0)
{
if (play == 1)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
}
}
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda"); // indikator jika pemain mengklik pictureBox jika belum memilih
}
else if (play > 0 && p1 == 0)
{
if (play % 2 == 0)
{
pictureBox1.BackgroundImage = Properties.Resources.x;
p1 = 2;
}
else
{
pictureBox1.BackgroundImage = Properties.Resources.o;
p1 = 1;
}
//com();
input = 1;
com_expert(1);
}
menang();
}
private void pictureBox2_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p2 == 0)
{
if (play % 2 == 0)
{
pictureBox2.BackgroundImage = Properties.Resources.x;
p2 = 2;
}
else
{
pictureBox2.BackgroundImage = Properties.Resources.o;
p2 = 1;
}
//com();
input = 2;
com_expert(2);
}
menang();
}
private void pictureBox3_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p3 == 0)
{
if (play % 2 == 0)
{
pictureBox3.BackgroundImage = Properties.Resources.x;
p3 = 2;
}
else
{
pictureBox3.BackgroundImage = Properties.Resources.o;
p3 = 1;
}
//com();
input = 3;
com_expert(3);
}
menang();
}
private void pictureBox4_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p4 == 0)
{
if (play % 2 == 0)
{
pictureBox4.BackgroundImage = Properties.Resources.x;
p4 = 2;
}
else
{
pictureBox4.BackgroundImage = Properties.Resources.o;
p4 = 1;
}
//com();
input = 4;
com_expert(4);
}
menang();
}
private void pictureBox5_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p5 == 0)
{
if (play % 2 == 0)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
input = 5;
com_expert(5);
//com();
}
menang();
}
private void pictureBox6_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p6 == 0)
{
if (play % 2 == 0)
{
pictureBox6.BackgroundImage = Properties.Resources.x;
p6 = 1;
}
else
{
pictureBox6.BackgroundImage = Properties.Resources.o;
p6 = 1;
}
//com();
input = 6;
com_expert(6);
}
menang();
}
private void pictureBox7_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p7 == 0)
{
if (play % 2 == 0)
{
pictureBox7.BackgroundImage = Properties.Resources.x;
p7 = 2;
}
else
{
pictureBox7.BackgroundImage = Properties.Resources.o;
p7 = 1;
}
//com();
input = 7;
com_expert(7);
}
menang();
}
private void pictureBox8_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p8 == 0)
{
if (play % 2 == 0)
{
pictureBox8.BackgroundImage = Properties.Resources.x;
p8 = 2;
}
else
{
pictureBox8.BackgroundImage = Properties.Resources.o;
p8 = 1;
}
//com();
input = 8;
com_expert(8);
}
menang();
}
private void pictureBox9_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p9 == 0)
{
if (play % 2 == 0)
{
pictureBox9.BackgroundImage = Properties.Resources.x;
p9 = 2;
}
else
{
pictureBox9.BackgroundImage = Properties.Resources.o;
p9 = 1;
}
//com();
input = 9;
com_expert(9);
}
menang();
}
void menang()
{
//1 ,2 ,3
if (p1 == 2 && p2 == 2 && p3 == 2)
{
textBox1.Text = "X WON";
}
else if (p1 == 1 && p2 == 1 && p3 == 1)
{
textBox1.Text = "O WON";
}
//4, 5, 6
else if (p4 == 2 && p5 == 2 && p6 == 2)
{
textBox1.Text = "X WON";
}
else if (p4 == 1 && p5 == 1 && p6 == 1)
{
textBox1.Text = "O WON";
}
//win 7 , 8 , 9
else if (p7 == 2 && p8 == 2 && p9 == 2)
{
textBox1.Text = "X WON";
}
else if (p7 == 1 && p8 == 1 && p9 == 1)
{
textBox1.Text = "O WON ";
}
//1, 4 ,7
else if (p1 == 2 && p4 == 2 && p7 == 2)
{
textBox1.Text = "X WON";
}
else if (p1 == 1 && p4 == 1 && p7 == 1)
{
textBox1.Text = "O WON";
}
//2, 5, 8
else if (p2 == 2 && p5 == 2 && p8 == 2)
{
textBox1.Text = "X WON";
}
else if (p2 == 1 && p5 == 1 && p8 == 1)
{
textBox1.Text = "O WON";
}
//3, 6 , 9
else if (p3 == 2 && p6 == 2 && p9 == 2)
{
textBox1.Text = "X WON";
}
else if (p3 == 1 && p6 == 1 && p9 == 1)
{
textBox1.Text = "O WON";
}
//diagonal
//1, 5 , 9
else if (p1 == 2 && p5 == 2 && p9 == 2)
{
textBox1.Text = "X WON";
}
else if (p1 == 1 && p5 == 1 && p9 == 1)
{
textBox1.Text = "O WON";
}
//3, 5 , 7
else if (p3 == 2 && p5 == 2 && p7 == 2)
{
textBox1.Text = "X WON";
}
else if (p3 == 1 && p5 == 1 && p7 == 1)
{
textBox1.Text = "O WON";
}
}
private void radioButton2_CheckedChanged_1(object sender, EventArgs e)
{
if (play == 0)
{
play = 2;
}
label1.Text = " YOU X dan COM O";
}
private void radioButton1_CheckedChanged_1(object sender, EventArgs e)
{
if (play == 0)
{
play = 1;
}
label1.Text = " YOU O dan COM X";
}
private void button1_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;
p1 = p2 = p3 = p4 = p5 = p6 = p7 = p8 = p9 = 0;
label1.Text = "";
textBox1.Text = "";
play = 0;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
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
{
int play = 0;
int p1 = 0, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0, p7 = 0, p8 = 0, p9 = 0;
int input;
public Form1()
{
InitializeComponent();
}
void com_expert(int masukan)
{
if (masukan == 5) // ketika player memilih pictureBox 5
{
if (p2 == 0) // akan di tahan di pictureBox 2
{
if (play == 1)
{
pictureBox2.BackgroundImage = Properties.Resources.x;
p2 = 2; //tampilan sesuai pilihan
}
else
{
pictureBox2.BackgroundImage = Properties.Resources.o;
p2 = 1;
}
}
else if (p1 == 0)
{
if (play == 1)
{
pictureBox1.BackgroundImage = Properties.Resources.x;
p1 = 2;
}
else
{
pictureBox1.BackgroundImage = Properties.Resources.o;
p1 = 1;
}
}
else if (p3 == 0)
{
if (play == 1)
{
pictureBox3.BackgroundImage = Properties.Resources.x;
p3 = 2;
}
else
{
pictureBox3.BackgroundImage = Properties.Resources.o;
p3 = 1;
}
}
else if (p4 == 0)
{
if (play == 1)
{
pictureBox4.BackgroundImage = Properties.Resources.x;
p4 = 2;
}
else
{
pictureBox4.BackgroundImage = Properties.Resources.o;
p4 = 1;
}
}
else if (p6 == 0)
{
if (play == 1)
{
pictureBox6.BackgroundImage = Properties.Resources.x;
p6 = 2;
}
else
{
pictureBox6.BackgroundImage = Properties.Resources.o;
p6 = 1;
}
}
else if (p7 == 0 && p3 == 1 && p5 == 1)
{
if (play == 1)
{
pictureBox7.BackgroundImage = Properties.Resources.x;
p7 = 2;
}
else
{
pictureBox7.BackgroundImage = Properties.Resources.o;
p7 = 1;
}
}
else if (p8 == 0)
{
if (play == 1)
{
pictureBox8.BackgroundImage = Properties.Resources.x;
p8 = 2;
}
else
{
pictureBox8.BackgroundImage = Properties.Resources.o;
p8 = 1;
}
}
else if (p9 == 0)
{
if (play == 1)
{
pictureBox9.BackgroundImage = Properties.Resources.x;
p9 = 2;
}
else
{
pictureBox9.BackgroundImage = Properties.Resources.o;
p9 = 1;
}
}
}
if (masukan == 1)
{
if (p2 == 0)
{
if (play == 1)
{
pictureBox2.BackgroundImage = Properties.Resources.x;
p2 = 2;
}
else
{
pictureBox2.BackgroundImage = Properties.Resources.o;
p2 = 1;
}
}
}
if (masukan == 2)
{
if (p1 == 0)
{
if (play == 1)
{
pictureBox1.BackgroundImage = Properties.Resources.x;
p1 = 2;
}
else
{
pictureBox1.BackgroundImage = Properties.Resources.o;
p1 = 1;
}
}
else if (p3 == 0)
{
if (play == 1)
{
pictureBox3.BackgroundImage = Properties.Resources.x;
p3 = 2;
}
else
{
pictureBox3.BackgroundImage = Properties.Resources.o;
p3 = 1;
}
}
else if (p5 == 0)
{
if (play == 1)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
}
else if (p8 == 0)
{
if (play == 1)
{
pictureBox8.BackgroundImage = Properties.Resources.x;
p8 = 2;
}
else
{
pictureBox8.BackgroundImage = Properties.Resources.o;
p8 = 1;
}
}
}
if (masukan == 3)
{
if (p2 == 0)
{
if (play == 1)
{
pictureBox2.BackgroundImage = Properties.Resources.x;
p2 = 2;
}
else
{
pictureBox2.BackgroundImage = Properties.Resources.o;
p2 = 1;
}
}
else if (p1 == 0)
{
if (play == 1)
{
pictureBox1.BackgroundImage = Properties.Resources.x;
p1 = 2;
}
else
{
pictureBox1.BackgroundImage = Properties.Resources.o;
p1 = 1;
}
}
else if (p6 == 0)
{
if (play == 1)
{
pictureBox6.BackgroundImage = Properties.Resources.x;
p6 = 2;
}
else
{
pictureBox6.BackgroundImage = Properties.Resources.o;
p6 = 1;
}
}
else if (p5 == 0)
{
if (play == 1)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
}
else if (p7 == 0)
{
if (play == 1)
{
pictureBox7.BackgroundImage = Properties.Resources.x;
p7 = 2;
}
else
{
pictureBox7.BackgroundImage = Properties.Resources.o;
p7 = 1;
}
}
else if (p9 == 0)
{
if (play == 1)
{
pictureBox9.BackgroundImage = Properties.Resources.x;
p9 = 2;
}
else
{
pictureBox9.BackgroundImage = Properties.Resources.o;
p9 = 1;
}
}
}
if (masukan == 4)
{
if (p1 == 0)
{
if (play == 1)
{
pictureBox1.BackgroundImage = Properties.Resources.x;
p1 = 2;
}
else
{
pictureBox1.BackgroundImage = Properties.Resources.o;
p1 = 1;
}
}
else if (p5 == 0)
{
if (play == 1)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
}
else if (p6 == 0)
{
if (play == 1)
{
pictureBox6.BackgroundImage = Properties.Resources.x;
p6 = 2;
}
else
{
pictureBox6.BackgroundImage = Properties.Resources.o;
p6 = 1;
}
}
else if (p7 == 0)
{
if (play == 1)
{
pictureBox7.BackgroundImage = Properties.Resources.x;
p7 = 2;
}
else
{
pictureBox7.BackgroundImage = Properties.Resources.o;
p7 = 1;
}
}
}
if (masukan == 6)
{
if (p3 == 0)
{
if (play == 1)
{
pictureBox3.BackgroundImage = Properties.Resources.x;
p3 = 2;
}
else
{
pictureBox3.BackgroundImage = Properties.Resources.o;
p3 = 1;
}
}
else if (p9 == 0)
{
if (play == 1)
{
pictureBox9.BackgroundImage = Properties.Resources.x;
p9 = 2;
}
else
{
pictureBox9.BackgroundImage = Properties.Resources.o;
p9 = 1;
}
}
else if (p4 == 0)
{
if (play == 1)
{
pictureBox4.BackgroundImage = Properties.Resources.x;
p4 = 2;
}
else
{
pictureBox4.BackgroundImage = Properties.Resources.o;
p4 = 1;
}
}
else if (p5 == 0)
{
if (play == 1)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
}
}
if (masukan == 7)
{
if (p3 == 0)
{
if (play == 1)
{
pictureBox3.BackgroundImage = Properties.Resources.x;
p3 = 2;
}
else
{
pictureBox3.BackgroundImage = Properties.Resources.o;
p3 = 1;
}
}
else if (p5 == 0)
{
if (play == 1)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
}
else if (p1 == 0)
{
if (play == 1)
{
pictureBox1.BackgroundImage = Properties.Resources.x;
p1 = 2;
}
else
{
pictureBox1.BackgroundImage = Properties.Resources.o;
p1 = 1;
}
}
else if (p4 == 0)
{
if (play == 1)
{
pictureBox4.BackgroundImage = Properties.Resources.x;
p4 = 2;
}
else
{
pictureBox4.BackgroundImage = Properties.Resources.o;
p4 = 1;
}
}
else if (p8 == 0)
{
if (play == 1)
{
pictureBox8.BackgroundImage = Properties.Resources.x;
p8 = 2;
}
else
{
pictureBox8.BackgroundImage = Properties.Resources.o;
p8 = 1;
}
}
else if (p9 == 0)
{
if (play == 1)
{
pictureBox9.BackgroundImage = Properties.Resources.x;
p9 = 2;
}
else
{
pictureBox9.BackgroundImage = Properties.Resources.o;
p9 = 1;
}
}
}
if (masukan == 8)
{
if (p2 == 0)
{
if (play == 1)
{
pictureBox2.BackgroundImage = Properties.Resources.x;
p2 = 2;
}
else
{
pictureBox2.BackgroundImage = Properties.Resources.o;
p2 = 1;
}
}
else if (p5 == 0)
{
if (play == 1)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
}
else if (p7 == 0)
{
if (play == 1)
{
pictureBox7.BackgroundImage = Properties.Resources.x;
p7 = 2;
}
else
{
pictureBox7.BackgroundImage = Properties.Resources.o;
p7 = 1;
}
}
else if (p9 == 0)
{
if (play == 1)
{
pictureBox9.BackgroundImage = Properties.Resources.x;
p9 = 2;
}
else
{
pictureBox9.BackgroundImage = Properties.Resources.o;
p9 = 1;
}
}
}
if (masukan == 9)
{
if (p1 == 0)
{
if (play == 1)
{
pictureBox1.BackgroundImage = Properties.Resources.x;
p1 = 2;
}
else
{
pictureBox1.BackgroundImage = Properties.Resources.o;
p1 = 1;
}
}
else if (p3 == 0)
{
if (play == 1)
{
pictureBox3.BackgroundImage = Properties.Resources.x;
p3 = 2;
}
else
{
pictureBox3.BackgroundImage = Properties.Resources.o;
p3 = 1;
}
}
else if (p6 == 0)
{
if (play == 1)
{
pictureBox6.BackgroundImage = Properties.Resources.x;
p6 = 2;
}
else
{
pictureBox6.BackgroundImage = Properties.Resources.o;
p6 = 1;
}
}
else if (p7 == 0)
{
if (play == 1)
{
pictureBox7.BackgroundImage = Properties.Resources.x;
p7 = 2;
}
else
{
pictureBox7.BackgroundImage = Properties.Resources.o;
p7 = 1;
}
}
else if (p8 == 0)
{
if (play == 1)
{
pictureBox8.BackgroundImage = Properties.Resources.x;
p8 = 2;
}
else
{
pictureBox8.BackgroundImage = Properties.Resources.o;
p8 = 1;
}
}
else if (p5 == 0)
{
if (play == 1)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
}
}
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda"); // indikator jika pemain mengklik pictureBox jika belum memilih
}
else if (play > 0 && p1 == 0)
{
if (play % 2 == 0)
{
pictureBox1.BackgroundImage = Properties.Resources.x;
p1 = 2;
}
else
{
pictureBox1.BackgroundImage = Properties.Resources.o;
p1 = 1;
}
//com();
input = 1;
com_expert(1);
}
menang();
}
private void pictureBox2_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p2 == 0)
{
if (play % 2 == 0)
{
pictureBox2.BackgroundImage = Properties.Resources.x;
p2 = 2;
}
else
{
pictureBox2.BackgroundImage = Properties.Resources.o;
p2 = 1;
}
//com();
input = 2;
com_expert(2);
}
menang();
}
private void pictureBox3_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p3 == 0)
{
if (play % 2 == 0)
{
pictureBox3.BackgroundImage = Properties.Resources.x;
p3 = 2;
}
else
{
pictureBox3.BackgroundImage = Properties.Resources.o;
p3 = 1;
}
//com();
input = 3;
com_expert(3);
}
menang();
}
private void pictureBox4_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p4 == 0)
{
if (play % 2 == 0)
{
pictureBox4.BackgroundImage = Properties.Resources.x;
p4 = 2;
}
else
{
pictureBox4.BackgroundImage = Properties.Resources.o;
p4 = 1;
}
//com();
input = 4;
com_expert(4);
}
menang();
}
private void pictureBox5_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p5 == 0)
{
if (play % 2 == 0)
{
pictureBox5.BackgroundImage = Properties.Resources.x;
p5 = 2;
}
else
{
pictureBox5.BackgroundImage = Properties.Resources.o;
p5 = 1;
}
input = 5;
com_expert(5);
//com();
}
menang();
}
private void pictureBox6_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p6 == 0)
{
if (play % 2 == 0)
{
pictureBox6.BackgroundImage = Properties.Resources.x;
p6 = 1;
}
else
{
pictureBox6.BackgroundImage = Properties.Resources.o;
p6 = 1;
}
//com();
input = 6;
com_expert(6);
}
menang();
}
private void pictureBox7_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p7 == 0)
{
if (play % 2 == 0)
{
pictureBox7.BackgroundImage = Properties.Resources.x;
p7 = 2;
}
else
{
pictureBox7.BackgroundImage = Properties.Resources.o;
p7 = 1;
}
//com();
input = 7;
com_expert(7);
}
menang();
}
private void pictureBox8_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p8 == 0)
{
if (play % 2 == 0)
{
pictureBox8.BackgroundImage = Properties.Resources.x;
p8 = 2;
}
else
{
pictureBox8.BackgroundImage = Properties.Resources.o;
p8 = 1;
}
//com();
input = 8;
com_expert(8);
}
menang();
}
private void pictureBox9_Click(object sender, EventArgs e)
{
if (play == 0)
{
MessageBox.Show("Silahkan Masukkan Pilihan anda");
}
else if (play > 0 && p9 == 0)
{
if (play % 2 == 0)
{
pictureBox9.BackgroundImage = Properties.Resources.x;
p9 = 2;
}
else
{
pictureBox9.BackgroundImage = Properties.Resources.o;
p9 = 1;
}
//com();
input = 9;
com_expert(9);
}
menang();
}
void menang()
{
//1 ,2 ,3
if (p1 == 2 && p2 == 2 && p3 == 2)
{
textBox1.Text = "X WON";
}
else if (p1 == 1 && p2 == 1 && p3 == 1)
{
textBox1.Text = "O WON";
}
//4, 5, 6
else if (p4 == 2 && p5 == 2 && p6 == 2)
{
textBox1.Text = "X WON";
}
else if (p4 == 1 && p5 == 1 && p6 == 1)
{
textBox1.Text = "O WON";
}
//win 7 , 8 , 9
else if (p7 == 2 && p8 == 2 && p9 == 2)
{
textBox1.Text = "X WON";
}
else if (p7 == 1 && p8 == 1 && p9 == 1)
{
textBox1.Text = "O WON ";
}
//1, 4 ,7
else if (p1 == 2 && p4 == 2 && p7 == 2)
{
textBox1.Text = "X WON";
}
else if (p1 == 1 && p4 == 1 && p7 == 1)
{
textBox1.Text = "O WON";
}
//2, 5, 8
else if (p2 == 2 && p5 == 2 && p8 == 2)
{
textBox1.Text = "X WON";
}
else if (p2 == 1 && p5 == 1 && p8 == 1)
{
textBox1.Text = "O WON";
}
//3, 6 , 9
else if (p3 == 2 && p6 == 2 && p9 == 2)
{
textBox1.Text = "X WON";
}
else if (p3 == 1 && p6 == 1 && p9 == 1)
{
textBox1.Text = "O WON";
}
//diagonal
//1, 5 , 9
else if (p1 == 2 && p5 == 2 && p9 == 2)
{
textBox1.Text = "X WON";
}
else if (p1 == 1 && p5 == 1 && p9 == 1)
{
textBox1.Text = "O WON";
}
//3, 5 , 7
else if (p3 == 2 && p5 == 2 && p7 == 2)
{
textBox1.Text = "X WON";
}
else if (p3 == 1 && p5 == 1 && p7 == 1)
{
textBox1.Text = "O WON";
}
}
private void radioButton2_CheckedChanged_1(object sender, EventArgs e)
{
if (play == 0)
{
play = 2;
}
label1.Text = " YOU X dan COM O";
}
private void radioButton1_CheckedChanged_1(object sender, EventArgs e)
{
if (play == 0)
{
play = 1;
}
label1.Text = " YOU O dan COM X";
}
private void button1_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;
p1 = p2 = p3 = p4 = p5 = p6 = p7 = p8 = p9 = 0;
label1.Text = "";
textBox1.Text = "";
play = 0;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
lalu coba run dengan menekan tombol play atau tombol F5 pada keyboard.
gambar diatas adalah hasil dari program yang saya buat. semoga teman-teman bisa juga untuk membuatnya.untuk penjelasan yang tidak dapat saya jelaskan pada post ini akan coba saya jelaskan pada video di bawah ini.
Langganan:
Postingan (Atom)