Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
reserv_PZ.docx
Скачиваний:
1
Добавлен:
01.05.2025
Размер:
1.02 Mб
Скачать

3.3 Интерфейс пользователя

После запуска игры пользователь видит меню, представленное на рисунке 3.1.

Рисунок 3.1 – Главное меню игры

При нажатии кнопки “Помощь ” пользователь получит всю необходимую информацию об игре (правила игры , управление)

Рисунок 3.2 – Помощь пользователю (пункт меню)

Рисунок 3.3 – Игровой процесс

На рисунке 3.3 представлен игровой процесс. Игра предназначена для двух пользователей, один пользователь будет играть «Красными» , другой – «Зелёными». В начале, игроки поочерёдно выбирают одну из трёх предложенных ему секторов, затем на жёлтом секторе расставляют юниты, характеристики юнитов и ресурсы будут видны справа на иконках.

После раскрытие секторов наступает пора атакующих действий. Игроки могут атаковать как вражеские так и нейтральные сектора, вступив на территорию своими юнитами. В ответ на вторжение противник, может расставить свои войска в этом секторе, независимо от его принадлежности. Вы контролируете сектор, если столица занята вами и на его территории нет ни одного вражеского юнита. Сектор находящийся под вашим контролем приносит доход.

Игроку, чтоб выделить необходимый юнит, нужно кликнуть левой кнопкой мыши по нему, так же необходимо поступить при атаке на вражескую технику. В конце каждого хода игрок может докупить юниты, во всех ему доступных секторах. Сначала необходимо выбрать сектор, а затем на этом же секторе расставить технику.

Рисунок 3.4 – Игровой процесс (Мобилизация сектора)

Если один из игроков взял под свой контроль 6 секторов, или уничтожил все вражеские юниты, то он считается победителем, и игра заканчивается.

Рисунок 3.4 – Окончание игрового процесса

3.4. Критерии качества программных средств

Положительные качества, которыми обладает созданная программа:

- Надежность программного продукта: разработанная программа способна выполнять заданные функции в соответствии с программными документами в условиях возникновения отклонений в среде функционирования;

- Модифицируемость: благодаря использованию объектно-ориентированного подхода, обеспечивается простота устранения ошибок в программе и программных документах, улучшается читаемость кода, и возможность модификации и поддержания программы в актуальном состоянии

- Удобство применения: программа и программные документы способствуют быстрому освоению, применению и эксплуатации программы с минимальными трудозатратами;

- Легкость освоения кода: программные документы и сама программа способствует пониманию логики функционирования программы в целом и ее частей;

- Ресурсоемкость: разработанная программа требует достаточно малые вычислительные ресурсы – программа запустится на всех современных ЭВМ.

Отрицательные качества, которыми обладает созданная система:

- Для запуска созданной игры необходимо наличие XNA Framework и .NET Framework 4.0

- Переносимость: программа написана на языке C#, соответственно она не является кроссплатформенной. Игру можно запустить только на операционной системе Windows.

Заключение

Программа разработана в соответствии с постановкой задачи на курсовое проектирование по теме «Игра – пошаговая стратегия» по дисциплине «Объектно-ориентированное программирование». При написании программы были использованы методические указания по курсовому проектированию по дисциплине «Объектно-ориентированное программирование». Интерфейс программы прост и удобен для использования. Тестирование программы подтвердило, что программа корректно выполняет взаимодействие объектов различных классов в соответствии с вариантом.

Относительно объектно-ориентированного подхода сделаны следующие выводы:

Сам подход (разбиение на классы и описание взаимодействия объектов этих классов) является эффективным методом программирования;

Разработка приложений с использованием объектно-ориентированного анализа и проектирования дает отличные результаты, повышая гибкость программы, позволяя без проблем внедрять дополнительные модули;

С использованием объектно-ориентированного подхода повышается читабельность кода, что позволяет работать над проектом целой команде программистов.

Программа организована достаточно доступно и ясно, что позволит (при надобности) легко ее модифицировать.

Цель курсового проекта была достигнута – была создана пошаговая стратегия.

Перечень ссылок

1. Шилдт Г. С# 4.0: полное руководство.; Пер. с англ. / Г. Шилдт. // 3-е изд. – М. : ООО "И.Д. Вильямс", 2011. – 1056 с.

2. Reed Aaron Learning XNA 4.0: Пер. с англ. / Aaron Reed // O'Reilly Media, 2010. – 430 c.

3. Карли В. и др. C#. Программист программисту.: Пер с англ. / В. Карли и др. // СПб.: Лори, 2004. – 880 с.

Приложение А

/*Главный файл*/

using System;

namespace Massive_Assault

{

#if WINDOWS || XBOX

static class Program

{

/// <summary>

/// The main entry point for the application.

/// </summary>

static void Main(string[] args)

{

using (Menu1 game = new Menu1())

{

game.Run();

}

}

}

#endif

}

/*Интерфейс игры (меню)*/

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 Massive_Assault

{

public class Menu1 : Microsoft.Xna.Framework.Game

{

GraphicsDeviceManager graphics;

SpriteBatch spriteBatch;

MouseState mouseState;

MouseState prevMouseState;

// Texures 2D

Texture2D headband;

Texture2D copyright;

Texture2D start1;

Texture2D start2;

Texture2D help1;

Texture2D help2;

Texture2D exit1;

Texture2D exit2;

Texture2D tank;

Texture2D menuIngame, menuHelp, menuExit;

public static float width;

public static float height;

// Flags

bool click = false;

bool ingameFlag = false;

bool helpFlag = false;

// Game state components

Help help;

Ingame ingame;

enum GameState { start, ingame, exit, help }

GameState curentGameState = GameState.start;

GameState menuState = GameState.start;

public Menu1()

{

graphics = new GraphicsDeviceManager(this);

Content.RootDirectory = "Content";

graphics.PreferredBackBufferWidth = 1366;

graphics.PreferredBackBufferHeight = 768;

graphics.PreferMultiSampling = false;

graphics.ToggleFullScreen();

width = Window.ClientBounds.Width;

height = Window.ClientBounds.Height;

}

protected override void Initialize()

{

// TODO: Add your initialization logic here

// ingame component

ingame = new Ingame(this);

Components.Add(ingame);

ingame.Enabled = false;

ingame.Visible = false;

// help component

help = new Help(this);

Components.Add(help);

help.Enabled = false;

help.Visible = false;

base.Initialize();

}

protected override void LoadContent()

{

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

spriteBatch = new SpriteBatch(GraphicsDevice);

headband = Content.Load<Texture2D>(@"Images/headband");

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

copyright = Content.Load<Texture2D>(@"Images/copy");

start1 = Content.Load<Texture2D>(@"Images/start1");

start2 = Content.Load<Texture2D>(@"Images/start2");

help1 = Content.Load<Texture2D>(@"Images/help1");

help2 = Content.Load<Texture2D>(@"Images/help2");

exit1 = Content.Load<Texture2D>(@"Images/exit1");

exit2 = Content.Load<Texture2D>(@"Images/exit2");

tank = Content.Load<Texture2D>(@"Images/tank2");

}

protected override void Update(GameTime gameTime)

{

// Allows the game to exit

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

this.Exit();

if (ingame.Enabled == false && curentGameState == GameState.ingame && ingameFlag == true)

{

ingameFlag = false;

curentGameState = GameState.start;

}

if (help.Enabled == false && curentGameState == GameState.help && helpFlag == true)

{

helpFlag = false;

curentGameState = GameState.start;

}

switch (curentGameState)

{

case GameState.start:

// Checking the mouse state

prevMouseState = mouseState;

mouseState = Mouse.GetState();

IsMouseVisible = true;

curentGameState = SelectGameState();

break;

case GameState.help:

help.Enabled = true;

help.Visible = true;

helpFlag = true;

break;

case GameState.ingame:

ingame.Enabled = true;

ingame.Visible = true;

ingameFlag = true;

break;

case GameState.exit:

this.Exit();

break;

default: break;

}

base.Update(gameTime);

}

protected override void Draw(GameTime gameTime)

{

switch (curentGameState)

{

case GameState.start:

GraphicsDevice.Clear(Color.Black);

DrawMenu1();

break;

case GameState.help:

break;

case GameState.ingame:

break;

}

base.Draw(gameTime);

}

private void DrawMenu1()

{

Color lblue = new Color(210, 240, 255);

GraphicsDevice.Clear(lblue);

menuIngame = start1;

menuHelp = help1;

menuExit = exit1;

switch (menuState)

{

case GameState.ingame:

menuIngame = start2;

break;

case GameState.help:

menuHelp = help2;

break;

case GameState.exit:

menuExit = exit2;

break;

}

spriteBatch.Begin();

// Ingame

spriteBatch.Draw(menuIngame,

new Vector2(

(width / 2) - (start1.Width / 2),

(height / 2) - ((start1.Height * 4 + 225) / 2)),

Color.White);

// Help

spriteBatch.Draw(menuHelp,

new Vector2(

(width / 2) - (start1.Width / 2),

(height / 2) - ((start1.Height * 4 + 225) / 2) + 75),

Color.White);

// Exit

spriteBatch.Draw(menuExit,

new Vector2(

(width / 2) - (start1.Width / 2),

(height / 2) - ((start1.Height * 4 + 225) / 2) + 150),

Color.White);

spriteBatch.Draw(tank,

new Vector2(

15,

(height / 2) - (tank.Height) / 2),

Color.White);

spriteBatch.End();

}

//If LeftButton was Pressed, Game state would be selected

private GameState SelectGameState()

{

bool flag = false;

int posx = (Window.ClientBounds.Width / 2) - (start1.Width / 2);

int posy = (Window.ClientBounds.Height / 2) - ((start1.Height * 4 + 225) / 2);

//rectangles

Rectangle rHelp = new Rectangle(posx, posy + 75, help1.Width, help1.Height);

Rectangle rExit = new Rectangle(posx, posy + 150, exit1.Width, exit1.Height);

Rectangle rIngame = new Rectangle(posx, posy, start1.Width, start1.Height);

Point mouse;

mouse.X = mouseState.X;

mouse.Y = mouseState.Y;

if (rIngame.Contains(mouse))

{

flag = true;

menuState = GameState.ingame;

if (mouseState.LeftButton != ButtonState.Pressed)

click = true;

if (mouseState.LeftButton == ButtonState.Pressed && click==true)

return GameState.ingame;

}

if (rHelp.Contains(mouse))

{

flag = true;

menuState = GameState.help;

if (mouseState.LeftButton != ButtonState.Pressed)

click = true;

if (mouseState.LeftButton == ButtonState.Pressed && click==true)

return GameState.help;

}

if (rExit.Contains(mouse))

{

flag = true;

menuState = GameState.exit;

if (mouseState.LeftButton != ButtonState.Pressed)

click = true;

if (mouseState.LeftButton == ButtonState.Pressed && click == true)

return GameState.exit;

}

if (flag == false)

{

menuState = GameState.start;

click = false;

}

return GameState.start;

}

}

}

