Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace WebApplication3
- {
- public partial class WebForm1 : System.Web.UI.Page
- {
- public static bool isX = true;
- public static string[] spaces = new string[]{"a","b","c","d","e","f","g","h","i"};
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void TextboxChange(object sender, EventArgs e)
- {
- string chatString = ChatBox.Text;
- DateTime today = DateTime.Today;
- // int dt = Convert.ToInt32((today.Ticks % 4000000));
- int dt = 4;
- Label1.Text = "it work " + dt;
- SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Database1ConStr"].ToString());
- SqlCommand cmd = new SqlCommand();
- cmd.CommandText = "INSERT INTO tblChat (message) VALUES (@msgText)";
- cmd.Parameters.Add("@msgText", SqlDbType.NVarChar).Value = chatString;
- // cmd.Parameters.Add("@dt", SqlDbType.Int).Value = dt;
- cmd.Connection = conn;
- conn.Open();
- cmd.ExecuteNonQuery();
- conn.Close();
- }
- protected void space(object sender, EventArgs e)
- {
- // object ref
- Button btn = sender as Button;
- // store the space for checking wins
- string buttonString, intString;
- int spaceNum;
- buttonString = btn.ID;
- intString = Regex.Match(buttonString, @"\d+").Value;
- spaceNum = Int32.Parse(intString);
- if (btn.Text != "X" && btn.Text != "O")
- {
- if (isX)
- {
- // change button & array
- btn.Text = "X";
- btn.Enabled = false;
- isX = false;
- spaces[spaceNum] = "X";
- }
- else if (isX == false)
- {
- btn.Text = "O";
- isX = true;
- btn.Enabled = false;
- spaces[spaceNum] = "O";
- }
- string winS = CheckWin();
- Label1.Text = winS;
- }
- if(Label1.Text.Contains("wins"))
- {
- EndGame();
- }
- }
- public string CheckWin()
- {
- // check all win conditions
- // horizontal win conditions
- if (spaces[0] == spaces[1] && spaces[1] == spaces[2])
- return (spaces[0] + " wins!");
- else if (spaces[3] == spaces[4] && spaces[4] == spaces[5])
- return (spaces[3] + " wins!");
- else if (spaces[6] == spaces[7] && spaces[7] == spaces[8])
- return (spaces[0] + " wins!");
- // vertical win conditions
- else if (spaces[0] == spaces[3] && spaces[3] == spaces[6])
- return (spaces[0] + " wins!");
- else if (spaces[1] == spaces[4] && spaces[4] == spaces[7])
- return (spaces[1] + " wins!");
- else if (spaces[2] == spaces[5] && spaces[5] == spaces[8])
- return (spaces[2] + " wins!");
- // diagonal
- else if (spaces[0] == spaces[4] && spaces[4] == spaces[8])
- return (spaces[0] + " wins!");
- else if (spaces[2] == spaces[4] && spaces[4] == spaces[6])
- return (spaces[2] + " wins!");
- // no winner
- else
- return "No Winner Yet!";
- }
- public void EndGame()
- {
- Table1.Enabled = false;
- }
- /*
- protected void methodName(object sender, EventArgs e)
- {
- }
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement