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

Приложения

Приложение №1. Используемые шрифты.

Font1.spritefont

<?xml version="1.0" encoding="utf-8"?>

<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">

<Asset Type="Graphics:FontDescription">

<FontName>Bookman Old Style</FontName>

<Size>20</Size>

<Spacing>0</Spacing>

<UseKerning>true</UseKerning>

<Style>Bold</Style>

<CharacterRegions>

<CharacterRegion>

<Start> </Start>

<End></End>

</CharacterRegion>

<CharacterRegion>

<Start>А</Start>

<End>я</End>

</CharacterRegion>

<CharacterRegion>

<Start>№</Start>

<End>℠</End>

</CharacterRegion>

</CharacterRegions>

</Asset>

</XnaContent>

Приложение №2. Методы, реализующие основную логику игры.

Game1.cs

using System;

using System.Collections.Generic;

using System.Linq;

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 Curs_TRPO_Part1_romaferox_Pitnashki

{

public class Game1 : Microsoft.Xna.Framework.Game

{

GraphicsDeviceManager graphics;

SpriteBatch spriteBatch;

Menu menu;

Level level1;

Level level2;

Level level3;

TablRek table;

SpriteFont font;

int Uroven = 0, pred_ur = 0,score=0;

public Game1()

{

graphics = new GraphicsDeviceManager(this);

Content.RootDirectory = "Content";

graphics.PreferredBackBufferWidth = 1350; //ширина экрана

graphics.PreferredBackBufferHeight = 660; //высота экрана

}

protected override void Initialize()

{

// TODO: Add your initialization logic here

spriteBatch = new SpriteBatch(GraphicsDevice);

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

Window.Title = "Пятнашки";

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

this.IsMouseVisible = true;

menu = new Menu(this);

level1 = new Level(this, 1);

level2 = new Level(this, 2);

level3 = new Level(this, 3);

table = new TablRek(this);

base.Initialize();

}

protected override void LoadContent()

{

// Create a new SpriteBatch, which can be used to draw textures.

spriteBatch = new SpriteBatch(GraphicsDevice);

// TODO: use this.Content to load your game content here

}

protected override void UnloadContent()

{

// TODO: Unload any non ContentManager content here

}

protected override void Update(GameTime gameTime)

{

// Allows the game to exit

if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)

this.Exit();

// TODO: Add your update logic here

switch (Uroven)

{

case 0: //меню

{

menu.Update(gameTime);

pred_ur = Uroven;

Uroven = menu.Perehod(Uroven);

score = 0;

break;

}

case 1: //первый уровень

{

level1.Update(gameTime);

pred_ur = Uroven;

Uroven = level1.Perehod(Uroven);

break;

}

case 2: //второй уровень

{

level2.Update(gameTime);

pred_ur = Uroven;

Uroven = level2.Perehod(Uroven);

break;

}

case 3: //третий уровень

{

level3.Update(gameTime);

pred_ur = Uroven;

Uroven = level3.Perehod(Uroven);

break;

}

case 4: //ввод имени для таблицы

{

score = level1.score_up() + level2.score_up() + evel3.score_up();

table.podscet(score);

table.Update(gameTime);

pred_ur = Uroven;

Uroven = table.Perehod(Uroven);

break;

}

case 5: //вывод таблицы рекордов

{

table.Update(gameTime);

pred_ur = Uroven;

Uroven = table.Perehod(Uroven);

break;

}

}

base.Update(gameTime);

}

protected override void Draw(GameTime gameTime)

{

GraphicsDevice.Clear(Color.CornflowerBlue);

// TODO: Add your drawing code here

switch (Uroven)

{

case 0:

{

menu.Draw(gameTime);

break;

}

case 1:

{

level1.Draw(gameTime);

break;

}

case 2:

{

level2.Draw(gameTime);

break;

}

case 3:

{

level3.Draw(gameTime);

break;

}

case 4:

{

table.Draw(gameTime);

table.podscet(score);

break;

}

case 5:

{

table.Table(gameTime);

break;

}

}

base.Draw(gameTime);

}

}

}

