#include<iostream>
#include<cstdlib>
#include<ctime>
#include<conio.h>
using std::cout;
using std::cin;
using std::endl;
bool gameOver;
const int width = 25;
const int height = 25;
int x, y, fruitX, fruitY, score;
int tailX[100], tailY[100];
int nTail;
enum eDirection { STOP = 0, LEFT, RIGHT, UP, DOWN };
eDirection dir;
void Setup() {
gameOver = false;
dir = STOP;
x = width / 2 - 1;
y = height / 2 - 1;
fruitX = rand() % width;
fruitY = rand() % height;
score = 0;
};
void Draw() {
cout << "w = UP" << endl;
cout << "s = DOVN" << endl;
cout << "d = RIGHT" << endl;
cout << "a = LEFT" << endl;
system("cls");//system("clear");
for (int i = 0;i < width + 1;i++) {
cout << "##";
for (int i = 0;i < height;i++) {
for (int j = 0;j < width;j++) {
if (j == 0 || j == width - 1) {
if (i == y && j == x) {
cout << "0";
}
else if (i == fruitY && j == fruitX) {
cout << "F";
else {
bool print = false;
for (int k = 0;k < nTail;k++) {
if (tailX[k] == j && tailY[k] == i) {
print = true;
cout << "o";
if (!print) {
cout << " ";
cout << endl;
for (int i = 0;i < width;i++) {
cout << "#";
cout << "Score: " << score << endl;
void Input() {
if (_kbhit()) {
switch (_getch()) {
case'a': {
dir = LEFT;
break;
case'd': {
dir = RIGHT;
case'w': {
dir = UP;
case's': {
dir = DOWN;
case'x': {
gameOver = true;
void Logic() {
int prevX = tailX[0];
int prevY = tailY[0];
int prev2X, prev2Y;
tailX[0] = x;
tailY[0] = y;
for (int i = 1;i < nTail;i++) {
prev2X = tailX[i];
prev2Y = tailY[i];
tailX[i] = prevX;
tailY[i] = prevY;
prevX = prev2X;
prevY = prev2Y;
switch (dir)
{
case LEFT:
x--;
case RIGHT:
x++;
case UP:
y--;
case DOWN:
y++;
/*
if (x > width || x < 0 || y>height || y < 0) {
};*/
if (x >= width - 1) {
x = 0;
else if (x < 0) {
x = width - 2;
if (y >= height) {
y = 0;
else if (y < 0) {
y = height - 1;
for (int i = 0;i < nTail;i++) {
if (tailX[i] == x && tailY[i] == y) {
if (x == fruitX && y == fruitY) {
score += 10;
nTail++;
int main() {
srand(time(0));
Setup();
while (!gameOver) {
Draw();
Input();
Logic();
return 0;
Объяснение:
эта игра работает только в кампиляторе Visual studio или qt creater
5591(20), 5623(16), 5639(23), 5641(16), 5647(22), - 4
5651(17), 5653(19), 5657(23), 5659(25), 5669(26), - 1
5683(22), 5689(28), 5693(23), 5701(13), 5711(14), - 3
5717(20), 5737(22), 5741(17), 5743(19), 5749(25), - 2
5779(28), 5783(23), 5791(22), 5801(14), 5807(20), - 4
5813(17), 5821(16), 5827(22), 5839(25), 5843(20), - 3
5849(26), 5851(19), 5857(25), 5861(20), 5867(26), - 3
5869(28), 5879(29), 5881(22), 5897(29), 5903(17), - 2
5923(19), 5927(23), 5939(26), 5953(22), 5981(23), - 2
5987(29), 6007(13), 6011(09), 6029(17), 6037(16), - 1
6043(13), 6047(17), 6053(14), 6067(19), 6073(16), - 2
6079(22), 6089(23), 6091(16), 6101(08), 6113(11), - 3
6121(10), 6131(11), 6133(13), 6143(14), 6151(13), - 2
6163(17), 6173(17), 6197(23), 6199(25), 6203(11), - 0
6211(10), 6217(16), 6221(11), 6229(19), 6247(19), - 2
6257(20), 6263(17), 6269(23), 6271(16), 6277(22), - 3
6287(23), 6299(26), 6301(10), 6311(11), 6317(17), - 2
6323(14), 6329(20), 6337(19), 6343(16), 6353(17), - 3
6359(23), 6361(16), 6367(22), 6373(19), 6379(25), - 2
6389(26), 6397(25), 6421(13), 6427(19), 6449(23), - 1
6451(16), 6469(25), 6473(20), 6481(19), 6491(20), - 3
6521(14), 6529(22), 6547(22), 6551(17), 6553(19), - 3
6563(20), 6569(26), 6571(19), 6577(25), 6581(20), - 3
6599(29), 6607(19), 6619(22), 6637(22), 6653(20). - 3
Всего 120 простых чисел, из них 57 имеют четную сумму цифр.
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<conio.h>
using std::cout;
using std::cin;
using std::endl;
bool gameOver;
const int width = 25;
const int height = 25;
int x, y, fruitX, fruitY, score;
int tailX[100], tailY[100];
int nTail;
enum eDirection { STOP = 0, LEFT, RIGHT, UP, DOWN };
eDirection dir;
void Setup() {
gameOver = false;
dir = STOP;
x = width / 2 - 1;
y = height / 2 - 1;
fruitX = rand() % width;
fruitY = rand() % height;
score = 0;
};
void Draw() {
cout << "w = UP" << endl;
cout << "s = DOVN" << endl;
cout << "d = RIGHT" << endl;
cout << "a = LEFT" << endl;
system("cls");//system("clear");
for (int i = 0;i < width + 1;i++) {
cout << "##";
};
for (int i = 0;i < height;i++) {
for (int j = 0;j < width;j++) {
if (j == 0 || j == width - 1) {
cout << "##";
};
if (i == y && j == x) {
cout << "0";
}
else if (i == fruitY && j == fruitX) {
cout << "F";
}
else {
bool print = false;
for (int k = 0;k < nTail;k++) {
if (tailX[k] == j && tailY[k] == i) {
print = true;
cout << "o";
}
}
if (!print) {
cout << " ";
}
};
cout << " ";
};
cout << endl;
};
cout << endl;
for (int i = 0;i < width;i++) {
cout << "#";
};
cout << endl;
cout << "Score: " << score << endl;
};
void Input() {
if (_kbhit()) {
switch (_getch()) {
case'a': {
dir = LEFT;
}
break;
case'd': {
dir = RIGHT;
}
break;
case'w': {
dir = UP;
}
break;
case's': {
dir = DOWN;
}
break;
case'x': {
gameOver = true;
}
break;
}
};
};
void Logic() {
int prevX = tailX[0];
int prevY = tailY[0];
int prev2X, prev2Y;
tailX[0] = x;
tailY[0] = y;
for (int i = 1;i < nTail;i++) {
prev2X = tailX[i];
prev2Y = tailY[i];
tailX[i] = prevX;
tailY[i] = prevY;
prevX = prev2X;
prevY = prev2Y;
}
switch (dir)
{
case LEFT:
x--;
break;
case RIGHT:
x++;
break;
case UP:
y--;
break;
case DOWN:
y++;
break;
}
/*
if (x > width || x < 0 || y>height || y < 0) {
gameOver = true;
};*/
if (x >= width - 1) {
x = 0;
}
else if (x < 0) {
x = width - 2;
}
if (y >= height) {
y = 0;
}
else if (y < 0) {
y = height - 1;
}
for (int i = 0;i < nTail;i++) {
if (tailX[i] == x && tailY[i] == y) {
gameOver = true;
}
}
if (x == fruitX && y == fruitY) {
score += 10;
fruitX = rand() % width;
fruitY = rand() % height;
nTail++;
}
}
int main() {
srand(time(0));
Setup();
while (!gameOver) {
Draw();
Input();
Logic();
}
return 0;
}
Объяснение:
эта игра работает только в кампиляторе Visual studio или qt creater