有谁懂利用VS和Qtjava编写五子棋制作五子棋小游戏的吗

博客分类:
简易五子棋
10 GRAPH:CLS:FOR X= 4 TO 148 STEP 8: FOR Y=4 TO 68 STEP 8: BOX X,Y,X+8,Y+8: NEXT:NEXT
20 A=1:X=76:Y=44 :B=0
30 X=X+160*(X〈 4)-160*(X〉156):Y=Y+80*( Y〈 4 )-80*(Y〉76)
40 BOX X-4,Y-4,X+4,Y+4,1,2:M=ASC(INKEY$):BOX X-4,Y-4,X+4,Y+4,1,2
50 Y=Y-8*(M=20)+8*(M=21):X=X+8*(M=22)-8*(M=23) :IF M=29 GOTO 10
60 IF M=13 AND PEEK(20*Y+(X-4)/8+2436)&&62 GOTO 100
70 IF M=31 AND B=1 THEN CIRCLE W,V,3,1,0 : LINE W-4,V,W+4,V : LINE W,V-4,W,V+4:A=(A=0) :B=0
80 IF M=27 THEN CLS:LOCATE 3 ,9 : PRINT“退出”: END
90 GOTO 30
100 CIRCLE X,Y,3,A,1 :CIRCLE X,Y,2,1,A :W=X:V=Y:B=1
110 Z=65+62*A:K$(1)=“白棋”:K$(2)=“黑棋”:P=0:Q=0:R=0:S=0:FOR L=-32 TO 32 STEP +8
120 E=(PEEK(20*(Y+L)+(X+L-4)/8+2536)=Z):F=(PEEK(20*(Y-L)+(X+L-4)/8+2536)=Z)
130 G=(PEEK(20*Y+(X+L-4)/8+2536)=Z):H=(PEEK(20*(Y+L)+(X-4)/8+2536)=Z)
140 P=E*(P+E):Q=F*(Q+F):R=G*(R+G):S=H*(S+H)
150 IF P=5 OR Q=5 OR R=5 OR S=5 THEN CLS:LOCATE 3 ,6: PRINT K$(A+1);“胜啦!”:END
160 NEXT:A=(A=0):GOTO 30
20 赋予各数初始值
30 使光标到了屏幕边界后能循环到另一边
40 画光标,读键,反显消除上次画的光标
50 方向键,光标坐标移8点。F2键,回到10句的CLS(清屏)。
60 输入键,PEEK(20*Y+(X-4)/8+2496-60)不等于0+0+32+16+8+4+2+0=62表示该棋位没有棋。(此为NC1020型,其它型的把2496改成相应型显存的第一个PEEK值)
70 F4键,把所下棋空白掉,LINE是把空白掉的棋盘补好。
80 跳出键,END结束程序。M=等于的数就是各键所对应的ASCII码,修改它,就可用其它键控制。
90 重复读键。
100 画棋子。
110---150 判断胜负。PEEK(20*Y+(X-4)/8+2496+40)等于0+64+32+16+8+4+2+1=127表示X,Y(或X+L,Y+L)棋位棋有黑棋,PEEK值等于0+64+0+0+0+0+0+1=65表示有白棋,PEEK值等于0+0+0+0+8+0+0+0=8(在顶上一横格时等于0)表示没有棋。知道这个原理,加个禁手,自已应该可以解决了。(此为NC1020型,其它型的把2496改成相应显存的第一个PEEK值)。
160 A=(A=0)使A的值反复0和1,这样就会交替出现黑棋和白棋。
如需转帖,请注名原作者:o_o
若要加存档功能,把:
80 IF M=27 THEN CLS:LOCATE 3 ,9 : PRINT“退出”:END
80 IF M=27 THEN 170
然后在10句前面加:
9 PRINT “档中存有棋局,是否继续?”:LOCATE 3,8:“Y是/N否”:M=ASC(INKEY$)
在10句后加:
11 DIM D(200):IF M&&121 GOTO 20
12 OPEN “DANG”FOR INPUT AS #1:WRITE #1,A,P$
:FOR X=4 TO 156 STEP 8:FOR Y=4 TO 76 STEP 8
13 INPUT #1,D,P$:IF D=127 THEN CIRCLE X,Y,4,1,1
14 IF D=65 THEN CIRCLE X,Y,3,1,0:CIRCLE X,Y,4
15 NEXT:NEXT:CLOSE #1:X=76,Y=44:GOTO 30
在程序后面加:
170 FOR X= 1 TO 20 : FOR Y=1 TO 10 :W=W+1: D(W)=PEEK(160*Y+X+2455):NEXT:NEXT
180 CLS:PRINT “未下完,是否存档?”:LOCATE 3,8:PRINT“Y是/N否”
190 M=ASC(INKEY$):IF M&&121 GOTO 220
200 CLS:LOCATE 3,5:PRINT“正在存档...”
200 OPEN “DANG”FOR OUTPUT AS #1:WRITE #1,A,“,”:FOR W=1 TO 200:WRITE #1,D(W),“,”
210 NEXT:CLOSE #1:CLS:LOCATE 3,6:PRINT“存档成功!”:INKEY$
220 CLS:LOCATE 3,4:PRINT“欢迎下次再来!” END
加完后,第一次运行,应在出现“档中存有棋局,是否继续?”时不要按Y键按其它键,而在出现“未下完,是否存档?”时按Y键。这样就会生成一个“DANG”的DAT数据文件。
用这种顺序存贮是比较慢的,如果用批量法要快得多。
浏览: 1226794 次
来自: 杭州699号
谢谢大神分享,比起新手看复杂的dubbo框架还不如看大神的这一 ...
你好,请问一下。&dubbo:consumer filt ...
a44ce234fb3d5a6a9b24f8b8bac0b77 ...
google一下就有免费的
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'啊叻?视频不见了?如何用qml(Qt Quick)做界面,用C++(Qt)实现业务逻辑? - 知乎261被浏览<strong class="NumberBoard-itemValue" title="5分享邀请回答quitcoding.com/download/Qt_Quick_Game_Programming_1_0.pdf用的Qt Quick版本较老,但思路可以借鉴。不谢。72添加评论分享收藏感谢收起doc.qt.io/qt-5/qtqml-cppintegration-topic.htmlQtQuickControls以及QtQuickControls2的最新进展,QtCS2015 QtQuickControls2BackgroundQtQuick.Controls 1 has tons and tons of objects per controlOverviewQtQuick.Controls 2 has interaction logic in C++, greatly decreases object overhead and number of contextsQtQuick.Controls 2 has visual items still in a (thin) QML layerStyling, theming and customizationNative/platform styles currently out of scopeWould be in a separate (derived) imports?Currently QtQuick.Controls 2 has a simple themable QML layerOngoing work adapting the palette concept from widgets (QTBUG-45839)Parts of controls can be replaced with custom delegatesStatusPopup items vs. popup windowsText selection handles via IMNo scaling (logical units?) thought of yetDiscussionAccessibility in the QML layer? Needed as it's private from QtQuickSome embedded users don't want accessibility. Seems "Short-sighted".Continue with controls 1 until native/desktop gets brought into the controls 2 ideaAs in done and maintained, but R&D on controls 2大家可以参考:61 条评论分享收藏感谢收起效果图:FIR.pro[cpp] view plain #-------------------------------------------------
# Project created by QtCreator T01:01:27
#-------------------------------------------------
&#43;= core gui
greaterThan(QT_MAJOR_VERSION, 4): QT &#43;= widgets
TARGET = FIR
TEMPLATE = app
SOURCES &#43;= main.cpp\
mainwindow.cpp
&#43;= mainwindow.h
mainwindow.h[cpp] view plain #ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include &QtGui&
class MainWindow : public QMainWindow
MainWindow(QWidget *parent = 0);
~MainWindow();
void paintEvent(QPaintEvent *);
void mouseReleaseEvent(QMouseEvent *);
int a[15][15];
int isWin(int, int);
int f1(int, int);
int f2(int, int);
int f3(int, int);
int f4(int, int);
#endif // MAINWINDOW_H
man.cpp[cpp] view plain #include &QApplication&
#include "mainwindow.h"
int main(int argc, char *argv[])
QApplication a(argc, argv);
return a.exec();
mianwindow.cpp[cpp] view plain #include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
resize(640, 640);
memset(a, 0, 15 * 15 * sizeof(int));
player = 0;
MainWindow::~MainWindow()
void MainWindow::paintEvent(QPaintEvent *)
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing, true);
for (i = 0; i & 16; i&#43;&#43;)
p.drawLine(20, 20 &#43; i * 40, 620, 20 &#43; i * 40);
p.drawLine(20 &#43; i * 40, 20, 20 &#43; i * 40, 620);
brush.setStyle(Qt::SolidPattern);
for (i = 0; i & 15; i&#43;&#43;)
for (j = 0; j & 15; j&#43;&#43;)
if (a[i][j] == 1)
brush.setColor(Qt::black);
p.setBrush(brush);
p.drawEllipse(QPoint((i &#43; 1) * 40, (j &#43; 1) * 40), 15, 15);
else if (a[i][j] == 2)
brush.setColor(Qt::white);
p.setBrush(brush);
p.drawEllipse(QPoint((i &#43; 1) * 40, (j &#43; 1) * 40), 15, 15);
void MainWindow::mouseReleaseEvent(QMouseEvent *e)
if(e-&x() &= 20 && e-&x() & 620 && e-&y() &= 20 && e-&y() & 620)
x = (e-&x() - 20) / 40;
y = (e-&y() - 20) / 40;
if (!a[x][y])
a[x][y] = player&#43;&#43; % 2 &#43; 1;
if(isWin(x, y))
setEnabled(false);
QMessageBox::information(this, "Win", "Win", QMessageBox::Ok);
int MainWindow::isWin(int x, int y)
return f1(x, y) || f2(x, y) || f3(x, y) || f4(x ,y);
int MainWindow::f1(int x, int y)
for (i = 0; i & 5; i&#43;&#43;)
if(y - i &= 0 &&
y &#43; 4 - i &= 0xF &&
a[x][y - i] == a[x][y &#43; 1 - i] &&
a[x][y - i] == a[x][y &#43; 2 - i] &&
a[x][y - i] == a[x][y &#43; 3 - i] &&
a[x][y - i] == a[x][y &#43; 4 - i])
int MainWindow::f2(int x, int y)
for (i = 0; i & 5; i&#43;&#43;)
if(x - i &= 0 &&
x &#43; 4 - i &= 0xF &&
a[x - i][y] == a[x &#43; 1 - i][y] &&
a[x - i][y] == a[x &#43; 2 - i][y] &&
a[x - i][y] == a[x &#43; 3 - i][y] &&
a[x - i][y] == a[x &#43; 4 - i][y])
int MainWindow::f3(int x, int y)
for (i = 0; i & 5; i&#43;&#43;)
if(x - i &= 0 &&
y - i &= 0 &&
x &#43; 4 - i &= 0xF &&
y &#43; 4 - i &= 0xF &&
a[x - i][y - i] == a[x &#43; 1 - i][y &#43; 1 - i] &&
a[x - i][y - i] == a[x &#43; 2 - i][y &#43; 2 - i] &&
a[x - i][y - i] == a[x &#43; 3 - i][y &#43; 3 - i] &&
a[x - i][y - i] == a[x &#43; 4 - i][y &#43; 4 - i])
int MainWindow::f4(int x, int y)
for (i = 0; i & 5; i&#43;&#43;)
if(x &#43; i &= 0xF &&
y - i &= 0 &&
x - 4 &#43; i &= 0 &&
y &#43; 4 - i &= 0xF &&
a[x &#43; i][y - i] == a[x - 1 &#43; i][y &#43; 1 - i] &&
a[x &#43; i][y - i] == a[x - 2 &#43; i][y &#43; 2 - i] &&
a[x &#43; i][y - i] == a[x - 3 &#43; i][y &#43; 3 - i] &&
a[x &#43; i][y - i] == a[x - 4 &#43; i][y &#43; 4 - i])
from:http://blog.csdn.net/zhangguangyi888/article/details/8192276您所在的位置:&&&&&&
最多人玩的小游戏
与学做美味蛋糕相似的小游戏
游戏介绍:厨房里藏着许多美味,可是要做成你喜欢的蛋糕必须把原料找出来呢操作方法:
找出物品游戏目标:找出需要的原料如何开始:游戏载入后,点击start,选择想要做的甜品开始游戏
游戏下载:
猜我喜欢的小游戏
最多人玩的游戏专辑
猜你喜欢的
热门小游戏
最新小游戏
大家都在玩
男生游戏 >
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
女生游戏 >
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
热门游戏 >
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
热门专题 >
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}

我要回帖

更多关于 mfc编写五子棋游戏 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信