Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
PZ.doc
Скачиваний:
4
Добавлен:
12.09.2019
Размер:
4.24 Mб
Скачать

Список литературы

  1. XNA Статьи/ [Электронный ресурс]. URL: http://www.gamedev.ru/community/xna (дата обращения 03.04.2012)

  2. Уэллс Д. Википедия / [Электронный ресурс]. URL: http://ru.wikipedia.org/ (дата обращения 09.04.2012).

  3. Learning XNA 4.0 / Изучаем XNA 4.0 [Электронный ресурс]. URL: http://unmail22.narod.ru/Books/Learning_XNA4/Learning_XNA4.html (дата обращения 03.04.2012)

  4. Язык C# [Электронный ресурс]. URL: http://www.interface.ru/home.asp?artId=3896 (дата обращения 03.04.2012)

  5. MSDN Library [Электронный ресурс]. URL: http://msdn.microsoft.com/en-us/library/ms123401.aspx (дата обращения 31.03.2012)

  6. Найти 2 одинаковые картинки/ [Электронный ресурс]. URL: http://pechali.net.ua/games/najti-2-odinakovye-kartinki.html (дата обращения 09.04.2012).

  7. Найди 2 одинаковые картинки/ [Электронный ресурс]. URL: http://www.ofigennoe.ru/blogs/0/16/post623.html (дата обращения 09.04.2012).

  8. Игра - Пегас/ [Электронный ресурс]. URL: http://www.igrytut.com/Barbie_igri/barbie_ucan.html (дата обращения 09.04.2012).

Приложение а. Game1.Cs.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Diagnostics;

using System.Runtime.InteropServices;

using Microsoft.Xna.Framework;

using Microsoft.Xna.Framework.Audio;

using Microsoft.Xna.Framework.Content;

using Microsoft.Xna.Framework.GamerServices;

using Microsoft.Xna.Framework.Graphics;

using Microsoft.Xna.Framework.Input;

using Microsoft.Xna.Framework.Media;

namespace Картиночки

