Recent Posts
None | 5 sec ago
Java | 11 sec ago
None | 15 sec ago
MySQL | 24 sec ago
PHP | 26 sec ago
None | 38 sec ago
Bash | 47 sec ago
None | 1 min ago
None | 1 min ago
PHP | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Profas on the 24th of Dec 2008 10:00:50 PM Download | Raw | Embed | Report
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Text;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. using SdlDotNet.Input;
  8. using SdlDotNet.Core;
  9. using SdlDotNet.Graphics;
  10. using SdlDotNet.Graphics.Sprites;
  11.  
  12.  
  13. namespace BALOONS
  14. {
  15.     public class Main
  16.     {
  17.         #region Fields
  18.         public Collection<Rectangle> rects = new Collection<Rectangle>();
  19.         public Collection<Rectangle> bals = new Collection<Rectangle>();
  20.         public Collection<Rectangle> active_rec = new Collection<Rectangle>();
  21.         public Collection<Rectangle> bullets_rec = new Collection<Rectangle>();
  22.         public SpriteCollection main = new SpriteCollection();
  23.         public SpriteCollection bal = new SpriteCollection();
  24.         public SpriteCollection active_spr = new SpriteCollection();
  25.         public SpriteCollection bullets_spr = new SpriteCollection();
  26.         public Surface screen;
  27.         public ReadStep rs;
  28.         private Sprite board;
  29.         public List<Baloon> baloon = new List<Baloon>();
  30.         public int baloons = 0;
  31.         private int counter = 0;
  32.         private Random rand = new Random();
  33.         public int killed = 0;
  34.         private MapGenerator mapengine;
  35.         public SdlDotNet.Graphics.Font font;
  36.         public SdlDotNet.Graphics.Font cfont;
  37.         public SdlDotNet.Graphics.Font ufont;
  38.         public Surface[] rightText = new Surface[3];
  39.         public Surface[] leftText = new Surface[3];
  40.         public Surface[] uText = new Surface[2];
  41.         public string[] lefttxt = new string[3];
  42.         public string[] righttxt = new string[3];
  43.         public string[] utxt = new string[2];
  44.         public long money;
  45.         public int life;
  46.         public Surface[] centerText = new Surface[2];
  47.         public bool pause = true;
  48.         private bool gameover = false;
  49.         private int update_c = 0;
  50.         private Levels levels;
  51.         #endregion
  52.  
  53.         #region Main
  54.         public Main(string map, int dif)
  55.         {
  56.             Events.Fps = 65;
  57.             Events.Tick += new EventHandler<TickEventArgs>(Tick);
  58.             Events.KeyboardDown += new EventHandler<KeyboardEventArgs>(KeyboardDown);
  59.             Events.MouseButtonDown += new EventHandler<MouseButtonEventArgs>(MouseDown);
  60.  
  61.             screen = Video.SetVideoMode(700, 805, 16, false, false, true, false, true);
  62.  
  63.             string fontpath = "failai/other/COPRGTB.TTF";
  64.  
  65.             font = new SdlDotNet.Graphics.Font(@fontpath, 17);
  66.             cfont = new SdlDotNet.Graphics.Font(@fontpath, 30);
  67.             ufont = new SdlDotNet.Graphics.Font(@"failai/other/AGENCYR.TTF", 18);
  68.  
  69.             righttxt[0] = "Choose the tower to build, ";
  70.             righttxt[1] = "or click on your towers to ";
  71.             righttxt[2] = "sell or upgrade them.";
  72.  
  73.             for (int i = 0; i < 2; i++)
  74.             {
  75.                 utxt[i] = "";
  76.                 uText[i] = ufont.Render(utxt[i], Color.Black);
  77.             }
  78.  
  79.             switch (dif)
  80.             {
  81.                 case 1:
  82.                     life = 150;
  83.                     money = 500;
  84.                     break;
  85.                 case 2:
  86.                     life = 100;
  87.                     money = 350;
  88.                     break;
  89.                 case 3:
  90.                     life = 50;
  91.                     money = 200;
  92.                     break;
  93.             }
  94.  
  95.             lefttxt[0] = "Life: " + life.ToString() + ".";
  96.             lefttxt[1] = "Round: 1.";
  97.             lefttxt[2] = "$" + money.ToString() + ".";
  98.  
  99.             for (int i = 0; i < 3; i++)
  100.             {
  101.                 leftText[i] = font.Render(lefttxt[i], Color.Gold);
  102.                 rightText[i] = font.Render(righttxt[i], Color.White);
  103.             }
  104.  
  105.             Video.WindowCaption = "PRO-BALOONS :: By Profas";
  106.  
  107.             board = new Sprite(new Surface(@"failai/buttom_board.bmp"));
  108.             board.Position = new Point(0, 705);
  109.             board.Z = 2;
  110.  
  111.             main.Add(board);
  112.            
  113.             rs = new ReadStep("failai/map/" + map);
  114.             mapengine = new MapGenerator(rs, main);
  115.             BuyEngine buyengine = new BuyEngine(this, mapengine.buildBlocks);
  116.  
  117.             centerText[0] = cfont.Render(":: ROUND 1 ::", Color.White);
  118.             centerText[1] = cfont.Render(":: CLICK TO START ::", Color.White);
  119.            
  120.             levels = new Levels(this);
  121.  
  122.             screen.Blit(main);
  123.             screen.Update();
  124.         }
  125.         ~Main() { }
  126.         #endregion
  127.  
  128.         #region Tick
  129.         private void Tick(object sender, TickEventArgs args)
  130.         {
  131.             if (!gameover)
  132.             {
  133.                 rects = screen.Blit(main);
  134.                 bals = screen.Blit(bal);
  135.                 active_rec = screen.Blit(active_spr);
  136.                 bullets_rec = screen.Blit(bullets_spr);
  137.  
  138.                 for (int i = 0; i < 3; i++)
  139.                     screen.Blit(rightText[i], new Point(418, 715 + (i * 25)));
  140.  
  141.                 for (int i = 0; i < 3; i++)
  142.                     screen.Blit(leftText[i], new Point(10, 715 + (i * 25)));
  143.  
  144.                 for (int i = 0; i < 2; i++)
  145.                     screen.Blit(uText[i], new Point(413, 745 + (i * 25)));
  146.  
  147.                 if (!pause)
  148.                     walk();
  149.                 else
  150.                 {
  151.                     screen.Blit(centerText[0], new Point(255, 250));
  152.                     screen.Blit(centerText[1], new Point(208, 300));
  153.                     screen.Update(new Rectangle(new Point(208, 250), new Size(400, 500)));
  154.                 }
  155.  
  156.                 screen.Update(bals);
  157.                 screen.Update(active_rec);
  158.                 screen.Update(bullets_rec);
  159.                 screen.Update(new Rectangle(new Point(0, 700), new Size(700, 105)));
  160.  
  161.                 if (update_c++ == 500)
  162.                 {
  163.                     update_c = 0;
  164.                     screen.Update(new Rectangle(new Point(0, 0), new Size(700, 700)));
  165.                 }
  166.  
  167.                 if (!screen.FullScreen)
  168.                     Video.WindowCaption = (
  169.                          " :: PRO-BALOONS :: By Profas" +
  170.                          " :: FPS: " + Events.Fps.ToString() +
  171.                          " :: Baloons IN: " + (baloons - killed).ToString() +
  172.                          " :: Baloons: " + baloons.ToString() +
  173.                          " :: Killed: " + killed.ToString() + " ::");
  174.             }
  175.             else
  176.             {
  177.                 screen.Blit(centerText[0], new Point(255, 250));
  178.                 screen.Blit(centerText[1], new Point(208, 300));
  179.                 screen.Update(new Rectangle(new Point(0, 0), new Size(700, 805)));
  180.             }
  181.         }
  182.         #endregion
  183.  
  184.         #region walk
  185.         private void walk()
  186.         {
  187.            
  188.             if (counter++ == 40 - levels.speed)
  189.             {
  190.                 counter = 0;
  191.  
  192.                 if (!levels.wait)
  193.                 {
  194.                     int getbaloon;
  195.  
  196.                     if ((getbaloon = levels.GetBaloon()) != 0)
  197.                     {
  198.                         baloon.Add(new Baloon(rand.Next(levels.baloon_speed_min, levels.baloon_speed), this, getbaloon));
  199.                         bal.Add(baloon[baloon.Count - 1]);
  200.                         baloons++;
  201.                     }
  202.                 }
  203.                 else
  204.                     if (baloons - killed == 0)
  205.                     {
  206.                         pause = true;
  207.                         levels.NewLevel();
  208.                     }
  209.             }
  210.         }
  211.         #endregion
  212.  
  213.         #region MouseDown
  214.         private void MouseDown(object sender, MouseButtonEventArgs args)
  215.         {
  216.             if (pause)
  217.                 pause = false;
  218.         }
  219.         #endregion
  220.  
  221.         #region KeyboardDown
  222.         private void KeyboardDown(object sender, KeyboardEventArgs args)
  223.         {
  224.             if (args.Key == Key.Escape)
  225.                 Events.QuitApplication();
  226.         }
  227.         #endregion
  228.  
  229.         #region CheckMapGeneratorBuildBlock
  230.         public int CheckMapGeneratorBuildBlock(int X, int Y, bool id)
  231.         {
  232.             if (id)
  233.                 return mapengine.CheckBuildBlock(X, Y, id);
  234.  
  235.             if (mapengine.CheckBuildBlock(X, Y, id) == 1)
  236.                 return 1;
  237.  
  238.             return 2;
  239.         }
  240.         #endregion
  241.  
  242.         #region GameOver
  243.         public void GameOver(int nr)
  244.         {
  245.             if (!gameover)
  246.             {
  247.                 bals.Clear();
  248.                 main.Clear();
  249.                 screen.Fill(Color.Black);
  250.  
  251.                 if (nr == 0)
  252.                     centerText[0] = cfont.Render(" :: GAME OVER ::", Color.White);
  253.                 else
  254.                     centerText[0] = cfont.Render(" :: YOU WIN! ::", Color.White);
  255.  
  256.                 centerText[1] = cfont.Render(":: PRESS ESC TO QUIT ::", Color.White);
  257.  
  258.                 screen.Update();
  259.                 gameover = true;
  260.             }
  261.         }
  262.         #endregion
  263.     }
  264.  
  265.     public class BuyEngine
  266.     {
  267.         #region Fields
  268.         private Tower[] tower = new Tower[12];
  269.         private Functions fc = new Functions();
  270.         private Sprite[] red_blue = new Sprite[2];
  271.         private Sprite selectItem;
  272.         private Main main;
  273.         private List<ShootingTower> sTower = new List<ShootingTower>();
  274.         private int sTowersCount = 0;
  275.         private int cur_buy_tower;
  276.         private bool selected_buy = false;
  277.         private bool buy = false;
  278.         private int buildBlocks;
  279.         private int[] blocksPer;
  280.         private bool builded;
  281.         private bool upgrade = false;
  282.         private int currentUpgrade = -1;
  283.         #endregion
  284.  
  285.         #region BuyEngine
  286.         public BuyEngine(Main main, int buildBlocks)
  287.         {
  288.             this.main = main;
  289.             this.buildBlocks = buildBlocks;
  290.  
  291.             string _path = "failai/other/";
  292.            
  293.             blocksPer = new int[196];
  294.  
  295.             red_blue[0] = new Sprite(new Surface(@_path + "red.bmp"));
  296.             red_blue[1] = new Sprite(new Surface(@_path + "blue.bmp"));
  297.  
  298.             selectItem = new Sprite(new Surface(@_path + "itemselect.bmp"));
  299.             selectItem.Z = 3;
  300.             selectItem.Visible = false;
  301.             selectItem.Transparent = true;
  302.             selectItem.TransparentColor = Color.Black;
  303.             main.active_spr.Add(selectItem);
  304.  
  305.             for (int i = 0; i < 2; i++)
  306.             {
  307.                 red_blue[i].Visible = false;
  308.                 red_blue[i].Position = new Point(600, 710);
  309.                 red_blue[i].Z = 3;
  310.                 red_blue[i].Transparent = true;
  311.                 red_blue[i].TransparentColor = Color.Black;
  312.                 main.active_spr.Add(red_blue[i]);
  313.             }
  314.  
  315.             SuperRw rw = new SuperRw();
  316.             Coder coder = new Coder();
  317.  
  318.             string towers_info = coder.UnCode(rw.Read(@"failai/tower_info.txt"));
  319.  
  320.             string[,] buy_info = new string[12, 3];
  321.  
  322.             for (int i = 0; i < 12; i++)
  323.             {
  324.                 buy_info[i, 0] = "- [ BUY ] :: [ " + fc.ReadWord(i + 1, 1, towers_info, ':', false) + " ] -";
  325.                 buy_info[i, 1] = "- Cost: " + fc.ReadWord(i + 1, 2, towers_info, ':', false) + "$. Damage: "
  326.                     + fc.ReadWord(i + 1, 3, towers_info, ':', false) + ". -";
  327.                 buy_info[i, 2] = "- Speed: " + fc.ReadWord(i + 1, 4, towers_info, ':', false) + ". Region: "
  328.                     + fc.ReadWord(i + 1, 5, towers_info, ':', false) + ". -";
  329.             }
  330.  
  331.             int a = 0;
  332.             int b = 0;
  333.  
  334.             for (int i = 0; i < 12; i++)
  335.             {
  336.                 a++;
  337.                 tower[i] = new Tower(i);
  338.                 tower[i].Z = 5;
  339.                 tower[i].Position = new Point((46 * a) + 85, (46 * b) + 712);
  340.                 tower[i].name = fc.ReadWord(i + 1, 1, towers_info, ':', false);
  341.                 tower[i].cost = Convert.ToInt32(fc.ReadWord(i + 1, 2, towers_info, ':', false));
  342.                 tower[i].damage = Convert.ToInt32(fc.ReadWord(i + 1, 3, towers_info, ':', false));
  343.                 tower[i].speed = Convert.ToInt32(fc.ReadWord(i + 1, 4, towers_info, ':', false));
  344.                 tower[i].region = Convert.ToInt32(fc.ReadWord(i + 1, 5, towers_info, ':', false));
  345.  
  346.                 for (int j = 0; j < 3; j++)
  347.                     tower[i].info[j] = buy_info[i, j];
  348.  
  349.                 if (i == 5)
  350.                 {
  351.                     a = 0;
  352.                     b++;
  353.                 }
  354.  
  355.                 main.main.Add(tower[i]);
  356.             }
  357.  
  358.             Events.MouseButtonDown += new EventHandler<MouseButtonEventArgs>(MouseDown);
  359.             Events.MouseMotion += new EventHandler<MouseMotionEventArgs>(MouseMove);
  360.         }
  361.         ~BuyEngine() { }
  362.         #endregion
  363.  
  364.         #region MouseDown
  365.         private void MouseDown(object sender, MouseButtonEventArgs args)
  366.         {
  367.             if (args.Button == MouseButton.PrimaryButton)
  368.             {
  369.                     if (UpgradeClick(args))
  370.                     {
  371.                         if (!buy)
  372.                         {
  373.                             for (int i = 0; i < 12; i++)
  374.                                 if ((args.Position.X > tower[i].X) && (args.Position.X < tower[i].X + tower[i].Width))
  375.                                     if ((args.Position.Y > tower[i].Y) && (args.Position.Y < tower[i].Y + tower[i].Height))
  376.                                     {
  377.                                         cur_buy_tower = i;
  378.                                         selected_buy = true;
  379.                                         selectItem.Visible = true;
  380.                                         selectItem.Position = new Point(tower[cur_buy_tower].X - 2, tower[cur_buy_tower].Y - 2);
  381.  
  382.                                         for (int j = 0; j < 3; j++)
  383.                                             if (j != 0)
  384.                                                 main.rightText[j] = main.font.Render(tower[i].info[j], Color.Gold);
  385.                                             else
  386.                                                 main.rightText[j] = main.font.Render(tower[i].info[j], Color.LightBlue);
  387.  
  388.                                         break;
  389.                                     }
  390.  
  391.                             for (int i = 0; i < sTowersCount; i++)
  392.                                 sTower[i].imgRegion.Visible = false;
  393.  
  394.                             if (upgrade)
  395.                             {
  396.                                 upgrade = false;
  397.                                 InfoRefresh();
  398.                             }
  399.  
  400.                             for (int i = 0; i < sTowersCount; i++)
  401.                             {
  402.                                 int selected = -1;
  403.  
  404.                                 if ((args.X > sTower[i].Position.X) && (args.X < sTower[i].Position.X + sTower[i].Width))
  405.                                     if ((args.Y > sTower[i].Position.Y) && (args.Y < sTower[i].Position.Y + sTower[i].Height))
  406.                                     {
  407.                                         selected = i;
  408.                                         sTower[i].imgRegion.Visible = true;
  409.                                         SelectTowerUpgrade(i);
  410.                                         selected_buy = false;
  411.                                         upgrade = true;
  412.  
  413.                                         break;
  414.                                     }
  415.  
  416.                                 if (selected != -1)
  417.                                 { }
  418.                                 else
  419.                                     sTower[i].imgRegion.Visible = false;
  420.                             }
  421.                         }
  422.  
  423.                         if (buy)
  424.                             if ((args.Position.X > 0) && (args.Position.X < 700))
  425.                                 if ((args.Position.Y > 0) && (args.Position.Y < 700))
  426.                                 {
  427.                                     if (main.CheckMapGeneratorBuildBlock(args.Position.X, args.Position.Y, false) == 1)
  428.                                     {
  429.                                         int gID = main.CheckMapGeneratorBuildBlock(args.Position.X, args.Position.Y, true);
  430.  
  431.                                         builded = false;
  432.  
  433.                                         for (int i = 0; i < 196; i++)
  434.                                             if (gID == blocksPer[i])
  435.                                                 builded = true;
  436.  
  437.                                         if (!builded)
  438.                                         {
  439.                                             blocksPer[gID] = gID;
  440.                                             red_blue[0].Visible = false;
  441.                                             red_blue[1].Visible = false;
  442.  
  443.                                             buy = false;
  444.  
  445.                                             main.leftText[2] = main.font.Render("$" + (main.money -= tower[cur_buy_tower].cost).ToString() + ".", Color.Gold);
  446.  
  447.                                             Point posXY = args.Position;
  448.  
  449.                                             while (posXY.X-- % 50 != 0) ;
  450.                                             while (posXY.Y-- % 50 != 0) ;
  451.  
  452.                                             sTower.Add(new ShootingTower(main, new Point(posXY.X + 6, posXY.Y + 6), tower[cur_buy_tower].damage, tower[cur_buy_tower].speed,
  453.                                                 tower[cur_buy_tower].region, tower[cur_buy_tower].name, tower[cur_buy_tower].cost, tower[cur_buy_tower].Surface, cur_buy_tower));
  454.  
  455.                                             sTower[sTowersCount].id = gID;
  456.  
  457.                                             main.main.Add(sTower[sTowersCount++]);
  458.  
  459.                                             main.screen.Blit(main.main);
  460.                                             main.screen.Update(new Rectangle(new Point(sTower[sTowersCount - 1].Center.X - 50,
  461.                                                 sTower[sTowersCount - 1].Center.Y - 50), new Size(100, 100)));
  462.  
  463.                                             SelectTowerUpgrade((currentUpgrade = sTowersCount - 1));
  464.  
  465.                                             selected_buy = false;
  466.  
  467.                                             main.screen.Fill(Color.Black);
  468.                                         }
  469.                                         else
  470.                                             main.rightText[2] = main.font.Render("You Cant Build There.", Color.Red);
  471.                                     }
  472.                                 }
  473.  
  474.  
  475.                         if (selected_buy)
  476.                             if ((args.Position.X > 440) && (args.Position.X < 680))
  477.                                 if ((args.Position.Y > 710) && (args.Position.Y < 745))
  478.                                 {
  479.                                     if (main.money >= tower[cur_buy_tower].cost)
  480.                                     {
  481.                                         buy = true;
  482.                                         selected_buy = false;
  483.  
  484.                                         main.rightText[0] = main.font.Render("      :: [ " + tower[cur_buy_tower].name + " ] ::", Color.LightBlue);
  485.                                         main.rightText[1] = main.font.Render("Choose place to build.", Color.Gold);
  486.                                         main.rightText[2] = main.font.Render("(Right Click to Cancel.)", Color.Gold);
  487.                                     }
  488.                                     else
  489.                                         main.rightText[2] = main.font.Render("Dont have money enought.", Color.Red);
  490.                                 }
  491.                     }
  492.             }
  493.             else
  494.                 if (args.Button == MouseButton.SecondaryButton)
  495.                 {
  496.                     for (int i = 0; i < sTowersCount; i++)
  497.                         sTower[i].imgRegion.Visible = false;
  498.  
  499.                     if (buy)
  500.                     {
  501.                         buy = false;
  502.                         selected_buy = true;
  503.                         red_blue[0].Visible = false;
  504.                         red_blue[1].Visible = false;
  505.                     }
  506.  
  507.                     upgrade = false;
  508.  
  509.                     InfoRefresh();
  510.                 }
  511.  
  512.             main.screen.Blit(main.main);
  513.             main.screen.Update(new Rectangle(new Point(0,0),new Size(700,700)));
  514.         }
  515.         #endregion
  516.  
  517.         #region InfoRefresh
  518.         private void InfoRefresh()
  519.         {
  520.             selected_buy = true;
  521.  
  522.             for (int j = 0; j < 3; j++)
  523.                 if (j != 0)
  524.                     main.rightText[j] = main.font.Render(tower[cur_buy_tower].info[j], Color.Gold);
  525.                 else
  526.                     main.rightText[j] = main.font.Render(tower[cur_buy_tower].info[j], Color.LightBlue);
  527.  
  528.             for (int j = 0; j < 2; j++)
  529.                 main.uText[j] = main.ufont.Render("", Color.Black);
  530.         }
  531.         #endregion
  532.  
  533.         #region SelectTowerUpgrade
  534.         private void SelectTowerUpgrade(int nr)
  535.         {
  536.             currentUpgrade = nr;
  537.             upgrade = true;
  538.  
  539.             for (int i = 1; i < 3; i++)
  540.                 main.rightText[i] = main.font.Render("", Color.Black);
  541.  
  542.             TowerInfoRefresh(nr);
  543.         }
  544.         #endregion
  545.  
  546.         #region TowerInfoRefresh
  547.         public void TowerInfoRefresh(int nr)
  548.         {
  549.             main.rightText[0] = main.font.Render(":: [ " + sTower[nr].name + " Upgrade ] ::", Color.LightBlue);
  550.             main.uText[0] = main.ufont.Render(":: [ Speed " + sTower[nr].speed.ToString() + "+" + sTower[nr].uspeed.ToString() + " $80 ] : "
  551.                 + "[ Region " + sTower[nr].region.ToString() + "+" + sTower[nr].uregion.ToString() + " $90 (2x) ] ::", Color.Gold);
  552.             main.uText[1] = main.ufont.Render(":: [ Damage " + sTower[nr].dmg.ToString() + "+" + sTower[nr].udmg.ToString() + " $110 ] : "
  553.                 + "[ SELL " + (sTower[nr].cost / 2).ToString() + " (50%) ] ::", Color.Gold);
  554.         }
  555.         #endregion
  556.  
  557.         #region UpgradeClick
  558.         private bool UpgradeClick(MouseButtonEventArgs args)
  559.         {
  560.             if (upgrade)
  561.                 if (fc.PositionCheck(args.Position, new Point(425, 670), new Point(700, 820)))
  562.                 {
  563.                     if (fc.PositionCheck(args.Position, new Point(412, 543), new Point(744, 766)))
  564.                         sTower[currentUpgrade].Upgrade(1);
  565.                     else if (fc.PositionCheck(args.Position, new Point(557, 690), new Point(744, 766)))
  566.                         sTower[currentUpgrade].Upgrade(2);
  567.                     else if (fc.PositionCheck(args.Position, new Point(412, 550), new Point(775, 798)))
  568.                         sTower[currentUpgrade].Upgrade(3);
  569.  
  570.                     TowerInfoRefresh(currentUpgrade);
  571.  
  572.                     if (fc.PositionCheck(args.Position, new Point(565, 690), new Point(775, 798)))
  573.                     {
  574.                         SellTower(currentUpgrade);
  575.                         InfoRefresh();
  576.                     }
  577.  
  578.                     return false;
  579.                 }
  580.  
  581.             return true;
  582.         }
  583.         #endregion
  584.  
  585.         #region MouseMove
  586.         private void MouseMove(object sender, MouseMotionEventArgs args)
  587.         {
  588.             if (upgrade)
  589.             {
  590.                 if (fc.PositionCheck(args.Position, new Point(412, 527), new Point(744, 766)))
  591.                     Cursor.Current = Cursors.Hand;
  592.                 else if (fc.PositionCheck(args.Position, new Point(547, 690), new Point(744, 766)))
  593.                     Cursor.Current = Cursors.Hand;
  594.                 else if (fc.PositionCheck(args.Position, new Point(412, 540), new Point(775, 798)))
  595.                     Cursor.Current = Cursors.Hand;
  596.                 else if (fc.PositionCheck(args.Position, new Point(560, 690), new Point(775, 798)))
  597.                     Cursor.Current = Cursors.Hand;
  598.             }
  599.             else if (selected_buy)
  600.                 if (fc.PositionCheck(args.Position, new Point(440, 680), new Point(710, 745)))
  601.                     Cursor.Current = Cursors.Hand;
  602.  
  603.             if (buy)
  604.             {
  605.                 for (int i = 0; i < 2; i++)
  606.                     main.screen.Update(new Rectangle(new Point(red_blue[i].Position.X - 50, red_blue[i].Position.Y - 50),
  607.                         new Size(red_blue[i].Size.Width + 100, red_blue[i].Size.Height + 100)));
  608.  
  609.                 if (fc.PositionCheck(args.Position, new Point(0, 700), new Point(0, 700)))
  610.                     {
  611.                         if (main.CheckMapGeneratorBuildBlock(args.Position.X, args.Position.Y, false) == 1)
  612.                         {
  613.                             red_blue[1].Position = new Point(args.Position.X - (red_blue[1].Width / 2),
  614.                                 args.Position.Y - (red_blue[1].Height / 2));
  615.                             red_blue[1].Visible = true;
  616.                             red_blue[0].Visible = false;
  617.                         }
  618.                         else
  619.                         {
  620.                             red_blue[0].Position = new Point(args.Position.X - (red_blue[0].Width / 2),
  621.                                 args.Position.Y - (red_blue[0].Height / 2));
  622.                             red_blue[0].Visible = true;
  623.                             red_blue[1].Visible = false;
  624.                         }
  625.                     }
  626.             }
  627.         }
  628.         #endregion
  629.  
  630.         #region SellTower
  631.         private void SellTower(int nr)
  632.         {
  633.             blocksPer[sTower[nr].id] = -1;
  634.             Rectangle last_pos = sTower[nr]._region;
  635.             sTower[nr].Sell();
  636.  
  637.             main.screen.Update(last_pos);
  638.  
  639.             main.leftText[2] = main.font.Render("$" + (main.money += (sTower[nr].cost/2)).ToString() + ".", Color.Gold);
  640.  
  641.             InfoRefresh();
  642.  
  643.             upgrade = false;
  644.         }
  645.         #endregion
  646.     }
  647.  
  648.     public class Start : Sprite
  649.     {
  650.         #region Fields
  651.         private Sprite start_spr = new Sprite();
  652.         private Surface screen;
  653.         private bool run = true;
  654.         private bool meniu = true;
  655.         private string map;
  656.         private Sprite checker;
  657.         #endregion
  658.  
  659.         #region Start
  660.         public Start()
  661.         {
  662.             map = "map3.txt";
  663.             Events.MouseButtonDown += new EventHandler<MouseButtonEventArgs>(MouseDown);
  664.  
  665.             screen = Video.SetVideoMode(700, 805, 16, false, false, true, false, true);
  666.  
  667.             start_spr = new Sprite(new Surface(@"failai/start/start_1.bmp"));
  668.  
  669.             checker = new Sprite(new Surface(@"failai/other/checker.bmp"));
  670.             checker.Transparent = true;
  671.             checker.Visible = false;
  672.             checker.TransparentColor = Color.Green;
  673.             checker.Z = 5;
  674.             checker.Position = new Point(97, 122);
  675.  
  676.             screen.Blit(start_spr);
  677.             screen.Update();
  678.  
  679.             Events.Run();
  680.         }
  681.         ~Start() { }
  682.         #endregion
  683.  
  684.         #region MouseDown
  685.         private void MouseDown(object sender, MouseButtonEventArgs args)
  686.         {
  687.             if (run)
  688.             {
  689.                 if (meniu)
  690.                 {
  691.                     if ((args.X > 260) && (args.X < 410))
  692.                         if ((args.Y > 285) && (args.Y < 320))
  693.                         {
  694.                             checker.Visible = true;
  695.                             start_spr.Surface = new Surface(@"failai/start/start_2.bmp");
  696.                             screen.Blit(start_spr);
  697.                             screen.Blit(checker);
  698.                             screen.Update();
  699.                             meniu = false;
  700.                         }
  701.  
  702.                     if ((args.X > 275) && (args.X < 385))
  703.                         if ((args.Y > 350) && (args.Y < 390))
  704.                             Events.QuitApplication();
  705.                 }
  706.  
  707.                 if (!meniu)
  708.                 {
  709.                     if ((args.X > 95) && (args.X < 300))
  710.                         if ((args.Y > 120) && (args.Y < 325))
  711.                         {
  712.                             checker.Position = new Point(97, 122);
  713.                             screen.Blit(start_spr);
  714.                             screen.Blit(checker);
  715.                             screen.Update();
  716.                             map = "map3.txt";
  717.                         }
  718.  
  719.                     if ((args.X > 387) && (args.X < 590))
  720.                         if ((args.Y > 120) && (args.Y < 325))
  721.                         {
  722.                             checker.Position = new Point(386, 122);
  723.                             screen.Blit(start_spr);
  724.                             screen.Blit(checker);
  725.                             screen.Update();
  726.                             map = "map1.txt";
  727.                         }
  728.  
  729.                     if ((args.X > 95) && (args.X < 300))
  730.                         if ((args.Y > 360) && (args.Y < 560))
  731.                         {
  732.                             checker.Position = new Point(97, 364);
  733.                             screen.Blit(start_spr);
  734.                             screen.Blit(checker);
  735.                             screen.Update();
  736.                             map = "map2.txt";
  737.                         }
  738.  
  739.                     if ((args.X > 387) && (args.X < 590))
  740.                         if ((args.Y > 360) && (args.Y < 560))
  741.                         {
  742.                             checker.Position = new Point(386, 364);
  743.                             screen.Blit(start_spr);
  744.                             screen.Blit(checker);
  745.                             screen.Update();
  746.                             map = "map4.txt";
  747.                         }
  748.  
  749.                     if ((args.X > 25) && (args.X < 180))
  750.                         if ((args.Y > 700) && (args.Y < 745))
  751.                             Go(1);
  752.  
  753.                     if ((args.X > 210) && (args.X < 455))
  754.                         if ((args.Y > 700) && (args.Y < 745))
  755.                             Go(2);
  756.  
  757.                     if ((args.X > 475) && (args.X < 675))
  758.                         if ((args.Y > 700) && (args.Y < 745))
  759.                             Go(3);
  760.                 }
  761.             }
  762.         }
  763.         #endregion
  764.  
  765.         #region Go
  766.         private void Go(int dif)
  767.         {
  768.             run = false;
  769.             start_spr.Dispose();
  770.             start_spr.Close();
  771.             start_spr.Kill();
  772.             start_spr.Visible = false;
  773.             Main main = new Main(map, dif);
  774.             screen.Dispose();
  775.             this.Dispose();
  776.             this.Kill();
  777.             this.Close();
  778.         }
  779.         #endregion
  780.     }
  781.  
  782.     public class Shoot
  783.     {
  784.         #region Fields
  785.         private Main main;
  786.         private Sprite bullet;
  787.         private Point location;
  788.         private Point destination;
  789.         private Rectangle region;
  790.         private int counterX=0;
  791.         private int counterY=0;
  792.         private int x;
  793.         private int y;
  794.         private int division = 2;
  795.         private int speed = 5;
  796.         private int dmg;
  797.         private bool dead = false;
  798.         private Baloon baloon;
  799.         private Rectangle dest_new;
  800.         private int generate;
  801.         #endregion
  802.  
  803.         #region Shoot
  804.         public Shoot(Main main, Point location, Rectangle region, Baloon baloon, int dmg)
  805.         {
  806.             this.main = main;
  807.             this.dmg = dmg;
  808.             this.baloon = baloon;
  809.             this.location = location;
  810.             this.destination = baloon.Center;
  811.             this.region = region;
  812.  
  813.             x = destination.X - location.X;
  814.             y = destination.Y - location.Y;
  815.  
  816.             if (x <= 0)
  817.                 x *= -1;
  818.  
  819.             if (y <= 0)
  820.                 y *= -1;
  821.  
  822.             generate = ((y + x) / 2) + (region.Width / 10);
  823.  
  824.             if (generate < 35)
  825.                 generate += 10;
  826.  
  827.             dest_new = new Rectangle(new Point(baloon.Center.X - 15, baloon.Center.Y - 15), new Size(30, 30));
  828.  
  829.             bullet = new Sprite(new Surface(@"failai/bullets/bullet.bmp"));
  830.             bullet.Z = 5;
  831.             bullet.Transparent = true;
  832.             bullet.TransparentColor = Color.White;
  833.             bullet.Position = new Point(location.X - (bullet.Width / 2), location.Y - (bullet.Height / 2));
  834.             main.bullets_spr.Add(bullet);
  835.  
  836.             Events.Tick += new EventHandler<TickEventArgs>(MoveTick);
  837.         }
  838.         ~Shoot() { }
  839.         #endregion
  840.  
  841.         #region GoBullet
  842.         private void GoBullet()
  843.         {
  844.             if (dead == false)
  845.             {
  846.                 if ((bullet.Center.X > region.X) && (bullet.Center.X < region.X + region.Width))
  847.                     if ((bullet.Center.Y > region.Y) && (bullet.Center.Y < region.Y + region.Height))
  848.                     {
  849.                         for (int i = 0; i < generate; i++)
  850.                         {
  851.                             if ((bullet.Center.X > dest_new.X) && (bullet.Center.X < dest_new.X + dest_new.Width))
  852.                                 if ((bullet.Center.Y > dest_new.Y) && (bullet.Center.Y < dest_new.Y + dest_new.Height))
  853.                                 {
  854.                                     dead = true;
  855.                                     break;
  856.                                 }
  857.  
  858.                             if (location.Y > destination.Y)
  859.                                 if (counterY++ == y / division - 5)
  860.                                 {
  861.                                     counterY = 0;
  862.                                     bullet.Y -= speed;
  863.                                 }
  864.                                 else { }
  865.                             else if (location.Y < destination.Y)
  866.                                 if (counterY++ == y / division - 5)
  867.                                 {
  868.                                     counterY = 0;
  869.                                     bullet.Y += speed;
  870.                                 }
  871.  
  872.                             if (location.X > destination.X)
  873.                                 if (counterX++ == x / division - 5)
  874.                                 {
  875.                                     counterX = 0;
  876.                                     bullet.X -= speed;
  877.                                 }
  878.                                 else { }
  879.                             else if (location.X < destination.X)
  880.                                 if (counterX++ == x / division - 5)
  881.                                 {
  882.                                     counterX = 0;
  883.                                     bullet.X += speed;
  884.                                 }
  885.                         }
  886.                     }
  887.                     else
  888.                         dead = true;
  889.                 else
  890.                     dead = true;
  891.  
  892.                 if ((bullet.Center.X > dest_new.X) && (bullet.Center.X < dest_new.X + dest_new.Width))
  893.                     if ((bullet.Center.Y > dest_new.Y) && (bullet.Center.Y < dest_new.Y + dest_new.Height))
  894.                         dead = true;
  895.  
  896.                 if (dead == true)
  897.                     KillBullet();
  898.             }
  899.         }
  900.         #endregion
  901.  
  902.         #region KillBullet
  903.         private void KillBullet()
  904.         {
  905.             baloon.ShootAtIt(dmg);
  906.  
  907.             dead = true;
  908.             bullet.Visible = false;
  909.             Rectangle last_pos = new Rectangle(new Point(bullet.X - 25, bullet.Y - 25), new Size(bullet.Width + 50, bullet.Height + 50));
  910.             bullet.Kill();
  911.             bullet.Close();
  912.             bullet.Dispose();
  913.             Events.CloseTimer();
  914.             main.screen.Blit(main.main);
  915.             main.screen.Update(last_pos);
  916.         }
  917.         #endregion
  918.  
  919.         #region MoveTick
  920.         private void MoveTick(object sender, TickEventArgs args)
  921.         {
  922.             GoBullet();
  923.         }
  924.         #endregion
  925.     }
  926.  
  927.     public class Baloon : Sprite
  928.     {
  929.         #region Fields
  930.         private int count = 0;
  931.         private ReadStep rs;
  932.         private int speed = 5;
  933.         private int direction = 1;
  934.         private int cur_step = 28;
  935.         public bool enabled = true;
  936.         private int life;
  937.         private SpriteCollection bals;
  938.         private Main main;
  939.         private int number;
  940.         private int takedmg;
  941.         private int morelife;
  942.         #endregion
  943.  
  944.         #region Baloon
  945.         public Baloon(int speed, Main main, int number)
  946.         {
  947.             this.number = number;
  948.             this.main = main;
  949.             this.rs = main.rs;
  950.             this.bals = main.bal;
  951.             this.life = number;
  952.  
  953.             if (number > 9)
  954.                 this.morelife = number;
  955.  
  956.             if (speed == 3)
  957.                 speed += 2;
  958.  
  959.             if (speed == 4)
  960.                 speed += 6;
  961.  
  962.             this.speed = speed;
  963.  
  964.             Surface _all = new Surface(@"failai/baloons/b" + number.ToString() + ".bmp");
  965.  
  966.             this.Surface = _all;
  967.             this.Position = new Point(0, 100);
  968.             this.Z = 3;
  969.             this.Transparent = true;
  970.             this.TransparentColor = Color.Green;
  971.  
  972.             Events.Tick += new EventHandler<TickEventArgs>(MoveTick);
  973.         }
  974.         ~Baloon() { }
  975.         #endregion
  976.  
  977.         #region Move
  978.         public void Move()
  979.         {
  980.             if (enabled)
  981.             {
  982.                 Point center = new Point(this.X + (this.Width / 2), this.Y + (this.Height / 2));
  983.  
  984.                 if (center.Y > 660)
  985.                 {
  986.                     main.leftText[0] = main.font.Render("Life: " + (--main.life).ToString() + ".", Color.Gold);
  987.  
  988.                     if (main.life <= 0)
  989.                         main.GameOver(0);
  990.  
  991.                     KillIt();
  992.                 }
  993.  
  994.                 switch (direction)
  995.                 {
  996.                     case 0:
  997.                         if (rs.GetStep(cur_step - 14) != "0")
  998.                         {
  999.                             count += speed;
  1000.                             this.Y -= speed;
  1001.  
  1002.                             if (count == 50)
  1003.                             {
  1004.                                 count = 0;
  1005.                                 cur_step -= 14;
  1006.                             }
  1007.                         }
  1008.                         else
  1009.                             direction = FindDirection(direction);
  1010.                         break;
  1011.                     case 1:
  1012.                         if (rs.GetStep(cur_step + 1) != "0")
  1013.                         {
  1014.                             count += speed;
  1015.                             this.X += speed;
  1016.  
  1017.                             if (count == 50)
  1018.                             {
  1019.                                 count = 0;
  1020.                                 cur_step++;
  1021.                             }
  1022.                         }
  1023.                         else
  1024.                             direction = FindDirection(direction);
  1025.                         break;
  1026.                     case 2:
  1027.                         if (rs.GetStep(cur_step + 14) != "0")
  1028.                         {
  1029.                             count += speed;
  1030.                             this.Y += speed;
  1031.  
  1032.                             if (count == 50)
  1033.                             {
  1034.                                 count = 0;
  1035.                                 cur_step += 14;
  1036.                             }
  1037.                         }
  1038.                         else
  1039.                             direction = FindDirection(direction);
  1040.                         break;
  1041.  
  1042.                     case 3:
  1043.                         if (rs.GetStep(cur_step - 1) != "0")
  1044.                         {
  1045.                             count += speed;
  1046.                             this.X -= speed;
  1047.  
  1048.                             if (count == 50)
  1049.                             {
  1050.                                 count = 0;
  1051.                                 cur_step -= 1;
  1052.                             }
  1053.                         }
  1054.                         else
  1055.                             direction = FindDirection(direction);
  1056.                         break;
  1057.                 }
  1058.             }
  1059.         }
  1060.         #endregion
  1061.  
  1062.         #region FindDirection
  1063.         private int FindDirection(int current)
  1064.         {
  1065.             if ((rs.GetStep(cur_step + 1) != "0") && (current != 3))
  1066.                     return 1;
  1067.             else if ((rs.GetStep(cur_step + 14) != "0") && (current != 0))
  1068.                     return 2;
  1069.             else if ((rs.GetStep(cur_step - 1) != "0") && (current != 1))
  1070.                     return 3;
  1071.             else if ((rs.GetStep(cur_step - 14) != "0") && (current != 2))
  1072.                     return 0;
  1073.  
  1074.             return 0;
  1075.         }
  1076.         #endregion
  1077.  
  1078.         #region MoveTick
  1079.         private void MoveTick(object sender, TickEventArgs args)
  1080.         {
  1081.             Move();
  1082.         }
  1083.         #endregion
  1084.  
  1085.         #region ShootAtIt
  1086.         public void ShootAtIt(int dmg)
  1087.         {
  1088.             if (this.Visible == true)
  1089.             {
  1090.                 if (dmg >= life)
  1091.                     takedmg = life;
  1092.                 else
  1093.                     takedmg = dmg;
  1094.  
  1095.                 if (takedmg > 0)
  1096.                     if (number > 9)
  1097.                         morelife -= takedmg;
  1098.  
  1099.                 if (morelife <= 0)
  1100.                 {
  1101.                     if (takedmg > 0)
  1102.                     {
  1103.                         main.leftText[2] = main.font.Render("$" + (main.money += takedmg).ToString() + ".", Color.Gold);
  1104.  
  1105.                         life -= dmg;
  1106.                     }
  1107.  
  1108.                     if (life > 0)
  1109.                     {
  1110.                         this.Surface = new Surface(@"failai/baloons/b" + life.ToString() + ".bmp");
  1111.                         this.Z = 3;
  1112.                         this.Transparent = true;
  1113.                         this.TransparentColor = Color.Green;
  1114.                     }
  1115.                     else
  1116.                     {
  1117.                         life--;
  1118.                         KillIt();
  1119.                     }
  1120.                 }
  1121.             }
  1122.         }
  1123.         #endregion
  1124.  
  1125.         #region KillIt
  1126.         public void KillIt()
  1127.         {
  1128.             Rectangle last_pos = new Rectangle(new Point(this.Position.X - 25, this.Position.Y - 25),
  1129.                 new Size(this.Size.Width + 50, this.Size.Height + 50));
  1130.  
  1131.             this.Visible = false;
  1132.             main.killed++;
  1133.             Events.CloseTimer();
  1134.             bals.Remove(this);
  1135.             this.Kill();
  1136.             this.Dispose();
  1137.             this.enabled = false;
  1138.  
  1139.             main.rects = main.screen.Blit(main.main);
  1140.             main.screen.Update(last_pos);
  1141.         }
  1142.         #endregion
  1143.     }
  1144.  
  1145.     public class ShootingTower : Sprite
  1146.     {
  1147.         #region Fields
  1148.         public int id;
  1149.         public Sprite imgRegion;
  1150.         public int dmg;
  1151.         public int speed;
  1152.         public int region;
  1153.         public Rectangle _region;
  1154.         public int cost;
  1155.         public string name;
  1156.         private Main main;
  1157.         private int counter = 0;
  1158.         private Shoot shoot;
  1159.         private bool enabled = true;
  1160.         public int udmg;
  1161.         public int uregion;
  1162.         public int uspeed;
  1163.         private int totalspeed;
  1164.         #endregion
  1165.  
  1166.         #region ShootingTower
  1167.         public ShootingTower(Main main, Point position, int dmg, int speed, int region, string name, int cost, Surface surf, int id)
  1168.         {
  1169.             this.main = main;
  1170.             this.dmg = dmg;
  1171.             this.speed = speed;
  1172.             this.region = region;
  1173.             this.cost = cost;
  1174.             this.name = name;
  1175.             this.Surface = surf;
  1176.             this.Position = position;
  1177.  
  1178.             DrawRegion(_region = ChangeRegion(region+uregion));
  1179.  
  1180.             Events.Tick += new EventHandler<TickEventArgs>(ShootCheck);
  1181.         }
  1182.         #endregion
  1183.  
  1184.         #region ChangeRegion
  1185.         public Rectangle ChangeRegion(int region)
  1186.         {
  1187.             Point center = this.Center;
  1188.             Size _size = new Size((10 + region) * 10, (10 + region) * 10);
  1189.             Point _point = new Point(center.X - (_size.Width / 2), center.Y - (_size.Height / 2));
  1190.  
  1191.             return new Rectangle(_point, _size);
  1192.         }
  1193.         #endregion
  1194.  
  1195.         #region DrawRegion
  1196.         private void DrawRegion(Rectangle rec)
  1197.         {
  1198.             Surface surRegion = new Surface(@"failai/other/region.bmp");
  1199.             surRegion.Transparent = true;
  1200.             surRegion.TransparentColor = Color.Black;
  1201.             surRegion = surRegion.CreateScaledSurface(region+uregion + 10, false);
  1202.             surRegion.Alpha = 80;
  1203.             surRegion.AlphaBlending = true;
  1204.             imgRegion = new Sprite(surRegion);
  1205.             imgRegion.Z = 5;
  1206.             imgRegion.Position = new Point(rec.Location.X, rec.Location.Y);
  1207.  
  1208.             main.screen.Blit(imgRegion);
  1209.             main.active_spr.Add(imgRegion);
  1210.             main.screen.Update(new Rectangle(new Point(0, 0), new Size(700, 700)));
  1211.         }
  1212.         #endregion
  1213.  
  1214.         #region ShootCheck
  1215.         private void ShootCheck(object sender, TickEventArgs args)
  1216.         {
  1217.             if (enabled)
  1218.             {
  1219.                 int baloons_count = main.baloon.Count;
  1220.  
  1221.                 totalspeed = 49 - (speed + uspeed);
  1222.  
  1223.                 if (counter++ == totalspeed - 3)
  1224.                 {
  1225.                     counter = 0;
  1226.  
  1227.                     for (int i = 0; i < baloons_count; i++)
  1228.                         if (main.baloon[i].enabled)
  1229.                             if ((main.baloon[i].Center.X > _region.X) && (main.baloon[i].Center.X < _region.X + _region.Width))
  1230.                                 if ((main.baloon[i].Center.Y > _region.Y) && (main.baloon[i].Center.Y < _region.Y + _region.Height))
  1231.                                 {
  1232.                                     shoot = new Shoot(main, this.Center, this._region, main.baloon[i], dmg + udmg);
  1233.  
  1234.                                     break;
  1235.                                 }
  1236.                                 else { }
  1237.                             else { }
  1238.                         else
  1239.                         {
  1240.                             baloons_count--;
  1241.                             main.baloon.RemoveAt(i);
  1242.  
  1243.                             continue;
  1244.                         }
  1245.                 }
  1246.  
  1247.                 if (counter > 46)
  1248.                     counter = 0;
  1249.             }
  1250.         }
  1251.         #endregion
  1252.  
  1253.         #region Sell
  1254.         public void Sell()
  1255.         {
  1256.             imgRegion.Visible = false;
  1257.             imgRegion.Kill();
  1258.             imgRegion.Dispose();
  1259.             enabled = false;
  1260.             this.Position = new Point(-50, -50);
  1261.             this.Visible = false;
  1262.         }
  1263.         #endregion
  1264.  
  1265.         #region Upgrade
  1266.         public void Upgrade(int upgr)
  1267.         {
  1268.             switch (upgr)
  1269.             {
  1270.                 case 1:
  1271.                     if(main.money>=80)
  1272.                         if (totalspeed > 20)
  1273.                         {
  1274.                             uspeed++;
  1275.                             cost += 80;
  1276.                             main.money -= 80;
  1277.                         }
  1278.                     break;
  1279.                 case 2:
  1280.                     if(main.money>=90)
  1281.                         if ((region + uregion) < 34)
  1282.                         {
  1283.                             uregion += 2;
  1284.                             cost += 90;
  1285.                             main.money -= 90;
  1286.                             imgRegion.Visible = false;
  1287.                             imgRegion.Dispose();
  1288.                             imgRegion.Kill();
  1289.                             DrawRegion(_region = ChangeRegion(region + uregion));
  1290.                         }
  1291.                     break;
  1292.                 case 3:
  1293.                     if(main.money>=110)
  1294.                         if (dmg + udmg < 16)
  1295.                         {
  1296.                             udmg++;
  1297.                             cost += 100;
  1298.                             main.money -= 100;
  1299.                         }
  1300.                     break;
  1301.             }
  1302.  
  1303.             main.leftText[2] = main.font.Render("$" + (main.money).ToString() + ".", Color.Gold);
  1304.         }
  1305.         #endregion
  1306.     }
  1307.  
  1308.     public class Coder
  1309.     {
  1310.         #region Coder
  1311.         public Coder() { }
  1312.         ~Coder() { }
  1313.         #endregion
  1314.  
  1315.         #region ToCode
  1316.         public string ToCode(string SourceData)
  1317.         {
  1318.             int charASCII;
  1319.             int Step;
  1320.             string Data;
  1321.             string CodedData = "";
  1322.             Data = SourceData;
  1323.  
  1324.             for (int i = 0; i < Data.Length;i++)
  1325.             {
  1326.                 if ((Data[i] == '\n') || (Data[i] == '\r'))
  1327.                 {
  1328.                     CodedData = CodedData + Data[i];
  1329.                     continue;
  1330.                 }
  1331.  
  1332.                 charASCII = (int)Data[i];
  1333.                 Step = ((((Data.Length + i) % 7) * 52) % 92) + 33;
  1334.  
  1335.                 if (charASCII + Step > 126)
  1336.                 {
  1337.                     Step = Step - (126 - charASCII);
  1338.                     charASCII = Step + 33;
  1339.                 }
  1340.                 else
  1341.                     charASCII = charASCII + Step;
  1342.  
  1343.                 CodedData = CodedData + Convert.ToChar(charASCII);
  1344.             }
  1345.  
  1346.             return CodedData;
  1347.         }
  1348.         #endregion
  1349.  
  1350.         #region UnCode
  1351.         public string UnCode(string SourceData)
  1352.         {
  1353.             int charASCII;
  1354.             int Step;
  1355.             string Data;
  1356.             string UnCodedData = "";
  1357.             Data = SourceData;
  1358.  
  1359.             for (int i = 0; i < Data.Length; i++)
  1360.             {
  1361.                 if ((Data[i] == '\n') || (Data[i] == '\r'))
  1362.                 {
  1363.                     UnCodedData = UnCodedData + Data[i];
  1364.                     continue;
  1365.                 }
  1366.  
  1367.                 charASCII = (int)Data[i];
  1368.                 Step = ((((Data.Length + i) % 7) * 52) % 92) + 33;
  1369.  
  1370.                 if (charASCII - Step < 33)
  1371.                 {
  1372.                     Step = Step - charASCII;
  1373.                     charASCII = 126 - Step - 33;
  1374.                 }
  1375.                 else
  1376.                     charASCII = charASCII - Step;
  1377.  
  1378.                 UnCodedData = UnCodedData + Convert.ToChar(charASCII);
  1379.             }
  1380.  
  1381.             return UnCodedData;
  1382.         }
  1383.         #endregion
  1384.     }
  1385.  
  1386.     class Functions
  1387.     {
  1388.         #region Functions
  1389.         public Functions()
  1390.         { }
  1391.         ~Functions() { }
  1392.         #endregion
  1393.  
  1394.         #region ReadWord
  1395.         public string ReadWord(int line, int word, string text, char sign, bool only_line)
  1396.         {
  1397.             string buf = "";
  1398.             string text_line = "";
  1399.             int line_nr = 0;
  1400.             int sign_nr = 1;
  1401.             bool end = false;
  1402.  
  1403.             --line;
  1404.             if (word > 0)
  1405.             {
  1406.                 for (int i = 0; i < text.Length; i++)
  1407.                 {
  1408.                     if (line != 0)
  1409.                     {
  1410.                         if (text[i] == '\n')
  1411.                             line_nr++;
  1412.                         else
  1413.                             continue;
  1414.  
  1415.                         if (line_nr == line)
  1416.                         {
  1417.                             ++i;
  1418.                             while ((i != text.Length) && (text[i] != '\n') && (text[i] != '\r'))
  1419.                                 text_line += text[i++];
  1420.  
  1421.                             if (only_line != false)
  1422.                                 return text_line;
  1423.  
  1424.                             break;
  1425.                         }
  1426.                     }
  1427.                     else
  1428.                     {
  1429.                         while ((i != text.Length) && (text[i] != '\n') && (text[i] != '\r'))
  1430.                             text_line += text[i++];
  1431.  
  1432.                         if (only_line != false)
  1433.                             return text_line;
  1434.  
  1435.                         break;
  1436.                     }
  1437.                 }
  1438.  
  1439.                 for (int i = 0; i < text_line.Length; i++)
  1440.                 {
  1441.                     if (word == 1)
  1442.                     {
  1443.                         while ((i != text_line.Length) && (text_line[i] != sign) && (text[i] != '\n') && (text[i] != '\r'))
  1444.                             buf += text_line[i++];
  1445.  
  1446.                         return buf;
  1447.                     }
  1448.  
  1449.                     else
  1450.                     {
  1451.                         for (int j = 0; j < text_line.Length; j++)
  1452.                         {
  1453.                             while (sign_nr != word)
  1454.                                 if (text_line[j++] == sign)
  1455.                                     sign_nr++;
  1456.  
  1457.                             while ((j != text_line.Length) && (text_line[j] != '\n') && (text_line[j] != sign))
  1458.                                 buf += text_line[j++];
  1459.  
  1460.                             end = true;
  1461.  
  1462.                             if (end == true)
  1463.                                 break;
  1464.                         }
  1465.                     }
  1466.                     if (end == true)
  1467.                         break;
  1468.                 }
  1469.             }
  1470.             else
  1471.                 return null;
  1472.  
  1473.             if (buf != "")
  1474.                 return buf;
  1475.             else
  1476.                 return null;
  1477.         }
  1478.         #endregion
  1479.  
  1480.         #region ChangeWord
  1481.         public string ChangeWord(int line, int word, string text, string newWord, char sign)
  1482.         {
  1483.             string buf = "";
  1484.             string text_line = "";
  1485.             int line_nr = 0;
  1486.             int sign_nr = 1;
  1487.             bool end = false;
  1488.  
  1489.             --line;
  1490.             if (word > 0)
  1491.             {
  1492.                 for (int i = 0; i < text.Length; i++)
  1493.                 {
  1494.                     if (line != 0)
  1495.                     {
  1496.                         if (text[i] == '\n')
  1497.                             line_nr++;
  1498.                         else
  1499.                             continue;
  1500.  
  1501.                         if (line_nr == line)
  1502.                         {
  1503.                             ++i;
  1504.                             while ((i != text.Length) && (text[i] != '\n') && (text[i] != '\r'))
  1505.                                 text_line += text[i++];
  1506.  
  1507.                             break;
  1508.                         }
  1509.                     }
  1510.                     else
  1511.                     {
  1512.                         while ((i != text.Length) && (text[i] != '\n') && (text[i] != '\r'))
  1513.                             text_line += text[i++];
  1514.  
  1515.                         break;
  1516.                     }
  1517.                 }
  1518.  
  1519.                 for (int i = 0; i < text_line.Length; i++)
  1520.                 {
  1521.                     if (word == 1)
  1522.                     {
  1523.                         while (text_line[i] != sign)
  1524.                             i++;
  1525.  
  1526.                         while ((i != text_line.Length) && (text_line[i] != '\n'))
  1527.                             buf += text_line[i++];
  1528.  
  1529.                         buf = newWord + buf;
  1530.                     }
  1531.                     else
  1532.                     {
  1533.                         for (int j = 0; j < text_line.Length; j++)
  1534.                         {
  1535.                             while (sign_nr != word)
  1536.                             {
  1537.                                 buf += text_line[j];
  1538.                                 if (text_line[j++] == sign)
  1539.                                     sign_nr++;
  1540.                             }
  1541.  
  1542.                             buf += newWord;
  1543.  
  1544.                             while ((j != text_line.Length) && (text_line[j] != '\n') && (text_line[j] != sign))
  1545.                                 j++;
  1546.  
  1547.                             while (j != text_line.Length)
  1548.                                 buf += text_line[j++];
  1549.  
  1550.                             end = true;
  1551.  
  1552.                             if (end != false)
  1553.                                 break;
  1554.                         }
  1555.                     }
  1556.                     if (end != false)
  1557.                         break;
  1558.                 }
  1559.             }
  1560.             else
  1561.                 return null;
  1562.  
  1563.             int curline = 0;
  1564.             string all = "";
  1565.  
  1566.             for (int i = 0; i < text.Length; i++)
  1567.             {
  1568.                 if (text[i] == '\n')
  1569.                     curline++;
  1570.  
  1571.                 if (curline == line_nr)
  1572.                 {
  1573.                     all += buf;
  1574.  
  1575.                     while ((++i != text.Length) && (text[i] != '\n'))
  1576.                         continue;
  1577.  
  1578.                     while (i != text.Length)
  1579.                         all += text[i++];
  1580.  
  1581.                     break;
  1582.                 }
  1583.  
  1584.                 all += text[i];
  1585.             }
  1586.  
  1587.             if (all != "")
  1588.                 return all;
  1589.             else
  1590.                 return null;
  1591.         }
  1592.         #endregion
  1593.  
  1594.         #region LineCount
  1595.         public int LineCount(string text)
  1596.         {
  1597.             int line = 0;
  1598.  
  1599.             for (int i = 0; i < text.Length; i++)
  1600.                 if (text[i] == '\n')
  1601.                     ++line;
  1602.  
  1603.             return line;
  1604.         }
  1605.         #endregion
  1606.  
  1607.         #region LineDelete
  1608.         public string LineDelete(int nr, string text)
  1609.         {
  1610.             int current = 0;
  1611.             string buf = "";
  1612.  
  1613.             if (nr != 0)
  1614.             {
  1615.                 for (int i = 0; i < text.Length; i++)
  1616.                 {
  1617.                     if (text[i] == '\n')
  1618.                         current++;
  1619.  
  1620.                     if (current == nr)
  1621.                     {
  1622.                         while (text[++i] != '\n')
  1623.  
  1624.                         current++;
  1625.                     }
  1626.  
  1627.                     if (i <= text.Length)
  1628.                         buf += text[i];
  1629.                 }
  1630.             }
  1631.             else
  1632.             {
  1633.                 int line = 0;
  1634.  
  1635.                 while (text[line++] != '\n')
  1636.                     continue;
  1637.  
  1638.                 for (int i = line; i < text.Length; i++)
  1639.                     buf += text[i];
  1640.             }
  1641.  
  1642.             return buf;
  1643.         }
  1644.         #endregion
  1645.  
  1646.         #region PositionCheck
  1647.         public bool PositionCheck(Point args, Point X, Point Y)
  1648.         {
  1649.             if ((args.X > X.X) && (args.X < X.Y))
  1650.                 if ((args.Y > Y.X) && (args.Y < Y.Y))
  1651.                     return true;
  1652.                 else
  1653.                     return false;
  1654.             else
  1655.                 return false;
  1656.         }
  1657.         #endregion
  1658.     }
  1659.  
  1660.     public class Levels
  1661.     {
  1662.         #region Fields
  1663.         public int round;
  1664.         public int[] count = new int[21];
  1665.         public int speed;
  1666.         public int baloon_nr;
  1667.         private int dif_baloons;
  1668.         private Main main;
  1669.         private int current;
  1670.         public bool wait = false;
  1671.         public int baloon_speed;
  1672.         public int baloon_speed_min;
  1673.         private int max;
  1674.         #endregion
  1675.  
  1676.         #region Levels
  1677.         public Levels(Main main)
  1678.         {
  1679.             baloon_speed_min = 1;
  1680.             baloon_speed = 2;
  1681.             speed = 0;
  1682.             this.main = main;
  1683.             dif_baloons = 1;
  1684.             round = 1;
  1685.             count[0] = 6;
  1686.             current = 0;
  1687.             max = 10;
  1688.         }
  1689.         #endregion
  1690.  
  1691.         #region GetBaloon
  1692.         public int GetBaloon()
  1693.         {
  1694.             int all = 0;
  1695.  
  1696.             for (int i = 0; i < dif_baloons; i++)
  1697.                 all += count[i];
  1698.  
  1699.             //System.Diagnostics.Debug.WriteLine("ALL: "+all.ToString());
  1700.  
  1701.             if (all != 0)
  1702.             {
  1703.                 if (--count[current] > 0)
  1704.                     return current + 1;
  1705.                 else
  1706.                 {
  1707.                     current++;
  1708.  
  1709.                     return current;
  1710.                 }
  1711.             }
  1712.             else
  1713.             {
  1714.                 wait = true;
  1715.  
  1716.                 return 0;
  1717.             }
  1718.         }
  1719.         #endregion
  1720.  
  1721.         #region NewLevel
  1722.         public void NewLevel()
  1723.         {
  1724.             if (++round < 71)
  1725.             {
  1726.                 wait = false;
  1727.                 current = 0;
  1728.                 main.money += 100;
  1729.  
  1730.                 if (dif_baloons < 20)
  1731.                     if (round % 4 == 0)
  1732.                         dif_baloons++;
  1733.  
  1734.                 if (round == 15)
  1735.                     dif_baloons++;
  1736.  
  1737.                 if (round == 30)
  1738.                     dif_baloons++;
  1739.  
  1740.                 if (round == 50)
  1741.                     dif_baloons++;
  1742.  
  1743.                 if (round == 65)
  1744.                     dif_baloons++;
  1745.  
  1746.                 if (round == 70)
  1747.                     speed = 40;
  1748.  
  1749.                 for (int i = 0; i < dif_baloons; i++)
  1750.                     count[i] = max;
  1751.  
  1752.                 if (round % 25 == 0)
  1753.                     max += 20;
  1754.  
  1755.                 if (round == 5)
  1756.                     max += 2;
  1757.  
  1758.                 if (speed < 38)
  1759.                     if (round % 1 == 0)
  1760.                         speed++;
  1761.  
  1762.                 if (baloon_speed < 5)
  1763.                     if (round % 7 == 0)
  1764.                         baloon_speed++;
  1765.  
  1766.                 if (round == 42)
  1767.                     baloon_speed++;
  1768.  
  1769.                 if (dif_baloons > 2)
  1770.                     for (int i = 0; i < dif_baloons - 2; i++)
  1771.                         count[i] -= 5;
  1772.  
  1773.                 if (round == 45)
  1774.                     baloon_speed_min++;
  1775.  
  1776.                 if (round == 50)
  1777.                 {
  1778.                     baloon_speed_min++;
  1779.                     speed++;
  1780.                 }
  1781.  
  1782.                 if (round == 55)
  1783.                     baloon_speed_min++;
  1784.  
  1785.                 if (round == 25)
  1786.                     speed -= 3;
  1787.  
  1788.                 if (dif_baloons > 5)
  1789.                     for (int i = 0; i < 3; i++)
  1790.                         count[i] -= 3;
  1791.  
  1792.                 if (dif_baloons > 10)
  1793.                     for (int i = 0; i < 6; i++)
  1794.                         count[i] -= 4;
  1795.  
  1796.                 if (dif_baloons > 16)
  1797.                     for (int i = 0; i < 12; i++)
  1798.                         count[i] -= 5;
  1799.  
  1800.                 if (dif_baloons > 18)
  1801.                     for (int i = 0; i < 15; i++)
  1802.                         count[i] -= 15;
  1803.  
  1804.                 if (round > 50)
  1805.                 {
  1806.                     for (int i = 0; i < 7; i++)
  1807.                         count[i] -= 10;
  1808.  
  1809.                     for (int i = 5; i < 9; i++)
  1810.                         count[i] = i;
  1811.                 }
  1812.  
  1813.                 main.centerText[0] = main.cfont.Render(":: ROUND " + round.ToString() + " ::", System.Drawing.Color.White);
  1814.                 main.leftText[1] = main.font.Render("Round: " + round.ToString() + ".", System.Drawing.Color.Gold);
  1815.                 main.leftText[2] = main.font.Render("$" + (main.money).ToString(), System.Drawing.Color.Gold);
  1816.             }
  1817.             else
  1818.                 main.GameOver(1);
  1819.         }
  1820.         #endregion
  1821.     }
  1822.  
  1823.     static class Program
  1824.     {
  1825.         [STAThread]
  1826.         static void Main()
  1827.         {
  1828.             Start start = new Start();
  1829.         }
  1830.     }
  1831.  
  1832.     public class ReadStep
  1833.     {
  1834.         #region Fields
  1835.         private string file;
  1836.         private int step;
  1837.         private string info = "";
  1838.         #endregion
  1839.  
  1840.         #region ReadStep
  1841.         public ReadStep(string file)
  1842.         {
  1843.             this.file = file;
  1844.             info = ReadFile();
  1845.         }
  1846.         ~ReadStep() { }
  1847.         #endregion
  1848.  
  1849.         #region ReadFile
  1850.         private string ReadFile()
  1851.         {
  1852.             try
  1853.             {
  1854.                 Coder coder = new Coder();
  1855.                 SuperRw rw = new SuperRw();
  1856.                 return coder.UnCode(rw.Read(@file));
  1857.             }
  1858.             catch { return null; }
  1859.         }
  1860.         #endregion
  1861.  
  1862.         #region GetStep
  1863.         public string GetStep(int step)
  1864.         {
  1865.             this.step = step;
  1866.             string buf = "";
  1867.  
  1868.             if ((step > -1) && (step < info.Length + 1))
  1869.                 for (int i = 0; i < info.Length; i++)
  1870.                 {
  1871.                     if ((info[i] == '\r') || (info[i] == '\n'))
  1872.                         step++;
  1873.  
  1874.                     buf = info[i].ToString();
  1875.  
  1876.                     if (i == step)
  1877.                         break;
  1878.                 }
  1879.  
  1880.             return buf;
  1881.         }
  1882.         #endregion
  1883.     }
  1884.  
  1885.     public class SuperRw
  1886.     {
  1887.         #region SuperRw
  1888.         public SuperRw() { }
  1889.         ~SuperRw() { }
  1890.         #endregion
  1891.  
  1892.         #region Read
  1893.         public string Read(string file)
  1894.         {
  1895.             FileStream rfile = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Read);
  1896.             StreamReader read = new StreamReader(rfile);
  1897.             string info = read.ReadToEnd();
  1898.             read.Close();
  1899.             rfile.Close();
  1900.  
  1901.             return info;
  1902.         }
  1903.         #endregion
  1904.  
  1905.         #region Write
  1906.         public void Write(string info, string file)
  1907.         {
  1908.             FileStream wfile = new FileStream(@file, FileMode.Create, FileAccess.Write);
  1909.             StreamWriter write = new StreamWriter(wfile);
  1910.             write.Write(info);
  1911.             write.Close();
  1912.             wfile.Close();
  1913.         }
  1914.         #endregion
  1915.  
  1916.         #region FLineRead
  1917.         public string FLineRead(string file, int line)
  1918.         {
  1919.             string info = Read(file);
  1920.             string buf = "";
  1921.             int ln = 0;
  1922.  
  1923.             for (int i = 0; i < info.Length; i++)
  1924.             {
  1925.                 if (info[i] == '\n')
  1926.                     ln++;
  1927.  
  1928.                 if (line == ln)
  1929.                 {
  1930.                     if (line != 0)
  1931.                         ++i;
  1932.  
  1933.                     while ((i != info.Length) && (info[i] != '\n'))
  1934.                         if (info[i++] != '\r')
  1935.                             buf += info[i - 1];
  1936.  
  1937.                     break;
  1938.                 }
  1939.             }
  1940.  
  1941.             return buf;
  1942.         }
  1943.         #endregion
  1944.     }
  1945.  
  1946.     public class Tower : Sprite
  1947.     {
  1948.         #region Fields
  1949.         public string[] info = new string[3];
  1950.         public string name;
  1951.         public int number;
  1952.         public int cost;
  1953.         public int damage;
  1954.         public int region;
  1955.         public int speed;
  1956.         #endregion
  1957.  
  1958.         #region Tower
  1959.         public Tower(int number)
  1960.         {
  1961.             this.number = number;
  1962.             Surface img = new Surface(@"failai/towers/" + number.ToString() + ".bmp");
  1963.             this.Surface = img;
  1964.             this.Transparent = true;
  1965.             this.TransparentColor = Color.Magenta;
  1966.         }
  1967.         ~Tower() { }
  1968.         #endregion
  1969.     }
  1970.  
  1971.     public class MapGenerator
  1972.     {
  1973.         #region Fields
  1974.         private Sprite[] blocks = new Sprite[196];
  1975.         private ReadStep rs;
  1976.         private int map_size;
  1977.         public int buildBlocks = 0;
  1978.         #endregion
  1979.  
  1980.         #region MapGenerator
  1981.         public MapGenerator(ReadStep rs, SpriteCollection main)
  1982.         {
  1983.             this.rs = rs;
  1984.  
  1985.             map_size = 196;
  1986.  
  1987.             int a = 0;
  1988.             int b = 0;
  1989.             string g;
  1990.  
  1991.             for (int i = 0; i < map_size; i++)
  1992.             {
  1993.                 g = rs.GetStep(i).ToString();
  1994.  
  1995.                 if (g == "0")
  1996.                     buildBlocks++;
  1997.  
  1998.                 Surface _map = new Surface(@"failai/map/" + g + ".bmp");
  1999.  
  2000.                 blocks[i] = new Sprite(_map);
  2001.                 blocks[i].Position = new Point(a * 50, b * 50);
  2002.                 blocks[i].Z = 1;
  2003.  
  2004.                 a++;
  2005.  
  2006.                 if (a == 14)
  2007.                 {
  2008.                     a = 0;
  2009.                     b++;
  2010.                 }
  2011.  
  2012.                 main.Add(blocks[i]);
  2013.             }
  2014.         }
  2015.         ~MapGenerator() { }
  2016.         #endregion
  2017.  
  2018.         #region CheckBuildBlock
  2019.         public int CheckBuildBlock(int X, int Y, bool id)
  2020.         {
  2021.             for (int i = 0; i < map_size; i++)
  2022.                 if (blocks[i] != null)
  2023.                     if ((X > blocks[i].X) && (X < blocks[i].X + blocks[i].Width))
  2024.                         if ((Y > blocks[i].Y) && (Y < blocks[i].Y + blocks[i].Height))
  2025.                             if (rs.GetStep(i) == "0")
  2026.                                 if (!id)
  2027.                                     return 1;    
  2028.                                 else
  2029.                                     return i;
  2030.  
  2031.             return 2;
  2032.         }
  2033.         #endregion
  2034.     }
  2035. }
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: