public void Draw(Field centerField)
		{
			if (centerField != null)
			{
				int posX = (centerField.X - ColumnCount/4)/ (ColumnCount/2);
				int posY = (centerField.Y - RowCount/4)/ (RowCount/2);

				if (this.mapPartX != posX || this.mapPartY != posY)
				{
					this.mapPartX = posX;
					this.mapPartY = posY;
					updateMap(posX * (ColumnCount/2), posY * (RowCount/2));
				}
			}

			for (int i = 0; i < fields.GetLength(0); ++i)
			{
				for (int j = 0; j < fields.GetLength(1); ++j)
				{
					if (fields[i, j] != null)
					{
						if (centerField != null && fields[i,j].Field != null)
							fields[i, j].RefreshField(mapModel.isSightBetweenFields(centerField, fields[i, j].Field));
						else
							fields[i, j].RefreshField(true);
					}
				}
			}
		}
		public ThrowCommand(Creature thrower, Field targetField, Map map, IRandomNumberGenerator randomNumberGenerator)
		{
			this.thrower = thrower;
			this.targetField = targetField;
			this.map = map;
			this.randomNumberGenerator = randomNumberGenerator;
		}
		public void generateLoot(Field f)
		{
			Random r = new Random();
			int generatedValue = randomGenerator.Next(5);
			if (generatedValue == 0)
			{
				f.placeObject(new Ammo() { Bullets = randomGenerator.Next(5) + 1, Grenades = 1 });
			}
			else if (generatedValue == 1)
			{
				f.placeObject(new MedKit() { Health = randomGenerator.Next(8) + 3 });
			}
			else if (generatedValue == 2)
			{
				f.placeObject(new Weapon() { Damage = randomGenerator.Next(10) + 1 });
			}
			else if (generatedValue == 3)
			{
				f.placeObject(new RangedWeapon() { Damage = randomGenerator.Next(10) + 1, Range = randomGenerator.Next(10) + 1, Chance = randomGenerator.NextDouble() });
			}
			else
			{
				f.placeObject(new GrenadeWeapon() { Damage = randomGenerator.Next(10) + 5, Range = randomGenerator.Next(10) + 1, Spread = randomGenerator.Next(3)+1, Ammo = 1 + randomGenerator.Next(3) });
			}
		}
		public void generateLoot(Field f)
		{
			Random r = new Random();
			int generatedValue = randomGenerator.Next(23);
			if (0 <= generatedValue && generatedValue <= 3)
			{
				int spread = randomGenerator.Next(4) + 1;
				f.placeObject(new GrenadeWeapon() { Damage = randomGenerator.Next(9) + 5, Range = 1 + randomGenerator.Next(9) + spread, Spread = spread, Ammo = 1 + randomGenerator.Next(3) });
			}
			else if (4 <= generatedValue && generatedValue <= 7)
			{
				MeleeWeapon w = new MeleeWeapon() { Damage = randomGenerator.Next(10) + 1 };
				w.BrokeChance = (double)(1 + w.Damage/5 + r.Next(4)) / 100;
				f.placeObject(w);
			}
			else if (8 <= generatedValue && generatedValue <= 11)
			{
				f.placeObject(new RangedWeapon() { Damage = randomGenerator.Next(10) + 1, Range = randomGenerator.Next(10) + 1, Chance = 0.1 + 0.9*randomGenerator.NextDouble(), Ammo = 10 + r.Next(15) });
			}
			else if (12 <= generatedValue && generatedValue <= 16)
			{
				f.placeObject(new Ammo() { Bullets = randomGenerator.Next(8) + 4, Grenades = randomGenerator.Next(3) });
			}
			else if (17 <= generatedValue && generatedValue <= 22)
			{
				f.placeObject(new MedKit() { Health = randomGenerator.Next(8) + 3 });
			}
			else
			{
			}
		}
		public GuiMapField this[Field field]
		{
			get 
			{
				foreach(GuiMapField guiField in fields)
				{
					if(guiField != null && guiField.Field == field)
						return guiField;
				}
				return null;
			}	
		}
		public void processKey(Key key)
		{
			switch (key)
			{
				case Key.B: //
				case Key.NumPad1:
					this.TargetField = this.manager.GameService.Map[this.TargetField.Y + 1, this.TargetField.X - 1];
					break;
				case Key.N://
				case Key.NumPad2:
					this.TargetField = this.manager.GameService.Map[this.TargetField.Y + 1, this.TargetField.X];
					break;
				case Key.M://
				case Key.NumPad3:
					this.TargetField = this.manager.GameService.Map[this.TargetField.Y + 1, this.TargetField.X + 1];
					break;
				case Key.G://
				case Key.NumPad4:
					this.TargetField = this.manager.GameService.Map[this.TargetField.Y, this.TargetField.X - 1];
					break;
				case Key.J://
				case Key.NumPad6:
					this.TargetField = this.manager.GameService.Map[this.TargetField.Y, this.TargetField.X + 1];
					break;
				case Key.T://
				case Key.NumPad7:
					this.TargetField = this.manager.GameService.Map[this.TargetField.Y - 1, this.TargetField.X - 1];
					break;
				case Key.Y://
				case Key.NumPad8:
					this.TargetField = this.manager.GameService.Map[this.TargetField.Y - 1, this.TargetField.X];
					break;
				case Key.U://
				case Key.NumPad9:
					this.TargetField = this.manager.GameService.Map[this.TargetField.Y - 1, this.TargetField.X + 1];
					break;
				case Key.Q:
					if (this.targetField != null)
						manager.MapDrawer.Draw(manager.GameService.Player.Field);
					this.manager.KeyProcessor = new MainKeyProcessor(this.manager);
					break;
				case Key.Enter:
					if (this.targetField != null)
						this.manager.PlayerCommand(new ThrowCommand(manager.GameService.Player, this.targetField, manager.GameService.Map, new RandomNumberGenerator()));
					break;
			}
		}