{

public class Game1 : Microsoft.Xna.Framework.Game

{

[DllImport("user32.dll", CharSet = CharSet.Auto)]

public static extern uint MessageBox(IntPtr hWnd, String text, String caption, uint type);

GraphicsDeviceManager graphics;

SpriteBatch spriteBatch,fon,mes;

spriteComp [] gameObject=new spriteComp[20];

spriteComp[] vopros = new spriteComp[20];

Texture2D texture,for_mes;

private Texture2D MySprite;

private Vector2 position = new Vector2(0, 0);

int[] index = new int[20];//массив индексов картинок

int n1 = 50, n2 = 50, i1 = 50, i2 = 50, count = 0, f = 0, flag = 0, flag_mb = 1;

SoundEffect soundEffect;

// Cекундомер

Stopwatch stopWatch = new Stopwatch();

string elapsedTime= String.Format("{0:00}:{1:00}:{2:00}", 0, 0, 0);

TimeSpan ts;

//Для хранения шрифтов

SpriteFont font;

public Game1()

{

graphics = new GraphicsDeviceManager(this);

graphics.PreferredBackBufferWidth = 800;

graphics.PreferredBackBufferHeight = 600;

Content.RootDirectory = "Content";

}

protected override void Initialize()

{

base.Initialize();

this.IsMouseVisible = true;

soundEffect.Play();// воспроизводим звук

}

protected override void LoadContent()

{

soundEffect = Content.Load<SoundEffect>("music");

font = this.Content.Load<SpriteFont>("SpriteFont1");

fon = new SpriteBatch(GraphicsDevice);

MySprite = Content.Load<Texture2D>("fon");

spriteBatch = new SpriteBatch(GraphicsDevice);

Services.AddService(typeof(SpriteBatch), spriteBatch);

texture = Content.Load<Texture2D>("all");

mes = new SpriteBatch(GraphicsDevice);

for_mes = Content.Load<Texture2D>("message");

CreateNewObject();

}

protected void CreateNewObject()

{

int i,n,f;

Random r = new Random();

int[] c = new int[10];

int x1, x=30, y=10;//координаты х1 для изображения, х,у куда выводить

for (i = 0; i < 20; i++)

{

f = 0;

do

{

n = r.Next(10);//генерируем число рандомом

if (c[n] < 2)

{

c[n]++;

f = 1;

x1 = n * 130;

if (i == 5 || i == 10 || i == 15)//для перехода на новую строку

{

x = 30;

y = y + 145;

}

gameObject[i] = new spriteComp(this, ref texture,

new Rectangle(x1, 0, 130, 130), new Vector2(x, y));

Components.Add(gameObject[i]);

vopros[i] = new spriteComp(this, ref texture,

new Rectangle(1300, 0, 130, 130), new Vector2(x, y));

Components.Add(vopros[i]);

x = x + 150;

}

} while (f == 0) ;

index[i] = n;

}

}

protected override void UnloadContent()

{

// TODO: Unload any non ContentManager content here

}

protected override void Update(GameTime gameTime)

{

int i, j, x1 = 30, x2 = 160, y1 = 10, y2 = 140;

if (count != 0)//если пользователь начал игру,

//т.е хотя бы раз нажал на кнопку

{

stopWatch.Start();

ts = stopWatch.Elapsed;

elapsedTime = String.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds);//секундомер

}

MouseState mState = Mouse.GetState();

if (mState.LeftButton == ButtonState.Released)

flag = 0;

if (mState.LeftButton == ButtonState.Pressed)

{

x1 = 30; y1 = 10;

f = 1;//для сообщения

if (flag_mb == 0)

{

if ((mState.X > 280) & (mState.X < 380) & (mState.Y > 325) & (mState.Y < 360))//для кнопки да

{

CreateNewObject();

stopWatch.Reset();//сброс секундомера

count = 0; flag_mb = 1;

}

if ((mState.X > 420) & (mState.X < 520) & (mState.Y > 325) & (mState.Y < 360))//для кнопки нет

{

Exit();

}

}

for (i=0;i<20;i++)

{

if (i == 5 | i == 10 | i == 15)

{

x1 = 30;

y1 = y1 + 145;

}

x2 = x1 + 130;

y2 = y1 + 130;

if ((mState.X > x1) & (mState.X < x2) &( mState.Y > y1) &( mState.Y < y2))

{

flag++;//чтобы инициировалось одно нажатие как одно нажатие

if (flag==1) count++;

vopros[i].Visible = false;

if (count == 3)

{

count = 1;

if (n1 != n2)

{

vopros[i1].Visible = true;

vopros[i2].Visible = true;

}

}

if (count == 1)

{

n1 = index[i];

i1 = i;

}

if (count == 2)

{

n2 = index[i];

i2 = i;

if ((n1 == n2) & (i1!=i2))

{

vopros[i1].Visible = false;

vopros[i2].Visible = false;

gameObject[i1].Visible = false;

gameObject[i2].Visible = false;

}

}

flag_mb = 0;

for (j = 0; j < 20; j++)

{

if (gameObject[j].Visible == true)

{

flag_mb = 1;

break;

}

}

break;

}

x1 = x1 + 150;

}

}

base.Update(gameTime);

}

protected override void Draw(GameTime gameTime)

{

graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

fon.Begin();

fon.Draw(MySprite, position, Color.White);

fon.End();

spriteBatch.Begin();

spriteBatch.DrawString(font,"Time:" + elapsedTime, new Vector2(650, 577), Color.White);

base.Draw(gameTime);

spriteBatch.End();

if (flag_mb == 0&&f!=0)

{

mes.Begin();

stopWatch.Stop();//остановка секундомера

mes.Draw(for_mes, new Vector2(250, 200), Color.White);

mes.DrawString(font,"Your time:" + elapsedTime, new Vector2(300, 410), Color.White);

mes.End();

}

}

}

}

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]