c++ - 架构 x86_64 c++ Visual Studio 代码的未定义符号。游戏蛇和梯子
问题描述
在我看来,这个错误专门在两个类中出现,并在主体中被引用。老实说,我不知道发生了什么。
"Boxes::fillLadder(char**, int**, int, int, int)", referenced from:
Boxes::fill(char**, int**, int, int) in SnakesAndLadders2-455af6.o
Board::draw(char**, int**, int, int) in SnakesAndLadders2-455af6.o
"Boxes::fillSnake(char**, int**, int, int, int)", referenced from:
Boxes::fill(char**, int**, int, int) in SnakesAndLadders2-455af6.o
Board::draw(char**, int**, int, int) in SnakesAndLadders2-455af6.o
"Boxes::Boxes()", referenced from:
Board::draw(char**, int**, int, int) in SnakesAndLadders2-455af6.o
_main in SnakesAndLadders2-455af6.o
ld: symbol(s) not found for architecture x86_64
这是类盒子
#include <iostream>
#include <string>
using namespace std;
class Boxes{
public:
Boxes();
void fill(char **board, int **positions, int y, int x);
void fillLadder(char **board, int **positions, int y, int x, int lenght);
void fillSnake(char **board, int **positions, int y, int x, int lenght);
};
void Boxes::fill(char **board, int **positions, int y, int x)
{
for (int i = 0; i < y; i++)
{
for (int w = 0; w < x; w++)
{
board[i][w] = 'N';
positions[i][w] = 0;
}
}
if (y % 2 != 0)
{
board[0][x - 1] = 'O';
}
else
{
board[0][0] = 'O';
}
board[y - 1][0] = 'O';
if (y < 8)
{
fillLadder(board, positions, y - 1, 2, y / 2);
fillLadder(board, positions, y / 2, 4, 2);
fillSnake(board, positions, 0, 1, -1 * y / 2 + 1);
}
if (y >= 8 && y <= 12)
{
fillLadder(board, positions, y - 1, 3, 3);
fillLadder(board, positions, 4, x - 3, 2);
fillLadder(board, positions, 2, x - 2, 2);
fillSnake(board, positions, 0, 4, -4);
fillSnake(board, positions, 4, x - 4, -4);
fillSnake(board, positions, 4, 0, -3);
}
if (y > 12)
{
fillLadder(board, positions, y - 1, 3, 6);
fillLadder(board, positions, 6, x - 3, 5);
fillLadder(board, positions, 7, x - 2, 6);
fillLadder(board, positions, 9, 3, 3);
fillSnake(board, positions, 0, 4, -7);
fillSnake(board, positions, 4, x - 4, -6);
fillSnake(board, positions, 7, 0, -3);
fillSnake(board, positions, 5, 2, -2);
}
}
这是班板
#include <iostream>
#include <string>
#include <ctime>
#include "Player.h"
#include "Boxes.h"
using namespace std;
class Board{
public:
void loop(char **board, int **positions, int y, int x);
void draw(char **board, int **positions, int y, int x);
};
void Board::loop(char **board, int **positions, int x, int y)
{
player1.location = 0;
player2.location = 0;
player1.level = y - 1;
player2.level = y - 1;
bool game = true;
Player p;
bool playerFlag;
int &movement = movement;
void Movement(int &movement, bool playerFlag);
{
Dice dice;
int status = 0;
if (playerFlag == true)
{
std::cout << "Player 1: Press 1 to roll the dice." << std::endl;
cin >> status;
if (status == 1)
{
dice.roll();
movement = dice.roll();
std::cout << "Player 1 rolled a: " << dice.roll() << std::endl;
}
}
if (playerFlag == false)
{
std::cout << "Player 2: Press 2 to roll the dice." << std::endl;
cin >> status;
if (status == 2)
{
dice.roll();
movement = dice.roll();
std::cout << "Player 2 rolled a: " << dice.roll() << std::endl;
}
}
}
while (game == true)
{
p.Movement(player1.movement, true);
p.logic(board, positions, y, x, player1.movement, player1.location, player1.level, player1.movestatus);
if (p.checkWin(y, x, player1.location, player1.level) == true)
{
std::cout << "Player 1 HAS WON THE GAME !!!!!!" << std::endl;
game = false;
}
else
{
p.updatePlayerLevel(positions, y, x, player1.location, player1.level, player1.movestatus);
board[player1.level][player1.location] = player1.symbol;
draw(board, positions, y, x);
}
if (player2.on == true)
{
p.Movement(player2.movement, false);
p.logic(board, positions, y, x, player2.movement, player2.location, player2.level, player2.movestatus);
if (p.checkWin(y, x, player2.location, player2.level) == true)
{
std::cout << "Player 2 HAS WON THE GAME !!!!!!" << std::endl;
game = false;
}
else
{
p.updatePlayerLevel(positions, y, x, player2.location, player2.level, player2.movestatus);
board[player2.level][player2.location] = player2.symbol;
draw(board, positions, y, x);
}
}
}
}
void Board::draw(char **board, int **positions, int y, int x)
{
Boxes bx;
if (y % 2 != 0)
{
board[0][x - 1] = 'O';
}
else
{
board[0][0] = 'O';
}
board[y - 1][0] = 'O';
for (int i = 0; i < y; i++)
{
if ((y - 1) > 9)
{
std::cout << y - 1 << " ⎪" << std::endl;
}
else
{
std::cout << y - 1 << " ⎪" << std::endl;
}
for (int y = 0; y < x; y++)
{
std::cout << board[i][y] << " " << std::endl;
}
std::cout << " " << std::endl;
}
if (y < 8)
{
bx.fillLadder(board, positions, y - 1, 2, y / 2);
bx.fillLadder(board, positions, y / 2, 4, 2);
bx.fillLadder(board, positions, 0, 1, -1 * y / 2 + 1);
}
if (y >= 8 && y <= 12)
{
bx.fillLadder(board, positions, y - 1, 3, 3);
bx.fillLadder(board, positions, 4, x - 3, 2);
bx.fillLadder(board, positions, 2, x - 2, 2);
bx.fillSnake(board, positions, 0, 4, -4);
bx.fillSnake(board, positions, 4, x - 4, -4);
bx.fillSnake(board, positions, 4, 0, -3);
}
if (y > 12)
{
bx.fillLadder(board, positions, y - 1, 3, 6);
bx.fillLadder(board, positions, 6, x - 3, 5);
bx.fillLadder(board, positions, 7, x - 2, 6);
bx.fillLadder(board, positions, 9, 3, 3);
bx.fillSnake(board, positions, 0, 4, -7);
bx.fillSnake(board, positions, 4, x - 4, -6);
bx.fillSnake(board, positions, 7, 0, -3);
bx.fillSnake(board, positions, 5, 2, -2);
}
}
而且主要
#include <iostream>
#include <string>
#include <ctime>
#include "Board.h"
using namespace std;
int main()
{
Boxes f;
Board bo;
std::cout << "****** SNAKES AND LADDERS ******" << std::endl;
int size_y;
int size_x;
std::cout << "What size board do you want? Pick the number of rows and columns." << std::endl;
std::cout << "For balance, best size is 10x10." << std::endl;
std::cout << "Rows: " << std::endl;
cin >> size_y;
std::cout << "Columns: " << std::endl;
cin >> size_x;
int flag;
std::cout << "Press 2 if you want to play multiplayer (2 players). Press 1 for single player." << std::endl;
cin >> flag;
if (flag == 2)
{
player2.on = true;
}
std::cout << "Player 1: Select a letter/number on the keyboard for your character." << std::endl;
cin >> player1.symbol;
if (player2.on == true)
{
std::cout << "PLayer 2: Select a letter/number on the keyboard for your character." << std::endl;
cin >> player2.symbol;
}
system("CLS");
char **board;
board = new char *[size_y];
int **position_status;
position_status = new int *[size_y];
for (int i = 0; i < size_y; i++)
{
board[i] = new char [size_x];
position_status[i] = new int [size_x];
}
f.fill(board, position_status, size_y, size_x);
bo.draw(board, position_status, size_y, size_x);
bo.loop(board, position_status, size_y, size_x);
char stop;
std::cout << "Press e to end the programme." << std::endl;
cin >> stop;
for (int i = 0; i < size_y; i++)
{
delete[] board[i];
delete[] position_status[i];
}
delete board;
delete position_status;
return 0;
}
这段代码是关于蛇和梯子的游戏。如果您需要班级播放器,请告诉我,因为我在班级板上使用过它。
解决方案
推荐阅读
- mysql - 如何在日期时间中减去 1 天?
- firebase - 我可以在 Firebase 中使用哪些软件包版本?
- c# - Xamarin - Is there a similar framework to Photokit (iOS) available for Android, or a good way to get the filestream of all images in the gallery?
- python-3.x - 概念问题:序列 - 有序 - 可单独访问的元素容器 [k]
- php - PHP:设置公共属性时调用函数
- sql - Doctrine 抛出错误:预期的 Doctrine\ORM\Query\Lexer::T_FROM, got end of string." 错误
- javascript - 如何显示来自另一个网站的元素?
- swift - 如何从当前视图控制器更改前一个视图控制器的颜色?
- python - django unitest 多个类实例
- java - Spring Boot 在配置中使用 bean