Пример #7
0
		public bool isSightBetweenFields(Field sourceField, Field destField)
		{
			double distance = getDistanceBetweenFields(sourceField, destField);
			if(distance > 0)
			{
				double stepX = (destField.X - sourceField.X) / distance;
				double stepY = (destField.Y - sourceField.Y) / distance;
				double currentX = sourceField.X + 0.5;
				double currentY = sourceField.Y + 0.5;

				for(int i=0; i<=distance; i++)
				{
					if(Math.Abs(currentX - (int)currentX) > 0.95)
					{
						if (this[(int)currentY, (int)currentX].blocksSight() || this[(int)currentY, (int)currentX + 1].blocksSight())
							return false;
					}
					else if( Math.Abs(currentX - (int)currentX) < 0.05)
					{
						if (this[(int)currentY, (int)currentX].blocksSight() || this[(int)currentY, (int)currentX - 1].blocksSight())
							return false;
					}
					else if(Math.Abs(currentY - (int)currentY) > 0.95)
					{
						if (this[(int)currentY, (int)currentX].blocksSight() || this[(int)currentY + 1, (int)currentX].blocksSight())
							return false;
					}
					else if(Math.Abs(currentY - (int)currentY) < 0.05)
					{
						if (this[(int)currentY, (int)currentX].blocksSight() || this[(int)currentY - 1, (int)currentX].blocksSight())
							return false;
					}
					else
					{
						if (this[(int)currentY, (int)currentX].blocksSight())
							return false;
					}
					currentX += stepX;
					currentY += stepY;
				}
			}
			
			return true;
		}
Пример #8
0
		public int getEuclideanDistanceBetweenFields(Field sourceField, Field destField)
		{
			return Math.Abs(sourceField.X - destField.X) + Math.Abs(sourceField.Y - destField.Y);
		}
Пример #9
0
		public int getDistanceBetweenFields(Field sourceField, Field destField)
		{
			return Math.Max(Math.Abs(sourceField.X - destField.X), Math.Abs(sourceField.Y - destField.Y));
		}
		public FieldSelectKeyProcessor(GameManager manager)
		{
			this.manager = manager;
			TargetField = this.manager.GameService.Player.Field;
		}
Пример #11
0
		public void interactWithField(Field field)
		{
			CreatureVisitor visitor = new CreatureVisitor(this);
			field.accept(visitor);
		}
Пример #12
0
		public bool canInteractWithField(Field field)
		{
			if (!(field is Wall) && field.Creature == null)
				return true;
			return false;
		}
		public GuiMapField(Map m, Field field)
		{
			this.map = m;
			this.Field = field;
		}