NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

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;
using System.Net.Sockets;

namespace WindowsFormsApp3
{
public partial class Form2 : Form
{
private char playerChar;
private char opponentChar;
private Socket sck;
private BackgroundWorker msgReceiver = new BackgroundWorker();
private TcpListener server = null;
private TcpClient client;



public Form2(bool isHost, string ip=null)
{
InitializeComponent();
msgReceiver.DoWork += MsgReceiver_DoWork;

if (isHost)
{
playerChar = 'X';
opponentChar = 'O';

server = new TcpListener(System.Net.IPAddress.Any, 5732);
server.Start();

sck = server.AcceptSocket();
}
else
{
playerChar = 'O';
opponentChar = 'X';
try
{
client = new TcpClient(ip,5732);
sck = client.Client;
msgReceiver.RunWorkerAsync();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
Close();
}
}

}

private void MsgReceiver_DoWork(object sender, DoWorkEventArgs e)
{
if (WinState())
return;
StopAll();
label1.Text = "Opponent's Turn";
RecieveCmd();
label1.Text = " Your Turn";
if (!WinState())
EnableAll();
}


private bool WinState()
{
//hundlun 1
if(button1.Text == button2.Text && button2.Text == button3.Text
&& button3.Text != "")
{
if (button1.Text[0] == playerChar)
{
label1.Text = "You Won!";
MessageBox.Show("You Won!");
RestartGame();
}
else
{
label1.Text = "You lose!";
MessageBox.Show("You lost!");
RestartGame();
}
return true;

}
//hundlun 2
else if (button4.Text == button5.Text && button5.Text == button6.Text
&& button6.Text != "")
{
if (button4.Text[0] == playerChar)
{
label1.Text = "You Won!";
MessageBox.Show("You Won!");
RestartGame();
}
else
{
label1.Text = "You lose!";
MessageBox.Show("You lost!");
RestartGame();
}
return true;

}
//hundlun 3
else if (button7.Text == button8.Text && button8.Text == button9.Text
&& button9.Text != "")
{
if (button7.Text[0] == playerChar)
{
label1.Text = "You Won!";
MessageBox.Show("You Won!");
RestartGame();
}
else
{
label1.Text = "You lose!";
MessageBox.Show("You lost!");
RestartGame();
}
return true;

}
//bosoo 1
else if (button1.Text == button4.Text && button4.Text == button7.Text
&& button7.Text != "")
{
if (button1.Text[0] == playerChar)
{
label1.Text = "You Won!";
MessageBox.Show("You Won!");
RestartGame();
}
else
{
label1.Text = "You lose!";
MessageBox.Show("You lost!");
RestartGame();
}
return true;

}

//bosoo 2
else if (button2.Text == button5.Text && button5.Text == button8.Text
&& button8.Text != "")
{
if (button2.Text[0] == playerChar)
{
label1.Text = "You Won!";
MessageBox.Show("You Won!");
RestartGame();
}
else
{
label1.Text = "You lose!";
MessageBox.Show("You lost!");
RestartGame();
}
return true;

}

//bosoo3
else if (button3.Text == button6.Text && button6.Text == button9.Text
&& button9.Text != "")
{
if (button3.Text[0] == playerChar)
{
label1.Text = "You Won!";
MessageBox.Show("You Won!");
RestartGame();
}
else
{
label1.Text = "You lose!";
MessageBox.Show("You lost!");
RestartGame();
}
return true;

}

//tashuu 1
else if (button1.Text == button5.Text && button5.Text == button9.Text
&& button9.Text != "")
{
if (button9.Text[0] == playerChar)
{
label1.Text = "You Won!";
MessageBox.Show("You Won!");
RestartGame();
}
else
{
label1.Text = "You lose!";
MessageBox.Show("You lost!");
RestartGame();
}
return true;

}
//tashuu2
else if (button3.Text == button5.Text && button5.Text == button7.Text
&& button7.Text != "")
{
if (button3.Text[0] == playerChar)
{
label1.Text = "You Won!";
MessageBox.Show("You Won!");
RestartGame();
}
else
{
label1.Text = "You lose!";
MessageBox.Show("You lost!");
RestartGame();
}
return true;

}else if(button1.Text!="" && button1.Text != "" && button2.Text != "" && button3.Text != "" &&
button4.Text != "" && button5.Text != "" && button6.Text != "" && button7.Text != "" &&
button8.Text != "" && button9.Text != "")
{
label1.Text = "It's a Draw";
MessageBox.Show("It's a Draw");
RestartGame();
return true;
}
return false;
}
private void RestartGame()
{
this.Close();
}

private void StopAll()
{
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
button6.Enabled = false;
button7.Enabled = false;
button8.Enabled = false;
button9.Enabled = false;

}

private void EnableAll()
{
if (button1.Text == "")
button1.Enabled = true;
if (button2.Text == "")
button2.Enabled = true;
if (button3.Text == "")
button3.Enabled = true;
if (button4.Text == "")
button4.Enabled = true;
if (button5.Text == "")
button5.Enabled = true;
if (button6.Text == "")
button6.Enabled = true;
if (button7.Text == "")
button7.Enabled = true;
if (button8.Text == "")
button8.Enabled = true;
if (button9.Text == "")
button9.Enabled = true;
}

private void RecieveCmd()
{
byte[] buffer = new byte[1];
sck.Receive(buffer);

if (buffer[0] == 1)
button1.Text = opponentChar.ToString();
if (buffer[0] == 2)
button2.Text = opponentChar.ToString();
if (buffer[0] == 3)
button3.Text = opponentChar.ToString();
if (buffer[0] == 4)
button4.Text = opponentChar.ToString();
if (buffer[0] == 5)
button5.Text = opponentChar.ToString();
if (buffer[0] == 6)
button6.Text = opponentChar.ToString();
if (buffer[0] == 7)
button7.Text = opponentChar.ToString();
if (buffer[0] == 8)
button8.Text = opponentChar.ToString();
if (buffer[0] == 9)
button9.Text = opponentChar.ToString();

}

private void button1_Click(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{

}

private void button3_Click(object sender, EventArgs e)
{

}

private void button4_Click(object sender, EventArgs e)
{

}

private void button5_Click(object sender, EventArgs e)
{

}

private void button6_Click(object sender, EventArgs e)
{

}

private void button7_Click(object sender, EventArgs e)
{

}

private void button8_Click(object sender, EventArgs e)
{

}

private void button9_Click(object sender, EventArgs e)
{

}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.