My Name Is Salman Masood , I am Computer Science &Amp; Maths Graduate from University of Karachi, Pakistan , Teaching Is My Passion and My Aim Is to Deliver All My Knowledge among Those Students Who Can'T Afford Tutors or Expensive Institute Fees. I Will Be Keep Sharing My All Knowledge and Information with You .... Remember Me in Your Prayers !
Thursday, 19 October 2017
How to make KBC game in C# (part-3/5)
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.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace kbc
{
public partial class QUIZ : Form
{
int[] x = new int[15];
int p = 0;
string ansfromdb, ansselect;
public static string score;
returnclass rc = new returnclass();
int qid;
private string connstring = ConfigurationManager.ConnectionStrings["kbc"].ConnectionString;
public QUIZ()
{
InitializeComponent();
}
private void QUIZ_Load(object sender, EventArgs e)
{
// label2.Text = startgame.NAME;
Random r = new Random();
qid= r.Next(3, 17);
x[p] = qid;
displayquestion(qid);
LABELCOLORCHANGED(p);
}
public void LABELCOLORCHANGED(int P)
{
if (p==0)
{
label7.BackColor = Color.Orange;
label7.ForeColor = Color.Purple;
score= "0";
}
if (p == 1)
{
label8.BackColor = Color.Orange;
label8.ForeColor = Color.Purple;
label7.BackColor = Color.BlueViolet;
label7.ForeColor = Color.White;
score = label7.Text;
}
if (p == 2)
{
label9.BackColor = Color.Orange;
label9.ForeColor = Color.Purple;
label8.BackColor = Color.BlueViolet;
label8.ForeColor = Color.White;
score = label8.Text;
}
if (p == 3)
{
label10.BackColor = Color.Orange;
label10.ForeColor = Color.Purple;
label9.BackColor = Color.BlueViolet;
label9.ForeColor = Color.White;
score = label9.Text;
}
if (p == 4)
{
label11.BackColor = Color.Orange;
label11.ForeColor = Color.Purple;
label10.BackColor = Color.BlueViolet;
label10.ForeColor = Color.White;
score = label10.Text;
}
if (p == 5)
{
label12.BackColor = Color.Orange;
label12.ForeColor = Color.Purple;
label11.BackColor = Color.BlueViolet;
label11.ForeColor = Color.White;
score = label11.Text;
}
if (p == 6)
{
label13.BackColor = Color.Orange;
label13.ForeColor = Color.Purple;
label12.BackColor = Color.BlueViolet;
label12.ForeColor = Color.White;
score = label12.Text;
}
if (p == 7)
{
label14.BackColor = Color.Orange;
label14.ForeColor = Color.Purple;
label13.BackColor = Color.BlueViolet;
label13.ForeColor = Color.White;
score = label13.Text;
}
if (p == 8)
{
label15.BackColor = Color.Orange;
label15.ForeColor = Color.Purple;
label14.BackColor = Color.BlueViolet;
label14.ForeColor = Color.White;
score = label14.Text;
}
if (p == 9)
{
label16.BackColor = Color.Orange;
label16.ForeColor = Color.Purple;
label15.BackColor = Color.BlueViolet;
label15.ForeColor = Color.White;
score = label15.Text;
}
if (p == 10)
{
label17.BackColor = Color.Orange;
label17.ForeColor = Color.Purple;
label16.BackColor = Color.BlueViolet;
label16.ForeColor = Color.White;
score = label16.Text;
}
if (p == 11)
{
label18.BackColor = Color.Orange;
label18.ForeColor = Color.Purple;
label17.BackColor = Color.BlueViolet;
label17.ForeColor = Color.White;
score = label17.Text;
}
} //label changed method................
public void universalcode()
{
if (p == 12)
{
this.Hide();
last L = new last();
L.Show();
}
if (ansselect.Equals(ansfromdb))
{
// MessageBox.Show("correct ans!");
qid++;
displayquestion(qid);
l1:
Random r = new Random();
int s = r.Next(1, 17);
bool c = search(x, s);
if (c == true)
{
goto l1;
}
else
{
p++;
qid = s;
x[p] = qid;
displayquestion(qid);
LABELCOLORCHANGED(p);
}
}
else
{
this.Hide();
gameover go = new gameover();
go.Show();
}
} //universal method end......
private void label3_Click(object sender, EventArgs e)
{
ansselect = label3.Text;
universalcode();
}
private void label4_Click(object sender, EventArgs e)
{
ansselect = label4.Text;
universalcode();
}
private void label5_Click(object sender, EventArgs e)
{
ansselect = label5.Text;
universalcode();
}
private void label6_Click(object sender, EventArgs e)
{
ansselect = label6.Text;
universalcode();
}
public void displayquestion(int q_id)
{
string sql = "select q_question,q_opA,q_opB,q_opC,q_opD,q_opcORRECT from questions where q_id=" + q_id;
SqlConnection connection = new SqlConnection(connstring);
try
{
connection.Open();
SqlCommand cmd = new SqlCommand(sql, connection);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
label1.Text = reader.GetValue(0).ToString(); //question
label3.Text = reader.GetValue(1).ToString(); //opa
label4.Text = reader.GetValue(2).ToString();//opb
label5.Text = reader.GetValue(3).ToString();//opc
label6.Text = reader.GetValue(4).ToString();//opd
ansfromdb = reader.GetValue(5).ToString();//correct option.........
}
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Errro 202");
}
} //method ends....................
public static bool search(int[] x, int s)
{
bool c = false;
for (int i = 0; i < x.Length; i++)
{
if (s == x[i])
{
c = true;
break;
}
}
return c;
} //function of searching.....................
}
}
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.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace kbc
{
public partial class QUIZ : Form
{
int[] x = new int[15];
int p = 0;
string ansfromdb, ansselect;
public static string score;
returnclass rc = new returnclass();
int qid;
private string connstring = ConfigurationManager.ConnectionStrings["kbc"].ConnectionString;
public QUIZ()
{
InitializeComponent();
}
private void QUIZ_Load(object sender, EventArgs e)
{
// label2.Text = startgame.NAME;
Random r = new Random();
qid= r.Next(3, 17);
x[p] = qid;
displayquestion(qid);
LABELCOLORCHANGED(p);
}
public void LABELCOLORCHANGED(int P)
{
if (p==0)
{
label7.BackColor = Color.Orange;
label7.ForeColor = Color.Purple;
score= "0";
}
if (p == 1)
{
label8.BackColor = Color.Orange;
label8.ForeColor = Color.Purple;
label7.BackColor = Color.BlueViolet;
label7.ForeColor = Color.White;
score = label7.Text;
}
if (p == 2)
{
label9.BackColor = Color.Orange;
label9.ForeColor = Color.Purple;
label8.BackColor = Color.BlueViolet;
label8.ForeColor = Color.White;
score = label8.Text;
}
if (p == 3)
{
label10.BackColor = Color.Orange;
label10.ForeColor = Color.Purple;
label9.BackColor = Color.BlueViolet;
label9.ForeColor = Color.White;
score = label9.Text;
}
if (p == 4)
{
label11.BackColor = Color.Orange;
label11.ForeColor = Color.Purple;
label10.BackColor = Color.BlueViolet;
label10.ForeColor = Color.White;
score = label10.Text;
}
if (p == 5)
{
label12.BackColor = Color.Orange;
label12.ForeColor = Color.Purple;
label11.BackColor = Color.BlueViolet;
label11.ForeColor = Color.White;
score = label11.Text;
}
if (p == 6)
{
label13.BackColor = Color.Orange;
label13.ForeColor = Color.Purple;
label12.BackColor = Color.BlueViolet;
label12.ForeColor = Color.White;
score = label12.Text;
}
if (p == 7)
{
label14.BackColor = Color.Orange;
label14.ForeColor = Color.Purple;
label13.BackColor = Color.BlueViolet;
label13.ForeColor = Color.White;
score = label13.Text;
}
if (p == 8)
{
label15.BackColor = Color.Orange;
label15.ForeColor = Color.Purple;
label14.BackColor = Color.BlueViolet;
label14.ForeColor = Color.White;
score = label14.Text;
}
if (p == 9)
{
label16.BackColor = Color.Orange;
label16.ForeColor = Color.Purple;
label15.BackColor = Color.BlueViolet;
label15.ForeColor = Color.White;
score = label15.Text;
}
if (p == 10)
{
label17.BackColor = Color.Orange;
label17.ForeColor = Color.Purple;
label16.BackColor = Color.BlueViolet;
label16.ForeColor = Color.White;
score = label16.Text;
}
if (p == 11)
{
label18.BackColor = Color.Orange;
label18.ForeColor = Color.Purple;
label17.BackColor = Color.BlueViolet;
label17.ForeColor = Color.White;
score = label17.Text;
}
} //label changed method................
public void universalcode()
{
if (p == 12)
{
this.Hide();
last L = new last();
L.Show();
}
if (ansselect.Equals(ansfromdb))
{
// MessageBox.Show("correct ans!");
qid++;
displayquestion(qid);
l1:
Random r = new Random();
int s = r.Next(1, 17);
bool c = search(x, s);
if (c == true)
{
goto l1;
}
else
{
p++;
qid = s;
x[p] = qid;
displayquestion(qid);
LABELCOLORCHANGED(p);
}
}
else
{
this.Hide();
gameover go = new gameover();
go.Show();
}
} //universal method end......
private void label3_Click(object sender, EventArgs e)
{
ansselect = label3.Text;
universalcode();
}
private void label4_Click(object sender, EventArgs e)
{
ansselect = label4.Text;
universalcode();
}
private void label5_Click(object sender, EventArgs e)
{
ansselect = label5.Text;
universalcode();
}
private void label6_Click(object sender, EventArgs e)
{
ansselect = label6.Text;
universalcode();
}
public void displayquestion(int q_id)
{
string sql = "select q_question,q_opA,q_opB,q_opC,q_opD,q_opcORRECT from questions where q_id=" + q_id;
SqlConnection connection = new SqlConnection(connstring);
try
{
connection.Open();
SqlCommand cmd = new SqlCommand(sql, connection);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
label1.Text = reader.GetValue(0).ToString(); //question
label3.Text = reader.GetValue(1).ToString(); //opa
label4.Text = reader.GetValue(2).ToString();//opb
label5.Text = reader.GetValue(3).ToString();//opc
label6.Text = reader.GetValue(4).ToString();//opd
ansfromdb = reader.GetValue(5).ToString();//correct option.........
}
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Errro 202");
}
} //method ends....................
public static bool search(int[] x, int s)
{
bool c = false;
for (int i = 0; i < x.Length; i++)
{
if (s == x[i])
{
c = true;
break;
}
}
return c;
} //function of searching.....................
}
}
Subscribe to:
Posts (Atom)
Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC
Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...
-
Load event: pictureBox3.Image = Image .FromFile( @"C:\Users\salman\Documents\Visual Studio 2013\Projects\WindowsFormsApplication3\W...