c++实现双人见缝插针
实现的要求:
(1)随着游戏的进行,针的速度越来越快,游戏难度越大;
(2)中间显示为“旋转蛇”的图像,每被针击中一次,换一次颜色;
(3)在右边新增一位玩家,并分别制作出计两位玩家的合作版和两个分别算分的竞争版。
代码:
合作版:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>int linenum = 0;
int hy()
{float PI = 3.1415926;int x, y, r, i;float h = rand() % 180;x = 400, y = 300;float offset, totaloffset = 0;COLORREF color1 = HSVtoRGB(linenum*5, 0.9, 0.8);COLORREF color2 = HSVtoRGB(linenum *5+ 180, 0.9, 0.7);for (r =60; r > 0; r = r - 10) {int left = x - r;int top = y - r;int right = x + r;int bottom = y + r;for (i = 0; i < 20; i++) {offset = i * PI / 10 + totaloffset;setfillcolor(color1);solidpie(left, top, right, bottom, offset, offset + 2 * PI / 60);setfillcolor(RGB(255, 255, 255));solidpie(left, top, right, bottom, offset + 2 * PI / 60, offset + 3 * PI / 60);setfillcolor(color2);solidpie(left, top, right, bottom, offset + 3 * PI / 60, offset + 5 * PI / 60);setfillcolor(RGB(0, 0, 0));solidpie(left, top, right, bottom, offset + 5 * PI / 60, offset + 6 * PI / 60);}totaloffset = totaloffset + PI / 20;}return 0;
}
int main() {const float pi = 3.1415926;int height, width;height = 600, width = 800;initgraph(width, height);setbkcolor(RGB(255, 255, 255));setlinestyle(PS_SOLID, 3);float lineLength = 150, xend, yend, rotatespeeed = pi / 360;float angles[1000];int score = 0;int i;BeginBatchDraw();while (1) {cleardevice();setlinecolor(RGB(0, 0, 0));line(0, height / 2, lineLength, height / 2);line(650, height / 2, 800, height / 2);for (i = 0; i < linenum; i++) {angles[i] = angles[i] + rotatespeeed;if (angles[i] > 2 * pi) {angles[i] = angles[i] - 2 * pi;}xend = lineLength * cos(-angles[i]) + width / 2;yend = lineLength * sin(-angles[i]) + height / 2;setlinecolor(RGB(0, 0, 255));if (i == linenum - 1) {setlinecolor(RGB(255, 0, 0));}line(xend, yend, width / 2, height / 2);}if (_kbhit() && rotatespeeed != 0) {char input = _getch();if (input == ' ') {linenum++;rotatespeeed += pi / 7200;angles[linenum - 1] = pi;xend = lineLength * cos(-angles[i - 1]) + width / 2;yend = lineLength * sin(-angles[i - 1]) + height / 2;line(xend, yend, width / 2, height / 2);for (i = 0; i < linenum - 1; i++) {if (fabs(angles[linenum - 1] - angles[i]) < pi / 60) {rotatespeeed = 0;break;}}score = score + 1;}if (input == 'a') {linenum++;rotatespeeed += pi / 7200;angles[linenum - 1] = 0;xend = lineLength * cos(-angles[i - 1]) + width / 2;yend = lineLength * sin(-angles[i - 1]) + height / 2;line(xend, yend, width / 2, height / 2);for (i = 0; i < linenum - 1; i++) {if (fabs(angles[linenum - 1] - angles[i]) < pi / 60) {rotatespeeed = 0;break;}}score = score + 1;}}hy();setlinecolor(HSVtoRGB(0, 0.9, 0.8));TCHAR s[20];_swprintf(s, _T("%d"), score);settextstyle(50, 0, _T("TIMES"));settextcolor(RGB(50, 50, 50));outtextxy(65, 200, s);FlushBatchDraw();Sleep(10);}closegraph();return 0;
}
竞技版:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>int linenum = 0;
int hy()
{float PI = 3.1415926;int x, y, r, i;float h = rand() % 180;x = 400, y = 300;float offset, totaloffset = 0;COLORREF color1 = HSVtoRGB(linenum*5, 0.9, 0.8);COLORREF color2 = HSVtoRGB(linenum *5+ 180, 0.9, 0.7);for (r =60; r > 0; r = r - 10) {int left = x - r;int top = y - r;int right = x + r;int bottom = y + r;for (i = 0; i < 20; i++) {offset = i * PI / 10 + totaloffset;setfillcolor(color1);solidpie(left, top, right, bottom, offset, offset + 2 * PI / 60);setfillcolor(RGB(255, 255, 255));solidpie(left, top, right, bottom, offset + 2 * PI / 60, offset + 3 * PI / 60);setfillcolor(color2);solidpie(left, top, right, bottom, offset + 3 * PI / 60, offset + 5 * PI / 60);setfillcolor(RGB(0, 0, 0));solidpie(left, top, right, bottom, offset + 5 * PI / 60, offset + 6 * PI / 60);}totaloffset = totaloffset + PI / 20;}return 0;
}
int main() {const float pi = 3.1415926;int height, width;height = 600, width = 800;initgraph(width, height);setbkcolor(RGB(255, 255, 255));setlinestyle(PS_SOLID, 3);float lineLength = 150, xend, yend, rotatespeeed = pi / 360;float angles[1000];int score1= 0,score2=0;int i;BeginBatchDraw();while (1) {cleardevice();setlinecolor(RGB(0, 0, 0));line(0, height / 2, lineLength, height / 2);line(650, height / 2, 800, height / 2);for (i = 0; i < linenum; i++) {angles[i] = angles[i] + rotatespeeed;if (angles[i] > 2 * pi) {angles[i] = angles[i] - 2 * pi;}xend = lineLength * cos(-angles[i]) + width / 2;yend = lineLength * sin(-angles[i]) + height / 2;setlinecolor(RGB(0, 0, 255));if (i == linenum - 1) {setlinecolor(RGB(255, 0, 0));}line(xend, yend, width / 2, height / 2);}if (_kbhit() && rotatespeeed != 0) {char input = _getch();if (input == ' ') {linenum++;rotatespeeed += pi / 7200;angles[linenum - 1] = pi;xend = lineLength * cos(-angles[i - 1]) + width / 2;yend = lineLength * sin(-angles[i - 1]) + height / 2;line(xend, yend, width / 2, height / 2);for (i = 0; i < linenum - 1; i++) {if (fabs(angles[linenum - 1] - angles[i]) < pi / 60) {rotatespeeed = 0;break;}}score1 = score1 + 1;}if (input == 'a') {linenum++;rotatespeeed += pi / 7200;angles[linenum - 1] = 0;xend = lineLength * cos(-angles[i - 1]) + width / 2;yend = lineLength * sin(-angles[i - 1]) + height / 2;line(xend, yend, width / 2, height / 2);for (i = 0; i < linenum - 1; i++) {if (fabs(angles[linenum - 1] - angles[i]) < pi / 60) {rotatespeeed = 0;break;}}score2 = score2 + 1;}}hy();setlinecolor(HSVtoRGB(0, 0.9, 0.8));TCHAR s[20];_swprintf(s, _T("%d"), score1);settextstyle(50, 0, _T("TIMES"));settextcolor(RGB(50, 50, 50));outtextxy(65, 200, s);setlinecolor(HSVtoRGB(0, 0.9, 0.8));TCHAR s1[20];_swprintf(s1, _T("%d"), score2);settextstyle(50, 0, _T("TIMES"));settextcolor(RGB(50, 50, 50));outtextxy(735, 200, s1);FlushBatchDraw();Sleep(10);}closegraph();return 0;
}
运行截图:
作者的一些话:我设置的左边玩家是空格发针,右边是a,这个可以随便设置,看过我之前文章的小伙伴应该知道我这期就是个缝合怪,不过不要紧啦,第一次做了双人游戏还是很高兴。
然后是基本每期基本都说说的安全性(说是安全性不如说是vs的bug):如果不设置的很多正常代码其实也无法运行,安全性对于个人开发者和学者其实必要性不是很大,初学者建议关闭,关闭方法是在调试按钮上选择最后一项,在选择c/c+,在将警告视为错误设置为否,在点击c/c++小三角,在代码生成的安全检测中选择禁用安全检查。
本学渣写文章也不易,希望大家点个赞,大家一起加油学习啊。
c++实现双人见缝插针相关推荐
- C++:见缝插针双人对战
简单说两句,这个双人对战只是实现了两人的对分,并没有做出相应判断,感兴趣的小伙伴可以自己动手写写.玩家一按数字1键,玩家二按数字2键,而且随着插入的针越来越多,速度也会越来越快.不过,你们可以自己更改 ...
- c语言倒计时不影响进程_2017级C语言大作业 - 见缝插针
分享17级同学大一上学期用C语言实现的见缝插针.分步骤代码.图片音乐素材.可执行程序可从百度网盘下载: 链接:https://pan.baidu.com/s/1dblHmOD2z0cUiJk3XSqu ...
- 2017级C语言大作业 - 见缝插针
见缝插针 C语言作业 分享17级同学大一上学期用C语言实现的见缝插针.分步骤代码.图片音乐素材.可执行程序可从百度网盘下载: 链接:https://pan.baidu.com/s/1dblHmOD2z ...
- 第5章 见缝插针(《C和C++游戏趣味编程》配套教学视频)
(图书介绍:童晶:<C和C++游戏趣味编程>新书预告) 本章我们将实现一个见缝插针的游戏.按下空格键后发射一根针到圆盘上,所有针逆时针方向转动:如果新发射的针碰到已有的针,游戏结束. 首先 ...
- 《Python游戏趣味编程》 第6章 见缝插针
6 见缝插针 Python游戏开发 图书简介可以看这里: 童晶:<Python游戏趣味编程>新书上架了 本章我们将编写一个见缝插针的游戏.按下空格键后发射一根针到圆盘上,所有发射的针跟着圆 ...
- C语言实现:见缝插针游戏!代码思路+源码分享
见缝插圆我们昨天已经用C语言实现了,今天将实现一个见缝插针的游戏. 游戏介绍:<见缝插针游戏>是一款非常休闲益智的且容易上头的小游戏,该游戏画面非常的简洁,米白色的背景中央,放置着一个不断 ...
- Python实现贪吃蛇小游戏(双人模式)
这篇文章主要为大家详细介绍了Python实现双人模式的贪吃蛇小游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 简单用py写了一个贪吃蛇游戏,有单人.双人模式,比较简 ...
- 双人五子棋对战(需要EasyX图像库)
实训要做项目呐.天天坐在电脑面前累死了.最近题刷的少.大多数都挺水.就不挨个编辑发上来了.发发白天写的项目吧.可能好几天更一下.实训结束恢复正常. 这个游戏需要EasyX的图像库.有兴趣的可以下一个图 ...
- js+html5双人五子棋(源码下载)
代码如下: 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type ...
最新文章
- python用raise手动抛出异常
- wiki-editor语法
- redis的基本使用笔记二
- 揭开互联网公司的神秘面纱,数据解读那些slay整个行业的互联网公司
- 吃屎是一种什么样的体验?
- 新手也能学会本地调试微信,natapp 官网映射
- 关于Python3.6下登陆接口的尝试
- 事务的四大特性和隔离级别
- IDEA autowired校验关闭方法
- UI实用素材模板|app底部导航栏的图标可临摹素材,教你分析!
- Django 基础,创建一个Django,并成功在网页中运行
- matlab 矩阵维度一致,错误使用 / 矩阵维度必须一致。
- Linux c/c++开发常用头文件
- DecoupleSegNet结构解读
- 以太网卡、IB网卡的详细介绍以及区别分析
- g mysql windows_Windows平台配置5.7版本+MySQL数据库服务
- mysql和mongo+查询效率_Mongodb VS Mysql 查询性能
- python123测试4四位玫瑰数_心理测试:4朵玫瑰,你最喜欢哪一朵?测测你这辈子会有多少情债...
- 洛谷P1005 矩阵取数游戏 ACM 大数+区间dp
- 共享yum资源库下一键安装虚拟机的脚本3【完全自动化】
热门文章
- 如何用python里的pycharm画等腰三角形
- 从实验开始零基础学网络路由交换 三十七,配置NAPT
- Android常用的网络框架介绍和使用
- 工作三年多女程序员,字字珠玑般的经验之谈
- YoloV7目标检测(Pytorch版)【详解】
- 网页php如何判断登录手机串号_php判断手机段登录,以及phpcms手机PC双模板调用...
- 海康android sdk联外网,海康网络摄像机SDK对接
- 利用OD进行软件破解需要用到的基础汇编知识
- 为什么牛逼?——Stonie is a KungFu monk游戏精品功能介绍与详细规范,以及其中的挑战...
- 17个短视频渠道分成收益全解析