- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的代码,对于一个机器项目,我只是在编程类(class)(基础知识)的第一年。这是一个口袋妖怪战斗模拟器,我只是设置口袋妖怪的 Action 和统计数据,以供用户决定他的口袋妖怪是什么。然而,当我开始打印玩家 1 的移动集时,strcpy() 会变得困惑,并且不知何故它后面包含了 strcpy() 的位。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
/*
Name: POKEMON 1v1 BATTLE SIMULATOR
Author: ADRIAN PAULE D. TY
Date Created: 10/18/2017
Last Modified: 10/18/2017
Description: This machine project is a program that puts two pokemon selected by the users against each other, taking the user's input to interact and determine the moves used.
*/
//--------------------------------------------------------------------------------------------------
//GLOBAL VARIABLES
///---Player 1
char cP1_Pokemon_Name[] = "POKEMON";
char cP1_Move1_Name[] = "TACKLE";
char cP1_Move2_Name[] = "POUND";
int nP1_HP_Base, nP1_HP_Current;
int nP1_Move1_PP, nP1_Move1_BP, nP1_Move2_PP, nP1_Move2_BP;
int nP1_Protect_PP= 5;
int nP1_Protect_Status = 0;
int nP1_ChargeUp_PP= 5;
int nP1_ChargeUp_Status = 0;
///---Player 2
char cP2_Pokemon_Name[] = "POKEMON";
char cP2_Move1_Name[] = "TACKLE";
char cP2_Move2_Name[] = "POUND";
int nP2_HP_Base, nP2_HP_Current;
int nP2_Move1_PP, nP2_Move1_BP, nP2_Move2_PP, nP2_Move2_BP;
int nP2_Protect_PP = 5;
int nP2_Protect_Status = 0;
int nP2_ChargeUp_PP = 5;
int nP2_ChargeUp_Status = 0;
//--------------------------------------------------------------------------------------------------
//FUNCTION PROTOTYPES
///---Player 1
void declare_pokemon_and_stats_1(int nChoice);
void display_player1_moveset_and_action();
///---Player 2
void declare_pokemon_and_stats_2(int nChoice);
void display_player2_moveset_and_action();
//--------------------------------------------------------------------------------------------------
//MAIN EXECUTION FUNCTION
int main(int argc, char *argv[]) {
int nP1_choice, nP2_choice;
printf("**************** POKEMON 1v1 BATTLE SIMULATOR **************** \n\n");
printf("Here are the POKEMON choices:\n");
printf("1 -- Entei\n");
printf("2 -- Milotic\n");
printf("3 -- Torterra\n");
printf("4 -- Pikachu\n");
printf("5 -- Groudon\n");
printf("6 -- Lapras\n");
printf("7 -- Stunfisk\n\n");
printf("PLAYER 1, please select your POKEMON: ");
scanf("%d", &nP1_choice);
declare_pokemon_and_stats_1(nP1_choice);
printf("PLAYER 2, please select your POKEMON: ");
scanf("%d", &nP2_choice);
declare_pokemon_and_stats_2(nP2_choice);
display_player1_moveset_and_action();
return 0;
}
//--------------------------------------------------------------------------------------------------
//FUNCTION DEFINITIONS
///---Declare Pokemon and Stats (PLAYER1)
/* This function sets the printed choice of PLAYER 1's Pokemon as well as the values for the stats, moves, PP of moves...... */
void declare_pokemon_and_stats_1(int nChoice){
int nP1_choice;
if (nChoice == 1){
nP1_HP_Base = 150;
nP1_HP_Current = 150;
strcpy(cP1_Move1_Name,"FIRE BLAST");
nP1_Move1_PP = 5;
nP1_Move1_BP = 30;
strcpy(cP1_Move2_Name,"EARTHQUAKE");
nP1_Move2_PP = 5;
nP1_Move2_BP = 30;
strcpy(cP1_Pokemon_Name, "ENTEI");
printf("PLAYER 1 has selected %s! \n\n", cP1_Pokemon_Name);
} else if (nChoice == 2){
nP1_HP_Base = 200;
nP1_HP_Current = 200;
strcpy(cP1_Move1_Name,"SCALD");
nP1_Move1_PP = 7;
nP1_Move1_BP = 20;
strcpy(cP1_Move2_Name,"ICE BEAM");
nP1_Move2_PP = 7;
nP1_Move2_BP = 20;
strcpy(cP1_Pokemon_Name,"MILOTIC");
printf("PLAYER 1 has selected %s! \n\n", cP1_Pokemon_Name);
} else if (nChoice == 3){
nP1_HP_Base = 220;
nP1_HP_Current = 220;
strcpy(cP1_Move1_Name,"DIG");
nP1_Move1_PP = 7;
nP1_Move1_BP = 20;
strcpy(cP1_Move2_Name,"LEAF STORM");
nP1_Move2_PP = 5;
nP1_Move2_BP = 40;
strcpy(cP1_Pokemon_Name,"TORTERRA");
printf("PLAYER 1 has selected %s! \n\n", cP1_Pokemon_Name);
} else if (nChoice == 4){
nP1_HP_Base = 120;
nP1_HP_Current = 120;
strcpy(cP1_Move1_Name,"THUNDERBOLT");
nP1_Move1_PP = 10;
nP1_Move1_BP = 10;
strcpy(cP1_Move2_Name,"DIG");
nP1_Move2_PP = 7;
nP1_Move2_BP = 20;
strcpy(cP1_Pokemon_Name,"PIKACHU");
printf("PLAYER 1 has selected %s! \n\n", cP1_Pokemon_Name);
} else if (nChoice == 5){
nP1_HP_Base = 150;
nP1_HP_Current = 150;
strcpy(cP1_Move1_Name,"FISSURE");
nP1_Move1_PP = 5;
nP1_Move1_BP = 40;
strcpy(cP1_Move2_Name,"FIRE BLAST");
nP1_Move2_PP = 5;
nP1_Move2_BP = 30;
strcpy(cP1_Pokemon_Name,"GROUDON");
printf("PLAYER 1 has selected %s! \n\n", cP1_Pokemon_Name);
} else if (nChoice == 6){
nP1_HP_Base = 190;
nP1_HP_Current = 190;
strcpy(cP1_Move1_Name,"ICE BEAM");
nP1_Move1_PP = 7;
nP1_Move1_BP = 20;
strcpy(cP1_Move2_Name,"SCALD");
nP1_Move2_PP = 7;
nP1_Move2_BP = 20;
strcpy(cP1_Pokemon_Name,"LAPRAS");
printf("PLAYER 1 has selected %s! \n\n", cP1_Pokemon_Name);
} else if (nChoice == 7){
nP1_HP_Base = 130;
nP1_HP_Current = 130;
strcpy(cP1_Move1_Name,"WATER GUN");
nP1_Move1_PP = 10;
nP1_Move1_BP = 10;
strcpy(cP1_Move2_Name,"EARTHQUAKE");
nP1_Move2_PP = 5;
nP1_Move2_BP = 30;
strcpy(cP1_Pokemon_Name,"STUNFISK");
printf("PLAYER 1 has selected %s! \n\n", cP1_Pokemon_Name);
} else {
printf("PLAYER 1, please select your POKEMON (from the list, Please): ");
scanf("%d", &nP1_choice);
declare_pokemon_and_stats_1(nP1_choice);
}
}
///---Declare Pokemon and Stats (PLAYER2)
/* This function sets the printed choice of PLAYER 2's POkemon as well as the values for the stats, moves, PP of moves...... */
void declare_pokemon_and_stats_2(int nChoice){
int nP2_choice;
if (nChoice == 1){
nP2_HP_Base = 150;
nP2_HP_Current = 150;
strcpy(cP2_Move1_Name,"FIREBLAST");
nP2_Move1_PP = 5;
nP2_Move1_BP = 30;
strcpy(cP2_Move2_Name,"EARTHQUAKE");
nP2_Move2_PP = 5;
nP2_Move2_BP = 30;
strcpy(cP2_Pokemon_Name,"ENTEI");
printf("PLAYER 2 has selected %s! \n\n", cP2_Pokemon_Name);
} else if (nChoice == 2){
nP2_HP_Base = 200;
nP2_HP_Current = 200;
strcpy(cP2_Move1_Name,"SCALD");
nP2_Move1_PP = 7;
nP2_Move1_BP = 20;
strcpy(cP2_Move2_Name,"ICE BEAM");
nP2_Move2_PP = 7;
nP2_Move2_BP = 20;
strcpy(cP2_Pokemon_Name,"MILOTIC");
printf("PLAYER 2 has selected %s! \n\n", cP2_Pokemon_Name);
} else if (nChoice == 3){
nP2_HP_Base = 220;
nP2_HP_Current = 220;
strcpy(cP2_Move1_Name,"DIG");
nP2_Move1_PP = 7;
nP2_Move1_BP = 20;
strcpy(cP2_Move2_Name,"LEAF STORM");
nP2_Move2_PP = 5;
nP2_Move2_BP = 40;
strcpy(cP2_Pokemon_Name,"TORTERRA");
printf("PLAYER 2 has selected %s! \n\n", cP2_Pokemon_Name);
} else if (nChoice == 4){
nP2_HP_Base = 120;
nP2_HP_Current = 120;
strcpy(cP2_Move1_Name,"THUNDERBOLT");
nP2_Move1_PP = 10;
nP2_Move1_BP = 10;
strcpy(cP2_Move2_Name,"DIG");
nP2_Move2_PP = 7;
nP2_Move2_BP = 20;
strcpy(cP2_Pokemon_Name,"PIKACHU");
printf("PLAYER 2 has selected %s! \n\n", cP2_Pokemon_Name);
} else if (nChoice == 5){
nP2_HP_Base = 150;
nP2_HP_Current = 150;
strcpy(cP2_Move1_Name,"FISSURE");
nP2_Move1_PP = 5;
nP2_Move1_BP = 40;
strcpy(cP2_Move2_Name,"FIRE BLAST");
nP2_Move2_PP = 5;
nP2_Move2_BP = 30;
strcpy(cP2_Pokemon_Name,"GROUDON");
printf("PLAYER 2 has selected %s! \n\n", cP2_Pokemon_Name);
} else if (nChoice == 6){
nP2_HP_Base = 190;
nP2_HP_Current = 190;
strcpy(cP2_Move1_Name,"ICE BEAM");
nP2_Move1_PP = 7;
nP2_Move1_BP = 20;
strcpy(cP2_Move2_Name,"SCALD");
nP2_Move2_PP = 7;
nP2_Move2_BP = 20;
strcpy(cP2_Pokemon_Name,"LAPRAS");
printf("PLAYER 2 has selected %s! \n\n", cP2_Pokemon_Name);
} else if (nChoice == 7){
nP2_HP_Base = 130;
nP2_HP_Current = 130;
strcpy(cP2_Move1_Name,"WATER GUN");
nP2_Move1_PP = 10;
nP2_Move1_BP = 10;
strcpy(cP2_Move2_Name,"EARTHQUAKE");
nP2_Move2_PP = 5;
nP2_Move2_BP = 30;
strcpy(cP2_Pokemon_Name,"STUNFISK");
printf("PLAYER 2 has selected %s! \n\n", cP2_Pokemon_Name);
} else {
printf("PLAYER 2, please select your POKEMON (from the list, Please): ");
scanf("%d", &nP2_choice);
declare_pokemon_and_stats_2(nP2_choice);
}
}
void display_player1_moveset_and_action(){
printf("***********************************************************************\n \n");
printf("%s: %d/%d HP\n", cP1_Pokemon_Name, nP1_HP_Base, nP1_HP_Current);
printf("%s: %d/%d HP\n\n", cP2_Pokemon_Name, nP2_HP_Base, nP2_HP_Current);
printf("%s's moves are: \n", cP1_Pokemon_Name);
printf("1 -- %s (%d BP, %d PP) \n", cP1_Move1_Name, nP1_Move1_BP, nP1_Move1_PP);
printf("2 -- %s (%d BP, %d PP) \n", cP1_Move2_Name, nP1_Move2_BP, nP1_Move2_PP);
printf("3 -- PROTECT (%d PP) \n", nP1_Protect_PP);
printf("4 -- CHARGE UP (%d PP) \n", nP1_ChargeUp_PP);
getch();
display_player2_moveset_and_action();
}
void display_player2_moveset_and_action(){
printf("***********************************************************************\n \n");
printf("%s: %d/%d HP\n", cP1_Pokemon_Name, nP1_HP_Base, nP1_HP_Current);
printf("%s: %d/%d HP\n\n", cP2_Pokemon_Name, nP2_HP_Base, nP2_HP_Current);
printf("%s's moves are: \n", cP2_Pokemon_Name);
printf("1 -- %s (%d BP, %d PP) \n", cP2_Move1_Name, nP2_Move1_BP, nP2_Move1_PP);
printf("2 -- %s (%d BP, %d PP) \n", cP2_Move2_Name, nP2_Move2_BP, nP2_Move2_PP);
printf("3 -- PROTECT (%d PP) \n", nP2_Protect_PP);
printf("4 -- CHARGE UP (%d PP) \n", nP2_ChargeUp_PP);
getch();
display_player1_moveset_and_action();
}
这是我得到的输出:
**************** POKEMON 1v1 BATTLE SIMULATOR ****************
Here are the POKEMON choices:
1 -- Entei
2 -- Milotic
3 -- Torterra
4 -- Pikachu
5 -- Groudon
6 -- Lapras
7 -- Stunfisk
PLAYER 1, please select your POKEMON:
1
PLAYER 1 has selected ENTEI!
PLAYER 2, please select your POKEMON: 4
PLAYER 2 has selected PIKACHU!
***********************************************************************
ENTEI: 150/150 HP
PIKACHU: 120/120 HP
ENTEI's moves are:
1 -- FIRE BLEARTHQUAKE (30 BP, 5 PP)
2 -- EARTHQUAKE (30 BP, 5 PP)
3 -- PROTECT (69 PP)
4 -- CHARGE UP (5 PP)
***********************************************************************
ENTEI: 150/150 HP
PIKACHU: 120/120 HP
PIKACHU's moves are:
1 -- THUNDERDIG (10 BP, 10 PP)
2 -- DIG (20 BP, 7 PP)
3 -- PROTECT (5 PP)
4 -- CHARGE UP (5 PP)
出于某种原因,应该是火焰爆炸的东西包含了一些地震(FIRE BLEARTHQUAKE),玩家 2 的其他 Action 组也是如此。
此外,由于某种原因,即使我设置了nP1_Protect_PP = 5
,它也会打印为69
感谢您的帮助
最佳答案
这两行显示出了什么问题:
以下行声明一个用“POUND”初始化的 char cP1_Move2_Name
数组。该数组的大小正好是 6 个字节,即“POUND”中的 5 个字符加上 NUL 终止符的 1 个字符(字符串以 NUL 字符终止,请阅读 C 教科书中处理字符串的章节以了解更多详细信息):
char cP1_Move2_Name[] = "POUND";
现在,在下面的行中,将“EARTHQUAKE”复制到数组cP1_Move2_Name
中。对于“EARTHQUAKE”,您需要 11 个字节,但如前所述,cP1_Move2_Name
数组的大小仅为 6。
strcpy(cP1_Move2_Name,"EARTHQUAKE");
因此,会发生的情况是复制的字节数超过了空间,因此其他一些内存将被覆盖,您可能会遇到各种问题。
为了纠正程序,您可以声明数组具有预定的最大大小,以确保始终有足够的空间。
#define MAXSTRINGLENGTH 100
...
char cP1_Pokemon_Name[MAXSTRINGLENGTH] = "POKEMON";
char cP1_Move1_Name[MAXSTRINGLENGTH] = "TACKLE";
char cP1_Move2_Name[MAXSTRINGLENGTH] = "POUND";
...
etc.
关于c - 多个连续的strcpy(),显示包含每个下一个strcpy()的位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46814219/
如何检查一个元素是否立即隐藏。即如何通知元素的可见性。 在我的例子中,该元素是通过 slideUp 函数隐藏的。我应该立即收到有关该元素的可见性的通知。 我想到了使用bind()方法。但它没有类似 o
if (srcbloc == NULL) { fprintf(stderr, "warning!: memrip source is null!\n"); exit(1); } if
当我在数据库的旧 View 中清理一些问题时,我遇到了这个“奇怪”的连接条件: from tblEmails [e] join tblPersonEmails [pe]
如何水平对齐多张图像,一张一张地?它们不必适合宽度屏幕:相反,我希望它们超过后者的宽度,如果这有任何意义的话。 我已经检查了很多类似问题的答案,但找不到任何可以解决我的问题的答案。 HTML:
我知道 Cassandra 中的列有 TTL。但是也可以在一行上设置 TTL 吗?在每列上设置 TTL 并不能解决我的问题,如下面的用例所示: 在某些时候,一个进程想要删除一个带有 TTL 的完整行(
我有一个 NSTextField 和 Label,其值绑定(bind)到 View Controller 中的相同 NSString 这里的问题是标签只有在我按 Tab 时才会更新。 如何使其连续,以
例如。 1."abc"; ===>abc 2."ab c"; ===>ab_c 3."ab c"; ===>ab_c 4."ab c" ===>ab_c 对于多个连续空格也是如此。 我怎样
大家好,我想获取前一天或最后一天的信息,只有当我按下按钮时,它才会显示最后一天(星期六)的所有信息,如果我再次单击按钮,它将显示最后一天的信息(星期五)如果我再次点击它(星期四)谢谢你们帮助我 编辑:
我需要从实时音频流中提取ICY元数据,并正在使用mplayer进行此操作,因为它在播放音频流时会输出元数据。我欢迎其他方式执行此操作,目标是将更新的元数据(歌曲信息)保存到文本文件中,只要歌曲(或数据
语音识别有没有解决方案 只有几个字(2 个就够了,10 个就不错了。100 个就很棒了。不需要更多) 也在移动浏览器上运行(是否可以为此使用 flash(而不是 java)?) 可以安装在您自己的服务
我有一个单词列表, list1 = ['hello', 'how', 'are', 'you?', 'i', 'am', 'fine', 'thanks.', 'great!'] 我想加入, list
我正在开发一个程序,但我不断收到“对‘dosell’的 undefined reference ”,我不太明白发生了什么。这是函数的声明: void dosell(int *cash, int *nu
我无法提出执行我要做的事情所需的查询。 我有三个这样的表: client_files ----------------------- client_id file_id ---------
我一直在寻找一个插件/脚本,当到达底部时,它会从头开始继续滚动网站,就像一个连续的循环。 示例:http://unfold.no/和 http://www.aquiesdonde.com.ar/ 我尝
这个问题在这里已经有了答案: How to prevent scanf causing a buffer overflow in C? (6 个答案) 关闭 6 年前。 我一直在使用一个非常简单的程
给定一个整数数组,找到具有相同数量的 x 和 y 的连续子序列的总数。例如 x=1 和 y=2 的数组 [1,2,1] ans = 2 表示它的两个子数组 [1,2] 和 [2,1]。检查每个连续的子
所以,我有一个所有正自然数的数组。我得到了一个阈值。我必须找出总和小于给定阈值的数字(连续)的最大计数。 For example, IP: arr = {3,1,2,1} Threshold = 5
我制作了像内置相机一样的相机应用。 我想实现像内置相机一样的连续对焦功能。(此功能我不触摸屏幕,但相机会尝试自行对焦。) 因此,将其设置为 surfaceCreated : Camera.Pa
我有这样的数据: f x A 1.1 A 2.2 A 3.3 B 3.5 B 3.7 B 3.9 B 4.1 B 4.5 A 5.1 A 5.2 C 5.4 C 5.5 C 6.1 B 6.2 B
假设我有一个包含一组数据点的表,每个数据点由一个时间戳和一个值组成。如果至少有 N 个连续记录(按时间戳排序)高于给定值 X,我将如何编写返回 true (1) 的查询,否则返回 false (0)?
我是一名优秀的程序员,十分优秀!