package com.kenki.emp
import javax.servlet.*
import javax.servlet.http.*
import java.io.*
import java.util.*
import java.sql.SQLException
import java.sql.*
public class emp extends HttpServlet {
private static final String CONTENT_TYPE = "text/htmlcharset=GBK"
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE)
PrintWriter out = response.getWriter()
String code = request.getParameter("code")
String name = request.getParameter("name")
String pay = request.getParameter("pay")
System.out.println("empcode:" + code)
System.out.println("name:" + name)
System.out.println("pay:" + pay)
//创建驱动
new com.microsoft.jdbc.sqlserver.SQLServerDriver()
String strd =
"jdbc:microsoft:sqlserver://localhost:1433databasename=emp_dates"
String username = "sa"
String pws = ""
try {
java.sql.Connection conn = java.sql.DriverManager.getConnection(
strd, username, pws)
String strs = "insert into emp values(?,?,?)"
java.sql.PreparedStatement pre = conn.prepareStatement(strs)
pre.setString(1, code)
pre.setString(2, name)
pre.setString(3, pay)
pre.execute()
pre.close()
conn.close()
//重定向至查询页面
out.println("成功保存!!")
response.sendRedirect("emp.html")
} catch (SQLException ss) {
ss.printStackTrace()
response.sendRedirect("/WebModule1/error.html")
}
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response)
}
//Clean up resources
public void destroy() {
}
}
using Systemusing System.Collections.Generic
using System.ComponentModel
using System.Data
using System.Drawing
using System.Text
using System.Windows.Forms
using System.Collections
namespace RIF
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent()
}
public class Arr
{
public int[,] arr = new int[25, 25]
public bool win
}
Arr a = new Arr()
bool cc = true
public void PaintLab()
{
Bitmap image = new Bitmap(300,300)
Graphics g = Graphics.FromImage(image)
g.Clear(Color.Tan)
Pen pen = new Pen(Color.Black, 1)
int i, j
i = j = 0
while (i <= 300)
{
g.DrawLine(pen, i, 0, i, 300)
i = i + 20
}
while (j <= 300)
{
g.DrawLine(pen, 0, j, 300, j)
j = j + 20
}
img.Image = image
}
private void Form1_Load(object sender, EventArgs e)
{
PaintLab()
}
private void img_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
int x = e.X
int y = e.Y
Graphics g = Graphics.FromImage(img.Image)
Brush pen
int myx = x / 20
int myy = y / 20
if (a.arr[myx, myy] != 0)
{
MessageBox.Show("这里已经有棋子了!")
return
}
else
{
if (cc)
{
pen = new SolidBrush(Color.White)
cc = false
a.arr[myx, myy] = 1
}
else
{
pen = new SolidBrush(Color.Black)
cc = true
a.arr[myx, myy] = 2
}
g.FillEllipse(pen, myx * 20 + 2, myy * 20 + 2, 16, 16)
img.Invalidate()
int z = IsWin(myx, myy, cc)
if (z != 0)
{
if (z == 1)
{
MessageBox.Show("白色获胜!")
}
else
{
MessageBox.Show("黑色获胜!")
}
img.Enabled = false
}
}
}
else
{
MessageBox.Show("本程序由Cantahu开发","作者信息",MessageBoxButtons.OK,MessageBoxIcon.Information)
}
}
private int IsWin(int x, int y,bool cc)
{
int m, n, count, p, q
int val = 0
bool win=false
if (cc)
{
val = 2
}
else
{
val = 1
}
#region 横向判断
count = 1
int f = 0
m = x-1
n = x+1
while (1==1)
{
if (count == 5)
{
win = true
break
}
else if (f == 5)
{
win = false
break
}
if (m >= 0 &&n <= 300)
{
if (a.arr[m, y] == val)
{
count = count + 1
m = m - 1
}
if (a.arr[n, y] == val)
{
count = count + 1
n = n + 1
}
}
f = f + 1
}
if (win)
{
return val
}
#endregion
#region 纵向判断
m = y - 1
n = y + 1
f = 0
count = 1
while (1 == 1)
{
if (count == 5)
{
win = true
break
}
if (f == 5)
{
win = false
break
}
if (m >= 0 &&n <= 300)
{
if(a.arr[x,m]==val)
{
count = count + 1
m = m - 1
}
if(a.arr[x,n]==val)
{
count = count + 1
n = n + 1
}
}
f = f + 1
}
if (win)
{
return val
}
#endregion
#region 左斜向判断
count = 1
f = 0
m = x - 1
n = y - 1
p = x + 1
q = y + 1
while (1 == 1)
{
if (count == 5)
{
win = true
break
}
if (f == 5)
{
win = false
break
}
if (m >= 0 &&n >= 0 &&p <= 300 &&q <= 300)
{
if (a.arr[m, n] == val)
{
count = count + 1
m = m - 1
n = n - 1
}
if (a.arr[p, q] == val)
{
count = count + 1
p = p + 1
q = q + 1
}
}
f = f + 1
}
if (win)
{
return val
}
#endregion
#region 右斜向
count = 1
f = 0
m = x - 1
n = y + 1
p = x + 1
q = y - 1
while (1 == 1)
{
if (count == 5)
{
win = true
break
}
if (f == 5)
{
win = false
break
}
if (m >= 0 &&n <= 300 &&p <= 300 &&q >= 0)
{
if (a.arr[m, n] == val)
{
count = count + 1
m = m - 1
n = n + 1
}
if (a.arr[p, q] == val)
{
count = count + 1
p = p + 1
q = q - 1
}
}
f = f + 1
}
if (win)
{
return val
}
#endregion
return 0
}
private void Btnstart_Click(object sender, EventArgs e)
{
img.Enabled = true
PaintLab()
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close()
}
}
}
这是我自己写的 五子棋代码 希望对你有帮助
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)