Polygon(多边形游戏)

40 篇文章 18 订阅 ¥9.90 ¥99.00
这是一款单人游戏,玩家在一个有N个顶点的多边形中操作,每个顶点标有整数,每条边标有加法或乘法符号。玩家首先移除一条边,然后通过选择边并根据边上的运算符更新顶点标签,直至只剩下一个顶点。程序需计算可能的最高得分并找出所有在首次移除时能达成这一分数的边。
摘要由CSDN通过智能技术生成

Description

 

Polygon is a game for one player that starts on a polygon with N vertices, like the one in Figure 1, where N=4. Each vertex is labelled with an integer and each edge is labelled with either the symbol + (addition) or the symbol * (product). The edges are numbered from 1 to N.

On the first move, one of the edges is removed. Subsequent moves involve the following steps: ?pick an edge E and the two vertices V1 and V2 that are linked by E; and ?replace them by a new vertex, labelled with the result of performing the operation indicated in E on the labels of V1 and V2. The game ends when there are no more edges, and its score is the label of the single vertex remaining. Consider the polygon of Figure 1. The player started by removing edge 3. After that, the player picked edge 1, then edge 4, and, finally, edge 2. The score is

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的多边形游戏的C代码示例,其中包括绘制多边形和检测多边形是否被点击: ```c #include <stdio.h> #include <graphics.h> #define MAX_POINTS 50 // 定义一个结构体来存储多边形的点 typedef struct { int x; int y; } point_t; // 绘制多边形 void draw_polygon(point_t points[], int num_points) { int i; for (i = 0; i < num_points; i++) { line(points[i].x, points[i].y, points[(i+1)%num_points].x, points[(i+1)%num_points].y); } } // 检测多边形是否被点击 int is_polygon_clicked(point_t points[], int num_points, int x, int y) { int i, j; int c = 0; for (i = 0, j = num_points-1; i < num_points; j = i++) { if (((points[i].y > y) != (points[j].y > y)) && (x < (points[j].x - points[i].x) * (y - points[i].y) / (points[j].y - points[i].y) + points[i].x)) { c = !c; } } return c; } int main() { int gd = DETECT, gm; initgraph(&gd, &gm, ""); point_t points[MAX_POINTS]; int num_points = 0; int i = 0; // 从用户输入中获取多边形点的数量和坐标 printf("Enter the number of points in the polygon: "); scanf("%d", &num_points); printf("Enter the coordinates of each point:\n"); for (i = 0; i < num_points; i++) { printf("Point %d: ", i+1); scanf("%d %d", &points[i].x, &points[i].y); } // 绘制多边形 draw_polygon(points, num_points); // 检测是否被点击 int x, y; while (!kbhit()) { if (ismouseclick(WM_LBUTTONDOWN)) { getmouseclick(WM_LBUTTONDOWN, x, y); if (is_polygon_clicked(points, num_points, x, y)) { printf("The polygon was clicked!\n"); } else { printf("The polygon was not clicked.\n"); } } } closegraph(); return 0; } ``` 注意,以上代码使用了graphics.h库,因此需要在编译时使用-lgraphics参数。例如,对于gcc编译器,可以使用以下命令来编译代码: ```shell gcc -o polygon_game polygon_game.c -lgraphics ``` 请确保你的编译环境中已经安装了graphics.h库。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值