Sign in to follow this  
  • entries
    11
  • comments
    15
  • views
    16225

Back to the (my) past.

Sign in to follow this  
Josip Mati?

1223 views

I've been working a little on my old laptop. After digging through My Documents in search for some old documents, I've noticed VS2010 folder in it. With my curiosity suddenly awakened, I suddenly found myself staring at the content of the Projects folder.

Reason: some of my old projects were there. Most of them were games. A collection of 1s and 0s, silently waiting for their creator to come back for them. And he came.

After copying all the projects to the PC I work on, I loaded each solution and, after performing some maintenance like retargeting compiler to compile using .NET 3.0, ran debugger for each of them.
And felt like I was back there, looking at younger me sitting in front of PC I had at that time and trying to cope up with a solution to the problem.

So, here there are, the "games" I made before. Please join me in the travel to the past.
Note: I'll post code of each project. Because it's going to be huge, I'll put it in spoilers so that you can skip it if you're not interested.

Year 2006: Duck Shooting



2hgfsbc.jpg

First game I ever made, using Visual Basic (.NET Framework 2.0) with XNA 3.1. I have no idea how long it took me to make it. Gameplay is simple: shoot ducks and dog using the mouse to score points. Blue ducks are the slowest and give least amount of points; green are in the middle and brown are fastest. Dog jumps at random times and gives the most points.

Maybe you, dear reader, recognize the ducks and dog. Yeah, they're from Duck Hunt. And yeah, I hated that dog so much I created a way to get my revenge on him for mocking me each time I missed those damned duck(s). However, game is satisfying to play for maximum 60 seconds.

