Advertisement Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    6
  • comments
    86
  • views
    1827

About this blog

warlords

Entries in this blog

 

c# tic tac toe game

here is my code for my tic tac toe game, I am still working on the computer player. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace wintictactoe { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } int [,] board_x=new int[3,3]; int[,] board_o = new int[3, 3]; private void Form1_MouseDown(object sender, MouseEventArgs e) { if(e.Button == MouseButtons.Left) { Random rnd = new Random(); int col = rnd.Next(325, 476); int row = rnd.Next(200, 351); Graphics g1 = this.CreateGraphics(); if (e.X - 10 >= 325 && e.X - 10 <= 375 && e.Y - 10 >= 200 && e.Y - 10 <= 250) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 215)); board_x[0, 0] = 1; } if (e.X - 10 >= 375 && e.X - 10 <= 425 && e.Y - 10 >= 200 && e.Y - 10 <= 250) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 215)); board_x[0, 1] = 1; } if (e.X - 10 >= 425 && e.X - 10 <= 475 && e.Y - 10 >= 200 && e.Y - 10 <= 250) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 215)); board_x[0, 2] = 1; } if (e.X - 10 >= 325 && e.X - 10 <= 375 && e.Y - 10 >= 250 && e.Y - 10 <= 300) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 260)); board_x[1, 0] = 1; } if (e.X - 10 >= 375 && e.X - 10 <= 425 && e.Y - 10 >= 250 && e.Y - 10 <= 300) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 260)); board_x[1, 1] = 1; } if (e.X - 10 >= 425 && e.X - 10 <= 475 && e.Y - 10 >= 250 && e.Y - 10 <= 300) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 260)); board_x[1, 2] = 1; } if (e.X - 10 >= 325 && e.X - 10 <= 375 && e.Y - 10 >= 300 && e.Y - 10 <= 350) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 315)); board_x[2, 0] = 1; } if (e.X - 10 >= 375 && e.X - 10 <= 425 && e.Y - 10 >= 300 && e.Y - 10 <= 350) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 315)); board_x[2, 1] = 1; } if (e.X - 10 >= 425 && e.X - 10 <= 475 && e.Y - 10 >= 300 && e.Y - 10 <= 350) { g1.DrawString("X", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 315)); board_x[2, 2] = 1; } if (col >= 325 && col <= 375 && row >= 200 && row <= 250) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 215)); board_o[0, 0] = 1; } if (col >= 375 && col <= 425 && row >= 200 && row <= 250) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 215)); board_o[0, 1] = 1; } if (col >= 425 && col <= 475 && row >= 200 && row <= 250) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 215)); board_o[0, 2] = 1; } if (col >= 325 && col <= 375 && row >= 250 && row <= 300) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 260)); board_o[1, 0] = 1; } if (col >= 375 && col <= 425 && row >= 250 && row <= 300) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 260)); board_o[1, 1] = 1; } if (col >= 425 && col <= 475 && row >= 250 && row <= 300) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 260)); board_o[1, 2] = 1; } if (col >= 325 && col <= 375 && row >= 300 && row <= 350) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(340, 315)); board_o[2, 0] = 1; } if (col >= 375 && col <= 425 && row >= 300 && row <= 350) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(390, 315)); board_o[2, 1] = 1; } if (col >= 425 && col <= 475 && row >= 300 && row <= 350) { g1.DrawString("O", new Font("Arial", 16), new SolidBrush(Color.Blue), new Point(440, 315)); board_o[2, 2] = 1; } g1.Dispose(); } } private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen redPen = new Pen(Color.Red,3); g.DrawLine(redPen, 375, 200, 375, 350); g.DrawLine(redPen, 425, 200, 425, 350); g.DrawLine(redPen, 325, 250, 475, 250); g.DrawLine(redPen, 325, 300, 475, 300); g.Dispose(); } } }  

phil67rpg

phil67rpg

 

c# pong game

