NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Media;
using System.Text;
using System.Windows.Forms;
using flappy.Properties;

namespace flappy
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

List<int> Pipe1 = new List<int>();
List<int> Pipe2 = new List<int>();
int pipeWith = 55;
int pipeDifferentY = 140;
int pipeDifferentX = 180;
bool start = true;
bool running;
int step = 5;
int OriginalX, OriginalY;
bool ResetPipes = false;
int points;
bool inPipe = false;
int score;
int ScoreDifferent;
int PipeWithMaxControl;
private void Die()
{
pictureBox1.Image = Resources.normal_bird;
running = false;
timer2.Enabled = false;
timer3.Enabled = false;
button1.Visible = true;
button1.Enabled = true;
ReadAndShowScore();
points = 0;
pictureBox1.Location = new Point(OriginalX, OriginalY);
ResetPipes = true;
Pipe1.Clear();

}
private void ReadAndShowScore()
{

using (StreamReader reader = new StreamReader("Score.ini"))
{
score = int.Parse(reader.ReadToEnd());
reader.Close();
if (int.Parse(label1.Text) == 0 | int.Parse(label1.Text) > 0)
{
ScoreDifferent = score - int.Parse(label1.Text) + 1;
}

if (score < int.Parse(label1.Text))
{
// MessageBox.Show(string.Format("Tebrikler, Eski Puanınızı Geçtiniz {0}, Yeni Puan : {1}", score, label1.Text), "Flappy Bird", MessageBoxButtons.OK, MessageBoxIcon.Information);
using (StreamWriter writer = new StreamWriter("Score.ini"))
{
writer.Write(label1.Text);
writer.Close();
}
}

if (score > int.Parse(label1.Text))
{
// MessageBox.Show(string.Format("Üzgünüz eski puanınızı geçemediniz {0}, En Yüksek Puan : {1}", score, label1.Text), "Flappy Bird", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

if (score == int.Parse(label1.Text))
{
// MessageBox.Show(string.Format("Puanınız eşit: {0}, {1}", score, label1.Text), "Flappy Bird", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}

private void StartGame()
{

ResetPipes = false;
timer1.Enabled = true;
timer2.Enabled = true;
timer3.Enabled = true;
PipeWithMaxControl = this.Width / 2 - 30;

Random random = new Random();
int num = random.Next(40, this.Height - this.pipeDifferentY);
int num1 = num + this.pipeDifferentY;
Pipe1.Clear();
Pipe1.Add(this.Width);
Pipe1.Add(num);
Pipe1.Add(this.Width);
Pipe1.Add(num1);

num = random.Next(40, (this.Height - pipeDifferentY));
num = num > PipeWithMaxControl ? (num - 40) : num;
num1 = num + pipeDifferentY;
Pipe2.Clear();
Pipe2.Add(this.Width + pipeDifferentX);
Pipe2.Add(num);
Pipe2.Add(this.Width + pipeDifferentX);
Pipe2.Add(num1);

button1.Visible = false;
button1.Enabled = false;
running = true;
Focus();

pictureBox1.Image = Resources.down_bird;

}

private void Form1_Load(object sender, EventArgs e)
{

OriginalX = pictureBox1.Location.X;
OriginalY = pictureBox1.Location.Y;
if (!File.Exists("Score.ini"))
{
File.Create("Score.ini").Dispose();
}

}

private void timer1_Tick(object sender, EventArgs e)
{
this.Invalidate();
}

private void button1_Click(object sender, EventArgs e)
{
StartGame();
}

private void timer2_Tick(object sender, EventArgs e)
{
if (Pipe1[0] + pipeWith <= 0 || start == true)
{
Random rnd = new Random();
int px = this.Width;
int py = rnd.Next(40, this.Height - pipeDifferentY);
py = py > PipeWithMaxControl ? (py - 40) : py;

var p2x = px;
var p2y = py + pipeDifferentY;
Pipe1.Clear();
Pipe1.Add(px);
Pipe1.Add(py);
Pipe1.Add(p2x);
Pipe1.Add(p2y);
}
else
{
Pipe1[0] = Pipe1[0] - 2;
Pipe1[2] = Pipe1[2] - 2;

}

if (Pipe2[0] + pipeWith <= 0)
{
Random rnd = new Random();
int px = this.Width;
int py = rnd.Next(40, this.Height - pipeDifferentY);
py = py > PipeWithMaxControl ? (py - 40) : py;

var p2x = px;
var p2y = py + pipeDifferentY;
int[] p1 = { px, py, p2x, p2y };
Pipe2.Clear();
Pipe2.Add(px);
Pipe2.Add(py);
Pipe2.Add(p2x);
Pipe2.Add(p2y);
}
else
{
Pipe2[0] = Pipe2[0] - 2;
Pipe2[2] = Pipe2[2] - 2;

}

if (start == true)
{
start = false;
}



}

private void Form1_Paint(object sender, PaintEventArgs e)
{
if (!ResetPipes && Pipe1.Any() && Pipe2.Any())
{
// ilk yukarı
e.Graphics.FillRectangle(Brushes.DarkGreen, new Rectangle(Pipe1[0], 0, pipeWith, Pipe1[1]));
e.Graphics.FillRectangle(Brushes.DarkGreen, new Rectangle(Pipe1[0] - 10, Pipe1[3] - pipeDifferentY -10, 75, 15));

//ilk aşağı
e.Graphics.FillRectangle(Brushes.DarkGreen, new Rectangle(Pipe1[2], Pipe1[3], pipeWith, this.Height - Pipe1[3]));
e.Graphics.FillRectangle(Brushes.DarkGreen, new Rectangle(Pipe1[2] - 10, Pipe1[3]-5, 75, 15));

// bir sonraki yukarı
e.Graphics.FillRectangle(Brushes.DarkGreen, new Rectangle(Pipe2[0], 0, pipeWith, Pipe2[1]));
e.Graphics.FillRectangle(Brushes.DarkGreen, new Rectangle(Pipe2[0] - 10, Pipe2[3] - pipeDifferentY-10, 75, 15));

// bir sonraki aşağı
e.Graphics.FillRectangle(Brushes.DarkGreen, new Rectangle(Pipe2[0], Pipe2[3], pipeWith, this.Height - Pipe2[3]));
e.Graphics.FillRectangle(Brushes.DarkGreen, new Rectangle(Pipe2[0] - 10, Pipe2[3]-5, 75, 15));

}
}

private void ChechForPoint()
{

Rectangle rec = pictureBox1.Bounds;
Rectangle rec1 = new Rectangle(Pipe1[2] + 20, Pipe1[3] - pipeDifferentY, 15, pipeDifferentY);
Rectangle rec2 = new Rectangle(Pipe2[2] + 20, Pipe2[3] - pipeDifferentY, 15, pipeDifferentY);
Rectangle intersect1 = Rectangle.Intersect(rec, rec1);
Rectangle intersect2 = Rectangle.Intersect(rec, rec2);
if (!ResetPipes | start)
{

if (intersect1 != Rectangle.Empty | intersect2 != Rectangle.Empty)
{
if (!inPipe)
{
points++;
// sound
SoundPlayer sp = new SoundPlayer(Properties.Resources.bading);
sp.Play();
inPipe = true;
}

}
else
{
inPipe = false;

}
}
}

private void CheckForCollsion()
{

Rectangle rec = pictureBox1.Bounds;
Rectangle rec1 = new Rectangle(Pipe1[0], 0, pipeWith, Pipe1[1]);
Rectangle rec2 = new Rectangle(Pipe1[2], Pipe1[3], pipeWith, this.Height - Pipe1[3]);
Rectangle rec3 = new Rectangle(Pipe2[0], 0, pipeWith, Pipe2[1]);
Rectangle rec4 = new Rectangle(Pipe2[0], Pipe2[3], pipeWith, this.Height - Pipe2[3]);

Rectangle intersect1 = Rectangle.Intersect(rec, rec1);
Rectangle intersect2 = Rectangle.Intersect(rec, rec2);
Rectangle intersect3 = Rectangle.Intersect(rec, rec3);
Rectangle intersect4 = Rectangle.Intersect(rec, rec4);

if (!ResetPipes | start)
{
if (intersect1 != Rectangle.Empty | intersect2 != Rectangle.Empty | intersect3 != Rectangle.Empty | intersect4 != Rectangle.Empty)
{
SoundPlayer sp = new SoundPlayer(Properties.Resources.smack);
sp.Play();
Die();
}
}
}

private void Form1_KeyDown(object sender, KeyEventArgs e)
{

if (running == false) return;
switch (e.KeyCode)
{

case Keys.Space:
step = -5;
pictureBox1.Image = Resources.normal_bird;
break;

}
}

private void timer3_Tick(object sender, EventArgs e)
{
pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y + step);



if (pictureBox1.Location.Y < 0)
{
pictureBox1.Location = new Point(pictureBox1.Location.X, 0);
}

if (pictureBox1.Location.Y + pictureBox1.Height > this.ClientSize.Height)
{
// pictureBox1.Location = new Point(pictureBox1.Location.X, this.ClientSize.Height - pictureBox1.Height);
SoundPlayer sp = new SoundPlayer(Properties.Resources.smack);
sp.Play();
Die();
goto step;
}

CheckForCollsion();

step: if (running)
{
ChechForPoint();
}

label1.Text = Convert.ToString(points);
}

private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (running == false) return;

switch (e.KeyCode)
{
case Keys.Space:
step = 5;
pictureBox1.Image = Resources.down_bird;

break;
}
}

}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.