AnsiString 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
--以怎么不用 MS VC++6 ??
编C语言一般都用啊
还有\xCD是C语言
Ascii代码 表示一个图形
用循环语句啊!
等我一下 晚上写出来 贴上哦
晚上10:00 上完课回来
呵呵 分给不给 随便 你的问题让我熟练了许多
分不重要了
我终于写出来了
调试了30分钟啊!
纯粹的循环 + 判断
-- 我就这点水平了 算法可能不好
如果有更好的告诉我 上QQ 或发百度消息给我
百度的显示有问题 最好
用源代码格式化工具格式化一下 百度有搜
#include <stdio.h>
void main()
{
int n,m,x,y,temp,j=0,i=0
printf("输入棋盘的横格数,竖格数:\n")
scanf("%d,%d",&x,&y)
printf("%d,%d\n",x,y)
n=2*x+1
m=2*y+1
printf("%d,%d\n",n,m)
while(j<m)
{
j++
temp=j%2
i=0
if(j==1)
{
while(i<n)
{
i++
if(i==1)
{
printf("\xC9")
continue
}
if(n==i)
{
printf("\xBB\n")
continue
}
if(i%2!=0)
{
printf("\xCB")
continue
}
if(i%2==0)
{
printf("\xCD\xCD\xCD")
continue
}
}
continue
}
if(m==j)
{
while(i<n)
{
i++
if(i==1)
{
printf("\xC8")
continue
}
if(n==i)
{
printf("\xBC\n")
continue
}
if(i%2!=0)
{
printf("\xCA")
continue
}
if(i%2==0)
{
printf("\xCD\xCD\xCD")
continue
}
}
continue
}
if(temp==0)
{
while(i<n)
{
i++
if(i%2!=0)
{
printf("\xBA")
if(n==i)printf("\n")
continue
}
if(i%2==0)
{
printf(" ")
continue
}
}
continue
}
if(temp!=0&&j!=1)
{
while(i<n)
{
i++
if(i==1)
{
printf("\xCC")
continue
}
if(n==i)
{
printf("\xB9\n")
continue
}
if(i%2!=0)
{
printf("\xCE")
continue
}
if(i%2==0)
{
printf("\xCD\xCD\xCD")
continue
}
}
continue
}
}
}
100%编译通过
可以画出任意大小的棋盘
如 5*3 5*5
只要你的屏幕能够显示
以上是用图像库画的棋盘
下面是用 __ 和 |
画的棋盘 其实很简单 替换一下就可以了
#include <stdio.h>
void main()
{
int n,m,x,y,temp,j=0,i=0
printf("输入棋盘的横格数,竖格数:\n")
scanf("%d,%d",&x,&y)
printf("%d,%d\n",x,y)
n=2*x+1
m=2*y+1
printf("%d,%d\n",n,m)
while(j<m)
{
j++
temp=j%2
i=0
if(j==1)
{
while(i<n)
{
i++
if(i==1)
{
printf("__")
continue
}
if(n==i)
{
printf("__\n")
continue
}
if(i%2!=0)
{
printf("__")
continue
}
if(i%2==0)
{
printf("__")
continue
}
}
continue
}
if(m==j)
{
while(i<n)
{
i++
if(i==1)
{
printf("__")
continue
}
if(n==i)
{
printf("__\n")
continue
}
if(i%2!=0)
{
printf("__")
continue
}
if(i%2==0)
{
printf("__")
continue
}
}
continue
}
if(temp==0)
{
while(i<n)
{
i++
if(i%2!=0)
{
printf("|")
if(n==i)printf("\n")
continue
}
if(i%2==0)
{
printf("")
continue
}
}
continue
}
if(temp!=0&&j!=1)
{
while(i<n)
{
i++
if(i==1)
{
printf("__")
continue
}
if(n==i)
{
printf("__\n")
continue
}
if(i%2!=0)
{
printf("__")
continue
}
if(i%2==0)
{
printf("__")
continue
}
}
continue
}
}
}
就给你一个吧,只不过没有添加棋子,你自己搞吧。import java.applet.*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()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)