-2
私は質問があります。私はopencvで簡単なスネークゲームを作っています。今私は蛇を動かしたいが、それはしない。私のコードに何が間違っていますか?私はsnakemove()私は私の蛇に適用されないことを作成すると思う。どのように私はこれを修正することはできますか?前もって感謝します。ここ は私のコードシンプルなスネークゲームを作る
#include<opencv2\core\core.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<opencv2\imgproc.hpp>
#include<stdio.h>
#include<conio.h>
#include<iostream>
bool gameover;
using namespace cv;
const int width = 500;
const int height = 500;
int x, y;
enum eDirection
{
STOP = 0,
LEFT,
RIGHT,
UP,
DOWN
};
eDirection dir;
void Setup()
{
gameover = false;
dir = STOP;
x = width/2;
y =height/2;
}
void DrawAsnake(Mat &img)
{
const int HEAD_SIZE = 10;
const int BODY_SIZE = 10;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
if (i == y && j == x)
{
circle(img, Point(x, y), HEAD_SIZE, Scalar(255, 0, 0), 2);
rectangle(img, Point(x - 2 * HEAD_SIZE, y), Point(x - HEAD_SIZE, y + HEAD_SIZE/2), Scalar(255, 0, 0), 2);
}
}
}
}
void SnakeMove()
{
if (_kbhit())
{
switch (_getch())
{
case 'a'://75
dir = LEFT;
break;
case'w' ://72
dir = UP;
break;
case 'd'://77
dir = RIGHT;
break;
case 's'://80
dir = DOWN;
break;
}
}
}
void GameLogic()
{
switch (dir)
{
case LEFT:
x--;
break;
case RIGHT:
x--;
break;
case UP:
y--;
break;
case DOWN:
y++;
default:
break;
}
}
void main()
{
Mat img(500, 800, CV_32FC3);
Setup();
while(!gameover)
{
DrawAsnake(img);
SnakeMove();
GameLogic();
imshow("main window", img);
waitKey(20);
img = Mat::zeros(img.rows, img.cols, CV_32FC3);
imshow("main window", img);
x++;
}
}
コールsnakeMove()関数imshowの呼び出しの間に()関数 –
あなたはいつか必要があります場合は、[それ]について考える(https://en.wikipedia.org/ですwiki/Unit_testing) –
@あなたのrely.wellのためのIdon'tcareのおかげで私は試みますが、それでも動作しません – Van