import java.awt.*
import java.awt.event.*
class ChessPad extends Panel implements MouseListener,ActionListener
{int x=-1,y=-1,棋子颜色=1
Button button=new Button("重新开局")
TextField text_1=new TextField("请黑棋下子"),
text_2=new TextField()
ChessPad()
{setSize(440,440)
setLayout(null)setBackground(Color.pink)
addMouseListener(this)add(button)button.setBounds(10,5,60,26)
button.addActionListener(this)
add(text_1)text_1.setBounds(90,5,90,24)
add(text_2)text_2.setBounds(290,5,90,24)
text_1.setEditable(false)text_2.setEditable(false)
}
public void paint(Graphics g)
{for(int i=40i<=380i+=20)
{g.drawLine(40,i,400,i)
}
g.drawLine(40,400,400,400)
for(int j=40j<=380j+=20)
{g.drawLine(j,40,j,400)
}
g.drawLine(400,40,400,400)
g.fillOval(97,97,6,6)g.fillOval(337,97,6,6)
g.fillOval(97,337,6,6)g.fillOval(337,337,6,6)
g.fillOval(217,217,6,6)
}
public void mousePressed(MouseEvent e)
{if(e.getModifiers()==InputEvent.BUTTON1_MASK)
{x=(int)e.getX()y=(int)e.getY()
ChessPoint_black chesspoint_black=new ChessPoint_black(this)
ChessPoint_white chesspoint_white=new ChessPoint_white(this)
int a=(x+10)/2,b=(y+10)/2
if(x/20<2||y/20<2||x/20>19||y/20>19)
{}
else
{
if(棋子颜色==1)
{this.add(chesspoint_black)
chesspoint_black.setBounds(a*20-7,b*20-7,16,16)
棋子颜色=棋子颜色*(-1)
text_2.setText("请白棋下子")
text_1.setText("")
}
else if(棋子颜色==-1)
{this.add(chesspoint_white)
chesspoint_white.setBounds(a*20-7,b*20-7,16,16)
棋子颜色=棋子颜色*(-1)
text_1.setText("请黑棋下子")
text_2.setText("")
}
}
}
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
public void actionPerformed(ActionEvent e)
{this.removeAll()棋子颜色=1
add(button)button.setBounds(10,5,60,26)
add(text_1)text_1.setBounds(90,5,90,24)
text_2.setText("")text_1.setText("请黑棋下子")
add(text_2)text_2.setBounds(290,5,90,24)
}
}
class ChessPoint_black extends Canvas implements MouseListener
{ChessPad chesspad=null
ChessPoint_black(ChessPad p)
{setSize(20,20)chesspad=paddMouseListener(this)
}
public void paint(Graphics g)
{g.setColor(Color.black)g.fillOval(0,0,14,14)
}
public void mousePressed(MouseEvent e)
{if(e.getModifiers()==InputEvent.BUTTON3_MASK)
{chesspad.remove(this)
chesspad.棋子颜色=1
chesspad.text_2.setText("")chesspad.text_1.setText("请黑棋下子")
}
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e)
{if(e.getClickCount()>=2)
chesspad.remove(this)
}
}
class ChessPoint_white extends Canvas implements MouseListener
{ChessPad chesspad=null
ChessPoint_white(ChessPad p)
{setSize(20,20)addMouseListener(this)
chesspad=p
}
public void paint(Graphics g)
{g.setColor(Color.white)g.fillOval(0,0,14,14)
}
public void mousePressed(MouseEvent e)
{if(e.getModifiers()==InputEvent.BUTTON3_MASK)
{chesspad.remove(this)
chesspad.棋子颜色=-1
chesspad.text_2.setText("请白棋下子")chesspad.text_1.setText("")
}
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e)
{if(e.getClickCount()>=2)
chesspad.remove(this)
}
}
public class Chess extends Frame
{ChessPad chesspad=new ChessPad()
Chess()
{setVisible(true)
setLayout(null)
Label label=new Label("单击左键下子,双击吃子,右击棋子悔棋",Label.CENTER)
add(label)label.setBounds(70,55,440,26)
label.setBackground(Color.orange)
add(chesspad)chesspad.setBounds(70,90,440,440)
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0)
}
})
pack()setSize(600,550)
}
public static void main (String args[])
{Chess chess=new Chess()
}
}
来~加 我 的QQ405557154 我做了一个,还有一同学做的,还有一是网上的朋友做的呵呵Private Sub Timer1_Timer()
Dim ms As Boolean
Dim Info, temp As String
Dim p, p1, p2, i As Integer
Dim Ch
' Begin of Time Show Process
If ModemState <>LOGIN And SocketState <>CONNECTED Then
'it is not a multiusers game
Exit Sub
Else
If (S_R = 1) And (TURN = BLACKP) Then
Black_Time = Black_Time + Time - Start_Time
TimeB.Caption = CDate(Black_Time / 200)
Else
If (S_R = 1) And (TURN = WHITEP) Then
White_Time = White_Time + Time - Start_Time
TimeW.Caption = CDate(White_Time / 200)
Else
If (S_R = 0) And (TURN = WHITEP) Then
Black_Time = Black_Time + Time - Start_Time
TimeB.Caption = CDate(Black_Time / 200)
Else
If (S_R = 0) And (TURN = BLACKP) Then
White_Time = White_Time + Time - Start_Time
TimeW.Caption = CDate(White_Time / 200)
End If
End If
End If
End If
End If
'End If
' End of Time Show Process
'Begin of winsockt process
If SocketState = CONNECTED And Begin_Flag = 1 Then
ms = Net.Message_Exist
If ms = False Then
Exit Sub
End If
Info = Net.WaitForValue(Chr$(26), 5)
If g_ErrorCode = 1 Then
'Some error such as Timeout occured
Exit Sub
End If
p1 = InStr(Info, "B")
p2 = InStr(Info, "E|")
If p1 = 0 Or p2 = 0 Then
Exit Sub
End If
temp = Mid$(Info, p1 + 1, p2 - p1 - 1)
ParseLine (temp)
Msg(Msg_No).No = CInt(ParseArray(1))
Msg(Msg_No).Color = CInt(ParseArray(2))
If IsNumeric(ParseArray(3)) Then
Msg(Msg_No).X = CInt(ParseArray(3))
Msg(Msg_No).Y = CInt(ParseArray(4))
Else
Msg(Msg_No).X = ParseArray(3)
Msg(Msg_No).Y = ParseArray(4)
End If
If Msg(Msg_No).Color = GIVEUP Then
Beep
MsgBox ("对方已经认输了")
Net.Winsock1.SendData ("R_O" + Chr$(26))
Pause 3
Call Begin_Click
Exit Sub
End If
If Side = BLACKP Then
p = Draw_Point(Msg(Msg_No).X, Msg(Msg_No).Y, WHITEP)
Record(Step).Color = WHITEP
step_show.Cls
step_show.Print Step
TURN = BLACKP
Else
p = Draw_Point(Msg(Msg_No).X, Msg(Msg_No).Y, BLACKP)
Record(Step).Color = BLACKP
step_show.Cls
step_show.Print Step
TURN = WHITEP
End If
Record(Step).X = Msg(Msg_No).X
Record(Step).Y = Msg(Msg_No).Y
Step = Step + 1
S_R = 1
R_R = 0
p = Count_All_Gas
If (Msg(Msg_No).X >0 And Msg(Msg_No).Y >0 _
And Msg(Msg_No).X <20 And Msg(Msg_No).Y <20) Then
Board(Msg(Msg_No).X, Msg(Msg_No).Y).Current = True
Refresh_Board
Board(Msg(Msg_No).X, Msg(Msg_No).Y).Current = False
End If
Msg_No = Msg_No + 1
Pause 1
Net.Winsock1.SendData ("R_O" + Chr$(26))
Exit Sub
End If
'End of process of winsocket
'Begin of modem process
If ModemState <>LOGIN Or R_R <>1 Then
'It isn't a Inter_Modem Game
Exit Sub
End If
ms = Modem_F.Exist_Msg
If ms = False Then
'IO Port don't have any message
Exit Sub
End If
Info = Modem_F.WaitForValue(Chr$(26), 5)
'Wait a playing message
If g_ErrorCode = 1 Then
'Some error such as Timeout occured
Exit Sub
End If
p1 = InStr(Info, "B")
p2 = InStr(Info, "E|")
If p1 = 0 Or p2 = 0 Then
Exit Sub
End If
temp = Mid$(Info, p1 + 1, p2 - p1 - 1)
ParseLine (temp)
Msg(Msg_No).No = CInt(ParseArray(1))
Msg(Msg_No).Color = CInt(ParseArray(2))
If IsNumeric(ParseArray(3)) Then
Msg(Msg_No).X = CInt(ParseArray(3))
Msg(Msg_No).Y = CInt(ParseArray(4))
Else
Msg(Msg_No).X = ParseArray(3)
Msg(Msg_No).Y = ParseArray(4)
End If
Modem_F.Comm1.InBufferCount = 0
'Clear Buffer
If Msg(Msg_No).Color = LOGOUT Then
Beep
MsgBox ("对方已经退出了")
Modem_F.Comm1.InBufferCount = 0
Modem_F.Comm1.Output = "R_O" + Chr$(26)
Cls
Step = 0
Start_Time = Time
Black_Time = 0
White_Time = 0
Exit Sub
End If
If Msg(Msg_No).Color = FINISHED Then
Beep
Ch = MsgBox("对方要求结束比赛,可以吗?", vbYesNo)
Modem_F.Comm1.InBufferCount = 0
If Ch = 6 Then
Modem_F.Comm1.Output = "YESR_O" + Chr$(26)
Else
Modem_F.Comm1.Output = "NOR_O" + Chr$(26)
Exit Sub
End If
PlayState = FINISHED
Count_Area.Enabled = True
End If
If Msg(Msg_No).Color = GIVEUP Then
Beep
MsgBox ("对方已经认输了")
Modem_F.Comm1.InBufferCount = 0
Modem_F.Comm1.Output = "R_O" + Chr$(26)
Call Begin_Click
Exit Sub
End If
If Msg(Msg_No).Color = TALK Then
Beep
MsgBox (Modem_F.His_Name.Text &"说: " &Msg(Msg_No).X)
Modem_F.Comm1.InBufferCount = 0
Modem_F.Comm1.Output = "R_O" + Chr$(26)
Exit Sub
End If
If Msg(Msg_No).Color = UNDO Then
Step = Step - 1
Beep
Modem_F.Comm1.InBufferCount = 0
Modem_F.Comm1.Output = "R_O" + Chr$(26)
Draw_Board
Ini_Board
For i = 1 To Step - 1
Board(Record(i).X, Record(i).Y).Current = False
p = Draw_Point(Record(i).X, Record(i).Y, Record(i).Color)
step_show.Cls
step_show.Print Step
p = Count_All_Gas
Next i
Board(Record(Step - 1).X, Record(Step - 1).Y).Current = True
Refresh_Board
Board(Record(Step - 1).X, Record(Step - 1).Y).Current = False
S_R = 1
R_R = 0
TURN = Side
Exit Sub
End If
Modem_F.Comm1.InBufferCount = 0
Modem_F.Comm1.Output = "R_O" + Chr$(26)
If Side = BLACKP Then
p = Draw_Point(Msg(Msg_No).X, Msg(Msg_No).Y, WHITEP)
Record(Step).Color = WHITEP
step_show.Cls
step_show.Print Step
Else
p = Draw_Point(Msg(Msg_No).X, Msg(Msg_No).Y, BLACKP)
Record(Step).Color = BLACKP
step_show.Cls
step_show.Print Step
End If
Record(Step).X = Msg(Msg_No).X
Record(Step).Y = Msg(Msg_No).Y
Step = Step + 1
S_R = 1
R_R = 0
p = Count_All_Gas
If (Msg(Msg_No).X >0 And Msg(Msg_No).Y >0 _
And Msg(Msg_No).X <20 And Msg(Msg_No).Y <20) Then
Board(Msg(Msg_No).X, Msg(Msg_No).Y).Current = True
Refresh_Board
Board(Msg(Msg_No).X, Msg(Msg_No).Y).Current = False
End If
Msg_No = Msg_No + 1
End Sub
Private Sub Timer2_Timer()
ShowS.Cls
ShowS.Print " :-):-):-):-):-) " + Show_String(C1) + " (:-(:-(:-(:-(:-"
C1 = C1 + 1
If C1 = 10 Then
C1 = 0
End If
Game_Time.Cls
Game_Time.Print " 现在时间: " &Time
End Sub
Private Sub Set_Hand(h As Integer)
'设置让子(1-9)
Dim p As Integer
If h <= 1 Then
'Not a Handicap game
Exit Sub
End If
部分代码。。
int Count = 600AnsiString CaTimer(int Value)
{
AnsiString ss
ss.printf("%02d:%02d:%02d",Value/(60*60), (Value%(60*60))/60,Value%60)
return ss
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Count--
Label1->Caption = CaTimer(Count)
}
// 要设置计时器 1秒钟 一次。 Timer1->Interval = 1000(毫秒)
// 打开关闭 可以设置 Timer1 的属性 Enabled 为true , false
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)