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.Threading;
namespace WindowsFormsApp1
{

public partial class Form1 : Form
{
enum PlayerTurn { None, Player1, Player2};
enum Winner { None, Player1, Player2, Draw};

PlayerTurn turn;
Winner winner;
void OnNewGame()
{
PictureBox[] allPictures = {pictureBox0,
pictureBox1,
pictureBox2,
pictureBox3,
pictureBox4,
pictureBox5,
pictureBox6,
pictureBox7,
pictureBox8,};

//Clear all Game board cells;
foreach (var p in allPictures)
p.Image = null;

turn = PlayerTurn.Player1;
winner = Winner.None;
ShowTurn();

}

Winner GetWinner()
{
PictureBox[] allWinningMoves= {
//Row
pictureBox0, pictureBox1, pictureBox2,
pictureBox3, pictureBox4, pictureBox5,
pictureBox6, pictureBox7, pictureBox8,
//Columns
pictureBox0, pictureBox3, pictureBox6,
pictureBox1, pictureBox4, pictureBox7,
pictureBox2, pictureBox5, pictureBox8,
//Diagonal
pictureBox0, pictureBox4, pictureBox8,
pictureBox2, pictureBox4, pictureBox6,
};
for(int i=0; i < allWinningMoves.Length; i+=3)
{
if(allWinningMoves[i].Image != null)
{
if (allWinningMoves[i].Image == allWinningMoves[i + 1].Image && allWinningMoves[i].Image == allWinningMoves[i+2].Image)
{
if (allWinningMoves[i].Image == player1.Image)
return Winner.Player1;
else
return Winner.Player2;
}
}

}
//Check for empty cell
PictureBox[] allPictures = {pictureBox0,
pictureBox1,
pictureBox2,
pictureBox3,
pictureBox4,
pictureBox5,
pictureBox6,
pictureBox7,
pictureBox8,
};

//Clear all Game board cells;
foreach (var p in allPictures)
if (p.Image == null)
return Winner.None;

//It's a draw
return Winner.Draw;
}
void ShowTurn()
{
string status = "";
string msg = "";

switch (winner)
{
case Winner.None:
if (turn == PlayerTurn.Player1)
status = "Turn: Player 1";
else
status = "Turn: Player 2";
break;
case Winner.Player1:
msg = status = "Player 1 Wins!";
break;
case Winner.Player2:
msg = status = "Player 2 Wins!";
break;
case Winner.Draw:
status = "You suck, it's a draw";
break;
}
lblStatus.Text = status;
if (msg != "")
MessageBox.Show(msg, "Winner!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public Form1()
{
Thread t = new Thread(new ThreadStart(SplashStart));
t.Start();
Thread.Sleep(4800);

InitializeComponent();

t.Abort();
}

public void SplashStart()
{
Application.Run(new Form3());
}

private void label1_Click(object sender, EventArgs e)
{

}

private void label1_Click_1(object sender, EventArgs e)
{

}

private void label3_Click(object sender, EventArgs e)
{

}

private void lblStatus_Click(object sender, EventArgs e)
{

}

private void OnClick(object sender, EventArgs e)
{
PictureBox p = sender as PictureBox;

if (p.Image != null)
return;
if (turn == PlayerTurn.None)
return;


if (turn == PlayerTurn.Player1)
p.Image = player1.Image;
else
p.Image = player2.Image;

//Check for winner
winner = GetWinner();
if (winner == Winner.None)
{

//Change turns
turn = (PlayerTurn.Player1 == turn) ? PlayerTurn.Player2 : PlayerTurn.Player1;
}
else
{
turn = PlayerTurn.None;
}
ShowTurn();
}

private void Form1_Load(object sender, EventArgs e)
{
OnNewGame();
}

private void btnNewGame_Click(object sender, EventArgs e)
{
var result = MessageBox.Show("Are you sure you want to start a new game?",
"New Game",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if(result == DialogResult.Yes)
OnNewGame();
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
var result = MessageBox.Show("Are you sure you want to exit now?",
"Exit",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if(result == DialogResult.No)
e.Cancel = true;
}
}
}


Splash Screen Code:

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 WindowsFormsApp1
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}

private void pictureBox1_Click(object sender, EventArgs e)
{

}

private void timer1_Tick(object sender, EventArgs e)
{
progressBar1.Increment(1);
if (progressBar1.Value == 100)
timer1.Stop();
}
}
}
     
 
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.