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.NetworkInformation;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
bool xis = true;
string[,] matriz = new string[3, 3];
// Vitória X
int xganha = 0;
string xganhast = "";
// Vitória O
int oganha = 0;
string oganhast = "";
// Derrotas X
int xderrota = 0;
string xderrotast = "";
// Derrotas O
int oderrota = 0;
string oderrotast = "";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
b11.Click += new EventHandler(BClick);
b12.Click += new EventHandler(BClick);
b13.Click += new EventHandler(BClick);
b21.Click += new EventHandler(BClick);
b22.Click += new EventHandler(BClick);
b23.Click += new EventHandler(BClick);
b31.Click += new EventHandler(BClick);
b32.Click += new EventHandler(BClick);
b33.Click += new EventHandler(BClick);
foreach (Control item in this.Controls)
{
if (item is Button)
{
item.TabStop = false;
}
}
}
private void BClick(object sender, EventArgs e)
{
((Button)sender).Text = this.xis ? "x" : "o";
((Button)sender).Enabled = false;
VerificarGanhador();
xis = !xis;
label1.Text = string.Format("{0}, é sua vez", this.xis ? "x" : "o");
}
private void EasyComputer(object sender, EventArgs e)
{
((Button)sender).Text = "a";
((Button)sender).Enabled = false;
}
private void VerificarGanhador()
{
if (
b11.Text != String.Empty && b11.Text == b12.Text && b12.Text == b13.Text || // Linha 1
b21.Text != String.Empty && b21.Text == b22.Text && b22.Text == b23.Text ||
b31.Text != String.Empty && b31.Text == b32.Text && b32.Text == b33.Text ||
b11.Text != String.Empty && b11.Text == b21.Text && b21.Text == b31.Text ||
b12.Text != String.Empty && b12.Text == b22.Text && b22.Text == b32.Text ||
b13.Text != String.Empty && b13.Text == b23.Text && b23.Text == b33.Text ||
b11.Text != String.Empty && b11.Text == b22.Text && b22.Text == b33.Text ||
b13.Text != String.Empty && b13.Text == b22.Text && b22.Text == b31.Text
)
{
MessageBox.Show(String.Format("Ganhador: {0}", xis ? "x" : "o"), "Vitoria", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (xis == true)
{
xganha++;
xganhast = xganha.ToString();
oderrota++;
oderrotast = oderrota.ToString();
label8.Text = oderrotast;
label9.Text = xganhast;
}
else
{
oganha++;
oganhast = oganha.ToString();
xderrota++;
xderrotast = xderrota.ToString();
label10.Text = xderrotast;
label7.Text = oganhast;
}
Reiniciar();
}
else
{
VerificarEmpate();
}
}
private void VerificarEmpate()
{
bool todosDesabilitados = true;
foreach (Control item in this.Controls)
{
if (item is Button && item.Enabled)
{
todosDesabilitados = false;
break;
}
}
if (todosDesabilitados)
{
MessageBox.Show(String.Format("Deu Veia"), "Atenção!!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Reiniciar();
}
}
private void Reiniciar()
{
const string message = "Deseja jogar novamente?";
const string caption = "Aviso:";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.No)
{
this.Close();
}
else
{
foreach (Control item in this.Controls)
{
if (item is Button)
{
item.Enabled = true;
item.Text = String.Empty;
}
}
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
const string message = "Deseja sair do jogo?";
const string caption = "Aviso:";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
this.Close();
}
}
private void aboutToolStripMenuItem1_Click(object sender, EventArgs e)
{
MessageBox.Show("Desenvolvido por SkyDangerous", "About");
}
private void resetGameToolStripMenuItem_Click(object sender, EventArgs e)
{
const string message = "Deseja reiniciar o jogo?";
const string caption = "Aviso:";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
foreach (Control item in this.Controls)
{
if (item is Button)
{
item.Enabled = true;
item.Text = String.Empty;
}
}
}
}
private void resetAllToolStripMenuItem_Click(object sender, EventArgs e)
{
const string message = "Deseja reiniciar a pontuação?";
const string caption = "Aviso:";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
label8.Text = label9.Text = label10.Text = label7.Text = "0";
oderrota = xderrota = oganha = xganha = 0;
}
}
private void toolStripTextBox1_Click(object sender, EventArgs e)
{
}
private void resetXVitóriaToolStripMenuItem_Click(object sender, EventArgs e)
{
if (xganha == 0)
{
MessageBox.Show("Aviso", "Nao pode resetar vitória sendo 0");
}
else
{
const string message = "Deseja reiniciar a pontuação de vitória do X?";
const string caption = "Aviso:";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
label9.Text = "0";
xganha = 0;
}
}
}
private void resetXDerrotasToolStripMenuItem_Click(object sender, EventArgs e)
{
if (xderrota == 0)
{
MessageBox.Show("Aviso", "Nao pode resetar derrota sendo 0");
}
else
{
const string message = "Deseja reiniciar a pontuação de derrotas X?";
const string caption = "Aviso:";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
label10.Text = "0";
xderrota = 0;
}
}
}
private void resetOVitóriasToolStripMenuItem_Click(object sender, EventArgs e)
{
if (oganha == 0)
{
MessageBox.Show("Aviso", "Nao pode resetar vitória sendo 0");
}
else
{
const string message = "Deseja reiniciar a pontuação de vitória O?";
const string caption = "Aviso:";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
label7.Text = "0";
oganha = 0;
}
}
}
private void resetODerrotasToolStripMenuItem_Click(object sender, EventArgs e)
{
if (oderrota == 0)
{
MessageBox.Show("Aviso", "Nao pode resetar derrota sendo 0");
}
else
{
const string message = "Deseja reiniciar a pontuação de derrotas O?";
const string caption = "Aviso:";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
label8.Text = "0";
xderrota = 0;
}
}
}
private void Som(object sender, EventArgs e)
{
//Função by SKydangerous
System.Media.SystemSounds.Exclamation.Play();
}
private void verificarIPToolStripMenuItem_Click(object sender, EventArgs e)
{
Form3 novaform = new Form3();
novaform.Show();
}
private void pingarHostToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 novaform = new Form2();
novaform.Show();
}
private void jogarToolStripMenuItem_Click(object sender, EventArgs e)
{
Form4 novaform = new Form4();
novaform.Show();
}
private void cHATToolStripMenuItem_Click(object sender, EventArgs e)
{
chat novaform = new chat();
novaform.Show();
}
private void easy_Click(object sender, EventArgs e)
{
}
}
}
--Para pegar o ip da sua internet
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.NetworkInformation;
using System.Net.Sockets;
using System.IO;
using System.Net;
namespace WindowsFormsApplication1
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
WebClient wb = new WebClient();
UTF8Encoding utf = new UTF8Encoding();
string st = utf.GetString(wb.DownloadData("http://myip.dk/")).ToString();
int i = st.IndexOf("IP Address:")+34;
while(st.Substring(i,1) != "<")
{
label1.Text += st.Substring(i,1);
i++;
}
}
}
}
--Pingar o host
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.NetworkInformation;
using System.Net.Sockets;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void bto_ping_Click(object sender, EventArgs e)
{
Ping ping1 = new Ping();
PingReply resp = ping1.Send(txt_host.Text);
txt_ip.Text = Convert.ToString(resp.Address);
if (Convert.ToString(resp.Status) == "Success")
txt_status.Text = "Ativo";
else
txt_status.Text = "Inativo";
}
private void bto_fechar_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void bto_Limpar_Click(object sender, EventArgs e)
{
txt_host.Clear();
txt_ip.Clear();
txt_status.Clear();
}
}
}
info
Grupo: Lorde
Registrado: 17/01/09
Posts: 2.1k
Reputação: +395
Char no Tibia: Adra Sata
Era um projeto, que pretendia fazer multiplayer.
Não deu certo .. ai eu vou postar.
algumas funções estava fazendo testes.. !
--Principal
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.NetworkInformation; namespace WindowsFormsApplication1 { public partial class Form1 : Form { bool xis = true; string[,] matriz = new string[3, 3]; // Vitória X int xganha = 0; string xganhast = ""; // Vitória O int oganha = 0; string oganhast = ""; // Derrotas X int xderrota = 0; string xderrotast = ""; // Derrotas O int oderrota = 0; string oderrotast = ""; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { b11.Click += new EventHandler(BClick); b12.Click += new EventHandler(BClick); b13.Click += new EventHandler(BClick); b21.Click += new EventHandler(BClick); b22.Click += new EventHandler(BClick); b23.Click += new EventHandler(BClick); b31.Click += new EventHandler(BClick); b32.Click += new EventHandler(BClick); b33.Click += new EventHandler(BClick); foreach (Control item in this.Controls) { if (item is Button) { item.TabStop = false; } } } private void BClick(object sender, EventArgs e) { ((Button)sender).Text = this.xis ? "x" : "o"; ((Button)sender).Enabled = false; VerificarGanhador(); xis = !xis; label1.Text = string.Format("{0}, é sua vez", this.xis ? "x" : "o"); } private void EasyComputer(object sender, EventArgs e) { ((Button)sender).Text = "a"; ((Button)sender).Enabled = false; } private void VerificarGanhador() { if ( b11.Text != String.Empty && b11.Text == b12.Text && b12.Text == b13.Text || // Linha 1 b21.Text != String.Empty && b21.Text == b22.Text && b22.Text == b23.Text || b31.Text != String.Empty && b31.Text == b32.Text && b32.Text == b33.Text || b11.Text != String.Empty && b11.Text == b21.Text && b21.Text == b31.Text || b12.Text != String.Empty && b12.Text == b22.Text && b22.Text == b32.Text || b13.Text != String.Empty && b13.Text == b23.Text && b23.Text == b33.Text || b11.Text != String.Empty && b11.Text == b22.Text && b22.Text == b33.Text || b13.Text != String.Empty && b13.Text == b22.Text && b22.Text == b31.Text ) { MessageBox.Show(String.Format("Ganhador: {0}", xis ? "x" : "o"), "Vitoria", MessageBoxButtons.OK, MessageBoxIcon.Information); if (xis == true) { xganha++; xganhast = xganha.ToString(); oderrota++; oderrotast = oderrota.ToString(); label8.Text = oderrotast; label9.Text = xganhast; } else { oganha++; oganhast = oganha.ToString(); xderrota++; xderrotast = xderrota.ToString(); label10.Text = xderrotast; label7.Text = oganhast; } Reiniciar(); } else { VerificarEmpate(); } } private void VerificarEmpate() { bool todosDesabilitados = true; foreach (Control item in this.Controls) { if (item is Button && item.Enabled) { todosDesabilitados = false; break; } } if (todosDesabilitados) { MessageBox.Show(String.Format("Deu Veia"), "Atenção!!", MessageBoxButtons.OK, MessageBoxIcon.Warning); Reiniciar(); } } private void Reiniciar() { const string message = "Deseja jogar novamente?"; const string caption = "Aviso:"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { this.Close(); } else { foreach (Control item in this.Controls) { if (item is Button) { item.Enabled = true; item.Text = String.Empty; } } } } private void exitToolStripMenuItem_Click(object sender, EventArgs e) { const string message = "Deseja sair do jogo?"; const string caption = "Aviso:"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { this.Close(); } } private void aboutToolStripMenuItem1_Click(object sender, EventArgs e) { MessageBox.Show("Desenvolvido por SkyDangerous", "About"); } private void resetGameToolStripMenuItem_Click(object sender, EventArgs e) { const string message = "Deseja reiniciar o jogo?"; const string caption = "Aviso:"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { foreach (Control item in this.Controls) { if (item is Button) { item.Enabled = true; item.Text = String.Empty; } } } } private void resetAllToolStripMenuItem_Click(object sender, EventArgs e) { const string message = "Deseja reiniciar a pontuação?"; const string caption = "Aviso:"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { label8.Text = label9.Text = label10.Text = label7.Text = "0"; oderrota = xderrota = oganha = xganha = 0; } } private void toolStripTextBox1_Click(object sender, EventArgs e) { } private void resetXVitóriaToolStripMenuItem_Click(object sender, EventArgs e) { if (xganha == 0) { MessageBox.Show("Aviso", "Nao pode resetar vitória sendo 0"); } else { const string message = "Deseja reiniciar a pontuação de vitória do X?"; const string caption = "Aviso:"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { label9.Text = "0"; xganha = 0; } } } private void resetXDerrotasToolStripMenuItem_Click(object sender, EventArgs e) { if (xderrota == 0) { MessageBox.Show("Aviso", "Nao pode resetar derrota sendo 0"); } else { const string message = "Deseja reiniciar a pontuação de derrotas X?"; const string caption = "Aviso:"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { label10.Text = "0"; xderrota = 0; } } } private void resetOVitóriasToolStripMenuItem_Click(object sender, EventArgs e) { if (oganha == 0) { MessageBox.Show("Aviso", "Nao pode resetar vitória sendo 0"); } else { const string message = "Deseja reiniciar a pontuação de vitória O?"; const string caption = "Aviso:"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { label7.Text = "0"; oganha = 0; } } } private void resetODerrotasToolStripMenuItem_Click(object sender, EventArgs e) { if (oderrota == 0) { MessageBox.Show("Aviso", "Nao pode resetar derrota sendo 0"); } else { const string message = "Deseja reiniciar a pontuação de derrotas O?"; const string caption = "Aviso:"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { label8.Text = "0"; xderrota = 0; } } } private void Som(object sender, EventArgs e) { //Função by SKydangerous System.Media.SystemSounds.Exclamation.Play(); } private void verificarIPToolStripMenuItem_Click(object sender, EventArgs e) { Form3 novaform = new Form3(); novaform.Show(); } private void pingarHostToolStripMenuItem_Click(object sender, EventArgs e) { Form2 novaform = new Form2(); novaform.Show(); } private void jogarToolStripMenuItem_Click(object sender, EventArgs e) { Form4 novaform = new Form4(); novaform.Show(); } private void cHATToolStripMenuItem_Click(object sender, EventArgs e) { chat novaform = new chat(); novaform.Show(); } private void easy_Click(object sender, EventArgs e) { } } }--Para pegar o ip da sua internet
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.NetworkInformation; using System.Net.Sockets; using System.IO; using System.Net; namespace WindowsFormsApplication1 { public partial class Form3 : Form { public Form3() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { WebClient wb = new WebClient(); UTF8Encoding utf = new UTF8Encoding(); string st = utf.GetString(wb.DownloadData("http://myip.dk/")).ToString(); int i = st.IndexOf("IP Address:")+34; while(st.Substring(i,1) != "<") { label1.Text += st.Substring(i,1); i++; } } } }--Pingar o host
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.NetworkInformation; using System.Net.Sockets; namespace WindowsFormsApplication1 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void bto_ping_Click(object sender, EventArgs e) { Ping ping1 = new Ping(); PingReply resp = ping1.Send(txt_host.Text); txt_ip.Text = Convert.ToString(resp.Address); if (Convert.ToString(resp.Status) == "Success") txt_status.Text = "Ativo"; else txt_status.Text = "Inativo"; } private void bto_fechar_Click(object sender, EventArgs e) { Application.Exit(); } private void bto_Limpar_Click(object sender, EventArgs e) { txt_host.Clear(); txt_ip.Clear(); txt_status.Clear(); } } }Até.