c - C语言10x10板上的替代棋子运动
问题描述
我试图让棋盘上的棋子在棋盘上向上移动时从左向右移动,然后从右向左移动。我使用二维数组来表示坐标和指针算法来操作它,因为我们不能在函数本身上使用二维数组。
while (k <= 11) { //I used K as a marker for the 11 vertical line Im going to make
if (lineOne == 1) {
printf("|");
lineOne = 0;
lineTwo = 1;
k++;
} else if (lineTwo == 1) {
if (row % 2 == 0) { //pointer arithmetic to go through each part of the array
printf("%c%c%c%c", *( * (arrA + row) + col),
*( * (arrB + row) + col),
*( * (arrC + row) + col),
*( * (arrD + row) + col));
col++;
} else if (row % 2 != 0) {
printf("%c%c%c%c", *( * (arrA + row) + col),
*( * (arrB + row) + col),
*( * (arrC + row) + col),
*( * (arrD + row) + col));
col--;
}
lineOne = 1;
lineTwo = 0;
}
}
row++;
divider = 1;
thirdLine = 0;
printf("\n");
这些是我的初始化
int row = 0, col = 0;
在我的脑海中,我的 2D 网格也是这样排列的
0
1
2
3
4
5
6
7
8
9
0 1 2 3 4 5 6 7 8 9
这是我的代码的输出。不要介意S,它是另一天的错误:(
+----+----+----+----+----+----+----+----+----+----+
|# |S |S |S |S |S |S |S |S |S |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
|- | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
a's turn.
a, press <Enter> to roll.
You rolled a 5
95
95
+----+----+----+----+----+----+----+----+----+----+
|# |S |S |S |S |S |S |S |S |S |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | |a | | | | |
+----+----+----+----+----+----+----+----+----+----+
95
get out
b's turn.
b, press <Enter> to roll.
这里 9 5 是我拥有的那个玩家的坐标
正如你所看到的,当它应该像这样从左到右进行时,它向左移动了 5 步
+----+----+----+----+----+----+----+----+----+----+
|# | S| | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | |l | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| |l | S| | | | | | s| |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | |L | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | |l | | |L |S | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | s| | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | s|L | | | | | | | |
|abcd| | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
a's turn.
a, press <Enter> to roll.
+----+----+----+----+----+----+----+----+----+----+
|# | S| | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | |l | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| |l | S| | | | | | s| |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | |L | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | |l | | |L |S | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | | | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | | | | | s| | | | |
| | | | | | | | | | |
+----+----+----+----+----+----+----+----+----+----+
| | s|L | | | | | | | |
| bcd| | | | a| | | | | |
+----+----+----+----+----+----+----+----+----+----+
a rolls a 4!
b's turn
b, press <Enter> to roll.
我只想让我的作品在每次向上移动 Y 轴时交替移动。
解决方案
推荐阅读
- hl7-fhir - 如何使用_content在fhir中搜索birthData?
- javascript - 如何在javascript中舍入一个整数
- python-3.x - 向外部服务器发出 POST 请求时出现 SSL 证书错误
- google-chrome - InboxSDK 获取线程中的所有附件
- sql - 连接 VarChar 和日期字段
- python-3.x - 比较响应 200,我需要 'true' 作为答案
- wordpress - Wordpress 媒体上传错误仅在屏幕上添加/编辑帖子
- reactjs - 如何文件上传React js web api不起作用
- java - 如何在 Android Studio 的列表视图中对数据进行排序
- r - 使用 dplyr 创建列