/* Игровой компонент Help*/

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 Massive_Assault

{

public class Help : Microsoft.Xna.Framework.DrawableGameComponent

{

SpriteBatch spriteBatch;

Texture2D texture;

public Help(Game game)

: base(game) {}

protected override void LoadContent()

{

spriteBatch = new SpriteBatch(Game.GraphicsDevice);

texture = Game.Content.Load<Texture2D>(@"Images/HelpM");

base.LoadContent();

}

public override void Update(GameTime gameTime)

{

if (Keyboard.GetState().IsKeyDown(Keys.Escape))

{

this.Enabled = false;

this.Visible = false;

}

// Allows the game to exit

base.Update(gameTime);

}

public override void Draw(GameTime gameTime)

{

spriteBatch.Begin();

Color lblue = new Color(210, 240, 255);

GraphicsDevice.Clear(lblue);

Vector2 temp = new Vector2();

temp.Y = 30;

temp.X = 300;

spriteBatch.Draw(texture, temp, Color.White);

spriteBatch.End();

base.Draw(gameTime);

}

}

}

/* Игровой компонент Ingame*/

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;

using System.Collections;

namespace Massive_Assault

{

public class Ingame : Microsoft.Xna.Framework.DrawableGameComponent

{

public static Map scene;

Player p;

int currentPhase=0;

//SpriteBatch for drawing

public static SpriteBatch spriteBatch;

bool Flag;

bool endGame=false;

int winner=0;

int countCadr = 250;

public static Texture2D[] messages = new Texture2D[13];

public static Texture2D[] messagesA = new Texture2D[4];

public static Texture2D geksN;

public static Texture2D geksC;

public static Texture2D geksP;

public static Texture2D geksM;

public static Texture2D geksNcap;

public static Texture2D geksCcap;

public static Texture2D geksPcap;

public static Texture2D geksMcap;

public static Texture2D tankT;

public static Texture2D hitpointC;

public static Texture2D hitpointP;

public static Texture2D geks;

public static Texture2D m;

public static Texture2D[] iconsA = new Texture2D[7];

public static Texture2D[] icons = new Texture2D[7];

public static Texture2D[]UsersUnit=new Texture2D[7];

public static Texture2D[] ComputerUnit = new Texture2D[7];

public static SpriteFont scoreFont;

Texture2D end1;

Texture2D end2;

public Ingame(Game game)

: base(game)

{

Flag = true;

}

protected override void LoadContent()

{

spriteBatch = new SpriteBatch(Game.GraphicsDevice);

geksN=Game.Content.Load<Texture2D>(@"Images/Geks/geksN");

geksC = Game.Content.Load<Texture2D>(@"Images/Geks/geksC");

geksP = Game.Content.Load<Texture2D>(@"Images/Geks/geksP");

geksM = Game.Content.Load<Texture2D>(@"Images/Geks/geksM");

m = Game.Content.Load<Texture2D>(@"Images/Geks/M");

geksNcap = Game.Content.Load<Texture2D>(@"Images/Geks/geksNcap");

geksCcap = Game.Content.Load<Texture2D>(@"Images/Geks/geksCcap");

geksPcap = Game.Content.Load<Texture2D>(@"Images/Geks/geksPcap");

geksMcap = Game.Content.Load<Texture2D>(@"Images/Geks/geksMcap");

tankT = Game.Content.Load<Texture2D>(@"Images/Units/ComputerControl/RocketLauncherC");

icons[0] = Game.Content.Load<Texture2D>(@"Images/Units/Icons/Cico");

iconsA[0] = Game.Content.Load<Texture2D>(@"Images/Units/Icons/CicoA");

icons[1] = Game.Content.Load<Texture2D>(@"Images/Units/Icons/CRico");

iconsA[1] = Game.Content.Load<Texture2D>(@"Images/Units/Icons/CRicoA");

icons[2] = Game.Content.Load<Texture2D>(@"Images/Units/Icons/DGico");

iconsA[2] = Game.Content.Load<Texture2D>(@"Images/Units/Icons/DGicoA");

icons[3] = Game.Content.Load<Texture2D>(@"Images/Units/Icons/LAVico");

iconsA[3] = Game.Content.Load<Texture2D>(@"Images/Units/Icons/LAVicoA");

icons[4] = Game.Content.Load<Texture2D>(@"Images/Units/Icons/Mico");

iconsA[4] = Game.Content.Load<Texture2D>(@"Images/Units/Icons/MicoA");

icons[5] = Game.Content.Load<Texture2D>(@"Images/Units/Icons/RLico");

iconsA[5] = Game.Content.Load<Texture2D>(@"Images/Units/Icons/RLicoA");

icons[6] = Game.Content.Load<Texture2D>(@"Images/Units/Icons/Tico");

iconsA[6] = Game.Content.Load<Texture2D>(@"Images/Units/Icons/TicoA");

UsersUnit[0] = Game.Content.Load<Texture2D>(@"Images/Units/UserControl/carrierP");

UsersUnit[1] = Game.Content.Load<Texture2D>(@"Images/Units/UserControl/combatRobotP");

UsersUnit[2] = Game.Content.Load<Texture2D>(@"Images/Units/UserControl/defensiveGunP");

UsersUnit[3] = Game.Content.Load<Texture2D>(@"Images/Units/UserControl/LAVP");

UsersUnit[4] = Game.Content.Load<Texture2D>(@"Images/Units/UserControl/mortarP");

UsersUnit[5] = Game.Content.Load<Texture2D>(@"Images/Units/UserControl/RocketLauncherP");

UsersUnit[6] = Game.Content.Load<Texture2D>(@"Images/Units/UserControl/tankP");

ComputerUnit[0] = Game.Content.Load<Texture2D>(@"Images/Units/ComputerControl/carrierC");

ComputerUnit[1] = Game.Content.Load<Texture2D>(@"Images/Units/ComputerControl/combatRobotC");

ComputerUnit[2] = Game.Content.Load<Texture2D>(@"Images/Units/ComputerControl/defensiveGunC");

ComputerUnit[3] = Game.Content.Load<Texture2D>(@"Images/Units/ComputerControl/LAVC");

ComputerUnit[4] = Game.Content.Load<Texture2D>(@"Images/Units/ComputerControl/mortarC");

ComputerUnit[5] = Game.Content.Load<Texture2D>(@"Images/Units/ComputerControl/RocketLauncherC");

ComputerUnit[6] = Game.Content.Load<Texture2D>(@"Images/Units/ComputerControl/tankC");

hitpointC = Game.Content.Load<Texture2D>(@"Images/Units/hitpoint");

hitpointP = Game.Content.Load<Texture2D>(@"Images/Units/hitpointP");

messages[0] = Game.Content.Load<Texture2D>(@"Images/message1");

messagesA[0] = Game.Content.Load<Texture2D>(@"Images/message1A");

messages[1] = Game.Content.Load<Texture2D>(@"Images/message2");

messagesA[1] = Game.Content.Load<Texture2D>(@"Images/message2A");

messages[2] = Game.Content.Load<Texture2D>(@"Images/message3");

messages[3] = Game.Content.Load<Texture2D>(@"Images/message4");

messages[5] = Game.Content.Load<Texture2D>(@"Images/message6");

messages[4] = Game.Content.Load<Texture2D>(@"Images/message5");

messages[6] = Game.Content.Load<Texture2D>(@"Images/message7");

messages[7] = Game.Content.Load<Texture2D>(@"Images/message8");

messages[8] = Game.Content.Load<Texture2D>(@"Images/message9");

messages[9] = Game.Content.Load<Texture2D>(@"Images/message10");

messages[10] = Game.Content.Load<Texture2D>(@"Images/message11");

messages[11] = Game.Content.Load<Texture2D>(@"Images/message12");

end1 = Game.Content.Load<Texture2D>(@"Images/end");

end2 = Game.Content.Load<Texture2D>(@"Images/end2");

// Load fonts

scoreFont = Game.Content.Load<SpriteFont>(@"fonts\score");

base.LoadContent();

}

public override void Update(GameTime gameTime)

{

if (Keyboard.GetState().IsKeyDown(Keys.Escape))

{

this.Enabled = false;

this.Visible = false;

Flag = true;

}

if (Flag == true)

{

scene = null;

Cell.ChangeCount(0);

scene = new Map();

p = new Player();

Flag = false;

currentPhase = 0;

winner = 0;

endGame = false;

}

currentPhase = ToDeterminePhase();

int phase = currentPhase;

if (endGame)

phase = -10;

switch (phase/10)

{

case 0:

p.Disclosure((phase%10)+1);

break;

case 1:

p.Battle((phase%10)+1);

break;

case 2:

p.Mobilization((phase % 10) + 1);

break;

case 3:

p.Partizan((phase%10)+1);

break;

default:

if (countCadr == 0)

{

this.Enabled = false;

this.Visible = false;

Flag = true;

}

countCadr--;

break;

}

base.Update(gameTime);

}

public override void Draw(GameTime gameTime)

{

Color lblue = new Color(210, 240, 255);

GraphicsDevice.Clear(lblue);

int phase = currentPhase;

if (endGame)

phase = -10;

switch ( phase/ 10)

{

case 0:

p.DrawDisclosure((phase % 10) + 1);

break;

case 1:

p.DrawBattle((phase % 10) + 1);

break;

case 2:

p.DrawMobilization((phase % 10) + 1);

break;

case 3:

p.DrawPartizan((phase % 10) + 1);

break;

default:

GraphicsDevice.Clear(lblue);

Texture2D texture = end1;

if (winner == 2)

texture=end2;

spriteBatch.Begin();

spriteBatch.Draw(texture,

new Vector2(

(1366/2 - (texture.Width / 2)),

(768 / 2) - (texture.Height / 2)),

null, Color.White);

spriteBatch.End();

break;

}

base.Draw(gameTime);

}

/// <summary>

/// function return (next Phase of game)*10 + number of player:

///0 -Disclosure

/// 1 -Battle

///2 -Mobilization

///3 -Partizan

/// </summary>

public int ToDeterminePhase()

{

if ( currentPhase== 0)

if (p.EndDisclosure == true)

{

p.EndDisclosure = false;

return 1;

}

else return 0;

if (currentPhase == 1)

if (p.EndDisclosure == true)

{

p.EndBattle = false;

p.StartBattle = true;

p.StartPartizan = p.CheckPartizan(2);

p.EndPartizan = false;

if (p.StartPartizan == true)

return 31;

return 11;

}

else return 1;

if (currentPhase == 11)

if (p.EndBattle == true)

{

p.EndMobilization = false;

p.StartMobilization = true;

if (p.ChechWinner(2) )

{

endGame = true;

winner = 2;

}

return 21;

}

else return 11;

if (currentPhase == 21)

if (p.EndMobilization == true)

{

p.EndBattle = false;

p.StartBattle = true;

p.StartPartizan = p.CheckPartizan(1);

p.EndPartizan = false;

if (p.StartPartizan == true)

return 30;

else return 10;

}

else return 21;

if (currentPhase == 10)

if (p.EndBattle == true)

{

p.EndMobilization = false;

p.StartMobilization = true;

if (p.ChechWinner(1))

{

endGame = true;

winner = 1;

}

return 20;

}

else return 10;

if (currentPhase == 20)

if (p.EndMobilization == true)

{

p.EndDisclosure = false;

return 0;

}

else return 20;

if (currentPhase == 30)

if (p.EndPartizan == true)

return 10;

else return 30;

if (currentPhase == 31)

if (p.EndPartizan == true)

return 11;

else return 31;

return -1;

}

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

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 Massive_Assault

{

class Player

{

public bool EndDisclosure = false;

public bool EndBattle = false;

public bool EndMobilization=false;

public bool EndPartizan = false;

public bool StartBattle = true;

public bool StartMobilization = true;

public bool StartPartizan = false;

private bool End = false;

private List<int> mobIndex = new List<int>();

bool flagUnit=false;

int UnitID = 0;

Rectangle Cico;

Rectangle CRico;

Rectangle DGico;

Rectangle LAVico;

Rectangle Mico;

Rectangle RLico;

Rectangle Tico;

Rectangle bay1;

Rectangle bay2;

Rectangle mes;

int number=-1;

Texture2D[] icons = new Texture2D[7];

MouseState mouseState;

MouseState prevMouseState;

bool action=false;

int id;

int Dresoures=-1;

int index=0;

int indexDisclousure=-1;

bool flagD=true;

bool flagR = false;

bool flagD2 = true;

int resources;

bool loadflag=false;

Unit tempUnit=null;

//constructor

public Player()

{

int t = 2;

int wid = (int)Menu1.width;

Cico = new Rectangle((1366 - Ingame.icons[0].Width-10), t, Ingame.icons[0].Width, Ingame.icons[0].Height);

t += Ingame.icons[0].Height;

CRico = new Rectangle((1366 - Ingame.icons[0].Width - 10), t, Ingame.icons[0].Width, Ingame.icons[0].Height);

bay1=new Rectangle ((1366 - Ingame.icons[0].Width - 10), t, Ingame.icons[0].Width, Ingame.icons[0].Height);

t += Ingame.icons[0].Height;

DGico = new Rectangle((1366 - Ingame.icons[0].Width - 10), t, Ingame.icons[0].Width, Ingame.icons[0].Height);

bay2=new Rectangle ((1366 - Ingame.icons[0].Width - 10), t, Ingame.icons[0].Width, Ingame.icons[0].Height);

t += Ingame.icons[0].Height;

LAVico = new Rectangle((1366 - Ingame.icons[0].Width - 10), t, Ingame.icons[0].Width, Ingame.icons[0].Height);

t += Ingame.icons[0].Height;

Mico = new Rectangle((1366 - Ingame.icons[0].Width - 10), t, Ingame.icons[0].Width, Ingame.icons[0].Height);

t += Ingame.icons[0].Height;

RLico = new Rectangle((1366 - Ingame.icons[0].Width - 10), t, Ingame.icons[0].Width, Ingame.icons[0].Height);

t += Ingame.icons[0].Height;

Tico = new Rectangle((1366 - Ingame.icons[0].Width - 10), t, Ingame.icons[0].Width, Ingame.icons[0].Height);

t =8;

mes = new Rectangle((1366 - Ingame.messages[0].Width - 170), t, Ingame.messages[0].Width, Ingame.messages[0].Height);

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

icons[i] = Ingame.icons[i];

tempUnit = null;

action = false;

EndBattle = false;

}

private int PlacementForces(int number, int resources)

{

Point mouse;

mouse.X = mouseState.X;

mouse.Y = mouseState.Y;

if (flagUnit == false )

{

// check 1st icon

if (Cico.Contains(mouse))

{

icons[0] = Ingame.iconsA[0];

if (mouseState.LeftButton == ButtonState.Pressed) {

flagUnit = true;

Dresoures=2;

UnitID = 1;

}

}

else icons[0] = Ingame.icons[0];

// check 2nd icon

if (CRico.Contains(mouse))

{

icons[1] = Ingame.iconsA[1];

if (mouseState.LeftButton == ButtonState.Pressed) {

flagUnit = true;

Dresoures=4;

UnitID = 2;

}

}

else icons[1] = Ingame.icons[1];

//check 3rd icon

if (DGico.Contains(mouse))

{

icons[2] = Ingame.iconsA[2];

if (mouseState.LeftButton == ButtonState.Pressed) {

flagUnit = true;

Dresoures=4;

UnitID = 3;

}

}

else icons[2] = Ingame.icons[2];

//check 4th icon

if (LAVico.Contains(mouse))

{

icons[3] = Ingame.iconsA[3];

if (mouseState.LeftButton == ButtonState.Pressed) {

flagUnit = true;

Dresoures=1;

UnitID = 4;

}

}

else icons[3] = Ingame.icons[3];

//check 5th icon

if (Mico.Contains(mouse))

{

icons[4] = Ingame.iconsA[4];

if (mouseState.LeftButton == ButtonState.Pressed) {

flagUnit = true;

Dresoures=2;

UnitID = 5;

}

}

else icons[4] = Ingame.icons[4];

//check 6th icon

if (RLico.Contains(mouse))

{

icons[5] = Ingame.iconsA[5];

if (mouseState.LeftButton == ButtonState.Pressed) {

flagUnit = true;

Dresoures=4;

UnitID = 6;

}

}

else icons[5] = Ingame.icons[5];

//check 7th icon

if (Tico.Contains(mouse))

{

icons[6] = Ingame.iconsA[6];

if (mouseState.LeftButton == ButtonState.Pressed) {

flagUnit = true;

Dresoures=2;

UnitID = 7;

}

}

else icons[6] = Ingame.icons[6];

}

if (flagUnit == true && (mouseState.LeftButton == ButtonState.Pressed))

if (resources-Dresoures>=0)

{

id = Ingame.scene.CheckCell(mouseState, Ingame.geksN);

if (id >-1 )

{

index = Ingame.scene.FoundCell(id);

if (Ingame.scene.world[index / 100].cells[index % 100].unit == null

&& (index/100) == indexDisclousure)

{

flagUnit = false;

CreateUnit(UnitID, index,number);

return resources - Dresoures;

}

}

}

else flagUnit = false;

if (resources == 0)

{

End = true;

flagD = true;

flagD2 = true;

}

return resources;

}

private void CreateUnit(int UnitID, int index, int number)

{

int id=Ingame.scene.world[index / 100].cells[index % 100].GetIDCell();

Texture2D[] unitTextures;

if (number == 2)

unitTextures = Ingame.UsersUnit;

else unitTextures = Ingame.ComputerUnit;

switch (UnitID)

{

case 1:

Ingame.scene.world[index / 100].cells[index % 100].unit

= (Unit)new Carrier(unitTextures[0], number, 2, 4, id, 5);

break;

case 2:

Ingame.scene.world[index / 100].cells[index % 100].unit

= (Unit)new Attacker(unitTextures[1], number, 4, 7, 2, 2, 3, id);

break;

case 3:

Ingame.scene.world[index / 100].cells[index % 100].unit

= (Unit)new Attacker(unitTextures[2], number, 4, 8, 2, 0, 2, id);

break;

case 4:

Ingame.scene.world[index / 100].cells[index % 100].unit

= (Unit)new Attacker(unitTextures[3], number, 1, 4, 1, 1, 1, id);

break;

case 5:

Ingame.scene.world[index / 100].cells[index % 100].unit

= (Unit)new Attacker(unitTextures[4], number, 2, 4, 2, 1, 2, id);

break;

case 6:

Ingame.scene.world[index / 100].cells[index % 100].unit

= (Unit)new Attacker(unitTextures[5], number, 4, 3, 3, 1, 3, id);

break;

case 7:

Ingame.scene.world[index / 100].cells[index % 100].unit

= (Unit)new Attacker(unitTextures[6], number, 2, 5, 1, 2, 2, id);

break;

}

}

public void Disclosure(int number)

{

prevMouseState = mouseState;

mouseState = Mouse.GetState();

EndDisclosure = true;

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

{

if (Ingame.scene.world[i].disclosure == false

&& Ingame.scene.world[i].owner == number

&& Ingame.scene.world[i].freeCountry == true)

EndDisclosure = false;

}

if (EndDisclosure == true)

{

End = false;

indexDisclousure = -1;

return;

}

int ind = -1;

if (mouseState.LeftButton == ButtonState.Released)

flagR = true;

if (flagD && mouseState.LeftButton == ButtonState.Pressed)

{

ind = Ingame.scene.CheckCell(mouseState, Ingame.geksM);

if (ind > -1)

{

ind = Ingame.scene.FoundCell(ind);

if (Ingame.scene.world[ind / 100].owner == number && flagR

&& Ingame.scene.world[ind / 100].disclosure==false

&& Ingame.scene.world[ind / 100].freeCountry==true

&& resources!=0)

{

flagD = false;

indexDisclousure = ind / 100;

}

}

}

if (flagD2)

{

resources = 10;

flagD2 = false;

}

resources=PlacementForces(number,resources);

if (End)

{

EndDisclosure = true;

End = false;

Ingame.scene.world[indexDisclousure].SetDisclosureResourses(10);

Ingame.scene.world[indexDisclousure].disclosure = true;

indexDisclousure = -1;

}

}

public void Partizan(int number)

{

prevMouseState = mouseState;

mouseState = Mouse.GetState();

Point mouse;

mouse.X = mouseState.X;

mouse.Y = mouseState.Y;

int ind = -1;

if (mouseState.LeftButton == ButtonState.Released)

flagR = true;

if (flagD && mouseState.LeftButton

== ButtonState.Pressed)

{

ind = Ingame.scene.CheckCell(mouseState, Ingame.geksM);

if (ind > -1)

{

ind = Ingame.scene.FoundCell(ind);

if (flagR && CheckPartizan(number,ind/100)

)

{

flagD = false;

indexDisclousure = ind / 100;

if (Ingame.scene.world[ind / 100].owner == 0)

Ingame.scene.world[ind / 100].owner = number;

}

}

}

if (flagD2 == true && flagD == false)

{

resources = Ingame.scene.world[indexDisclousure].

GetPartizanResourses();

flagD2 = false;

}

if (flagD == false)

{

resources = PlacementForces(number, resources);

}

if (End)

{

EndPartizan = true;

Ingame.scene.world[indexDisclousure].

SetPartizanResourses(4);

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

if ( CheckPartizan(number,i))

EndPartizan = false;

End = false;

indexDisclousure = -1;

flagR = false;

flagD = true;

}

}

public void Mobilization(int number)

{

prevMouseState = mouseState;

mouseState = Mouse.GetState();

Point mouse;

mouse.X = mouseState.X;

mouse.Y = mouseState.Y;

if (StartMobilization)

{

mobIndex = mobIndex = new List<int>();

StartMobilization = false;

}

bool flag=true;

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

{

if (Ingame.scene.world[i].disclosure

&& Ingame.scene.world[i].freeCountry

&& Ingame.scene.world[i].moblization

&& Ingame.scene.world[i].owner == number

&& Ingame.scene.world[i].freeCountry

&& (Ingame.scene.world[i].GetBalanceResourses() != 0

|| Ingame.scene.world[i].GetMobResourses() != 0))

flag = false;

}

if (flag)

{

EndMobilization = true;

for (int i = 0; i < mobIndex.Count; i++)

Ingame.scene.world[mobIndex[i]].moblization = true;

indexDisclousure = -1;

flagR = false;

flagD = true;

return;

}

int ind = -1;

if (mouseState.LeftButton == ButtonState.Released)

flagR = true;

if (flagD && mouseState.LeftButton == ButtonState.Pressed)

{

ind = Ingame.scene.CheckCell(mouseState, Ingame.geksM);

if (ind > -1)

{

ind = Ingame.scene.FoundCell(ind);

if (Ingame.scene.world[ind / 100].owner == number && flagR

&& Ingame.scene.world[ind / 100].freeCountry

&& Ingame.scene.world[ind/100].disclosure == true

&& (Ingame.scene.world[ind/100].GetBalanceResourses() != 0

|| Ingame.scene.world[ind/100].GetMobResourses() != 0))

{

flagD = false;

indexDisclousure = ind / 100;

}

}

}

if (flagD2 == true && flagD == false)

{

Ingame.scene.world[indexDisclousure].AddBalanceResourses();

resources = Ingame.scene.world[indexDisclousure].GetBalanceResourses();

flagD2 = false;

}

if (flagD == false)

{

resources = PlacementForces(number, resources);

}

if (End)

{

Ingame.scene.world[indexDisclousure].moblization = false;

mobIndex.Add(indexDisclousure);

EndMobilization = true;

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

if (Ingame.scene.world[i].moblization==true

&& Ingame.scene.world[i].freeCountry

&& Ingame.scene.world[i].owner==number

&& Ingame.scene.world[i].disclosure == true)

EndMobilization = false;

if (EndMobilization == true)

{

for (int i = 0; i < mobIndex.Count; i++)

Ingame.scene.world[mobIndex[i]].moblization = true;

}

End = false;

Ingame.scene.world[indexDisclousure].SetBalanceResourses(

Ingame.scene.world[indexDisclousure].GetBalanceResourses() );

indexDisclousure = -1;

flagR = false;

flagD = true;

}

if (mes.Contains(mouse)&& !flagD)

if (mouseState.LeftButton == ButtonState.Pressed)

{

End = false;

if (indexDisclousure > -1)

{

Ingame.scene.world[indexDisclousure].moblization = false;

mobIndex.Add(indexDisclousure);

}

EndMobilization = true;

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

if (Ingame.scene.world[i].moblization == true

&& Ingame.scene.world[i].freeCountry

&& Ingame.scene.world[i].owner == number

&& Ingame.scene.world[i].disclosure == true)

EndMobilization = false;

if (EndMobilization == true)

{

for (int i = 0; i < mobIndex.Count; i++)

Ingame.scene.world[mobIndex[i]].moblization = true;

}

End = false;

if (indexDisclousure > -1)

Ingame.scene.world[indexDisclousure].

SetBalanceResourses(

Ingame.scene.world[indexDisclousure].

GetBalanceResourses()-resources);

indexDisclousure = -1;

flagR = false;

flagD = true;

flagD2 = true;

}

}

public void DrawDisclosure(int number)

{

Texture2D geks;

Texture2D mesag=Ingame.messages[6];

Texture2D enemyGeks;

if (number==2)

mesag = Ingame.messages[7];

int enumber = 1;

if (number == 2)

{

geks = Ingame.geksP;

enemyGeks = Ingame.geksC;

}

else

{

geks = Ingame.geksC;

enemyGeks = Ingame.geksP;

enumber = 2;

}

//To draw countres

if (flagD)

{

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

{

if (Ingame.scene.world[i].owner == number)

Ingame.scene.world[i].DrawCountry(geks, Ingame.spriteBatch);

else if (Ingame.scene.world[i].owner == enumber

&& Ingame.scene.world[i].GetDisclosureResourses() == 0)

Ingame.scene.world[i].DrawCountry(enemyGeks, Ingame.spriteBatch);

else Ingame.scene.world[i].DrawCountry(Ingame.geksN, Ingame.spriteBatch);

}

Vector2 temp = new Vector2();

Ingame.spriteBatch.Begin();

temp.Y = (768 - mesag.Height) / 3;

temp.X = mes.X;

Ingame.spriteBatch.Draw(mesag, temp, Color.White);

Ingame.spriteBatch.End();

}

else

{

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

{

if (Ingame.scene.world[i].owner == number

&& i != indexDisclousure)

Ingame.scene.world[i].DrawCountry(geks, Ingame.spriteBatch);

else if (Ingame.scene.world[i].owner == number

&& i == indexDisclousure)

Ingame.scene.world[i].DrawCountry(Ingame.geksM, Ingame.spriteBatch);

else if (Ingame.scene.world[i].owner == enumber

&& Ingame.scene.world[i].GetDisclosureResourses() == 0)

Ingame.scene.world[i].DrawCountry(enemyGeks, Ingame.spriteBatch);

else Ingame.scene.world[i].DrawCountry(Ingame.geksN, Ingame.spriteBatch);

}

Vector2 temp = new Vector2();

Ingame.spriteBatch.Begin();

temp.Y = (768 - mesag.Height) / 3;

temp.X = mes.X;

string text = "Доступно " + resources + "$";

temp.Y -= 50;

Ingame.spriteBatch.DrawString(Ingame.scoreFont, text,

temp,

Color.Red);

Ingame.spriteBatch.End();

// To draw unit's icons

temp = new Vector2((Menu1.width - Ingame.icons[0].Width - 10), 2);

Ingame.spriteBatch.Begin();

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

{

Ingame.spriteBatch.Draw(icons[i], temp, Color.White);

temp.Y += Ingame.icons[i].Height;

}

Ingame.spriteBatch.End();

}

}

public void DrawMobilization(int number)

{

Texture2D geks;

Texture2D enemyGeks;

Texture2D but=Ingame.messages[0];

Texture2D mesag = Ingame.messages[10];

Point mouse;

mouse.X = mouseState.X;

mouse.Y = mouseState.Y;

if (number == 2)

mesag = Ingame.messages[11];

if (mes.Contains(mouse))

but = Ingame.messagesA[0];

int enumber = 1;

if (number == 2)

{

geks = Ingame.geksP;

enemyGeks = Ingame.geksC;

}

else

{

geks = Ingame.geksC;

enemyGeks = Ingame.geksP;

enumber = 2;

}

//To draw countres

if (flagD)

{

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

{

if (Ingame.scene.world[i].owner == number

&& Ingame.scene.world[i].moblization==true

&& Ingame.scene.world[i].freeCountry==true

&& Ingame.scene.world[i].disclosure==true

&& (Ingame.scene.world[i].GetBalanceResourses() != 0

|| Ingame.scene.world[i].GetMobResourses() != 0))

Ingame.scene.world[i].DrawCountry(Ingame.geksM, Ingame.spriteBatch);

else if (Ingame.scene.world[i].owner == enumber

&& Ingame.scene.world[i].GetDisclosureResourses() == 0)

Ingame.scene.world[i].DrawCountry(enemyGeks, Ingame.spriteBatch);

else if (Ingame.scene.world[i].owner == number)

Ingame.scene.world[i].DrawCountry(geks, Ingame.spriteBatch);

else Ingame.scene.world[i].DrawCountry(Ingame.geksN, Ingame.spriteBatch);

}

Vector2 temp = new Vector2();

Ingame.spriteBatch.Begin();

temp.Y = (768 - mesag.Height) / 3;

temp.X = mes.X;

Ingame.spriteBatch.Draw(mesag, temp, Color.White);

Ingame.spriteBatch.End();

}

else

{

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

{

if (Ingame.scene.world[i].owner == number

&& i != indexDisclousure)

Ingame.scene.world[i].DrawCountry(geks, Ingame.spriteBatch);

else if (Ingame.scene.world[i].owner == number

&& i == indexDisclousure)

Ingame.scene.world[i].DrawCountry(Ingame.geksM, Ingame.spriteBatch);

else if (Ingame.scene.world[i].owner == enumber

&& Ingame.scene.world[i].GetDisclosureResourses() == 0)

Ingame.scene.world[i].DrawCountry(enemyGeks, Ingame.spriteBatch);

else Ingame.scene.world[i].DrawCountry(Ingame.geksN, Ingame.spriteBatch);

}

// Draw text for intro splash screen

Vector2 temp = new Vector2();

Ingame.spriteBatch.Begin();

temp.Y = (768 - mesag.Height) / 3;

temp.X = mes.X;

string text = "Доступно "+Ingame.scene.world[indexDisclousure].GetBalanceResourses()+"$";

temp.Y -= 50;

Ingame.spriteBatch.DrawString(Ingame.scoreFont, text,

temp,

Color.Red);

Ingame.spriteBatch.End();

// To draw unit's icons

temp = new Vector2((Menu1.width - Ingame.icons[0].Width - 10), 2);

Ingame.spriteBatch.Begin();

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

{

Ingame.spriteBatch.Draw(icons[i], temp, Color.White);

temp.Y += Ingame.icons[i].Height;

}

temp.X = mes.Location.X;

temp.Y = mes.Location.Y;

Ingame.spriteBatch.Draw(but, temp, Color.White);

Ingame.spriteBatch.End();

}

}

public void Battle(int number)

{

prevMouseState = mouseState;

mouseState = Mouse.GetState();

Point mouse;

mouse.X = mouseState.X;

mouse.Y = mouseState.Y;

if (StartBattle)

{

if (mouseState.LeftButton == ButtonState.Pressed

&& prevMouseState != mouseState)

StartBattle = false;

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

{

int index_ = Ingame.scene.FoundCell(i);

Unit unit_ = Ingame.scene.world[index_ / 100].cells[index_ % 100].unit;

DefensiveGun gun_;

IMove moving_;

Carrier carrier_;

Invader invader_;

if (unit_ != null)

if (unit_.GetUnitOwner() == number)

{

if (unit_.GetTypeUnit() == 2 || unit_.GetTypeUnit() == 3)

{

gun_ = (DefensiveGun)unit_;

gun_.ToRecharge(true);

}

if (unit_.GetTypeUnit() == 2 || unit_.GetTypeUnit() == 1)

{

moving_ = (IMove)unit_;

moving_.SetBalanceDistance(moving_.GetMoveDistance());

if (unit_.GetTypeUnit() == 1)

{

carrier_ = (Carrier)unit_;

for (int j = 0; j < 2; j++)

if (carrier_.carrierUnit[j] != null)

{

invader_ = (Invader)carrier_.carrierUnit[j];

invader_.SetBalanceDistance(invader_.GetMoveDistance());

invader_.ToRecharge(true);

}

}

}

}

}

tempUnit = null;

}

if (!StartBattle)

{

if (mouseState.LeftButton == ButtonState.Pressed && prevMouseState != mouseState)

{

id = Ingame.scene.CheckCell(mouseState, Ingame.geksP);

if (id > -1)

{

index = Ingame.scene.FoundCell(id);

if (Ingame.scene.world[index / 100].cells[index % 100].unit != null)

{

if (Ingame.scene.world[index / 100].

cells[index % 100].unit.GetUnitOwner() == number)

{

if (tempUnit != null)

if (Ingame.scene.world[index / 100].

cells[index % 100].unit.GetTypeUnit() == 1 && tempUnit.GetTypeUnit() != 1)

action = true;

else { tempUnit = Ingame.scene.world[index / 100].

cells[index % 100].unit; action = false; loadflag = false;

}

else { tempUnit = Ingame.scene.world[index / 100].

cells[index % 100].unit; action = false; loadflag = false;

}

}

else action = true;

}

else action = true;

}

else

{

action = false;

if (tempUnit != null)

if (tempUnit.GetTypeUnit() == 1)

{

if (bay1.Contains(mouse))

{

this.number = 0;

loadflag = true;

}

if (bay2.Contains(mouse))

{

this.number = 1;

loadflag = true;

}

}

if (!bay1.Contains(mouse)

&& !bay2.Contains(mouse))

tempUnit = null;

}

}

else action = false;

if (action && tempUnit != null

&& prevMouseState != mouseState)

{

switch (tempUnit.GetTypeUnit())

{

//Carrier

case 1:

Carrier carrier = (Carrier)tempUnit;

if (Ingame.scene.world[index / 100].

cells[index % 100].unit == null)

if (loadflag)

{

carrier.ToLand(id, this.number);

// tempUnit = carrier;

loadflag = false;

}

else

{

carrier.Move(id, number);

}

break;

load: carrier = (Carrier)Ingame.scene.world[index / 100].

cells[index % 100].unit;

carrier.ToLoad(tempUnit.GetUnitCellID());

tempUnit = null;

break;

//Invader

case 2:

Invader invader = (Attacker)tempUnit;

if (Ingame.scene.world[index / 100].

cells[index % 100].unit != null)

if (Ingame.scene.world[index / 100].

cells[index % 100].unit.GetTypeUnit() == 1

&& Ingame.scene.world[index / 100].

cells[index % 100].unit.GetUnitOwner() == number)

goto load;

else

{

invader.Atack(id);

invader.SetBalanceDistance(0);

}

else invader.Move(id, number);

break;

//DefensiveGun

case 3:

DefensiveGun gun = (Attacker)tempUnit;

if (Ingame.scene.world[index / 100].

cells[index % 100].unit != null)

if (Ingame.scene.world[index / 100].

cells[index % 100].unit.GetTypeUnit() == 1)

{

if (Ingame.scene.world[index / 100].

cells[index % 100].unit.GetUnitOwner() != number)

gun.Atack(id);

}

else if (Ingame.scene.world[index / 100].

cells[index % 100].unit.GetUnitOwner() != number)

gun.Atack(id);

break;

}

action = false;

}

EndBattle = true;

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

{

int index_ = Ingame.scene.FoundCell(i);

Unit unit_ = Ingame.scene.world[index_ / 100]

.cells[index_ % 100].unit;

DefensiveGun gun_;

IMove moving_;

if (unit_ != null)

if (unit_.GetUnitOwner() == number)

{

if (unit_.GetTypeUnit() == 2

|| unit_.GetTypeUnit() == 3)

{

gun_ = (DefensiveGun)unit_;

if (gun_.GetRecharge()

&& gun_.EnemyDetection(number))

EndBattle = false;

}

if (unit_.GetTypeUnit() == 2

|| unit_.GetTypeUnit() == 1)

{

moving_ = (IMove)unit_;

if (moving_.GetBalanceDistance() > 0)

EndBattle = false;

}

}

}

if (EndBattle)

{

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

if (Ingame.scene.world[i].freeCountry == false

&& Ingame.scene.world[i].GetPartizanResourses()==0)

{

Ingame.scene.world[i].freeCountry = true;

for (int j = 0; j < 12; j++)

if (Ingame.scene.world[i].

cells[j].unit != null)

if (Ingame.scene.world[i].

cells[j].unit.GetUnitOwner()

!= Ingame.scene.world[i].owner)

Ingame.scene.world[i].freeCountry = false;

}

}

if (mes.Contains(mouse))

if (mouseState.LeftButton == ButtonState.Pressed)

{

EndBattle = true;

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

if (Ingame.scene.world[i].freeCountry == false

&& Ingame.scene.world[i].GetPartizanResourses() == 0)

{

Ingame.scene.world[i].freeCountry = true;

for (int j = 0; j < 12; j++)

if (Ingame.scene.world[i].

cells[j].unit != null)

if (Ingame.scene.world[i].

cells[j].unit.GetUnitOwner()

!= Ingame.scene.world[i].owner)

Ingame.scene.world[i].freeCountry = false;

}

}

}

}

public bool CheckPartizan(int number) {

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

{

if (Ingame.scene.world[i].freeCountry == false)

if ((Ingame.scene.world[i].owner == number || Ingame.scene.world[i].owner == 0

|| (Ingame.scene.world[i].owner != 0 && Ingame.scene.world[i].owner != number

&& Ingame.scene.world[i].GetPartizanResourses()!=0)))

if ( Ingame.scene.world[i].GetPartizanResourses() > 0)

for (int j = 0; j < 12; j++)

if (Ingame.scene.world[i].cells[j].unit != null)

if (Ingame.scene.world[i].cells[j].unit.GetUnitOwner() != number)

return true;

}

return false;

}

public bool CheckPartizan(int number, int i)

{

if (Ingame.scene.world[i].freeCountry == false)

if ((Ingame.scene.world[i].owner == number || Ingame.scene.world[i].owner == 0

|| (Ingame.scene.world[i].owner != 0 && Ingame.scene.world[i].owner != number

&& Ingame.scene.world[i].GetPartizanResourses() != 0)))

if (Ingame.scene.world[i].GetPartizanResourses() > 0)

for (int j = 0; j < 12; j++)

if (Ingame.scene.world[i].cells[j].unit != null)

if (Ingame.scene.world[i].cells[j].unit.GetUnitOwner() != number)

return true;

return false;

}

public void DrawBattle(int number)

{

Texture2D geks;

Texture2D enemyGeks;

Texture2D but = Ingame.messages[1];

Point mouse;

mouse.X = mouseState.X;

mouse.Y = mouseState.Y;

int enumber = 1;

if (number == 2)

{

geks = Ingame.geksP;

enemyGeks = Ingame.geksC;

}

else

{

geks = Ingame.geksC;

enemyGeks = Ingame.geksP;

enumber = 2;

}

if (mes.Contains(mouse))

but = Ingame.messagesA[1];

//To draw countres

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

if ( Ingame.scene.world[i].owner==enumber

&& Ingame.scene.world[i].GetDisclosureResourses()==0)

Ingame.scene.world[i].DrawCountry(enemyGeks, Ingame.spriteBatch);

else if (Ingame.scene.world[i].owner==enumber

&& Ingame.scene.world[i].GetDisclosureResourses()!=0

&& Ingame.scene.world[i].freeCountry==false)

Ingame.scene.world[i].DrawCountry(enemyGeks, Ingame.spriteBatch);

else if ( Ingame.scene.world[i].owner==number)

Ingame.scene.world[i].DrawCountry(geks, Ingame.spriteBatch);

else Ingame.scene.world[i].DrawCountry(Ingame.geksN, Ingame.spriteBatch);

Carrier carrier;

Texture2D texture=null;

Vector2 temp = new Vector2((Menu1.width -

Ingame.icons[0].Width - 10), 2);

if (tempUnit != null)

{

if (tempUnit.GetTypeUnit() == 1

|| tempUnit.GetTypeUnit() == 2)

{

IMove unit = (IMove)tempUnit;

unit.DrawMoveStep();

}

switch (tempUnit.GetTypeUnit())

{

case 1:

texture = Ingame.iconsA[0];

break;

case 2:

Invader invader = (Invader)tempUnit;

if (invader.GetFirepower() == 1)

texture = Ingame.iconsA[3];

if (invader.GetFirepower() == 3

&& invader.GetDamageRadius()==2)

texture = Ingame.iconsA[1];

if (invader.GetDamageRadius() == 1

&& invader.GetFirepower()==2)

texture = Ingame.iconsA[6];

if (invader.GetDamageRadius()==2

&& invader.GetFirepower() == 2)

texture = Ingame.iconsA[4];

if (invader.GetDamageRadius() == 3)

texture = Ingame.iconsA[5];

break;

case 3:

texture = Ingame.iconsA[2];

break;

}

if (texture!=null) {

Ingame.spriteBatch.Begin();

Ingame.spriteBatch.Draw(texture,

temp, Color.White);

Ingame.spriteBatch.End();

}

if (tempUnit.GetTypeUnit() == 1)

{

carrier = (Carrier)tempUnit;

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

if (carrier.carrierUnit[i] != null)

{

switch (carrier.carrierUnit[i].GetTypeUnit())

{

case 1:

texture = Ingame.icons[0];

break;

case 2:

Invader invader = (Invader)carrier.

carrierUnit[i];

if (invader.GetFirepower() == 1)

texture = Ingame.icons[3];

if (invader.GetHitpoint() == 7)

texture = Ingame.icons[1];

if (invader.GetHitpoint() == 5)

texture = Ingame.icons[6];

if (invader.GetHitpoint() == 4

&& invader.GetFirepower() == 2)

texture = Ingame.icons[4];

if (invader.GetHitpoint() == 3)

texture = Ingame.icons[5];

break;

case 3:

texture = Ingame.icons[2];

break;

}

temp.Y += texture.Height;

Ingame.spriteBatch.Begin();

Ingame.spriteBatch.Draw(texture,

temp, Color.White);

Ingame.spriteBatch.End();

}

}

}

Ingame.spriteBatch.Begin();

temp.X = mes.Location.X;

temp.Y = mes.Location.Y;

Ingame.spriteBatch.Draw(but, temp, Color.White);

Ingame.spriteBatch.End();

if (StartBattle)

{

Texture2D t = Ingame.messages[3];

if (number==2)

t = Ingame.messages[4];

Ingame.spriteBatch.Begin();

temp.Y = (768 - t.Height)/3;

temp.X = mes.X;

Ingame.spriteBatch.Draw(t, temp, Color.White);

Ingame.spriteBatch.End();

}

}

public void DrawPartizan(int number)

{

Texture2D geks;

Texture2D enemyGeks;

Texture2D mesag = Ingame.messages[9];

if (number == 2)

mesag = Ingame.messages[8];

int enumber = 1;

if (number == 2)

{

geks = Ingame.geksP;

enemyGeks = Ingame.geksC;

}

else

{

geks = Ingame.geksC;

enemyGeks = Ingame.geksP;

enumber = 2;

}

//To draw countres

if (flagD)

{

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

{

if (CheckPartizan(number,i))

Ingame.scene.world[i].DrawCountry(Ingame.geksM,

Ingame.spriteBatch);

else if (Ingame.scene.world[i].owner == number)

Ingame.scene.world[i].DrawCountry(geks,

Ingame.spriteBatch);

else if (Ingame.scene.world[i].owner == enumber

&& Ingame.scene.world[i].GetDisclosureResourses() == 0)

Ingame.scene.world[i].DrawCountry(enemyGeks,

Ingame.spriteBatch);

else Ingame.scene.world[i].DrawCountry(Ingame.geksN, Ingame.spriteBatch);

}

Vector2 temp = new Vector2();

Ingame.spriteBatch.Begin();

temp.Y = (768 - mesag.Height) / 3;

temp.X = mes.X;

Ingame.spriteBatch.Draw(mesag, temp, Color.White);

Ingame.spriteBatch.End();

// Draw text for intro splash screen

Ingame.spriteBatch.Begin();

string text = "Доступно 4$";

temp.Y -= 50;

Ingame.spriteBatch.DrawString(Ingame.scoreFont, text,

temp,

Color.Red);

Ingame.spriteBatch.End();

}

else

{

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

{

if (Ingame.scene.world[i].owner == number

&& i != indexDisclousure)

Ingame.scene.world[i].DrawCountry(geks, Ingame.spriteBatch);

else if ( i == indexDisclousure)

Ingame.scene.world[i].DrawCountry(Ingame.geksM, Ingame.spriteBatch);

else if (Ingame.scene.world[i].owner == enumber

&& Ingame.scene.world[i].

GetDisclosureResourses() == 0)

Ingame.scene.world[i].

DrawCountry(enemyGeks, Ingame.spriteBatch);

else Ingame.scene.world[i].DrawCountry(Ingame.geksN, Ingame.spriteBatch);

}

// To draw unit's icons

Vector2 temp = new Vector2((Menu1.width -

Ingame.icons[0].Width - 10), 2);

Ingame.spriteBatch.Begin();

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

{

Ingame.spriteBatch.Draw(icons[i], temp, Color.White);

temp.Y += Ingame.icons[i].Height;

}

Ingame.spriteBatch.End();

}

}

public bool ChechWinner(int number)

{

bool flag = true;

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

{

int index = Ingame.scene.FoundCell(i);

if (Ingame.scene.world[index / 100].

cells[index % 100].unit != null)

if (Ingame.scene.world[index / 100].

cells[index % 100].unit.GetUnitOwner() != number)

flag = false;

}

if (flag)

return true;

int countCountry=0;

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

if (Ingame.scene.world[i].owner == number

&& Ingame.scene.world[i].freeCountry==true)

countCountry++;

if (countCountry > 5)

return true;

return false;

}

}

}

/* Классы юниты*/

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

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 Massive_Assault

{

public class Unit:IUnit

{

protected int unitOwner;

protected int price;

protected int hitpoint;

protected int cellID;

protected Texture2D texture;

public Unit(Texture2D texture,

int owner,int price,

int hitpoint,int cellID)

{

this.unitOwner = owner;

this.price = price;

this.hitpoint = hitpoint;

this.cellID=cellID;

this.texture = texture;

}

public int GetUnitOwner() { return unitOwner; }

public int GetPrice() { return price; }

public int GetHitpoint() { return hitpoint; }

public void SetUnitCellID(int id) { cellID = id; }

public int GetUnitCellID() { return cellID; }

public int GetTypeUnit()

{

//Carrier

if (texture == Ingame.UsersUnit[0]

|| texture == Ingame.ComputerUnit[0])

return 1;

//DefensiveGun

if (texture == Ingame.UsersUnit[2]

|| texture == Ingame.ComputerUnit[2])

return 3;

//Invader

return 2;

}

public void ReduceHitpoint(int hp) {hitpoint-=hp;}

public void DrawUnit(SpriteBatch spriteBatch)

{

spriteBatch.Begin();

int index = Ingame.scene.FoundCell(this.cellID);

Cell currentCell = Ingame.scene.world[index / 100].

cells[index % 100];

Point currentPoint = currentCell.GetLocation();

Vector2 pos = new Vector2(currentPoint.X,

currentPoint.Y);

spriteBatch.Draw(texture, pos, Color.White);

pos.Y =pos.Y-10;

Texture2D hitp = Ingame.hitpointC;

if (this.unitOwner==2)

hitp = Ingame.hitpointP;

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

{

spriteBatch.Draw(hitp, pos, Color.White);

pos.X = pos.X + 10;

}

spriteBatch.End();

}

public Texture2D GetTexture() { return texture; }

}

public class Moving : Unit, IMove

{

protected int moveDistance;

protected int balanceDistance;

protected bool moveFlag;

// Constructor

public Moving(Texture2D texture,

int owner, int price, int hitpoint,

int cellID, int moveDistance)

:base(texture,owner,price,hitpoint,cellID)

{

this.moveDistance = moveDistance;

balanceDistance = moveDistance;

moveFlag = true;

}

public int GetMoveDistance() {

return moveDistance;

}

protected void Changes(int number,int index)

{

if (Ingame.scene.world[index / 100].owner != number

&& Ingame.scene.world[index / 100]

.cells[index % 100].capital)

{

Ingame.scene.world[index / 100].owner = number;

Ingame.scene.world[index / 100].freeCountry = false;

return;

}

else if (Ingame.scene.world[index / 100].owner != number

)

Ingame.scene.world[index / 100].freeCountry = false;

}

protected int MoveStep(int IDCell1, int IDCell2,

int balanceDistance,int distance)

{

int index = Ingame.scene.FoundCell(IDCell1);

Cell currentCell = Ingame.scene.world[index / 100].

cells[index % 100];

Cell cell = Ingame.scene.world[

Ingame.scene.FoundCell(IDCell2) / 100].

cells[Ingame.scene.FoundCell(IDCell2) % 100];

if (!currentCell.CheckNeighbors(IDCell2))

{

if (balanceDistance == 1)

return -1;

List<int> neihgbors=currentCell.GetNeighbors();

Cell c;

int ind;

Point loc;

double lDistaance=1000;

int id=0;

bool flag = true;

for (int i = 0; i < neihgbors.Count; i++)

{

ind = Ingame.scene.FoundCell(neihgbors[i]);

c = Ingame.scene.world[ind / 100].cells[ind % 100];

loc = c.GetLocation();

if (c.unit == null)

{

loc.X = Math.Abs(loc.X - cell.GetLocation().X);

loc.Y = Math.Abs(loc.Y - cell.GetLocation().Y);

lDistaance = Math.Sqrt(loc.X * loc.X + loc.Y * loc.Y);

id = neihgbors[i];

flag = false;

break;

}

}

if (flag)

return -1;

for (int i = 0; i < neihgbors.Count; i++)

{

ind = Ingame.scene.FoundCell(neihgbors[i]);

c = Ingame.scene.world[ind / 100].cells[ind % 100];

loc = c.GetLocation();

loc.X = Math.Abs(loc.X - cell.GetLocation().X);

loc.Y = Math.Abs(loc.Y - cell.GetLocation().Y);

if (lDistaance > Math.Sqrt(loc.X * loc.X + loc.Y * loc.Y) && c.unit==null)

{

lDistaance = Math.Sqrt(loc.X * loc.X + loc.Y * loc.Y);

id = neihgbors[i];

}

}

return MoveStep(id, IDCell2, (balanceDistance - 1), distance+1);

}

return distance+1;

}

public void DrawMoveStep()

{

int index=Ingame.scene.FoundCell(this.cellID);

for (int id=0; id<108; id++)

if (Ingame.scene.CheckDistance(index, id, balanceDistance))

{

if (MoveStep(this.cellID, id, balanceDistance, 0) > -1)

{

int ind = Ingame.scene.FoundCell(id);

Ingame.scene.world[ind / 100].cells[ind % 100].

Draw(Ingame.m, Ingame.geksMcap, Ingame.spriteBatch);

}

}

}

public int GetBalanceDistance()

{

return balanceDistance;

}

public void SetBalanceDistance(int v)

{

balanceDistance = v;

}

public bool Move(int IDCell, int number)

{

int index = Ingame.scene.FoundCell(this.cellID);

Cell currentCell = Ingame.scene.world[index / 100].cells[index % 100];

int indexL = Ingame.scene.FoundCell(IDCell);

Cell cell = Ingame.scene.world[indexL / 100].cells[indexL % 100];

if (!cell.CheckUnit() && balanceDistance>0)

if (Ingame.scene.CheckDistance(index, IDCell, moveDistance))

{

int d=MoveStep(this.cellID,IDCell,balanceDistance,0);

if (d>-1) {

cell.unit = currentCell.GetUnit();

currentCell.unit = null;

balanceDistance -= d;

Changes(number, indexL);

this.cellID = IDCell;

return true;

}

}

return false;

}

}

public class Carrier:Moving

{

public Unit[] carrierUnit = new Unit[2];

public Carrier(Texture2D texture,

int owner, int price, int hitpoint,

int cellID, int moveDistance)

: base(texture, owner,

price, hitpoint,

cellID, moveDistance)

{

carrierUnit[0] = null;

carrierUnit[1] = null;

}

public void ToLand(int cellID, int number)

{

int indexL = Ingame.scene.FoundCell(cellID);

Cell cell = Ingame.scene.world[indexL / 100].

cells[indexL % 100];

int index = Ingame.scene.FoundCell(this.cellID);

if (number != 0 && number != 1)

return;

Cell currentCell = Ingame.scene.world[index/100].

cells[index % 100];

if (carrierUnit[number] != null && currentCell.

CheckNeighbors(cellID) && cell.unit == null)

{

IMove unit = (IMove)carrierUnit[number];

if (unit.GetBalanceDistance() > 0)

{

unit.SetBalanceDistance(unit.GetBalanceDistance() - 1);

cell.unit = (Unit) unit;

cell.unit.SetUnitCellID(cellID);

carrierUnit[number] = null;

if (number == 0 && carrierUnit[1] != null)

{

carrierUnit[0] = carrierUnit[1];

carrierUnit[1] = null;

}

}

}

}

public void ToLoad(int cellID)

{

int index = Ingame.scene.FoundCell(this.cellID);

Cell currentCell = Ingame.scene.world[index / 100].

cells[index % 100];

int indexL = Ingame.scene.FoundCell(cellID);

Cell cell = Ingame.scene.world[indexL / 100].

cells[indexL % 100];

if (currentCell.CheckNeighbors(cellID) && (carrierUnit[0] == null

|| carrierUnit[1] == null) && (cell.unit!= null))

{

IMove unit = (IMove)cell.unit;

if (unit.GetBalanceDistance() > 0)

{

unit.SetBalanceDistance(unit.GetBalanceDistance() - 1);

int i = 1;

if (carrierUnit[0] == null)

i = 0;

carrierUnit[i] = (Unit)unit;

carrierUnit[i].SetUnitCellID(this.cellID);

cell.unit = null;

}

}

}

}

public class Attacker:Moving,DefensiveGun,Invader {

private int damageRadius;

private bool recharge;

private int firepower;

public Attacker(Texture2D texture,int owner,

int price, int hitpoint, int damageRadius,

int moveDistance, int firepower, int cellID)

: base(texture, owner, price,

hitpoint, cellID, moveDistance)

{

this.damageRadius=damageRadius;

recharge=true;

this.firepower=firepower;

}

public int GetDamageRadius() {return damageRadius;}

public int GetFirepower() { return firepower; }

public void ToRecharge(bool recharge) {

this.recharge=recharge;

}

public bool GetRecharge() {

return this.recharge;

}

public void Atack(int IDCell) {

int index = Ingame.scene.FoundCell(this.cellID);

Cell currentCell = Ingame.scene.world[index / 100].

cells[index % 100];

int indexL = Ingame.scene.FoundCell(IDCell);

Cell cell=Ingame.scene.world[indexL / 100].

cells[indexL % 100];

if (cell.CheckUnit() && recharge)

if (Ingame.scene.CheckDistance(index,IDCell,damageRadius)) {

cell.unit.ReduceHitpoint(firepower);

if (cell.unit.GetHitpoint() <= 0)

cell.unit = null;

recharge = false;

Ingame.scene.world[indexL / 100].

cells[indexL % 100].unit = cell.unit;

}

}

public bool EnemyDetection(int number) {

int index;

int indexl=Ingame.scene.FoundCell(this.cellID);

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

{

index = Ingame.scene.FoundCell(i);

if (Ingame.scene.CheckDistance(indexl, i, damageRadius))

if (Ingame.scene.world[index / 100].

cells[index % 100].unit != null)

if (Ingame.scene.world[index / 100].

cells[index % 100].unit.GetUnitOwner() != number)

return true;

}

return false;

}

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.Xna.Framework.Graphics;

namespace Massive_Assault

{

public interface IMove

{

bool Move(int IDCell,int number);

int GetMoveDistance();

void DrawMoveStep();

int GetBalanceDistance();

void SetBalanceDistance(int v);

}

public interface IUnit {

int GetUnitOwner();

int GetPrice();

int GetHitpoint();

void DrawUnit(SpriteBatch spriteBatch);

int GetTypeUnit();

void ReduceHitpoint(int hp);

Texture2D GetTexture();

void SetUnitCellID(int id);

}

public interface DefensiveGun:IUnit

{

void Atack(int IDCell);

bool EnemyDetection(int number);

int GetDamageRadius();

void ToRecharge(bool recharge);

int GetFirepower();

bool GetRecharge();

}

public interface Invader : DefensiveGun, IMove

{

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

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 Massive_Assault

{

public class Map

{

public List<Country> world;

//Constuctor

public Map()

{

world = new List<Country>();

// Creating the first country

Point temp =new Point();

temp.X=30;

temp.Y=20;

world.Add(new Country(0, temp));

// Creating the second country

temp.X += 4 * 80;

world.Add(new Country(0,temp));

// Creating the third country

temp.X += 4 * 80;

world.Add(new Country(0, temp));

// Creating the fourth country

temp.X = 30;

temp.Y += 3 * 80;

world.Add(new Country(0,temp));

// Creating the 5th country

temp.X += 4 * 80;

world.Add(new Country(0,temp));

// Creating the 6th country

temp.X += 4 * 80;

world.Add(new Country(0, temp));

// Creating the 7th country

temp.X = 30;

temp.Y += 3 * 80;

world.Add(new Country(0, temp));

// Creating the 8th country

temp.X += 4 * 80;

world.Add(new Country(0, temp));

// Creating the 9th country

temp.X += 4 * 80;

world.Add(new Country(0, temp));

//Distibiution of the world

Random rnd = new Random();

Random rn = new Random();

Random rc = new Random();

var buf = Guid.NewGuid().ToByteArray();

for (int i = 0,j=9; i < 3; i++,j--)

{

var randomValue32 = BitConverter.ToInt32(buf, 4);

int ch = rnd.Next();

int numCountry = (randomValue32+ch)%j;

if (numCountry < 0)

numCountry *= -1;

world[numCountry].owner = 2;

//sorting

world.Sort((c1, c2) => c1.owner.CompareTo(c2.owner));

}

for (int i = 0,j=6; i < 3; i++,j--)

{

var randomValue32 = BitConverter.ToInt32(buf, 4);

int ch = rnd.Next();

int numCountry = (randomValue32 + ch) % j;

if (numCountry < 0)

numCountry *= -1;

world[numCountry].owner = 1;

//sorting

world.Sort((c1, c2) => c1.owner.CompareTo(c2.owner));

}

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

{

world[i].SetDisclosureResourses(world[i].

GetDisclosureResourses());

world[i].disclosure = true;

}

// The creating communication between neighbors

for (int tempID = 0; tempID < 108; tempID++)

{

int index = this.FoundCell(tempID);

List<int> arrayIDCell = new List<int>();

arrayIDCell=foundNeighbors(index);

foreach (int cellID in arrayIDCell)

world[(int)(index/100)].

cells[(int)(index%100)].AddNeighbors(cellID);

}

}

public List<int> foundNeighbors(int index)

{

List<int> arrayIDCell = new List<int>();

Point tempPoint;

Point currentPoint =((world[(index/100)]).

cells[(int)(index%100)]).GetLocation();

for (int countryIndex=0; countryIndex<9; countryIndex++)

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

{

tempPoint = world[countryIndex].

cells[i].GetLocation();

if (Math.Abs(tempPoint.X - currentPoint.X) <= 85

&& Math.Abs(tempPoint.Y - currentPoint.Y) <= 85)

arrayIDCell.Add(world[countryIndex].

cells[i].GetIDCell());

}

return arrayIDCell;

}

public bool CheckDistance(int index1,int cellID,int moveDistance)

{

List<int> arrayIDCell = new List<int>();

Point tempPoint;

Point currentPoint =((world[(int)(index1/100)]).

cells[(int)(index1%100)]).GetLocation();

for (int countryIndex=0; countryIndex<9; countryIndex++)

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

{

tempPoint = world[countryIndex].

cells[i].GetLocation();

if ((Math.Abs(tempPoint.X - currentPoint.X) <= (85*moveDistance))

&& (Math.Abs(tempPoint.Y - currentPoint.Y) <= (85*moveDistance)))

arrayIDCell.Add(world[countryIndex].cells[i].GetIDCell());

}

foreach (int neighbor in arrayIDCell)

if (neighbor == cellID)

return true;

return false;

}

// returns country index, and cell index

//(100*countryIndex+ cellsIndex)

public int FoundCell(int cellID)

{

int index = -1;

//Found country

for (int countryIndex=0; countryIndex < 9; countryIndex++)

if ((world[countryIndex]).ContainsID(cellID) )

// Found cell

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

if ((world[countryIndex].cells[i].GetIDCell()) == cellID)

{

index = (int)100 * countryIndex + i;

return index;

}

return index;

}

public int CheckCell(MouseState mouseState, Texture2D geks)

{

Point mouse;

mouse.X = mouseState.X;

mouse.Y = mouseState.Y;

for (int countryIndex = 0; countryIndex < 9; countryIndex++)

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

{

Point temp = Ingame.scene.world[countryIndex].

cells[i].GetLocation();

if (Ingame.scene.world[countryIndex].

cells[i].unit != null)

geks = Ingame.scene.world[countryIndex].

cells[i].unit.GetTexture();

Rectangle rGeks = new Rectangle(temp.X, temp.Y,

geks.Width, geks.Height);

if (rGeks.Contains(mouse))

return Ingame.scene.world[countryIndex].

cells[i].GetIDCell();

}

return -1;

}

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

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 Massive_Assault

{

public class Country

{

public int owner; /*if ownrer==0, the country is the neutral

if owner==1, the country belongs to the player1

if owner==2, the country belongs to the player2 */

public bool freeCountry;

public bool disclosure = false;

public bool partizan = true;

private int MobResources;

private int partizanResourses;

private int balanceResourses;

private int disclosureResourses;

public bool moblization;

public List<Cell> cells;

public Country(int owner, Point startPoint)

{

cells = new List<Cell>();

this.owner = owner;

MobResources = 10;

moblization = true;

balanceResourses = 0;

disclosureResourses = 10;

freeCountry = true;

partizanResourses = 4;

//Creating the country

Point temp = new Point();

temp.X = startPoint.X;

temp.Y = startPoint.Y;

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

{

for (int j = 0; j < 4; j++)

{

cells.Add(new Cell(false, temp));

temp.X += 80;

}

temp.Y += 80;

temp.X = startPoint.X;

}

this.cells[5].capital = true;

}

public bool ContainsID(int CellID) {

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

if (CellID==((cells[i]).GetIDCell()))

return true;

return false;

}

public Cell GetCell(int IDCell)

{

foreach (Cell cell in cells)

if (cell.GetIDCell() == IDCell)

return cell;

Cell error = new Cell(new Point());

error.ChangeIDCell(-1);

return error;

}

public void DrawCountry(Texture2D geks,

SpriteBatch spriteBatch) {

Texture2D texture=geks;

if (this.owner == 2)

texture = Ingame.geksPcap;

if (this.owner == 1)

texture = Ingame.geksCcap;

if (this.owner == 0)

texture = Ingame.geksNcap;

if (geks==Ingame.geksM)

texture = Ingame.geksMcap;

if (geks == Ingame.geksN)

texture = Ingame.geksNcap;

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

{

cells[i].Draw(geks,texture,spriteBatch);

}

}

public bool TakeResources(int resoures)

{

if (this.balanceResourses - resoures >= 0)

{

this.balanceResourses -= MobResources;

return true;

}

return false;

}

public bool AddBalanceResourses()

{

if (MobResources > 0)

{

if (MobResources == 1)

{

balanceResourses += 1;

MobResources = 0;

}

else

{

balanceResourses += 2;

MobResources -= 2;

}

return true;

}

return false;

}

public bool CheckDisclosureResourses(int resoures)

{

if (this.disclosureResourses -resoures >= 0)

{

return true;

}

return false;

}

public int GetDisclosureResourses() {

return disclosureResourses;

}

public int GetPartizanResourses() {

return partizanResourses;

}

public void SetDisclosureResourses(int d) {

disclosureResourses-=d;

}

public void SetPartizanResourses(int d) {

partizanResourses-=d;

}

public void SetBalanceResourses(int d) {

balanceResourses -= d;

}

public int GetBalanceResourses() {

return balanceResourses;

}

public int GetMobResourses() {

return MobResources;

}

}

}

/* Класс клетка*/

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

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 Massive_Assault

{

public class Cell

{

private static int count = 0;

private Point location;

public Unit unit;

public bool capital; //if cell is the capital, capital=true

private int IDCell;

private List<int> neighborsID;

// constructors

public Cell(bool capital, Point location)

{

neighborsID = new List<int>();

this.capital = capital;

this.location = location;

IDCell = count;

count++;

}

public Cell(Point location)

{

this.capital = false;

this.location = location;

}

public Point GetLocation() { return location; }

public Unit GetUnit() { return unit; }

public void SetUnit(Unit unit) { this.unit = unit; }

public int GetIDCell() { return IDCell; }

public void AddNeighbors(int IDCell) { neighborsID.Add(IDCell); }

public bool CheckUnit( ) {

if (unit == null)

return false;

else return true;

}

public List<int> GetNeighbors() { return neighborsID; }

public bool CheckNeighbors(int IDCell)

{

neighborsID.Sort();

if (neighborsID.BinarySearch(IDCell) < 0)

return false;

else return true;

}

public void ChangeIDCell(int IDCell)

{

count--;

this.IDCell = IDCell;

}

public static void ChangeCount(int coun)

{

count = coun;

}

public void Draw(Texture2D geks, Texture2D geksCap,SpriteBatch spriteBatch)

{

Vector2 pos = new Vector2(location.X, location.Y);

if (unit == null)

{

Texture2D texture = geks;

if (geks != Ingame.m)

{

if (this.capital == true)

texture = geksCap;

}

else

{

pos.X -= 7;

pos.Y -=8 ;

}

spriteBatch.Begin();

spriteBatch.Draw(texture, pos, Color.White);

spriteBatch.End();

}

else unit.DrawUnit(Ingame.spriteBatch);

}

public void DestroyUnit()

{

this.unit = null;

}

}

}

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