As for the code... when I look it now, it is atrocious. However, when I calmed myself I realized that... I didn't know better at that time. That was my best. For those who love statistics and code analysis, here's the data Code Metrics gave:

  • Maintanability Index: 59
  • Cyclomatic Complexity: 52
  • Depth of Inheritance: 2
  • Class Coupling: 32
  • Lines of Code: 243

    Code for itself is rather easy to follow. However, I violated so many principles that it might be a bit painful to read.

    XNAGame class:
    [spoiler]Imports Microsoft.Xna.FrameworkImports Microsoft.Xna.Framework.GraphicsImports Microsoft.Xna.Framework.InputNamespace xna Public Class XNAGame Inherits Game Public Shared XNAGraphics As GraphicsDeviceManager Public Sub New() XNAGraphics = New GraphicsDeviceManager(Me) End Sub Protected Overrides Sub Initialize() MyBase.IsMouseVisible = True Randomize() XNAGraphics.PreferredBackBufferWidth = 800 XNAGraphics.PreferredBackBufferHeight = 600 XNAGraphics.IsFullScreen = False XNAGraphics.ApplyChanges() InitializeTextures() MyBase.Initialize() End Sub Protected Overrides Sub Update(ByVal gameTime As Microsoft.Xna.Framework.GameTime) Dim GetKeys As KeyboardState = Keyboard.GetState Dim GetMouse As MouseState = Mouse.GetState If GetKeys.IsKeyDown(Keys.Escape) Then MyBase.Exit() End If If ButtonState.Pressed = GetMouse.LeftButton And Pressed = False Then Pressed = True Detect(GetMouse.X, GetMouse.Y) End If If ButtonState.Released = GetMouse.LeftButton Then Pressed = False End If Me.Window.Title = "Duck Shooting " + Score.ToString MyBase.Update(gameTime) Application.DoEvents() End Sub Protected Overrides Sub Draw(ByVal gameTime As Microsoft.Xna.Framework.GameTime) DuckGame.DrawMain() MyBase.Draw(gameTime) End Sub End Class Module modMain Public Game1 As XNAGame Public Sub Main() Game1 = New XNAGame Game1.Run() End Sub End ModuleEnd Namespace
    [/spoiler]
    DuckGame module:
    [spoiler]Imports Microsoft.Xna.FrameworkImports Microsoft.Xna.Framework.GraphicsNamespace xna Module DuckGame Public Sub DrawMain() XNAGame.XNAGraphics.GraphicsDevice.Clear(ClearOptions.Target, Color.DeepSkyBlue, 1.0F, 0) Rand = Rnd() If (Rand < 0.002) And (DogJump = False) Then DogJump = True If DogJump = True Then DogSB.Begin() If x <= 400 Then DogRect1.X = x DogRect1.Y = Math.Pow(x - 400, 2) / 80 + 100 DogSB.Draw(DogTexture1, DogRect1, Color.White) Else DogRect2.X = x DogRect2.Y = Math.Pow(x - 400, 2) / 80 + 100 DogSB.Draw(DogTexture2, DogRect2, Color.White) If x = 600 Then x = 200 DogJump = False End If End If x += 3 DogSB.End() End If DuckSB.Begin() RBlueDuck.UpdateFrame() DuckSB.Draw(RBlueDuck.ShowFrame, RBlueDuckRect, Color.White) If RBlueDuckRect.X < xna.Game1.Window.ClientBounds.Right Then RBlueDuckRect.X += 2 Else RBlueDuckRect.X = -80 RBlueDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 End If LBlueDuck.UpdateFrame() DuckSB.Draw(LBlueDuck.ShowFrame, LBlueDuckRect, Color.White) If LBlueDuckRect.X > -80 Then LBlueDuckRect.X -= 2 Else LBlueDuckRect.X = xna.Game1.Window.ClientBounds.Width LBlueDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 End If RGreenDuck.UpdateFrame() DuckSB.Draw(RGreenDuck.ShowFrame, RGreenDuckRect, Color.White) If RGreenDuckRect.X < xna.Game1.Window.ClientBounds.Right Then RGreenDuckRect.X += 4 Else RGreenDuckRect.X = -80 RGreenDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 End If LGreenDuck.UpdateFrame() DuckSB.Draw(LGreenDuck.ShowFrame, LGreenDuckRect, Color.White) If LGreenDuckRect.X > -80 Then LGreenDuckRect.X -= 4 Else LGreenDuckRect.X = xna.Game1.Window.ClientBounds.Width LGreenDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 End If RRedDuck.UpdateFrame() DuckSB.Draw(RRedDuck.ShowFrame, RRedDuckRect, Color.White) If RRedDuckRect.X < xna.Game1.Window.ClientBounds.Right Then RRedDuckRect.X += 6 Else RRedDuckRect.X = -80 RRedDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 End If LRedDuck.UpdateFrame() DuckSB.Draw(LRedDuck.ShowFrame, LRedDuckRect, Color.White) If LRedDuckRect.X > -80 Then LRedDuckRect.X -= 6 Else LRedDuckRect.X = xna.Game1.Window.ClientBounds.Width LRedDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 End If DuckSB.End() BackgroundSB.Begin() BackgroundSB.Draw(BackgroundTexture, BackgroundRect, Color.White) BackgroundSB.End() End Sub End ModuleEnd Namespace
    [/spoiler]
    DefineTextures module:
    [spoiler]Imports Microsoft.Xna.FrameworkImports Microsoft.Xna.Framework.GraphicsNamespace xna Module DefineTextures Public Device As GraphicsDevice = XNAGame.XNAGraphics.GraphicsDevice 'Background Setup Public BackgroundSB As SpriteBatch = Nothing Public BackgroundRect As Rectangle = Nothing Public BackgroundTexture As Texture2D = Nothing Public BackgroundCreationParams As TextureCreationParameters = TextureCreationParameters.Default 'Dog Setup Public DogSB As SpriteBatch = Nothing Public DogRect1 As Rectangle = Nothing Public DogRect2 As Rectangle = Nothing Public DogTexture1 As Texture2D = Nothing Public DogTexture2 As Texture2D = Nothing Public DogCreationParams As TextureCreationParameters = TextureCreationParameters.Default Public DogJump As Boolean = False 'Duck Setup Public DuckSB As SpriteBatch = Nothing Public DuckCreationParams As TextureCreationParameters = TextureCreationParameters.Default Public RBlueDuck As New AnimatedTexture Public LBlueDuck As New AnimatedTexture Public RGreenDuck As New AnimatedTexture Public LGreenDuck As New AnimatedTexture Public RRedDuck As New AnimatedTexture Public LRedDuck As New AnimatedTexture Public RBlueDuckRect As Rectangle = Nothing Public LBlueDuckRect As Rectangle = Nothing Public RGreenDuckRect As Rectangle = Nothing Public LGreenDuckRect As Rectangle = Nothing Public RRedDuckRect As Rectangle = Nothing Public LRedDuckRect As Rectangle = Nothing 'Time and Score Public Score As Integer = 0 Public ScoreText As SpriteFont Public Time As Stopwatch = New Stopwatch Public TimeText As String 'Other Public GameState As String = "Menu" Public x As Integer = 200 Public Rand As Single Public Pressed As Boolean = False Public Sub InitializeTextures() Background() Dog() DuckSB = New SpriteBatch(Device) Ducks() End Sub Private Sub Background() BackgroundTexture = Texture2D.FromFile(Device, "../../../Images/Background.png") BackgroundRect.Width = xna.Game1.Window.ClientBounds.Width BackgroundRect.Height = xna.Game1.Window.ClientBounds.Height BackgroundSB = New SpriteBatch(Device) BackgroundRect.X = 0 BackgroundRect.Y = 0 End Sub Private Sub Dog() DogSB = New SpriteBatch(Device) DogTexture1 = Texture2D.FromFile(Device, "../../../Images/Dog-Up.png") DogTexture2 = Texture2D.FromFile(Device, "../../../Images/Dog-Down.png") DogRect1.Width = DogTexture1.Width * 2 DogRect1.Height = DogTexture1.Height * 2 DogRect2.Width = DogTexture2.Width * 2 DogRect2.Height = DogTexture2.Height * 2 End Sub Private Sub Ducks() RBlueDuck.Load("../../../Images/R-Blue-Duck-1.png", 1, 30) RBlueDuck.Load("../../../Images/R-Blue-Duck-2.png", 2, 30) RBlueDuck.Load("../../../Images/R-Blue-Duck-3.png", 3, 30) RBlueDuck.UpdateFrame() RBlueDuckRect.X = -80 RBlueDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 RBlueDuckRect.Width = RBlueDuck.ShowFrame.Width RBlueDuckRect.Height = RBlueDuck.ShowFrame.Height LBlueDuck.Load("../../../Images/L-Blue-Duck-1.png", 1, 30) LBlueDuck.Load("../../../Images/L-Blue-Duck-2.png", 2, 30) LBlueDuck.Load("../../../Images/L-Blue-Duck-3.png", 3, 30) LBlueDuck.UpdateFrame() LBlueDuckRect.X = xna.Game1.Window.ClientBounds.Width LBlueDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 LBlueDuckRect.Width = LBlueDuck.ShowFrame.Width LBlueDuckRect.Height = LBlueDuck.ShowFrame.Height RGreenDuck.Load("../../../Images/R-Green-Duck-1.png", 1, 20) RGreenDuck.Load("../../../Images/R-Green-Duck-2.png", 2, 20) RGreenDuck.Load("../../../Images/R-Green-Duck-3.png", 3, 20) RGreenDuck.UpdateFrame() RGreenDuckRect.X = -80 RGreenDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 RGreenDuckRect.Width = RGreenDuck.ShowFrame.Width RGreenDuckRect.Height = RGreenDuck.ShowFrame.Height LGreenDuck.Load("../../../Images/L-Green-Duck-1.png", 1, 20) LGreenDuck.Load("../../../Images/L-Green-Duck-2.png", 2, 20) LGreenDuck.Load("../../../Images/L-Green-Duck-3.png", 3, 20) LGreenDuck.UpdateFrame() LGreenDuckRect.X = xna.Game1.Window.ClientBounds.Width LGreenDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 LGreenDuckRect.Width = LGreenDuck.ShowFrame.Width LGreenDuckRect.Height = LGreenDuck.ShowFrame.Height RRedDuck.Load("../../../Images/R-Red-Duck-1.png", 1, 10) RRedDuck.Load("../../../Images/R-Red-Duck-2.png", 2, 10) RRedDuck.Load("../../../Images/R-Red-Duck-3.png", 3, 10) RRedDuck.UpdateFrame() RRedDuckRect.X = -80 RRedDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 RRedDuckRect.Width = RRedDuck.ShowFrame.Width RRedDuckRect.Height = RRedDuck.ShowFrame.Height LRedDuck.Load("../../../Images/L-Red-Duck-1.png", 1, 10) LRedDuck.Load("../../../Images/L-Red-Duck-2.png", 2, 10) LRedDuck.Load("../../../Images/L-Red-Duck-3.png", 3, 10) LRedDuck.UpdateFrame() LRedDuckRect.X = xna.Game1.Window.ClientBounds.Width LRedDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 LRedDuckRect.Width = LRedDuck.ShowFrame.Width LRedDuckRect.Height = LRedDuck.ShowFrame.Height End Sub End ModuleEnd Namespace
    [/spoiler]
    AnimatedTexture module:
    [spoiler]Imports Microsoft.Xna.FrameworkImports Microsoft.Xna.Framework.GraphicsNamespace xna Public Class AnimatedTexture Public ShowFrame As Texture2D Private Frame1 As Texture2D Private Frame2 As Texture2D Private Frame3 As Texture2D Private Frame4 As Texture2D Private FrameNbr As Byte = 1 Private TimePerFrame As Integer Public Sub Load(ByVal fileName As String, ByVal frame As Byte, ByVal tpf As Single) Select Case frame Case 1 Frame1 = Texture2D.FromFile(Device, fileName) Case 2 Frame2 = Texture2D.FromFile(Device, fileName) Frame4 = Texture2D.FromFile(Device, fileName) Case 3 Frame3 = Texture2D.FromFile(Device, fileName) End Select TimePerFrame = tpf End Sub Public Sub UpdateFrame() If RBlueDuckRect.X Mod TimePerFrame = 0 Then If FrameNbr < 4 Then FrameNbr += 1 Else FrameNbr = 1 End If End If Select Case FrameNbr Case 1 ShowFrame = Frame1 Case 2 ShowFrame = Frame2 Case 3 ShowFrame = Frame3 Case 4 ShowFrame = Frame4 End Select End Sub End ClassEnd Namespace
    [/spoiler]
    HitDetection module:
    [spoiler]Imports Microsoft.Xna.FrameworkImports Microsoft.Xna.Framework.InputNamespace xna Module HitDetection Public Sub Detect(ByVal x As Integer, ByVal y As Integer) If RBlueDuckRect.Contains(x, y) Then Score += 10 RBlueDuckRect.X = -80 RBlueDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 End If If LBlueDuckRect.Contains(x, y) Then Score += 10 LBlueDuckRect.X = xna.Game1.Window.ClientBounds.Width LBlueDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 End If If RGreenDuckRect.Contains(x, y) Then Score += 20 RGreenDuckRect.X = xna.Game1.Window.ClientBounds.Width RGreenDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 End If If LGreenDuckRect.Contains(x, y) Then Score += 20 LGreenDuckRect.X = xna.Game1.Window.ClientBounds.Width LGreenDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 End If If LRedDuckRect.Contains(x, y) Then Score += 30 LRedDuckRect.X = xna.Game1.Window.ClientBounds.Width LRedDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 End If If RRedDuckRect.Contains(x, y) Then Score += 30 RRedDuckRect.X = xna.Game1.Window.ClientBounds.Width RRedDuckRect.Y = Rnd() * xna.Game1.Window.ClientBounds.Height / 2 End If If DogRect1.Contains(x, y) OrElse DogRect2.Contains(x, y) Then Score += 50 DogJump = False DefineTextures.x = 200 DogRect1.X = -100 : DogRect1.Y = 0 DogRect2.X = -100 : DogRect2.Y = 0 End If End Sub End ModuleEnd Namespace
    [/spoiler]

    Year 2009 (I think): Battle Tanks v0



    30uzb14.jpg

    Wrote with C# (.NET 3.5) and XNA 3.1. This was my first try of making "player" move the objects using keyboard.
    This was also the project I learned why many of the modern games (League of Legends, for example) avoid using slick rotations of models unless needed.

    Project isn't particulary impressive. Just a box with a barrel moving around and rotating. With one interesting bug I didn't fix: pressing Space during rotation makes bullet stuck at that angle.

    Code is actually quite simple:
    [spoiler]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 BattleTanks{ /// /// This is the main type for your game /// public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; //Initialization private Texture2D Player1Tank; private Texture2D Bullet; private Vector2 TankOrig; private Vector2 TankPos; private Vector2 BulletPos; private Vector2 BulletOrig; private Single tankrotation; private Single bulletrotation; private Single scale; private Boolean BulletFired = false; private Boolean BulletFlying = false; private int BulletPower = 1; public Game1() { graphics = new GraphicsDeviceManager(this); graphics.GraphicsProfile = GraphicsProfile.Reach; Content.RootDirectory = "Content"; } /// /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// protected override void Initialize() { // TODO: Add your initialization logic here graphics.PreferredBackBufferHeight = 600; graphics.PreferredBackBufferWidth = 600; graphics.ApplyChanges(); base.Initialize(); } /// /// LoadContent will be called once per game and is the place to load /// all of your content. /// protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here Player1Tank = Content.Load("Textures/Player1-tank"); Bullet = Content.Load("Textures/Bullet"); scale = 0.125f; TankPos.X = 25; TankPos.Y = 25; TankOrig.X = Player1Tank.Bounds.Center.X; TankOrig.Y = Player1Tank.Bounds.Center.Y; BulletOrig.X = Bullet.Bounds.Center.X; BulletOrig.Y = Bullet.Bounds.Center.Y; tankrotation = (float) Math.PI * 0.5f; } /// /// UnloadContent will be called once per game and is the place to unload /// all content. /// protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } /// /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// /// Provides a snapshot of timing values. protected override void Update(GameTime gameTime) { // Allows the game to exit if (Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit(); // TODO: Add your update logic here #region "Player 1 movement" if (Keyboard.GetState().IsKeyDown(Keys.Right)) { if (Math.Round(tankrotation, 4) != Math.Round((float)Math.PI * 0.5f, 4)) { if ((tankrotation > (float)Math.PI * 1.5f) | (tankrotation < (float)Math.PI * 0.5f)) { tankrotation += (float)Math.PI * 0.0625f; if (tankrotation > (float)Math.PI * 2) tankrotation -= (float)Math.PI * 2; } else tankrotation -= (float)Math.PI * 0.0625f; } else if (TankPos.X < graphics.PreferredBackBufferWidth - Player1Tank.Bounds.Center.X * scale)TankPos.X += 2; } if (Keyboard.GetState().IsKeyDown(Keys.Left)) { if (Math.Round(tankrotation, 4) != Math.Round((float)Math.PI * 1.5f, 4)) { if ((tankrotation < (float)Math.PI * 0.5f) | (tankrotation > (float)Math.PI * 1.5f)) { tankrotation -= (float)Math.PI * 0.0625f; if (tankrotation < (float)Math.PI * 0) tankrotation += (float)Math.PI * 2; } else tankrotation += (float)Math.PI * 0.0625f; } else if (TankPos.X > Player1Tank.Bounds.Center.X * scale) TankPos.X -= 2; } if (Keyboard.GetState().IsKeyDown(Keys.Up)) { if (Math.Round(tankrotation, 4) != Math.Round((float)Math.PI * 0.0f, 4)) { if (tankrotation > (float)Math.PI) { tankrotation += (float)Math.PI * 0.0625f; if (tankrotation > (float)Math.PI * 2) tankrotation -= (float)Math.PI * 2; } else tankrotation -= (float)Math.PI * 0.0625f; } else if (TankPos.Y > Player1Tank.Bounds.Center.Y * scale) TankPos.Y -= 2; } if (Keyboard.GetState().IsKeyDown(Keys.Down)) { if (Math.Round(tankrotation, 4) != Math.Round((float)Math.PI * 1.0f, 4)) if (tankrotation > (float)Math.PI * 1.0f) { tankrotation -= (float)Math.PI * 0.0625f; if (tankrotation > (float)Math.PI * 2) tankrotation -= (float)Math.PI * 2; } else tankrotation += (float)Math.PI * 0.0625f; else if (TankPos.Y < graphics.PreferredBackBufferHeight - Player1Tank.Bounds.Center.Y * scale) TankPos.Y += 2; } #endregion #region "Bullet firing" if ((Keyboard.GetState().IsKeyDown(Keys.Space)) && (BulletFlying == false)) { BulletFired = true; BulletFlying = true; BulletPos.X = TankPos.X; BulletPos.Y = TankPos.Y; bulletrotation = tankrotation - (float)Math.PI * 0.5f; if (bulletrotation < -1) bulletrotation += (float)Math.PI * 2; } if (BulletFired == true) { if (Math.Round(bulletrotation, 4) == 0) BulletPos.X += 5 * BulletPower; if (Math.Round(bulletrotation, 4) == Math.Round((float)Math.PI * 0.5f, 4)) BulletPos.Y += 5 * BulletPower; if (Math.Round(bulletrotation, 4) == Math.Round((float)Math.PI, 4)) BulletPos.X -= 5 * BulletPower; if (Math.Round(bulletrotation, 4) == Math.Round((float)Math.PI * 1.5f, 4)) BulletPos.Y -= 5 * BulletPower; if ((BulletPos.X < 0) | (BulletPos.Y < 0) | (BulletPos.X > graphics.PreferredBackBufferWidth) | (BulletPos.Y > graphics.PreferredBackBufferHeight)) { BulletFired = false; BulletFlying = false; } } #endregion base.Update(gameTime); } /// /// This is called when the game should draw itself. /// /// Provides a snapshot of timing values. protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); // TODO: Add your drawing code here spriteBatch.Begin(); if (BulletFired == true) spriteBatch.Draw(Bullet, BulletPos, null, Color.White, bulletrotation, BulletOrig, scale, SpriteEffects.None, 0); spriteBatch.Draw(Player1Tank, TankPos, null, Color.Yellow, tankrotation, TankOrig, scale, SpriteEffects.None, 0); spriteBatch.End(); base.Draw(gameTime); } }}
    [/spoiler]

    I could say that the project is abandoned, but I won't; I used this project as a base for the one later.

    Year 2010: Nine Men's Morris



    2irr76o.jpg

    Back to the mouse based games. This one is once again written with C# (.NET 3.5) with XNA 3.1. I believe you can recognize the game, but in case you don't know, I'll explain:

    Two players, each has 9 pieces. Game is split into 2 phases.
    In phase 1, players alternately place their tokens on the board, trying to fill a row or column - make a "mill". After all 18 tokens are placed, each player can take away one of the opponents tokens from the board for each mill that player made. Tokens from mills cannot be taken out.
    In phase 2, each turn players can move one token to the adjacent cell. Goal is to take out all opponent tokens by making mills. Once player remains with only 3 tokens, he isn't restricted to the adjacent cells of each token and can "jump" over the whole board.

    Sadly, I never wrote a game beyond Phase 1. I might finish it one day... *looks at code* Screw it, if I ever decide to finish it I'll rather remake it from scratch:
    [spoiler]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 Mlin{ /// /// This is the main type for your game /// public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; // Graphics specific variables public Texture2D Board; public Texture2D Figure; public Texture2D Background; public Rectangle BoardRect; public Double GraphicScale; public Vector2 FigurePosition; public Vector2 FigureOffset; public string Gamestate; public Color Player1Color; public Color Player2Color; // Game logic variables public Char[,] FigurePlacement = new char[7,7]; public byte PlayerTurn; public bool PositionPhase = true; public byte FigureCount1 = 0; public byte FigureCount2 = 0; public bool Selected = false; public byte SelectedPos; public byte x, y; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } /// /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// protected override void Initialize() { // TODO: Add your initialization logic here graphics.PreferredBackBufferHeight = 800; graphics.PreferredBackBufferWidth = 800; graphics.ApplyChanges(); IsMouseVisible = true; PlayerTurn = 1; Player1Color = Color.Red; Player2Color = Color.Blue; base.Initialize(); } /// /// LoadContent will be called once per game and is the place to load /// all of your content. /// protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here Board = Content.Load("Images/Board"); Figure = Content.Load("Images/Figure"); // Setup BoardRect.Width = graphics.PreferredBackBufferWidth; BoardRect.Height = graphics.PreferredBackBufferHeight; BoardRect.X = 0; BoardRect.Y = 0; GraphicScale = (double) graphics.PreferredBackBufferHeight / Board.Height; FigureOffset.X = Figure.Bounds.Center.X; FigureOffset.Y = Figure.Bounds.Center.Y; } /// /// UnloadContent will be called once per game and is the place to unload /// all content. /// protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } /// /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// /// Provides a snapshot of timing values. protected override void Update(GameTime gameTime) { // Allows the game to exit if (Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit(); // TODO: Add your update logic here if (Mouse.GetState().LeftButton == ButtonState.Pressed && PositionPhase == true) { #region Positions // First line if (Mouse.GetState().X > ((int)(175 * GraphicScale)) && Mouse.GetState().X < ((int)(325 * GraphicScale)) && Mouse.GetState().Y > ((int)(175 * GraphicScale)) && Mouse.GetState().Y < ((int)(325 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[0, 0] == '\0') { FigurePlacement[0, 0] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(175 * GraphicScale)) && Mouse.GetState().X < ((int)(325 * GraphicScale)) && Mouse.GetState().Y > ((int)(175 * GraphicScale)) && Mouse.GetState().Y < ((int)(325 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[0, 0] == '\0') { FigurePlacement[0, 0] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(175 * GraphicScale)) && Mouse.GetState().Y < ((int)(325 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[3, 0] == '\0') { FigurePlacement[3, 0] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(175 * GraphicScale)) && Mouse.GetState().Y < ((int)(325 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[3, 0] == '\0') { FigurePlacement[3, 0] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(1675 * GraphicScale)) && Mouse.GetState().X < ((int)(1825 * GraphicScale)) && Mouse.GetState().Y > ((int)(175 * GraphicScale)) && Mouse.GetState().Y < ((int)(325 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[6, 0] == '\0') { FigurePlacement[6, 0] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(1675 * GraphicScale)) && Mouse.GetState().X < ((int)(1825 * GraphicScale)) && Mouse.GetState().Y > ((int)(175 * GraphicScale)) && Mouse.GetState().Y < ((int)(325 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[6, 0] == '\0') { FigurePlacement[6, 0] = '2'; ++FigureCount2; PlayerTurn = 1; } // Second line else if (Mouse.GetState().X > ((int)(375 * GraphicScale)) && Mouse.GetState().X < ((int)(525 * GraphicScale)) && Mouse.GetState().Y > ((int)(375 * GraphicScale)) && Mouse.GetState().Y < ((int)(525 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[1, 1] == '\0') { FigurePlacement[1, 1] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(375 * GraphicScale)) && Mouse.GetState().X < ((int)(525 * GraphicScale)) && Mouse.GetState().Y > ((int)(375 * GraphicScale)) && Mouse.GetState().Y < ((int)(525 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[1, 1] == '\0') { FigurePlacement[1, 1] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(375 * GraphicScale)) && Mouse.GetState().Y < ((int)(525 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[3, 1] == '\0') { FigurePlacement[3, 1] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(375 * GraphicScale)) && Mouse.GetState().Y < ((int)(525 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[3, 1] == '\0') { FigurePlacement[3, 1] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(1475 * GraphicScale)) && Mouse.GetState().X < ((int)(1625 * GraphicScale)) && Mouse.GetState().Y > ((int)(375 * GraphicScale)) && Mouse.GetState().Y < ((int)(525 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[5, 1] == '\0') { FigurePlacement[5, 1] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(1475 * GraphicScale)) && Mouse.GetState().X < ((int)(1625 * GraphicScale)) && Mouse.GetState().Y > ((int)(375 * GraphicScale)) && Mouse.GetState().Y < ((int)(525 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[5, 1] == '\0') { FigurePlacement[5, 1] = '2'; ++FigureCount2; PlayerTurn = 1; } // Third line else if (Mouse.GetState().X > ((int)(575 * GraphicScale)) && Mouse.GetState().X < ((int)(725 * GraphicScale)) && Mouse.GetState().Y > ((int)(575 * GraphicScale)) && Mouse.GetState().Y < ((int)(725 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[2, 2] == '\0') { FigurePlacement[2, 2] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(575 * GraphicScale)) && Mouse.GetState().X < ((int)(725 * GraphicScale)) && Mouse.GetState().Y > ((int)(575 * GraphicScale)) && Mouse.GetState().Y < ((int)(725 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[2, 2] == '\0') { FigurePlacement[2, 2] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(575 * GraphicScale)) && Mouse.GetState().Y < ((int)(725 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[3, 2] == '\0') { FigurePlacement[3, 2] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(575 * GraphicScale)) && Mouse.GetState().Y < ((int)(725 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[3, 2] == '\0') { FigurePlacement[3, 2] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(1275 * GraphicScale)) && Mouse.GetState().X < ((int)(1425 * GraphicScale)) && Mouse.GetState().Y > ((int)(575 * GraphicScale)) && Mouse.GetState().Y < ((int)(725 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[4, 2] == '\0') { FigurePlacement[4, 2] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(1275 * GraphicScale)) && Mouse.GetState().X < ((int)(1425 * GraphicScale)) && Mouse.GetState().Y > ((int)(575 * GraphicScale)) && Mouse.GetState().Y < ((int)(725 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[4, 2] == '\0') { FigurePlacement[4, 2] = '2'; ++FigureCount2; PlayerTurn = 1; } // 4th line else if (Mouse.GetState().X > ((int)(175 * GraphicScale)) && Mouse.GetState().X < ((int)(325 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[0, 3] == '\0') { FigurePlacement[0, 3] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(175 * GraphicScale)) && Mouse.GetState().X < ((int)(325 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[0, 3] == '\0') { FigurePlacement[0, 3] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(375 * GraphicScale)) && Mouse.GetState().X < ((int)(525 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[1, 3] == '\0') { FigurePlacement[1, 3] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(375 * GraphicScale)) && Mouse.GetState().X < ((int)(525 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[1, 3] == '\0') { FigurePlacement[1, 3] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(575 * GraphicScale)) && Mouse.GetState().X < ((int)(725 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[2, 3] == '\0') { FigurePlacement[2, 3] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(575 * GraphicScale)) && Mouse.GetState().X < ((int)(725 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[2, 3] == '\0') { FigurePlacement[2, 3] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(1275 * GraphicScale)) && Mouse.GetState().X < ((int)(1425 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[4, 3] == '\0') { FigurePlacement[4, 3] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(1275 * GraphicScale)) && Mouse.GetState().X < ((int)(1425 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[4, 3] == '\0') { FigurePlacement[4, 3] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(1475 * GraphicScale)) && Mouse.GetState().X < ((int)(1625 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[5, 3] == '\0') { FigurePlacement[5, 3] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(1475 * GraphicScale)) && Mouse.GetState().X < ((int)(1625 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[5, 3] == '\0') { FigurePlacement[5, 3] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(1675 * GraphicScale)) && Mouse.GetState().X < ((int)(1825 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[6, 3] == '\0') { FigurePlacement[6, 3] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(1675 * GraphicScale)) && Mouse.GetState().X < ((int)(1825 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[6, 3] == '\0') { FigurePlacement[6, 3] = '2'; ++FigureCount2; PlayerTurn = 1; } // 5th line else if (Mouse.GetState().X > ((int)(575 * GraphicScale)) && Mouse.GetState().X < ((int)(725 * GraphicScale)) && Mouse.GetState().Y > ((int)(1275 * GraphicScale)) && Mouse.GetState().Y < ((int)(1425 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[2, 4] == '\0') { FigurePlacement[2, 4] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(575 * GraphicScale)) && Mouse.GetState().X < ((int)(725 * GraphicScale)) && Mouse.GetState().Y > ((int)(1275 * GraphicScale)) && Mouse.GetState().Y < ((int)(1425 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[2, 4] == '\0') { FigurePlacement[2, 4] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(1275 * GraphicScale)) && Mouse.GetState().Y < ((int)(1425 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[3, 4] == '\0') { FigurePlacement[3, 4] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(1275 * GraphicScale)) && Mouse.GetState().Y < ((int)(1425 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[3, 4] == '\0') { FigurePlacement[3, 4] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(1275 * GraphicScale)) && Mouse.GetState().X < ((int)(1425 * GraphicScale)) && Mouse.GetState().Y > ((int)(1275 * GraphicScale)) && Mouse.GetState().Y < ((int)(1425 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[4, 4] == '\0') { FigurePlacement[4, 4] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(1275 * GraphicScale)) && Mouse.GetState().X < ((int)(1425 * GraphicScale)) && Mouse.GetState().Y > ((int)(1275 * GraphicScale)) && Mouse.GetState().Y < ((int)(1425 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[4, 4] == '\0') { FigurePlacement[4, 4] = '2'; ++FigureCount2; PlayerTurn = 1; } // 6th line else if (Mouse.GetState().X > ((int)(375 * GraphicScale)) && Mouse.GetState().X < ((int)(525 * GraphicScale)) && Mouse.GetState().Y > ((int)(1475 * GraphicScale)) && Mouse.GetState().Y < ((int)(1625 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[1, 5] == '\0') { FigurePlacement[1, 5] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(375 * GraphicScale)) && Mouse.GetState().X < ((int)(525 * GraphicScale)) && Mouse.GetState().Y > ((int)(1475 * GraphicScale)) && Mouse.GetState().Y < ((int)(1625 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[1, 5] == '\0') { FigurePlacement[1, 5] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(1475 * GraphicScale)) && Mouse.GetState().Y < ((int)(1625 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[3, 5] == '\0') { FigurePlacement[3, 5] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(1475 * GraphicScale)) && Mouse.GetState().Y < ((int)(1625 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[3, 5] == '\0') { FigurePlacement[3, 5] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(1475 * GraphicScale)) && Mouse.GetState().X < ((int)(1625 * GraphicScale)) && Mouse.GetState().Y > ((int)(1475 * GraphicScale)) && Mouse.GetState().Y < ((int)(1625 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[5, 5] == '\0') { FigurePlacement[5, 5] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(1475 * GraphicScale)) && Mouse.GetState().X < ((int)(1625 * GraphicScale)) && Mouse.GetState().Y > ((int)(1475 * GraphicScale)) && Mouse.GetState().Y < ((int)(1625 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[5, 5] == '\0') { FigurePlacement[5, 5] = '2'; ++FigureCount2; PlayerTurn = 1; } // Last line else if (Mouse.GetState().X > ((int)(175 * GraphicScale)) && Mouse.GetState().X < ((int)(325 * GraphicScale)) && Mouse.GetState().Y > ((int)(1675 * GraphicScale)) && Mouse.GetState().Y < ((int)(1825 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[0, 6] == '\0') { FigurePlacement[0, 6] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(175 * GraphicScale)) && Mouse.GetState().X < ((int)(325 * GraphicScale)) && Mouse.GetState().Y > ((int)(1675 * GraphicScale)) && Mouse.GetState().Y < ((int)(1825 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[0, 6] == '\0') { FigurePlacement[0, 6] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(1675 * GraphicScale)) && Mouse.GetState().Y < ((int)(1825 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[3, 6] == '\0') { FigurePlacement[3, 6] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(1675 * GraphicScale)) && Mouse.GetState().Y < ((int)(1825 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[3, 6] == '\0') { FigurePlacement[3, 6] = '2'; ++FigureCount2; PlayerTurn = 1; } else if (Mouse.GetState().X > ((int)(1675 * GraphicScale)) && Mouse.GetState().X < ((int)(1825 * GraphicScale)) && Mouse.GetState().Y > ((int)(1675 * GraphicScale)) && Mouse.GetState().Y < ((int)(1825 * GraphicScale)) && PlayerTurn == 1 && FigurePlacement[6, 6] == '\0') { FigurePlacement[6, 6] = '1'; ++FigureCount1; PlayerTurn = 2; } else if (Mouse.GetState().X > ((int)(1675 * GraphicScale)) && Mouse.GetState().X < ((int)(1825 * GraphicScale)) && Mouse.GetState().Y > ((int)(1675 * GraphicScale)) && Mouse.GetState().Y < ((int)(1825 * GraphicScale)) && PlayerTurn == 2 && FigurePlacement[6, 6] == '\0') { FigurePlacement[6, 6] = '2'; ++FigureCount2; PlayerTurn = 1; } #endregion if (FigureCount1 == 9 && FigureCount2 == 9) PositionPhase = false; } if (Mouse.GetState().LeftButton == ButtonState.Pressed && PositionPhase == false) { #region Selection decider if (Mouse.GetState().X > ((int)(175 * GraphicScale)) && Mouse.GetState().X < ((int)(325 * GraphicScale)) && Mouse.GetState().Y > ((int)(175 * GraphicScale)) && Mouse.GetState().Y < ((int)(325 * GraphicScale))) {SelectedPos = 1;} else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(175 * GraphicScale)) && Mouse.GetState().Y < ((int)(325 * GraphicScale))) {SelectedPos = 2;} else if (Mouse.GetState().X > ((int)(1675 * GraphicScale)) && Mouse.GetState().X < ((int)(1825 * GraphicScale)) && Mouse.GetState().Y > ((int)(175 * GraphicScale)) && Mouse.GetState().Y < ((int)(325 * GraphicScale))) {SelectedPos = 3;} else if (Mouse.GetState().X > ((int)(375 * GraphicScale)) && Mouse.GetState().X < ((int)(525 * GraphicScale)) && Mouse.GetState().Y > ((int)(375 * GraphicScale)) && Mouse.GetState().Y < ((int)(525 * GraphicScale))) {SelectedPos = 4;} else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(375 * GraphicScale)) && Mouse.GetState().Y < ((int)(525 * GraphicScale))) {SelectedPos = 5;} else if (Mouse.GetState().X > ((int)(1475 * GraphicScale)) && Mouse.GetState().X < ((int)(1625 * GraphicScale)) && Mouse.GetState().Y > ((int)(375 * GraphicScale)) && Mouse.GetState().Y < ((int)(525 * GraphicScale))) {SelectedPos = 6;} else if (Mouse.GetState().X > ((int)(575 * GraphicScale)) && Mouse.GetState().X < ((int)(725 * GraphicScale)) && Mouse.GetState().Y > ((int)(575 * GraphicScale)) && Mouse.GetState().Y < ((int)(725 * GraphicScale))) {SelectedPos = 7;} else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(575 * GraphicScale)) && Mouse.GetState().Y < ((int)(725 * GraphicScale))) {SelectedPos = 8;} else if (Mouse.GetState().X > ((int)(1275 * GraphicScale)) && Mouse.GetState().X < ((int)(1425 * GraphicScale)) && Mouse.GetState().Y > ((int)(575 * GraphicScale)) && Mouse.GetState().Y < ((int)(725 * GraphicScale))) {SelectedPos = 9;} else if (Mouse.GetState().X > ((int)(175 * GraphicScale)) && Mouse.GetState().X < ((int)(325 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale))) { SelectedPos = 10; } else if (Mouse.GetState().X > ((int)(375 * GraphicScale)) && Mouse.GetState().X < ((int)(525 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale))) { SelectedPos = 11; } else if (Mouse.GetState().X > ((int)(575 * GraphicScale)) && Mouse.GetState().X < ((int)(725 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale))) { SelectedPos = 12; } else if (Mouse.GetState().X > ((int)(1275 * GraphicScale)) && Mouse.GetState().X < ((int)(1425 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale))) { SelectedPos = 13; } else if (Mouse.GetState().X > ((int)(1475 * GraphicScale)) && Mouse.GetState().X < ((int)(1625 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale))) { SelectedPos = 14; } else if (Mouse.GetState().X > ((int)(1675 * GraphicScale)) && Mouse.GetState().X < ((int)(1825 * GraphicScale)) && Mouse.GetState().Y > ((int)(925 * GraphicScale)) && Mouse.GetState().Y < ((int)(1075 * GraphicScale))) { SelectedPos = 15; } else if (Mouse.GetState().X > ((int)(575 * GraphicScale)) && Mouse.GetState().X < ((int)(725 * GraphicScale)) && Mouse.GetState().Y > ((int)(1275 * GraphicScale)) && Mouse.GetState().Y < ((int)(1425 * GraphicScale))) { SelectedPos = 16; } else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(1275 * GraphicScale)) && Mouse.GetState().Y < ((int)(1425 * GraphicScale))) { SelectedPos = 17; } else if (Mouse.GetState().X > ((int)(1275 * GraphicScale)) && Mouse.GetState().X < ((int)(1425 * GraphicScale)) && Mouse.GetState().Y > ((int)(1275 * GraphicScale)) && Mouse.GetState().Y < ((int)(1425 * GraphicScale))) { SelectedPos = 18; } else if (Mouse.GetState().X > ((int)(375 * GraphicScale)) && Mouse.GetState().X < ((int)(525 * GraphicScale)) && Mouse.GetState().Y > ((int)(1475 * GraphicScale)) && Mouse.GetState().Y < ((int)(1625 * GraphicScale))) { SelectedPos = 19; } else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(1475 * GraphicScale)) && Mouse.GetState().Y < ((int)(1625 * GraphicScale))) { SelectedPos = 20; } else if (Mouse.GetState().X > ((int)(1475 * GraphicScale)) && Mouse.GetState().X < ((int)(1625 * GraphicScale)) && Mouse.GetState().Y > ((int)(1475 * GraphicScale)) && Mouse.GetState().Y < ((int)(1625 * GraphicScale))) { SelectedPos = 21; } else if (Mouse.GetState().X > ((int)(175 * GraphicScale)) && Mouse.GetState().X < ((int)(325 * GraphicScale)) && Mouse.GetState().Y > ((int)(1675 * GraphicScale)) && Mouse.GetState().Y < ((int)(1825 * GraphicScale))) { SelectedPos = 22; } else if (Mouse.GetState().X > ((int)(925 * GraphicScale)) && Mouse.GetState().X < ((int)(1075 * GraphicScale)) && Mouse.GetState().Y > ((int)(1675 * GraphicScale)) && Mouse.GetState().Y < ((int)(1825 * GraphicScale))) { SelectedPos = 23; } else if (Mouse.GetState().X > ((int)(1675 * GraphicScale)) && Mouse.GetState().X < ((int)(1825 * GraphicScale)) && Mouse.GetState().Y > ((int)(1675 * GraphicScale)) && Mouse.GetState().Y < ((int)(1825 * GraphicScale))) { SelectedPos = 24; } #endregion } base.Update(gameTime); } /// /// This is called when the game should draw itself. /// /// Provides a snapshot of timing values. protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here spriteBatch.Begin(); spriteBatch.Draw(Board, BoardRect, Color.Yellow); #region Figure drawing // First line if (FigurePlacement[0, 0] == '1') { FigurePosition.X = (int)(250 * GraphicScale); FigurePosition.Y = (int)(250 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color , 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[0, 0] == '2') { FigurePosition.X = (int)(250 * GraphicScale); FigurePosition.Y = (int)(250 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[3, 0] == '1') { FigurePosition.X = (int)(1000 * GraphicScale); FigurePosition.Y = (int)(250 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[3, 0] == '2') { FigurePosition.X = (int)(1000 * GraphicScale); FigurePosition.Y = (int)(250 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[6, 0] == '1') { FigurePosition.X = (int)(1750 * GraphicScale); FigurePosition.Y = (int)(250 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[6, 0] == '2') { FigurePosition.X = (int)(1750 * GraphicScale); FigurePosition.Y = (int)(250 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } // Second line if (FigurePlacement[1, 1] == '1') { FigurePosition.X = (int)(450 * GraphicScale); FigurePosition.Y = (int)(450 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[1, 1] == '2') { FigurePosition.X = (int)(450 * GraphicScale); FigurePosition.Y = (int)(450 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[3, 1] == '1') { FigurePosition.X = (int)(1000 * GraphicScale); FigurePosition.Y = (int)(450 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[3, 1] == '2') { FigurePosition.X = (int)(1000 * GraphicScale); FigurePosition.Y = (int)(450 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[5, 1] == '1') { FigurePosition.X = (int)(1550 * GraphicScale); FigurePosition.Y = (int)(450 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[5, 1] == '2') { FigurePosition.X = (int)(1550 * GraphicScale); FigurePosition.Y = (int)(450 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } // 3rd line if (FigurePlacement[2, 2] == '1') { FigurePosition.X = (int)(650 * GraphicScale); FigurePosition.Y = (int)(650 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[2, 2] == '2') { FigurePosition.X = (int)(650 * GraphicScale); FigurePosition.Y = (int)(650 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[3, 2] == '1') { FigurePosition.X = (int)(1000 * GraphicScale); FigurePosition.Y = (int)(650 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[3, 2] == '2') { FigurePosition.X = (int)(1000 * GraphicScale); FigurePosition.Y = (int)(650 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[4, 2] == '1') { FigurePosition.X = (int)(1350 * GraphicScale); FigurePosition.Y = (int)(650 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[4, 2] == '2') { FigurePosition.X = (int)(1350 * GraphicScale); FigurePosition.Y = (int)(650 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } // 4th line if (FigurePlacement[0, 3] == '1') { FigurePosition.X = (int)(250 * GraphicScale); FigurePosition.Y = (int)(1000 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[0, 3] == '2') { FigurePosition.X = (int)(250 * GraphicScale); FigurePosition.Y = (int)(1000 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[1, 3] == '1') { FigurePosition.X = (int)(450 * GraphicScale); FigurePosition.Y = (int)(1000 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[1, 3] == '2') { FigurePosition.X = (int)(450 * GraphicScale); FigurePosition.Y = (int)(1000 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[2, 3] == '1') { FigurePosition.X = (int)(650 * GraphicScale); FigurePosition.Y = (int)(1000 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[2, 3] == '2') { FigurePosition.X = (int)(650 * GraphicScale); FigurePosition.Y = (int)(1000 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[4, 3] == '1') { FigurePosition.X = (int)(1350 * GraphicScale); FigurePosition.Y = (int)(1000 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[4, 3] == '2') { FigurePosition.X = (int)(1350 * GraphicScale); FigurePosition.Y = (int)(1000 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[5, 3] == '1') { FigurePosition.X = (int)(1550 * GraphicScale); FigurePosition.Y = (int)(1000 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[5, 3] == '2') { FigurePosition.X = (int)(1550 * GraphicScale); FigurePosition.Y = (int)(1000 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[6, 3] == '1') { FigurePosition.X = (int)(1750 * GraphicScale); FigurePosition.Y = (int)(1000 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[6, 3] == '2') { FigurePosition.X = (int)(1750 * GraphicScale); FigurePosition.Y = (int)(1000 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } // 5th line if (FigurePlacement[2, 4] == '1') { FigurePosition.X = (int)(650 * GraphicScale); FigurePosition.Y = (int)(1350 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[2, 4] == '2') { FigurePosition.X = (int)(650 * GraphicScale); FigurePosition.Y = (int)(1350 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[3, 4] == '1') { FigurePosition.X = (int)(1000 * GraphicScale); FigurePosition.Y = (int)(1350 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[3, 4] == '2') { FigurePosition.X = (int)(1000 * GraphicScale); FigurePosition.Y = (int)(1350 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[4, 4] == '1') { FigurePosition.X = (int)(1350 * GraphicScale); FigurePosition.Y = (int)(1350 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[4, 4] == '2') { FigurePosition.X = (int)(1350 * GraphicScale); FigurePosition.Y = (int)(1350 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } // 6th line if (FigurePlacement[1, 5] == '1') { FigurePosition.X = (int)(450 * GraphicScale); FigurePosition.Y = (int)(1550 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[1, 5] == '2') { FigurePosition.X = (int)(450 * GraphicScale); FigurePosition.Y = (int)(1550 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[3, 5] == '1') { FigurePosition.X = (int)(1000 * GraphicScale); FigurePosition.Y = (int)(1550 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[3, 5] == '2') { FigurePosition.X = (int)(1000 * GraphicScale); FigurePosition.Y = (int)(1550 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[5, 5] == '1') { FigurePosition.X = (int)(1550 * GraphicScale); FigurePosition.Y = (int)(1550 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[5, 5] == '2') { FigurePosition.X = (int)(1550 * GraphicScale); FigurePosition.Y = (int)(1550 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } // Last line if (FigurePlacement[0, 6] == '1') { FigurePosition.X = (int)(250 * GraphicScale); FigurePosition.Y = (int)(1750 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[0, 6] == '2') { FigurePosition.X = (int)(250 * GraphicScale); FigurePosition.Y = (int)(1750 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[3, 6] == '1') { FigurePosition.X = (int)(1000 * GraphicScale); FigurePosition.Y = (int)(1750 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[3, 6] == '2') { FigurePosition.X = (int)(1000 * GraphicScale); FigurePosition.Y = (int)(1750 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[6, 6] == '1') { FigurePosition.X = (int)(1750 * GraphicScale); FigurePosition.Y = (int)(1750 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player1Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } if (FigurePlacement[6, 6] == '2') { FigurePosition.X = (int)(1750 * GraphicScale); FigurePosition.Y = (int)(1750 * GraphicScale); spriteBatch.Draw(Figure, FigurePosition, null, Player2Color, 0.0f, FigureOffset, (float)GraphicScale, SpriteEffects.None, 0); } #endregion spriteBatch.End(); base.Draw(gameTime); } }}
    [/spoiler]

    I wasn't that young anymore. I just finished high school and entered faculty (college, if you like). I learned QBasic, (Turbo) Pascal, Visual Basic and C# until that point and I was comfortable with Trigger Editor in WarCraft 3 World Editor. So, I have full right to ask this: "WHAT THE HELL WAS I THINKING!!!"

    Year 2011: Arkanoid

    (more like "Half Pong")

    6gvreo.jpg

    This one is also uncomplete. Written with C# (.NET 4.0) and XNA 4.0, I managed to get the basics (paddle moving and ball bouncing) before giving up for some reason. I think the reason was making the collision detection work the way I imagined it. While many people finished it (most recent example being superman3275), I decided to skip it... for now.

    Code is actually quite clean, however I think I made it more complicated than I should:
    [spoiler]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 Arkanoid{ /// /// This is the main type for your game /// public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; //variable private Texture2D Background; private Rectangle BackgroundRect; private Texture2D Bat; private Rectangle BatBorder; private Texture2D Ball; private Vector2 BallCenter; private Vector2 BallOffset; private bool BallLaunch; private double BallAngle; private int BallSpeed; private int BallRadius; private Texture2D Brick; private Rectangle[] BrickBorder = new Rectangle[30]; private double x; private Point Helper; public Game1() { graphics = new GraphicsDeviceManager(this); graphics.GraphicsProfile = GraphicsProfile.Reach; Content.RootDirectory = "Content"; } /// /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// protected override void Initialize() { // TODO: Add your initialization logic here graphics.PreferredBackBufferWidth = 500; graphics.PreferredBackBufferHeight = 600; graphics.ApplyChanges(); base.Initialize(); } /// /// LoadContent will be called once per game and is the place to load /// all of your content. /// protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here Bat = Content.Load("Textures/Bat"); BatBorder.Width = Bat.Width / 4; BatBorder.Height = 15; BatBorder.X = graphics.PreferredBackBufferWidth / 2 - Bat.Width / 8; BatBorder.Y = 550; Ball = Content.Load("Textures/Ball"); BallRadius = 10; BallOffset.X = Ball.Bounds.Center.X; BallOffset.Y = Ball.Bounds.Center.Y; BallCenter.X = graphics.PreferredBackBufferWidth / 2; BallCenter.Y = BatBorder.Y - BallRadius - 1; BallAngle = Math.PI * 5 / 4; BallSpeed = 2; BallLaunch = false; } /// /// UnloadContent will be called once per game and is the place to unload /// all content. /// protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } /// /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// /// Provides a snapshot of timing values. protected override void Update(GameTime gameTime) { // Allows the game to exit if (Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit(); // TODO: Add your update logic here #region Bat movement if ((Keyboard.GetState().IsKeyDown(Keys.Left)) && (BatBorder.Left >= 0)) { BatBorder.X -= 5; if (BallLaunch == false) { BallAngle = Math.PI * 5 / 4; BallCenter.X -= 5; } } if ((Keyboard.GetState().IsKeyDown(Keys.Right)) && (BatBorder.Right <= graphics.PreferredBackBufferWidth)) { BatBorder.X += 5; if (BallLaunch == false) { BallAngle = Math.PI * 7 / 4; BallCenter.X += 5; } } if (Keyboard.GetState().IsKeyDown(Keys.Space)) BallLaunch = true; #endregion #region Collision detection //Paziti na koordinatni sustav: ide CW, ne CCW kao inace //Znaci, 45? normalno je PI * 7 / 4 //Kolizija s rubom igraceg prostora if ((BallCenter.X <= BallRadius) || (BallCenter.X >= graphics.PreferredBackBufferWidth - BallRadius)) BallAngle = 3 * Math.PI - BallAngle; if (BallCenter.Y <= 10) BallAngle = 2 * Math.PI - BallAngle; #endregion //Pomak lopte if (BallLaunch) { for (x = 0; x <= BallSpeed; x++) { BallCenter.X += 1 / (float)Math.Cos(BallAngle); BallCenter.Y += 1 / (float)Math.Sin(BallAngle); //Kolizija if (((BallCenter.Y > (BatBorder.Top - BallRadius)) && (BallCenter.Y < (BatBorder.Bottom + BallRadius))) && ((BallCenter.X > (BatBorder.Left - BallRadius)) && (BallCenter.X < (BatBorder.Right + BallRadius)))) { BallAngle = 2 * Math.PI - BallAngle; break; } } } base.Update(gameTime); } /// /// This is called when the game should draw itself. /// /// Provides a snapshot of timing values. protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.DarkBlue); // TODO: Add your drawing code here spriteBatch.Begin(); spriteBatch.Draw(Bat, BatBorder, Color.LightGreen); spriteBatch.Draw(Ball, BallCenter, null, Color.Yellow, 0.0f, BallOffset, 0.05f, SpriteEffects.None, 1.0f); spriteBatch.End(); base.Draw(gameTime); } }}
    [/spoiler]

    Year 2012: Battle Tanks



    [sharedmedia=gallery:images:2885]

    This one should actually be familiar if you remember anything from my older journal entries. I won't ramble too much about it; based on "Box with barrel", it's actually the 2nd sensible thing I made after a huge gap and a huge step up. I slowly started to do actual object-oriented programming. I've wrote more about it in my earlier entries.

    For anyone interested in code:

    Game1 class:
    [spoiler]using System;using System.Collections.Generic;using System.Linq;using System.IO;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 Microsoft.Xna.Framework.Net;namespace BattleTanks{ /// /// This is the main type for your game /// public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } #region Variables Texture2D PlayableArea; Rectangle RectPlayable; Tank[] Tanks; Tile[] Metal; Tile[] Grass; Tile[] Water; Tile Castle; Player Player1; Player Player2; byte NumOpponents = 30; SpriteFont Font1; Vector2 Score1Text; Vector2 Score2Text; Vector2 NumberOppText; Vector2 P1LivesText; Vector2 P2LivesText; Vector2 EndText; Rectangle[] SpawnPoints; TimeSpan Time; byte PointBonus = 100; bool GameOver = false; bool Victory = false; #endregion /// /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// protected override void Initialize() { // TODO: Add your initialization logic here graphics.PreferredBackBufferWidth = 800; graphics.PreferredBackBufferHeight = 600; graphics.ApplyChanges(); base.Initialize(); } /// /// LoadContent will be called once per game and is the place to load /// all of your content. /// protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here // Load all textures PlayableArea = this.Content.Load("PlayableArea"); Font1 = this.Content.Load("Arial"); // Set up playable area RectPlayable.X = 0; RectPlayable.Y = 0; RectPlayable.Width = PlayableArea.Width; RectPlayable.Height = PlayableArea.Height; LevelLoad(); Player1 = new Player(); Player2 = new Player(); Player1.Initialize(Keys.Up, Keys.Down, Keys.Left, Keys.Right, Keys.Enter); Player2.Initialize(Keys.W, Keys.S, Keys.A, Keys.D, Keys.Space); Score1Text = new Vector2(610, 20); Score2Text = new Vector2(610, 70); NumberOppText = new Vector2(610, 150); P1LivesText = new Vector2(610, 300); P2LivesText = new Vector2(610, 330); EndText = new Vector2(RectPlayable.Center.X, RectPlayable.Center.Y); } /// /// UnloadContent will be called once per game and is the place to unload /// all content. /// protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } /// /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// /// Provides a snapshot of timing values. protected override void Update(GameTime gameTime) { // Allows the game to exit if (Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit(); // TODO: Add your update logic here if ((Player1.PlayerLives == 0) & (Player2.PlayerLives == 0)) { GameOver = true; Victory = false; } if (NumOpponents == 0) { GameOver = true; Victory = true; } if (GameOver == false) { Time = gameTime.TotalGameTime; TankRespawn(); #region Player 1 movement // Self explanatory if (Keyboard.GetState().IsKeyDown(Keys.Left)) { Tanks[0].MoveTank(true, -1, false); if (Collision(Tanks[0].TankHitbox, false, true)) Tanks[0].MoveTank(true, 1, true); } else if (Keyboard.GetState().IsKeyDown(Keys.Right)) { Tanks[0].MoveTank(true, 1, false); if (Collision(Tanks[0].TankHitbox, false, true)) Tanks[0].MoveTank(true, -1, true); } else if (Keyboard.GetState().IsKeyDown(Keys.Up)) { Tanks[0].MoveTank(false, -1, false); if (Collision(Tanks[0].TankHitbox, false, true)) Tanks[0].MoveTank(false, 1, true); } else if (Keyboard.GetState().IsKeyDown(Keys.Down)) { Tanks[0].MoveTank(false, 1, false); if (Collision(Tanks[0].TankHitbox, false, true)) Tanks[0].MoveTank(false, -1, true); } if ((Keyboard.GetState().IsKeyDown(Keys.Enter)) && (Tanks[0].BulletLaunched == false)) { Tanks[0].LaunchBullet(); } if (Tanks[0].BulletLaunched) { if (Collision(Tanks[0].BulletHitBox, true, true) == true) Tanks[0].RemoveBullet(); else Tanks[0].MoveBullet(); } #endregion #region Player 2 movement // Self explanatory if (Keyboard.GetState().IsKeyDown(Keys.A)) { Tanks[1].MoveTank(true, -1, false); if (Collision(Tanks[1].TankHitbox, false, true)) Tanks[1].MoveTank(true, 1, true); } else if (Keyboard.GetState().IsKeyDown(Keys.D)) { Tanks[1].MoveTank(true, 1, false); if (Collision(Tanks[1].TankHitbox, false, true)) Tanks[1].MoveTank(true, -1, true); } else if (Keyboard.GetState().IsKeyDown(Keys.W)) { Tanks[1].MoveTank(false, -1, false); if (Collision(Tanks[1].TankHitbox, false, true)) Tanks[1].MoveTank(false, 1, true); } else if (Keyboard.GetState().IsKeyDown(Keys.S)) { Tanks[1].MoveTank(false, 1, false); if (Collision(Tanks[1].TankHitbox, false, true)) Tanks[1].MoveTank(false, -1, true); } if ((Keyboard.GetState().IsKeyDown(Keys.Space)) && (Tanks[1].BulletLaunched == false)) { Tanks[1].LaunchBullet(); } if (Tanks[1].BulletLaunched) { if (Collision(Tanks[1].BulletHitBox, true, true) == true) Tanks[1].RemoveBullet(); else Tanks[1].MoveBullet(); } #endregion #region AI movement bool axis; int dir; string srdir; for (int x = 2; x < Tanks.Length; x++) { if (Tanks[x].TankDestroyed == false) { // Determine direction for movement Tanks[x].RotateAI(out axis, out dir, out srdir); // Move AI tank Tanks[x].MoveTank(axis, dir, false); // If collided with something, reposition tank properly and determine new direction if (Collision(Tanks[x].TankHitbox, false, false)) { Tanks[x].MoveTank(axis, -1 * dir, true); Tanks[x].TurnAI(srdir); } // Fire bullet if (Tanks[x].BulletLaunched == false) Tanks[x].FireAI(); } if (Tanks[x].BulletLaunched) { if (Collision(Tanks[x].BulletHitBox, true, false) == true) Tanks[x].RemoveBullet(); else Tanks[x].MoveBullet(); } } #endregion if (Keyboard.GetState().IsKeyDown(Keys.F1)) Player1.PlayerLives = 99; if (Keyboard.GetState().IsKeyDown(Keys.F2)) Player2.PlayerLives = 99; } base.Update(gameTime); } /// /// This is called when the game should draw itself. /// /// Provides a snapshot of timing values. protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.LightGray); // TODO: Add your drawing code here spriteBatch.Begin(); // Draw area spriteBatch.Draw(PlayableArea, RectPlayable, Color.White); if (GameOver == false) { for (int x = 0; x < Water.Length; x++) Water[x].Draw(spriteBatch); // Draw tanks and respective bullets for (int x = 0; x < Tanks.Length; x++) Tanks[x].Draw(spriteBatch); // Draw tiles walls Castle.Draw(spriteBatch); for (int x = 0; x < Metal.Length; x++) Metal[x].Draw(spriteBatch); for (int x = 0; x < Grass.Length; x++) Grass[x].Draw(spriteBatch); } if (GameOver == true) { if (Victory == true) spriteBatch.DrawString(Font1, "VICTORY!", EndText, Color.Red); else spriteBatch.DrawString(Font1, "GAME OVER!", EndText, Color.Red); } // Draw text string output; output = "Player 1 score: \n" + Player1.Score.ToString(); spriteBatch.DrawString(Font1, output, Score1Text, Color.Black); output = "Player 2 score: \n" + Player2.Score.ToString(); spriteBatch.DrawString(Font1, output, Score2Text, Color.Black); output = "Remaining Enemies: " + NumOpponents.ToString(); spriteBatch.DrawString(Font1, output, NumberOppText, Color.Black); output = "Player 1 lives: " + Player1.PlayerLives.ToString(); spriteBatch.DrawString(Font1, output, P1LivesText, Color.Black); output = "Player 2 lives: " + Player2.PlayerLives.ToString(); spriteBatch.DrawString(Font1, output, P2LivesText, Color.Black); spriteBatch.End(); base.Draw(gameTime); } public bool Collision(Rectangle Object, bool Projectile, bool PlayerTank) { // Is inside playing field? if (RectPlayable.Contains(Object) == false) return true; // Interaction between bullets and tanks for (int x = 0; x < Tanks.Length; x++) { if (Projectile) { // Collision between 2 bullets if ((Object != Tanks[x].BulletHitBox) & (Object.Intersects(Tanks[x].BulletHitBox))) { Tanks[x].RemoveBullet(); return true; } // Bullet hits tank if ((Object != Tanks[x].BulletHitBox) & (PlayerTank != Tanks[x].PlayerBullet) & (Object.Intersects(Tanks[x].TankHitbox))) { if (x == 0) Player1.PlayerDied(); else if (x == 1) Player2.PlayerDied(); else if (Object == Tanks[0].BulletHitBox) { Player1.PlayerKilled(PointBonus); --NumOpponents; } else if (Object == Tanks[1].BulletHitBox) { Player2.PlayerKilled(PointBonus); --NumOpponents; } Tanks[x].RemoveTank(Time); return true; } if ((Object != Tanks[x].BulletHitBox) & (Object.Intersects(Castle.TileRectangle))) GameOver = true; } // Bullet and tank collides with any tank if ((Object != Tanks[x].TankHitbox) & (!Object.Contains(Tanks[x].BulletHitBox)) & (Object.Intersects(Tanks[x].TankHitbox))) return true; } // Bullet and tank collides with metal for (int x = 0; x < Metal.Length; x++) if (Object.Intersects(Metal[x].TileRectangle)) return true; // Tank collides with water for (int x = 0; x < Water.Length; x++) if ((Object.Intersects(Water[x].TileRectangle)) && (Projectile == false)) return true; return false; } void LevelLoad() { string path = @"..\..\..\level1.txt"; int metalnum, grassnum, waternum, spawnnum; string[] level = new string[15]; // Read level using (StreamReader sr = File.OpenText(path)) { for (int i = 0; i < level.Length; i++) { level = sr.ReadLine(); } } metalnum = 0; grassnum = 0; waternum = 0; spawnnum = 2; for (int x = 0; x < level.Length; x++) { for (int y = 0; y < level[x].Length; y++) { if (level[x][y] == 'M') metalnum++; if (level[x][y] == 'B') metalnum++; if (level[x][y] == 'G') grassnum++; if (level[x][y] == 'W') waternum++; if (level[x][y] == 'S') spawnnum++; } } Metal = new Tile[metalnum]; Grass = new Tile[grassnum]; Water = new Tile[waternum]; Tanks = new Tank[spawnnum]; SpawnPoints = new Rectangle[spawnnum]; metalnum = 0; grassnum = 0; waternum = 0; spawnnum = 2; #region Tile placement for (int x = 0; x < level.Length; x++) { for (int y = 0; y < level[x].Length; y++) { switch (level[x][y]) { case 'M': { Metal[metalnum] = new Tile(); Metal[metalnum].LoadContent(this.Content, "Metal"); Metal[metalnum].Initialize(y * 40, x * 40, 0.1f); metalnum++; break; } case 'B': { Metal[metalnum] = new Tile(); Metal[metalnum].LoadContent(this.Content, "Brick"); Metal[metalnum].Initialize(y * 40, x * 40, 0.2f); metalnum++; break; } case 'G': { Grass[grassnum] = new Tile(); Grass[grassnum].LoadContent(this.Content, "Grass"); Grass[grassnum].Initialize(y * 40, x * 40, 0.2f); grassnum++; break; } case 'W': { Water[waternum] = new Tile(); Water[waternum].LoadContent(this.Content, "Water"); Water[waternum].Initialize(y * 40, x * 40, 0.2f); waternum++; break; } case '1': { SpawnPoints[0].Width = 40; SpawnPoints[0].Height = 40; SpawnPoints[0].Y = x * SpawnPoints[0].Width; SpawnPoints[0].X = y * SpawnPoints[0].Height; break; } case '2': { SpawnPoints[1].Width = 40; SpawnPoints[1].Height = 40; SpawnPoints[1].Y = x * SpawnPoints[1].Width; SpawnPoints[1].X = y * SpawnPoints[1].Height; break; } case 'C': { Castle = new Tile(); Castle.LoadContent(this.Content, "Castle"); Castle.Initialize(y * 40, x * 40, 0.1f); break; } case 'S': { SpawnPoints[spawnnum].Width = 40; SpawnPoints[spawnnum].Height = 40; SpawnPoints[spawnnum].Y = x * SpawnPoints[spawnnum].Width; SpawnPoints[spawnnum].X = y * SpawnPoints[spawnnum].Height; spawnnum++; break; } } } } #endregion #region Spawn Tanks for (int x = 0; x < Tanks.Length; x++) { Tanks[x] = new Tank(); if (x == 0) Tanks[x].LoadContent(this.Content, "Player1", "Bullet"); else if (x == 1) Tanks[x].LoadContent(this.Content, "Player2", "Bullet"); else Tanks[x].LoadContent(this.Content, "AITank", "Bullet"); if (x == 0) Tanks[x].Initialize(SpawnPoints[x].X, SpawnPoints[x].Y, 0, 0.4f, 2, true); else if (x == 1) Tanks[x].Initialize(SpawnPoints[x].X, SpawnPoints[x].Y, 0, 0.4f, 2, true); else Tanks[x].Initialize(SpawnPoints[x].X, SpawnPoints[x].Y, (float)Math.PI, 0.4f, 1, false); } #endregion } void TankRespawn() { bool OnSpawn; for (int x = 0; x < Tanks.Length; x++) { OnSpawn = false; for (int y = 0; y < Tanks.Length; y++) if ((Tanks[x].TankDestroyed) & (SpawnPoints[x].Intersects(Tanks[y].TankHitbox))) OnSpawn = true; if ((Tanks[x].TankDestroyed) & (!OnSpawn) & (Time.TotalSeconds - Tanks[x].TimeDestroyed.TotalSeconds >= 5)) { Tanks[x] = new Tank(); if ((x == 0) & (Player1.PlayerLives > 0)) Tanks[x].LoadContent(this.Content, "Player1", "Bullet"); else if ((x == 1) & (Player2.PlayerLives > 0)) Tanks[x].LoadContent(this.Content, "Player2", "Bullet"); else if (NumOpponents > 1) Tanks[x].LoadContent(this.Content, "AITank", "Bullet"); if ((x == 0) & (Player1.PlayerLives > 0)) Tanks[x].Initialize(SpawnPoints[x].X, SpawnPoints[x].Y, 0, 0.4f, 2, true); else if ((x == 1) & (Player2.PlayerLives > 0)) Tanks[x].Initialize(SpawnPoints[x].X, SpawnPoints[x].Y, 0, 0.4f, 2, true); else if (NumOpponents > 1) Tanks[x].Initialize(SpawnPoints[x].X, SpawnPoints[x].Y, (float)Math.PI, 0.4f, 1, false); } } } }}
    [/spoiler]

    Player class:
    [spoiler]using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.Xna.Framework;using Microsoft.Xna.Framework.Input;namespace BattleTanks{ class Player { private Keys MoveUp; private Keys MoveDown; private Keys MoveLeft; private Keys MoveRight; private Keys Fire; public byte PlayerLives; public UInt32 Score; public float ScoreMultiplier; public void Initialize(Keys Up, Keys Down, Keys Left, Keys Right, Keys Shoot) { // This part is currently useless MoveUp = Up; MoveDown = Down; MoveLeft = Left; MoveRight = Right; Fire = Shoot; PlayerLives = 3; Score = 0; ScoreMultiplier = 1.0f; } public void PlayerDied() { PlayerLives--; ScoreMultiplier = 1.0f; } public void PlayerKilled(byte Points) { Score += (UInt32)(Points * ScoreMultiplier); ScoreMultiplier += 0.1f; } }}
    [/spoiler]

    Tank class:
    [spoiler]using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.Xna.Framework;using Microsoft.Xna.Framework.Content;using Microsoft.Xna.Framework.Graphics;namespace BattleTanks{ class Tank { // Textures private Texture2D TankTexture; private Texture2D BulletTexture; // Tank parameters public Rectangle TankHitbox; public bool TankDestroyed; public TimeSpan TimeDestroyed; private Vector2 TankPosition; private Vector2 TankOrigin; private float TankRotation; private float TankScale; private int TankSpeed; // Bullet parameters public Rectangle BulletHitBox; public bool BulletLaunched = false; public bool PlayerBullet; private Vector2 BulletPosition; private Vector2 BulletOrigin; private int BulletSpeed = 5; private float BulletScale; private float BulletRotation; // AI parameters private int chanceTop; private int chanceLeft; private int chanceBottom; private int chanceRight; private int chanceFire = 50; private Random rnd; // Load all required content public void LoadContent(ContentManager content, string TankAssetName, string BulletAssetName) { TankTexture = content.Load(TankAssetName); BulletTexture = content.Load(BulletAssetName); } // Draw sprites public void Draw(SpriteBatch spriteBatch) { if (BulletLaunched) spriteBatch.Draw(BulletTexture, BulletPosition, null, Color.White, BulletRotation, BulletOrigin, BulletScale, SpriteEffects.None, 0); if (TankDestroyed == false) spriteBatch.Draw(TankTexture, TankPosition, null, Color.White, TankRotation, TankOrigin, TankScale, SpriteEffects.None, 0); } public void Initialize(int X, int Y, float rotation, float scaling, int speed, bool playerbullet) { // Tank properties TankRotation = rotation; TankScale = scaling; TankHitbox.X = X + 4; TankHitbox.Y = Y + 4; TankHitbox.Width = (int)(TankTexture.Width * scaling) - 8; TankHitbox.Height = (int)(TankTexture.Height * scaling) - 8; TankPosition.X = TankHitbox.Center.X; TankPosition.Y = TankHitbox.Center.Y; TankOrigin.X = TankTexture.Bounds.Center.X; TankOrigin.Y = TankTexture.Bounds.Center.Y; TankSpeed = speed; TankDestroyed = false; // Randomize rnd = new Random(); chanceBottom = 25; chanceLeft = 25; chanceRight = 25; chanceTop = 25; PlayerBullet = playerbullet; } public void MoveTank(bool HorAxis, int direction, bool cancel) { if (HorAxis) { // Moves tank on horizontal axis TankHitbox.X += TankSpeed * direction; TankPosition.X += TankSpeed * direction; if (!cancel) { if (direction < 0) TankRotation = 3 * (float)Math.PI / 2; if (direction > 0) TankRotation = (float)Math.PI / 2; } } else { // Moves tank on vertical axis TankHitbox.Y += TankSpeed * direction; TankPosition.Y += TankSpeed * direction; if (!cancel) { if (direction < 0) TankRotation = 0; if (direction > 0) TankRotation = (float)Math.PI; } } } public void RemoveTank(TimeSpan time) { TimeDestroyed = time; TankDestroyed = true; TankHitbox.X = 0; TankHitbox.Y = 0; TankHitbox.Width = 0; TankHitbox.Height = 0; } public void MoveBullet() { // Self explanatory if (BulletRotation == 0) { BulletHitBox.Y -= BulletSpeed; BulletPosition.Y -= BulletSpeed; } if (BulletRotation == (float)Math.PI / 2) { BulletHitBox.X += BulletSpeed; BulletPosition.X += BulletSpeed; } if (BulletRotation == (float)Math.PI) { BulletHitBox.Y += BulletSpeed; BulletPosition.Y += BulletSpeed; } if (BulletRotation == 3 * (float)Math.PI / 2) { BulletHitBox.X -= BulletSpeed; BulletPosition.X -= BulletSpeed; } } public void LaunchBullet() { // Creates and launches new bullet BulletScale = TankScale / 4; if ((TankRotation == 0) || (TankRotation == (float)Math.PI)) { BulletHitBox.Width = (int)(BulletTexture.Bounds.Width * BulletScale); BulletHitBox.Height = (int)(BulletTexture.Bounds.Height * BulletScale); } else { BulletHitBox.Width = (int)(BulletTexture.Bounds.Height * BulletScale); BulletHitBox.Height = (int)(BulletTexture.Bounds.Width * BulletScale); } BulletOrigin.X = BulletTexture.Bounds.Center.X; BulletOrigin.Y = BulletTexture.Bounds.Center.Y; BulletHitBox.X = TankHitbox.Center.X - BulletHitBox.Width / 2; BulletHitBox.Y = TankHitbox.Center.Y - BulletHitBox.Height / 2; BulletPosition.X = BulletHitBox.Center.X; BulletPosition.Y = BulletHitBox.Center.Y; BulletRotation = TankRotation; BulletLaunched = true; } public string BulletDirection() { // Returns bullet's current direction if (BulletRotation == 0) return "Up"; if (BulletRotation == (float)Math.PI / 2) return "Right"; if (BulletRotation == (float)Math.PI) return "Down"; if (BulletRotation == 3 * (float)Math.PI / 2) return "Left"; return null; } public void RemoveBullet() { BulletLaunched = false; BulletHitBox.X = 0; BulletHitBox.Y = 0; BulletHitBox.Width = 0; BulletHitBox.Height = 0; } public void RotateAI(out bool HorAxis, out int direction, out string text) { int dir; int left = chanceTop + chanceLeft; int bot = left + chanceBottom; HorAxis = false; direction = 0; text = null; dir = rnd.Next(0, 100); // Determine direction if ((0 < dir) & (dir <= chanceTop)) TankRotation = 0; if ((chanceTop < dir) & (dir <= left)) TankRotation = 3 * (float)Math.PI / 2; if ((left < dir) & (dir <= bot)) TankRotation = (float)Math.PI; if ((bot < dir) & (dir <= 100)) TankRotation = (float)Math.PI / 2; // Adjust direction priorities - currently moving direction has top priority if (TankRotation == 0) { HorAxis = false; direction = -1; text = "Up"; chanceTop = 97; chanceLeft = 1; chanceRight = 1; chanceBottom = 1; } if (TankRotation == (float)Math.PI / 2) { HorAxis = true; direction = 1; text = "Right"; chanceTop = 1; chanceLeft = 1; chanceRight = 97; chanceBottom = 1; } if (TankRotation == (float)Math.PI) { HorAxis = false; direction = 1; text = "Down"; chanceTop = 1; chanceLeft = 1; chanceRight = 1; chanceBottom = 97; } if (TankRotation == 3 * (float)Math.PI / 2) { HorAxis = true; direction = -1; text = "Left"; chanceTop = 1; chanceLeft = 97; chanceRight = 1; chanceBottom = 1; } } public void FireAI() { // AI fires bullet if (rnd.Next(0, 100) >= chanceFire) { LaunchBullet(); } } public void TurnAI(string direction) { // Changes priorities for direction switch (direction) { case "Left": { chanceTop = 32; chanceLeft = 4; chanceRight = 32; chanceBottom = 32; break; } case "Right": { chanceTop = 32; chanceLeft = 32; chanceRight = 4; chanceBottom = 32; break; } case "Up": { chanceTop = 4; chanceLeft = 32; chanceRight = 32; chanceBottom = 32; break; } case "Down": { chanceTop = 32; chanceLeft = 32; chanceRight = 32; chanceBottom = 4; break; } } } }}
    [/spoiler]

    Year 2013: Battle City



    6ymgbl.jpg

    Upgrade of Battle Tanks. I'm still working on it - on both code and art. I won't ramble much about it here, and just add: powerups are added.

    Now, take the picture above and compare it with this:
    30uzb14.jpg

    However, the biggest step is not the art - it's the code. Up to the Battle Tanks, I used strictly arrays and simple structures/classes and used only main class (the one automatically created with project), with a lot of copy/pasting, bad code etc. Now, with Battle City, I finally stepped - at least with one leg - into "true" object oriented programming. Skills I learned here helped me to deal with other tasks faster and easier. For example, laboratory tasks (like writing Finite State Machine) took no longer than 20 minutes of writing and debugging.

    Battle City is nowhere near completition, but here are code metrics for current state:

    • Maintanability Index: 78
    • Cyclomatic Complexity: 873
    • Depth of Inheritance: 3
    • Class Coupling: 85
    • Lines of Code: 2025

      If you wish to try it, head to my last entry and grab the attachement. That version doesn't have powerups but is still playable; I'd appreciate a feedback. I hope I'll be able to provide better version soon enough.

      I hope this little trip to the past was at least a little interesting. If nothing, I'll have this journal preserving my memories and as a reminder how I was before as a programmer.

      Thanks for reading and, I hope, see you in next entry.
Sign in to follow this  


4 Comments


Recommended Comments

Interesting read, makes me wish I still had more of my own early experiments -- alas, most are lost, and those that remain are on a hard disk that I've been meaning to retrieve the data from "sometime soon" for almost a year now.

 

Battle City is certainly an upgrade from your first Battle Tanks!

Share this comment


Link to comment

I like the remake of Duck Hunter and Battle Tank. They both take me back in time and drive me to play them. smile.png

Sadly I have lost a lot of old material due to my latest move.

Share this comment


Link to comment

Surprisingly, most of my early programming projects and experiments have in fact survived despite me being rather unorganized, and are currently sitting on my desk :) but if I knew I was going to be reading them a few years later.. from now on I'll inline little comment blocks in my code saying hello to future me.

 

That said if you're anything like me, your projects folder contains a large number of unfinished projects and an even larger number of projects where development never actually started (the IDE files set up, and perhaps a text file with a couple sentences jotted down hastily, but no actual code)

 

yeah.. those were good times.. strong nostalgia for sure ^_^

Share this comment


Link to comment

Thanks for comments :D

 

Navyman, I'll upload soon (probably in a week or two) improved version (one with powerups) so you can try it :D It won't be complete product, but at least it would be more playable than the version from my last entry...

Speaking of which, 14 downloads and 0 feedback... maybe I should've specified how to contact me, I expected feedback in comments...

 

Bacterius, I actually don't start most things until I have something to write, so my Projects is actually kinda empty. 2 unfinished projects (Battle Tanks and one Windows Phone app for Best Code Challenge tournament which was a little too difficult for me), Battle City and college lab assignments. I actually had "Element Fight" in plan (stickman in various colors representing elements fighting; basically Poor Man's Street Fighter) which I started... and never went beyond first Switch for game states XD

 

Maybe I also remake Boulder Dash over the summer... depending on how far my siblings (specifically my sister whos hobby is drawing) go with an art (I'll work on code and mechanics).

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now