I am working on a pong game using c# and gdi+. here is my code so far. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace winpong { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } int move = 0; float comp_move = 0.0f, comp_velocity = 1.0f, screen_height = 250.0f, flag = 0.0f; public void Form1_KeysDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Up)//key up { move-=5; if (move <= -250) { move = -250; } } if (e.KeyCode == Keys.Down)//key down { move+=5; if(move >= 210) { move = 210; } } Invalidate(); } private void timer1_Tick(object sender, EventArgs e) { comp_velocity = (comp_move < screen_height && flag == 0.0f) ? (comp_velocity = 5.0f) : (comp_velocity = -5.0f); comp_move = (comp_velocity == 5.0f) ? (comp_move += 5.0f) : (comp_move -= 5.0f); if(comp_move >= screen_height-40.0f) { flag = 1.0f; } if(comp_move <= -screen_height) { flag = 0.0f; } Invalidate(); } float x = 0.0f, y = 0.0f, xstep = 5.0f, ystep = 5.0f; private void timer2_Tick(object sender, EventArgs e) { if (x >= 395.0f || x <= -390.0f) { xstep = -xstep; } if (y >= 270.0f || y <= -290.0f) { ystep = -ystep; } x += xstep; y += ystep; Invalidate(); } public void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; SolidBrush blueBrush = new SolidBrush(Color.Blue); SolidBrush redBrush = new SolidBrush(Color.Red); SolidBrush whiteBrush = new SolidBrush(Color.White); RectangleF rect1 = new RectangleF(0, 250 + comp_move, 35, 100); //blue paddle Rectangle rect2 = new Rectangle(750, 250 + move, 35, 100); //red paddle RectangleF rect3 = new RectangleF(390+x, 290+y, 10, 10); //white ball g.FillRectangle(blueBrush, rect1); g.FillRectangle(redBrush, rect2); g.FillRectangle(whiteBrush, rect3); g.Dispose(); } } }  

phil67rpg

phil67rpg

 

1942 plane game

Well I have a peculiar problem. When I set my global variable screen=0.0f and I put my drawcollision_one() function in my display function it only draws a static collision sprite. However when I set my screen=0.0001f and I put my drawcollision_one() in my display function it draws an animated collision sprite. Also when I use my screen=-0.0f variable and I put my drawcollision_one() function in my collision detection function it draws a static collision sprite. However when I use my screen=0.0001f variable it does not draw anything when the drawcollision_one() function is in my collision detection function. What I want is to draw the animated collision sprite when the collision detection function is used. Let me know if you need further explanation.I am using freeglut 3.0.0 and SOIL in my program.

phil67rpg

phil67rpg

 

1943 Plane Game

I am still working on my 1943 plane game. I have got the one plane to move and shoot bullets in all directions. I am going to do the same for the second plane.

phil67rpg

phil67rpg

 

1945 game

I am still working on my 1945 plane game. I am stuck on how to rotate the bullet sprite around the plane sprite. I am using trig. functions and some linear algebra which is what I am taking in college classes. here is the code I am using. void drawbullet_one() { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture[2]); glPushMatrix(); glTranslatef(-5.0f, 0.5f, 0.0f); glBegin(GL_POLYGON); glTexCoord3f(0.0f, 0.0f, 0.0f); glVertex3f(0.0625f*cos(angle) - 0.0625f*sin(angle), 0.0625f*sin(angle) + 0.0625f*cos(angle)+up, 0.0f); glTexCoord3f(1.0f, 0.0f, 0.0f); glVertex3f(-0.0625f*cos(angle) - 0.0625f*sin(angle), -0.0625f*sin(angle) + 0.0625f*cos(angle)+up, 0.0f); glTexCoord3f(1.0f, 1.0f, 0.0f); glVertex3f(-0.0625f*cos(angle) + 0.0625f*sin(angle), -0.0625f*sin(angle) + -0.0625f*cos(angle)+up, 0.0f); glTexCoord3f(0.0f, 1.0f, 0.0f); glVertex3f(0.0625f*cos(angle) + 0.0625f*sin(angle), 0.0625f*sin(angle) + -0.0625f*cos(angle)+up, 0.0f); glEnd(); glTranslatef(5.0f, -0.5f, 0.0f); glPopMatrix(); glDisable(GL_TEXTURE_2D); }  

phil67rpg

phil67rpg

 

plane game

well I have drawn two plane sprites and have them move around the screen using keys. one them can also shoot bullets, I have drawn an animated collision sprite

phil67rpg

phil67rpg

Sign in to follow this  
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!