Level.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 Curs_TRPO_Part1_romaferox_Pitnashki

{

public class Level : Microsoft.Xna.Framework.DrawableGameComponent

{

byte flag = 0;

SpriteBatch spriteBatch, spriteComponentBatch;

Plitka[] plitka; //количество изображений

Texture2D texture, backTexture, but1, but2, skin,continew,

salut_base,end_but; //изображения(фон, карты, конпки)

int[] index; //массив индексов

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

int[] ii; //позиция части

int peredv = 0, //число передвижений

flag_mb = 0, //флаг сообщения

igra = 1, //запуск игры

plitki, //количество плиток

level, //номер уровня

shirina, //ширина плитки

prodoljenie = 0, //переход на след уровень

sc_vremy, //определение вермя на уровень

anim_kol_1 = 0, //номер анимации

lost_score=0, //потерянные очки

score, //очки

mus_count=0; //бесконечный музон

SpriteFont font; //для шрифта

Stopwatch stopWatch = new Stopwatch(); //время

string elapsedTime; //время

TimeSpan ts; //время

Game game;

Song levelmus; //музыка уровня

public SoundEffectInstance plita; //звук движущейся плитки

public Salut salut; //салют

public Level(Game game1,int Uroven) : base(game1)

{

// TODO: Construct any child components here

spriteComponentBatch = new SpriteBatch(Game.GraphicsDevice);

spriteBatch = new SpriteBatch(Game.GraphicsDevice);

game = game1;

backTexture = Game.Content.Load<Texture2D>("Fon1_2");

but1 = Game.Content.Load<Texture2D>(@"Button\Sort_but");

but2 = Game.Content.Load<Texture2D>(@"Button\Exit_but");

end_but=Game.Content.Load<Texture2D>(@"Button\End_but");

font = Game.Content.Load<SpriteFont>("Font1");

continew = Game.Content.Load<Texture2D>(@"Button\Continew_but");

plita = (Game.Content.Load<SoundEffect>(@"Sound\Plita")).CreateInstance();

salut_base = Game.Content.Load<Texture2D>(@"Salut\Salut");

salut = new Salut(game, ref salut_base, new Rectangle(0, 0, 400, 555), new Vector2(300, 300));

level=Uroven;

switch (level)

{

case 1:

{

plitki = 9;

shirina = 150;

sc_vremy = 3;

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

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

skin = Game.Content.Load<Texture2D>("Skin1");

levelmus = Game.Content.Load<Song>(@"Sound\Level_1");

break;

}

case 2:

{

plitki = 16;

shirina = 112;

sc_vremy = 5;

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

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

skin = Game.Content.Load<Texture2D>("Skin2");

levelmus = Game.Content.Load<Song>(@"Sound\Level_2");

break;

}

case 3:

{

plitki = 25;

shirina = 80;

sc_vremy = 10;

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

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

skin = Game.Content.Load<Texture2D>("Skin3");

levelmus = Game.Content.Load<Song>(@"Sound\Level_3");

break;

}

}

plitka = new Plitka[plitki];

index = new int[plitki];

ii = new int[plitki];

CreateNewObject();

score = 0;

}

public override void Initialize()

{

// TODO: Add your initialization code here

base.Initialize();

// this.IsMouseVisible = true;

}

private void CreateNewObject() //растановка плиток

{

int i, n, f;

Random r = new Random();

int[] c = new int[plitki];//счётчик числа выведенных объектов

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

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

{

f = 0;

do

{

n = r.Next(plitki);//рандомно генерируется номер

if (c[n] < 1)

{

c[n]++;

f = 1;

x1 = n * shirina;

switch (level)

{

case 1:

{

if (i == 3 || i == 6)

{

x = 0;

y += shirina;

}

break;

}

case 2:

{

if (i == 4 || i == 8 || i == 12)

{

x = 0;

y += shirina;

}

break;

}

case 3:

{

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

{

x = 0;

y += shirina;

}

break;

}

}

plitka[i] = new Plitka(game, ref texture, new Rectangle(x1, 0, shirina, shirina), new Vector2(x, y));

x += shirina;

}

} while (f == 0);

index[i] = n;

ii[i] = i;

}

}

private void AnimSalut(GameTime gameTime)

{

Random r = new Random();

int sh, v;

if (flag_mb == 0)

{

if (salut.Update_elem_1(gameTime) == 1)

{

anim_kol_1++;

if (anim_kol_1 == 4)

{

anim_kol_1 = 0;

sh = r.Next(950);

v = r.Next(100);

salut = new Salut(game, ref salut_base, new Rectangle(0, 0, 400, 555), new Vector2(sh, v));

}

}

}

}

public override void Update(GameTime gameTime)

{

// TODO: Add your update code here

int i;

Vremy();

if (flag_mb != 2)//проверка победы

{

flag_mb = 0;

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

{

if (index[i] != i)

{

flag_mb = 1;

break;

}

}

}

// if (peredv == 10) flag_mb = 0; //фальшивое условие победы

AnimSalut(gameTime);

if (flag_mb == 0)

{

if (lost_score == 0)

{

score = score - ts.Seconds - ts.Minutes * 60;

lost_score=1;

}

stopWatch.Stop();

}

// TODO: Add your update logic here

MouseState mState = Mouse.GetState();

if (mState.LeftButton == ButtonState.Released)//если кнопка отпущена

flag = 0;

if (mState.LeftButton == ButtonState.Pressed)//если кнопка нажата

{

if ((mState.X > 0) & (mState.X < 203) & (mState.Y > 550) & (mState.Y < 610) & (flag_mb!=0))//нажали на "перемешать"

Peremeshat();

if ((mState.X > 1000) & (mState.X < 1203) & (mState.Y > 550) & (mState.Y < 610) & (flag_mb != 0))//нажали на "выйти"

{ prodoljenie = 2; igra = 1; }

if ((flag_mb == 0) & (peredv > 0) & (mState.X > 500) & (mState.X < 703) & (mState.Y > 320) & (mState.Y < 380))// нажали продолжить после победы

{ prodoljenie = 1; igra = 1; lost_score = 0; }

if ((flag_mb == 0) & (peredv > 0) & (mState.X > 800) & (mState.X < 1003) & (mState.Y > 320) & (mState.Y < 380))// нажали закончить после победы

{ prodoljenie = 3; igra = 1; lost_score = 0; }

if (flag_mb == 1)//если время не закончилось и игра не пройдена

{

switch (level)

{

case 1:

{

Igra1(mState.X, mState.Y);

break;

}

case 2:

{

Igra2(mState.X, mState.Y);

break;

}

case 3:

{

Igra3(mState.X, mState.Y);

break;

}

}

}

base.Update(gameTime);

}

}

private void Vremy()

{

if (peredv > 0 && flag_mb != 2)

{

stopWatch.Start();

ts = stopWatch.Elapsed;//теккущяя секунда

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

}

if (ts.Minutes == sc_vremy)//если время кончилось

{

flag_mb = 2;

stopWatch.Stop();

stopWatch.Reset();

ts = stopWatch.Elapsed;

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

score = 0;

}

ts = stopWatch.Elapsed;

if (ts.Minutes == mus_count)

{

MediaPlayer.Volume = 0.5f;

MediaPlayer.Play(levelmus);

mus_count += 2;

}

}

void Peremeshat()

{

flag++;

if (flag == 1)

{

flag_mb = 1;

for (int i = 0; i < plitki; i++)

plitka[i].Visible = false;

stopWatch.Reset();

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

CreateNewObject();

peredv = 0;

mus_count = 0;

score = sc_vremy * 60;

}

}

void Igra1(int x,int y)

{

int i, z, x1 = 0, x2 = shirina, y1 = 0, y2 = 150;

int pozx = x, pozy = y;

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

{

if (i == 3 | i == 6)//переход на новую строку

{

x1 = 0;

y1 = y1 + 150;

}

x2 = x1 + shirina;

y2 = y1 + 150;

if ((pozx > x1) & (pozx < x2) & (pozy > y1) & (pozy < y2))

{

flag++;

if (index[i] != 8 & flag == 1)//

{

if (i > 2)//если не верхние

{

if (index[i - 3] == 8)//если клетка сверху свободна

{

plitka[ii[i]].sprPosition.Y -= 150;

index[i - 3] = index[i];

index[i] = 8;

z = ii[i];

ii[i] = ii[i - 3];

ii[i - 3] = z;

peredv++;

plita.Play();

break;

}

}

if (i != 0 & i != 3 & i != 6)//если не левые

{

if (index[i - 1] == 8)//если клетка слева свободна

{

plitka[ii[i]].sprPosition.X -= shirina;

index[i - 1] = index[i];

index[i] = 8;

z = ii[i];

ii[i] = ii[i - 1];

ii[i - 1] = z;

peredv++;

plita.Play();

break;

}

}

if (i != 2 & i != 5 & i != 8)//если не правые

{

if (index[i + 1] == 8)//если клетка справа свободна

{

plitka[ii[i]].sprPosition.X += shirina;

index[i + 1] = index[i];

index[i] = 8;

z = ii[i];

ii[i] = ii[i + 1];

ii[i + 1] = z;

peredv++;

plita.Play();

break;

}

}

if (!(i > 5))//если не нижние

{

if (index[i + 3] == 8)//если клетка снизу свободна

{

plitka[ii[i]].sprPosition.Y += 150;

index[i + 3] = index[i];

index[i] = 8;

z = ii[i];

ii[i] = ii[i + 3];

ii[i + 3] = z;

peredv++;

plita.Play();

break;

}

}

}

break;

}

x1 = x1 + shirina;

}

}

void Igra2(int x, int y)

{

int i, z, x1 = 0, x2 = shirina, y1 = 0, y2 = shirina;

int pozx = x, pozy = y;

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

{

if (i == 4 | i == 8 | i == 12)//переход на новую строку

{

x1 = 0;

y1 = y1 + shirina;

}

x2 = x1 + shirina;

y2 = y1 + shirina;

if ((pozx > x1) & (pozx < x2) & (pozy > y1) & (pozy < y2))

{

plita.Play();

flag++;

if (index[i] != 15 & flag == 1)//

{

if (i > 3)//если не верхние

{

if (index[i - 4] == 15)//если клетка сверху свободна

{

plitka[ii[i]].sprPosition.Y -= shirina;

index[i - 4] = index[i];

index[i] = 15;

z = ii[i];

ii[i] = ii[i - 4];

ii[i - 4] = z;

peredv++;

plita.Play();

break;

}

}

if (i != 0 & i != 4 & i != 8 & i != 12)//если не левые

{

if (index[i - 1] == 15)//если клетка слева свободна

{

plitka[ii[i]].sprPosition.X -= shirina;

index[i - 1] = index[i];

index[i] = 15;

z = ii[i];

ii[i] = ii[i - 1];

ii[i - 1] = z;

peredv++;

plita.Play();

break;

}

}

if (i != 3 & i != 7 & i != 11 & i != 15)//если не правые

{

if (index[i + 1] == 15)//если клетка справа свободна

{

plitka[ii[i]].sprPosition.X += shirina;

index[i + 1] = index[i];

index[i] = 15;

z = ii[i];

ii[i] = ii[i + 1];

ii[i + 1] = z;

peredv++;

plita.Play();

break;

}

}

if (!(i > 11))//если не нижние

{

if (index[i + 4] == 15)//если клетка снизу свободна

{

plitka[ii[i]].sprPosition.Y += shirina;

index[i + 4] = index[i];

index[i] = 15;

z = ii[i];

ii[i] = ii[i + 4];

ii[i + 4] = z;

peredv++;

plita.Play();

break;

}

}

}

break;

}

x1 = x1 + shirina;

}

}

void Igra3(int x, int y)

{

int i, z, x1 = 0, x2 = shirina, y1 = 0, y2 = shirina;

int pozx = x, pozy = y;

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

{

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

{

x1 = 0;

y1 = y1 + shirina;

}

x2 = x1 + shirina;

y2 = y1 + shirina;

if ((pozx > x1) & (pozx < x2) & (pozy > y1) & (pozy < y2))

{

flag++;

if (index[i] != 24 & flag == 1)//

{

if (i > 4)//если не верхние

{

if (index[i - 5] == 24)//если клетка сверху свободна

{

plitka[ii[i]].sprPosition.Y -= shirina;

index[i - 5] = index[i];

index[i] = 24;

z = ii[i];

ii[i] = ii[i - 5];

ii[i - 5] = z;

peredv++;

plita.Play();

break;

}

}

if (i != 0 & i != 5 & i != 10 & i != 15 & i != 20)//если не левые

{

if (index[i - 1] == 24)//если клетка слева свободна

{

plitka[ii[i]].sprPosition.X -= shirina;

index[i - 1] = index[i];

index[i] = 24;

z = ii[i];

ii[i] = ii[i - 1];

ii[i - 1] = z;

peredv++;

plita.Play();

break;

}

}

if (i != 4 & i != 9 & i != 14 & i != 19 & i != 24)//если не правые

{

if (index[i + 1] == 24)//если клетка справа свободна

{

plitka[ii[i]].sprPosition.X += shirina;

index[i + 1] = index[i];

index[i] = 24;

z = ii[i];

ii[i] = ii[i + 1];

ii[i + 1] = z;

peredv++;

plita.Play();

break;

}

}

if (!(i > 19))//если не нижние

{

if (index[i + 5] == 24)//если клетка снизу свободна

{

plitka[ii[i]].sprPosition.Y += shirina;

index[i + 5] = index[i];

index[i] = 24;

z = ii[i];

ii[i] = ii[i + 5];

ii[i + 5] = z;

peredv++;

plita.Play();

break;

}

}

}

break;

}

x1 = x1 + shirina;

}

}

public int Perehod(int x)

{

if (prodoljenie == 1)

{

prodoljenie = 0;

return x + 1;

}

else

if (prodoljenie == 2)

{

prodoljenie = 0;

return 0;

}

else

if (prodoljenie == 3)

{

prodoljenie = 0;

return 4;

}

else return x;

}

public int score_up()

{

int score_up = score;

igra = 1;

return score_up;

}

public override void Draw(GameTime gameTime)

{

// TODO: Add your drawing code here

if (igra == 1)

{

igra = 0;

Peremeshat();

}

spriteBatch.Begin();

spriteBatch.Draw(backTexture, new Vector2(0, 0), Color.Aquamarine);//фон

spriteBatch.Draw(skin, new Rectangle(900, 0, 450, 450), Color.WhiteSmoke);

spriteBatch.DrawString(font, "Ходы: " + peredv, new Vector2(500, 130), Color.Black);

spriteBatch.DrawString(font, "Время: " + elapsedTime, new Vector2(500, 150), Color.Black);

if (flag_mb == 2)//если время кончилось

{

spriteBatch.DrawString(font, "Неудача", new Vector2(500, 250), Color.Black);

}

if (flag_mb == 0 && peredv > 0)//если игра пройдена

{

spriteBatch.DrawString(font, "Cчет: " + score, new Vector2(500, 230), Color.Black);

spriteBatch.DrawString(font, "Победа, красавчик", new Vector2(500, 250), Color.Black);

spriteBatch.DrawString(font, "Для продолжения нажмите <Продолжить>", new Vector2(500, 270), Color.Black);

spriteBatch.DrawString(font, "Чтобы закончить нажмите <Закончить>", new Vector2(500, 290), Color.Black);

spriteBatch.Draw(continew, new Rectangle(500, 320, 203, 60), Color.WhiteSmoke);

spriteBatch.Draw(end_but, new Rectangle(800, 320, 203, 60), Color.WhiteSmoke);

}

spriteBatch.Draw(but1, new Rectangle(0, 550, 203, 60), Color.WhiteSmoke);

spriteBatch.Draw(but2, new Rectangle(1000, 550, 203, 60), Color.WhiteSmoke);

spriteBatch.End();

spriteComponentBatch.Begin();

for (int i = 0; i < plitki; i++)

{

plitka[i].Draw(gameTime);

}

if (flag_mb == 0 && peredv > 0) salut.Draw(gameTime);

spriteComponentBatch.End();

base.Draw(gameTime);

}

}

}

