Регистрация: 18.05.2011
Сообщений: 8
|
Змейка в C++
Есть змейка, помогите пожалуйста написать к ней меню, 2 пункта: Начать игру и выход, а то игра сразу начинается, как только скомпилируется...
Код:
// zm.cpp: определяет точку входа для консольного приложения.
//
#include "stdafx.h"
#include <iostream> //стандартная библиотека
#include <time.h> //случайные числа
#include <stdio.h> //для printf
#include <windows.h> // для HANDLE, курсора, цвета
#include <conio.h> //для kbhit
using namespace std;
HANDLE hConsole;
//HANDLE hStdout, hStdin;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
void GotoXY(int X, int Y)
{
COORD coord = { X, Y };
SetConsoleCursorPosition(hStdOut, coord);
}
//Цвет
enum ConsoleColor
{
Black = 0,
Blue = 1,
Green = 2,
Cyan = 3,
Red = 4,
Magenta = 5,
Brown = 6,
LightGray = 7,
DarkGray = 8,
LightBlue = 9,
LightGreen = 10,
LightCyan = 11,
LightRed = 12,
LightMagenta = 13,
Yellow = 14,
White = 15
};
int numer;
void SetColor(ConsoleColor text, ConsoleColor background)
{
SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text));
}
struct Zmeja // структура змейка
{
COORD *t; //точки
int PCount; //количество яблок
};
enum uprawlenie{LEFT,UP,RIGHT,DOWN}; //направление змейки
struct Game //даные-точности: змейки, яблок, передвижение по X и Y, задержка, направление
{
Zmeja gaduka; //змейка
COORD jabloko; //яблоко
int dx,dy, //передвижение
pause; //задержка
int nap; //направление
};
//Функция разброски яблок
void PlusJabloko(Game &g)
{
int i,x,y;
numer = rand() % 5+1;
int n = g.gaduka.PCount;
do
{
x = rand() % 16+3; //
y = rand() % 16+3; //кординаты яблока
for(i = 0; i < n; i++)
{
if(x == g.gaduka.t[i].X && y == g.gaduka.t[i].Y) // проверка чтоб яблоко не бросить на змею
break;
}
}
while(i < n);
g.jabloko.X = x; //
g.jabloko.Y = y; //запоминаем позицию яблока
SetConsoleCursorPosition(hConsole, g.jabloko); //переносим курсор в эту позицию
SetConsoleTextAttribute(hConsole,0x0c); //цвет яблока
printf("%d", numer); //рисуем яблоко каким хотим символом
}
// Функцыя старта змейки ее координат и скорости
void skorostGame(Game &g)
{
system("cls");
g.gaduka.PCount = 3; //сколько точек в змейки
g.gaduka.t = new COORD [3];//создали точки
for(int i = 0; i < 3; i++)
{
g.gaduka.t[i].X = 10 + i;
g.gaduka.t[i].Y = 10;
}
g.dx = 1;
g.dy = 0;
g.pause = 100;//скорость передвижение змеи
PlusJabloko(g);//рисуем яблока
}
void Level()
{
GotoXY(10,10);cout <<"Wu nikogda ne wuigraete "<<endl;
GotoXY(10,11);cout <<"eslu ne bydete bdutelnu!!!"<<endl;
}
void ZmejaStart()
{
GotoXY(10,15);cout <<"Soberite 75 Jablok togda posmotrim"<<endl;
}
void STENA_2()
{
SetColor(LightBlue , Black);GotoXY(20,0);
GotoXY(64,2);cout << "Danue:" << endl ;
GotoXY(64,3);cout << "Jablok:0" << endl ;
GotoXY(64,4); cout << "Dlina:3"<< endl;
GotoXY(64,5); cout << "Speed:0" << endl;
GotoXY(64,7); cout << "Uprawlenie:" << endl;
GotoXY(64,8); cout << "Esc:Wuxod" << endl;
GotoXY(64,9); cout << "P:Pause" << endl;
GotoXY(64,10); cout <<"S:Start" << endl;
GotoXY(64,11); cout <<"L:Level" << endl;
GotoXY(64,13);printf("%c",24);cout <<":Wwerx"<<endl;
GotoXY(64,14);printf("%c",25);cout<<":Wniz"<<endl;
GotoXY(64,15);printf("%c",27);cout<<":Wlewo"<<endl;
GotoXY(64,16);printf("%c",26);cout<<":Wprawo"<<endl;
SetColor(LightMagenta , Black);
GotoXY(2,2);
int m = 0;
for(m = 0; m < 20; m++)
{
printf("*");
}
{
GotoXY(2,20);
for(m = 0; m < 20;m++)
{
printf("*");
}
}
{
for(m = 2; m < 20;m++)
{
GotoXY(2,m);
printf("*");
}
}
{
for(m = 2; m < 21;m++)
{
GotoXY(22,m);
printf("*");
}
}
}
Последний раз редактировалось Neo151; 12.08.2011 в 13:00.
|