TablRek.cs

using System;

using System.IO;

using System.Collections.Generic;

using System.Linq;

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;

using System.Timers;

namespace Curs_TRPO_Part1_romaferox_Pitnashki

{

public class TablRek : Microsoft.Xna.Framework.DrawableGameComponent

{

SpriteBatch spriteBatch;

Texture2D fon, but_return;

Vector2 position_but_return;

MouseState mState, pred_mState;

Song rek;

SpriteFont font;

KeyboardState keyboardState, oldKeyboardState; // клавиатура

int inputWord = 0; // можно или нет вводить слово (имя)

string[] nameRecordTable = { "" }; // имена для таблицы рекордов

string[] scoreRecordTable = { "" }; // очки для таблицы рекордов типа string

int[] scoreRecordTableInt; // очки для таблицы рекордов типа int

public int[] znac; // массив для фиксирования была ли выведена буква или нет

string currentWord = ""; // введенное с клавиатуры слово (имя)

int score=0,

otv,

vvod=0,

tabl=1;

public TablRek(Game game): base(game)

{

// TODO: Construct any child components here

spriteBatch = new SpriteBatch(Game.GraphicsDevice);

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

but_return = Game.Content.Load<Texture2D>(@"Button\Menu_but");

rek = Game.Content.Load<Song>(@"Sound\Menu");

position_but_return = new Vector2(350, 550);

font = Game.Content.Load<SpriteFont>("Font1");

MediaPlayer.Volume = 0.5f;

MediaPlayer.Play(rek);

}

public override void Initialize()

{

// TODO: Add your initialization code here

base.Initialize();

}

public void podscet(int score_all)

{

if(score==0)

currentWord = "";

score = score_all;

if (score != 0)

{

inputWord = 1;

}

}

int play(int X, int Y) //попали ли по кнопке?

{

if (X > position_but_return.X && X < position_but_return.X + 203)

if (Y > position_but_return.Y && Y < position_but_return.Y + 60)

return 1;

return 0;

}

string[] ReadNameRecordFile() // чтение имени для таблицы рекордов

{

string[] phrase = { "" };

string path = @"Name.txt";

if (File.Exists(path))

{

phrase = File.ReadAllLines(path, System.Text.Encoding.UTF8);

}

return phrase;

}

string[] ReadScoreRecordFile() // чтение очков для таблицы рекордов

{

string[] score_read = { "" };

string path = @"Score.txt";

if (File.Exists(path))

{

score_read = File.ReadAllLines(path, System.Text.Encoding.UTF8);

}

return score_read;

}

public int Perehod(int z)

{

if (otv == 1)

{

otv = -1;

vvod = 0;

score = 0;

return 0;

}

else return z;

}

public override void Update(GameTime gameTime)

{

// TODO: Add your update code here

int a;

pred_mState = mState;

mState = Mouse.GetState();

if ((mState.LeftButton == ButtonState.Pressed && pred_mState.LeftButton == ButtonState.Released)||(vvod==1 ))

{

a = play(mState.X, mState.Y);

if ((a == 1)||(vvod==1))

{

otv = 1;

}

}

oldKeyboardState = Keyboard.GetState();

oldKeyboardState = keyboardState;

keyboardState = Keyboard.GetState();

if (inputWord == 1)

{

if (oldKeyboardState.IsKeyDown(Keys.Q) && keyboardState.IsKeyUp(Keys.Q))

currentWord += "й";

if (oldKeyboardState.IsKeyDown(Keys.W) && keyboardState.IsKeyUp(Keys.W))

currentWord += "ц";

if (oldKeyboardState.IsKeyDown(Keys.E) && keyboardState.IsKeyUp(Keys.E))

currentWord += "у";

if (oldKeyboardState.IsKeyDown(Keys.R) && keyboardState.IsKeyUp(Keys.R))

currentWord += "к";

if (oldKeyboardState.IsKeyDown(Keys.T) && keyboardState.IsKeyUp(Keys.T))

currentWord += "е";

if (oldKeyboardState.IsKeyDown(Keys.Y) && keyboardState.IsKeyUp(Keys.Y))

currentWord += "н";

if (oldKeyboardState.IsKeyDown(Keys.U) && keyboardState.IsKeyUp(Keys.U))

currentWord += "г";

if (oldKeyboardState.IsKeyDown(Keys.I) && keyboardState.IsKeyUp(Keys.I))

currentWord += "ш";

if (oldKeyboardState.IsKeyDown(Keys.O) && keyboardState.IsKeyUp(Keys.O))

currentWord += "щ";

if (oldKeyboardState.IsKeyDown(Keys.P) && keyboardState.IsKeyUp(Keys.P))

currentWord += "з";

if (oldKeyboardState.IsKeyDown(Keys.OemOpenBrackets) && keyboardState.IsKeyUp(Keys.OemOpenBrackets))

currentWord += "х";

if (oldKeyboardState.IsKeyDown(Keys.OemCloseBrackets) && keyboardState.IsKeyUp(Keys.OemCloseBrackets))

currentWord += "ъ";

if (oldKeyboardState.IsKeyDown(Keys.A) && keyboardState.IsKeyUp(Keys.A))

currentWord += "ф";

if (oldKeyboardState.IsKeyDown(Keys.S) && keyboardState.IsKeyUp(Keys.S))

currentWord += "ы";

if (oldKeyboardState.IsKeyDown(Keys.D) && keyboardState.IsKeyUp(Keys.D))

currentWord += "в";

if (oldKeyboardState.IsKeyDown(Keys.F) && keyboardState.IsKeyUp(Keys.F))

currentWord += "а";

if (oldKeyboardState.IsKeyDown(Keys.G) && keyboardState.IsKeyUp(Keys.G))

currentWord += "п";

if (oldKeyboardState.IsKeyDown(Keys.H) && keyboardState.IsKeyUp(Keys.H))

currentWord += "р";

if (oldKeyboardState.IsKeyDown(Keys.J) && keyboardState.IsKeyUp(Keys.J))

currentWord += "о";

if (oldKeyboardState.IsKeyDown(Keys.K) && keyboardState.IsKeyUp(Keys.K))

currentWord += "л";

if (oldKeyboardState.IsKeyDown(Keys.L) && keyboardState.IsKeyUp(Keys.L))

currentWord += "д";

if (oldKeyboardState.IsKeyDown(Keys.OemSemicolon) && keyboardState.IsKeyUp(Keys.OemSemicolon))

currentWord += "ж";

if (oldKeyboardState.IsKeyDown(Keys.OemQuotes) && keyboardState.IsKeyUp(Keys.OemQuotes))

currentWord += "э";

if (oldKeyboardState.IsKeyDown(Keys.Z) && keyboardState.IsKeyUp(Keys.Z))

currentWord += "я";

if (oldKeyboardState.IsKeyDown(Keys.X) && keyboardState.IsKeyUp(Keys.X))

currentWord += "ч";

if (oldKeyboardState.IsKeyDown(Keys.C) && keyboardState.IsKeyUp(Keys.C))

currentWord += "с";

if (oldKeyboardState.IsKeyDown(Keys.V) && keyboardState.IsKeyUp(Keys.V))

currentWord += "м";

if (oldKeyboardState.IsKeyDown(Keys.B) && keyboardState.IsKeyUp(Keys.B))

currentWord += "и";

if (oldKeyboardState.IsKeyDown(Keys.N) && keyboardState.IsKeyUp(Keys.N))

currentWord += "т";

if (oldKeyboardState.IsKeyDown(Keys.M) && keyboardState.IsKeyUp(Keys.M))

currentWord += "ь";

if (oldKeyboardState.IsKeyDown(Keys.OemComma) && keyboardState.IsKeyUp(Keys.OemComma))

currentWord += "б";

if (oldKeyboardState.IsKeyDown(Keys.OemPeriod) && keyboardState.IsKeyUp(Keys.OemPeriod))

currentWord += "ю";

if (oldKeyboardState.IsKeyDown(Keys.Space) && keyboardState.IsKeyUp(Keys.Space))

currentWord += " ";

if (oldKeyboardState.IsKeyDown(Keys.Back) && keyboardState.IsKeyUp(Keys.Back) && currentWord != "")

currentWord = currentWord.Remove(currentWord.Length - 1);

if (currentWord != "")

{

if (oldKeyboardState.IsKeyDown(Keys.Enter) && keyboardState.IsKeyUp(Keys.Enter))

{

inputWord = 0;

vvod = 1;

tabl = 0;

string path = @"Name.txt";

string path1 = @"Score.txt";

string score1 = Convert.ToString(score);

FileInfo file = new FileInfo(path);

FileInfo file1 = new FileInfo(path1);

File.AppendAllText(path, currentWord);

File.AppendAllText(path, "\r\n");

File.AppendAllText(path1, score1);

File.AppendAllText(path1, "\r\n");

}

}

}

nameRecordTable = ReadNameRecordFile();

scoreRecordTable = ReadScoreRecordFile();

base.Update(gameTime);

}

public void Table(GameTime gameTime)

{

score = 0;

tabl = 1;

if (score == 0)

{

vvod = 0;

if (tabl == 1)

{

nameRecordTable = ReadNameRecordFile();

scoreRecordTable = ReadScoreRecordFile();

tabl = 0;

}

scoreRecordTableInt = new int[scoreRecordTable.Length];

for (int i = 0; i < scoreRecordTable.Length; i++)

{

scoreRecordTableInt[i] = Convert.ToInt32(scoreRecordTable[i]);

}

int p;

string s;

for (int j = 0; j < (scoreRecordTableInt.Length - 1); j++) //{ цикл по числу "проходов" }

for (int i = 0; i < (scoreRecordTableInt.Length - 1 - j); i++)// { цикл сравнения элементов в оставшейся части массива }

if (scoreRecordTableInt[i] < scoreRecordTableInt[i + 1])

{

p = scoreRecordTableInt[i];

s = nameRecordTable[i];

scoreRecordTableInt[i] = scoreRecordTableInt[i + 1];

nameRecordTable[i] = nameRecordTable[i + 1];

scoreRecordTableInt[i + 1] = p;

nameRecordTable[i + 1] = s;

}

int y = 170;

spriteBatch.Begin();

spriteBatch.Draw(fon, new Vector2(0, 0), Color.Snow);

spriteBatch.Draw(but_return, position_but_return, Color.Snow);

spriteBatch.End();

for (int i = 0; i < 5; i++)

{

spriteBatch.Begin();

spriteBatch.DrawString(font, nameRecordTable[i], new Vector2(190, y), Color.Black);

spriteBatch.End();

y += 46;

}

y = 170;

for (int i = 0; i < 5; i++)

{

spriteBatch.Begin();

spriteBatch.DrawString(font, scoreRecordTableInt[i].ToString(), new Vector2(415, y), Color.Black);

spriteBatch.End();

y += 46;

}

base.Draw(gameTime);

}

}

public override void Draw(GameTime gameTime)

{

// TODO: Add your drawing code here

spriteBatch.Begin();

spriteBatch.Draw(fon, new Vector2(0, 0), Color.Snow);

spriteBatch.End();

if (inputWord == 1)

{

spriteBatch.Begin();

spriteBatch.DrawString(font, "ваше имя:", new Vector2(30, 200), Color.Black);

spriteBatch.DrawString(font, currentWord, new Vector2(200, 200), Color.Black);

spriteBatch.DrawString(font, "ваше счет:" + score, new Vector2(30, 250), Color.Black);

spriteBatch.End();

}

spriteBatch.Begin();

spriteBatch.DrawString(font, "введите имя и нажмите Enter чтобы продолжить", new Vector2(250, 300), Color.Black);

spriteBatch.End();

base.Draw(gameTime);

}

}

}

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