Commit deb91b3b authored by Ahmet Turan Koçak's avatar Ahmet Turan Koçak
Browse files

Initial commit

parents
<Application x:Class="Pinpon_Game.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Pinpon_Game"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace Pinpon_Game
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
using System.Windows;
[assembly:ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
<Window x:Class="Pinpon_Game.Game"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Pinpon_Game"
mc:Ignorable="d"
Title="Pinpon_Game" Height="450" Width="350" KeyDown="Window_KeyDown" Background="Black">
<StackPanel>
<Label FontSize="20" FontWeight="Bold" Foreground="White" Margin="85,0,0,0">PİNPON__GAME </Label>
<Canvas Name="Canvas1" Height="350" Width="250" Background="Ivory" >
</Canvas>
<Label FontSize="15" FontWeight="Bold" Foreground="White" >Oyuncu 1 = '← →'_____________________Oyuncu 2 = 'A -- D'</Label>
</StackPanel>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Pinpon_Game
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class Game : Window
{
private const int BallSize = 10;
private const int BallSpeed = 2;
private Ellipse Ball;
private Point BallPosition;
private Point BallVelocity; //Topun Güncel Hızı
Rectangle p1 = new Rectangle();
Rectangle p2 = new Rectangle();
Rect pinpon;
double x, y; //current position
int formW = 250; // Form
int formH = 350;
// 1.Oyuncu p1 oyuncusu
int p1W = 60;
int p1H = 8;
//2.Oyuncu p2 oyuncusu
int p2W = 60;
int p2H = 8;
bool z=false;
public Game()
{
InitializeComponent();
Canvas1.Children.Add(p1);
setP1();
Canvas1.Children.Add(p2);
setP2();
Ball = new Ellipse{Width = BallSize, Height = BallSize, Fill = Brushes.Black};
Canvas1.Children.Add(Ball);
//Topun başlangıç ​​konumunu ve hızı
BallPosition = new Point(Canvas1.ActualWidth / 10 - BallSize / 70,
Canvas1.ActualHeight / 10- BallSize / 70);
BallVelocity = new Point(2, 2);
// Enter Tusuna Basınca Oyunu Baslat
Canvas1.KeyDown += Window_KeyDown;
// Oyun döngüsünü başlat
CompositionTarget.Rendering += GameLoop;
}
private void setP1()
{
p1.Tag = "pinpon";
p1.Width = p1W;
p1.Height = p1H;
p1.Stroke = Brushes.Black;
p1.Fill = Brushes.Silver;
Canvas.SetLeft(p1, formW / 2);
Canvas.SetTop(p1, 334);
}
private void setP2()
{
p2.Tag = "pinpon";
p2.Width = p2W;
p2.Height = p2H;
p2.Stroke = Brushes.Black;
p2.Fill = Brushes.Silver;
Canvas.SetLeft(p2, formW / 2);
Canvas.SetTop(p2, 10);
// MessageBox.Show("Oyuna Baslamak için Enter Basınız");
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Left:
x = Canvas.GetLeft(p1) - 10;
if (x < 0) x = 0;
Canvas.SetLeft(p1, x);
break;
case Key.Right:
x = Canvas.GetLeft(p1) + 10;
if (x > formW - p1W) x = formW - p1W;
Canvas.SetLeft(p1, x);
break;
case Key.Enter:
BallVelocity.X = -BallSpeed;
BallVelocity.Y = BallSpeed;
break;
case Key.A:
x = Canvas.GetLeft(p2) - 10;
if (x < 0) x = 0;
Canvas.SetLeft(p2, x);
break;
case Key.D:
x = Canvas.GetLeft(p2) + 10;
if (x > formW - p2W) x = formW - p2W;
Canvas.SetLeft(p2, x);
break;
}
}
private void GameLoop(object sender, EventArgs e)
{
// Top pozisyonunu hıza göre güncelleyin
BallPosition.X += BallVelocity.X;
BallPosition.Y += BallVelocity.Y;
// Tuvalin kenarlarıyla çarpışma olup olmadığını kontrolü
if (BallPosition.X < 0 || BallPosition.X + BallSize > Canvas1.ActualWidth)
{
BallVelocity.X = -BallVelocity.X;
}
if (BallPosition.Y < 0 || BallPosition.Y + BallSize > Canvas1.ActualHeight)
{
//BallVelocity.Y = -BallVelocity.Y;
if(z)
{
Oyun_Bitti();
}
}
z=true;
// Topun Gidiş Yönleri
Canvas.SetLeft(Ball, BallPosition.X);
Canvas.SetTop(Ball, BallPosition.Y);
//Pinpon Carpma Kontrolü
pinpon = new Rect(Canvas.GetLeft(Ball), Canvas.GetTop(Ball), Ball.Width, Ball.Height);
foreach (var x in Canvas1.Children.OfType<Rectangle>())
{
Rect hit = new Rect(Canvas.GetLeft(x), Canvas.GetTop(x), x.Width, x.Height);
if ((string)x.Tag == "pinpon")
{
if (pinpon.IntersectsWith(hit))
{
BallVelocity.Y = -BallVelocity.Y;
}
}
}
}
private void Oyun_Bitti()
{
MessageBox.Show("---GAME OVER---");
this.Close();
}
}
}
<Window x:Class="Pinpon_Game.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Pinpon_Game"
mc:Ignorable="d"
Title="Pinpon_Game" Height="450" Width="350" Background="Black">
<StackPanel>
<Label FontSize="20" FontWeight="Bold" Foreground="White" Margin="85,0,0,0">PİNPON__GAME </Label>
<Button Name ="Oyun_Basla" FontSize="15" FontWeight="Bold" Background="Black" Click="Oyuna_Basla_Click" Margin="0,100,0,0" Width="100" Foreground="White">Oyuna Başla</Button>
<Button Name ="cikis" FontSize="15" Foreground="White" FontWeight="Bold" Background="Black" Click="Cikis_Click" Margin="0,40,0,0" Width="100">Çıkış</Button>
<!-- <Label FontSize="15" FontWeight="Bold" Foreground="White" >Oyuncu 1 = '← →'_____________________Oyuncu 2 = 'A D'</Label> -->
</StackPanel>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Pinpon_Game
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public void Oyuna_Basla_Click (Object Sender,RoutedEventArgs e){
Game g1 =new Game ();
this.Close();
g1.Show();
}
public void Cikis_Click (Object Sender,RoutedEventArgs e){
this.Close();
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v6.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v6.0": {
"Pinpon_Game/1.0.0": {
"runtime": {
"Pinpon_Game.dll": {}
}
}
}
},
"libraries": {
"Pinpon_Game/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
\ No newline at end of file
{
"runtimeOptions": {
"tfm": "net6.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "6.0.0"
}
]
}
}
\ No newline at end of file
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
#pragma checksum "..\..\..\App.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "EE65A630446DDBFA319E0DF597082753D0F51D75"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using Pinpon_Game;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Controls.Ribbon;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Shell;
namespace Pinpon_Game {
/// <summary>
/// App
/// </summary>
public partial class App : System.Windows.Application {
/// <summary>
/// InitializeComponent
/// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "6.0.2.0")]
public void InitializeComponent() {
#line 5 "..\..\..\App.xaml"
this.StartupUri = new System.Uri("MainWindow.xaml", System.UriKind.Relative);
#line default
#line hidden
}
/// <summary>
/// Application Entry Point.
/// </summary>
[System.STAThreadAttribute()]
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "6.0.2.0")]
public static void Main() {
Pinpon_Game.App app = new Pinpon_Game.App();
app.InitializeComponent();
app.Run();
}
}
}
#pragma checksum "..\..\..\App.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "EE65A630446DDBFA319E0DF597082753D0F51D75"
//------------------------------------------------------------------------------
// <auto-generated>
// Bu kod araç tarafından oluşturuldu.
// Çalışma Zamanı Sürümü:4.0.30319.42000
//
// Bu dosyada yapılacak değişiklikler yanlış davranışa neden olabilir ve
// kod yeniden oluşturulursa kaybolur.
// </auto-generated>
//------------------------------------------------------------------------------
using Pinpon_Game;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Controls.Ribbon;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Shell;
namespace Pinpon_Game {
/// <summary>
/// App
/// </summary>
public partial class App : System.Windows.Application {
/// <summary>
/// InitializeComponent
/// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "6.0.2.0")]
public void InitializeComponent() {
#line 5 "..\..\..\App.xaml"
this.StartupUri = new System.Uri("MainWindow.xaml", System.UriKind.Relative);
#line default
#line hidden
}
/// <summary>
/// Application Entry Point.
/// </summary>
[System.STAThreadAttribute()]
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "6.0.2.0")]
public static void Main() {
Pinpon_Game.App app = new Pinpon_Game.App();
app.InitializeComponent();
app.Run();
}
}
}
#pragma checksum "..\..\..\Game.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "18519635E3F23468D47E81414F5FB6724E159F0B"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using Pinpon_Game;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Controls.Ribbon;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Shell;
namespace Pinpon_Game {
/// <summary>
/// Game
/// </summary>
public partial class Game : System.Windows.Window, System.Windows.Markup.IComponentConnector {
#line 11 "..\..\..\Game.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Canvas Canvas1;
#line default
#line hidden
private bool _contentLoaded;
/// <summary>
/// InitializeComponent
/// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "6.0.2.0")]
public void InitializeComponent() {
if (_contentLoaded) {
return;
}
_contentLoaded = true;
System.Uri resourceLocater = new System.Uri("/Pinpon_Game;component/game.xaml", System.UriKind.Relative);
#line 1 "..\..\..\Game.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater);
#line default
#line hidden
}
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "6.0.2.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
switch (connectionId)
{
case 1:
#line 8 "..\..\..\Game.xaml"
((Pinpon_Game.Game)(target)).KeyDown += new System.Windows.Input.KeyEventHandler(this.Window_KeyDown);
#line default
#line hidden
return;
case 2:
this.Canvas1 = ((System.Windows.Controls.Canvas)(target));
return;
}
this._contentLoaded = true;
}
}
}
#pragma checksum "..\..\..\Game.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "18519635E3F23468D47E81414F5FB6724E159F0B"
//------------------------------------------------------------------------------
// <auto-generated>
// Bu kod araç tarafından oluşturuldu.
// Çalışma Zamanı Sürümü:4.0.30319.42000
//
// Bu dosyada yapılacak değişiklikler yanlış davranışa neden olabilir ve
// kod yeniden oluşturulursa kaybolur.
// </auto-generated>
//------------------------------------------------------------------------------
using Pinpon_Game;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Controls.Ribbon;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Shell;
namespace Pinpon_Game {
/// <summary>
/// Game
/// </summary>
public partial class Game : System.Windows.Window, System.Windows.Markup.IComponentConnector {
#line 11 "..\..\..\Game.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Canvas Canvas1;
#line default
#line hidden
private bool _contentLoaded;
/// <summary>
/// InitializeComponent
/// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "6.0.2.0")]
public void InitializeComponent() {
if (_contentLoaded) {
return;
}
_contentLoaded = true;
System.Uri resourceLocater = new System.Uri("/Pinpon_Game;V1.0.0.0;component/game.xaml", System.UriKind.Relative);
#line 1 "..\..\..\Game.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater);
#line default
#line hidden
}
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "6.0.2.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
switch (connectionId)
{
case 1:
#line 8 "..\..\..\Game.xaml"
((Pinpon_Game.Game)(target)).KeyDown += new System.Windows.Input.KeyEventHandler(this.Window_KeyDown);
#line default
#line hidden
return;
case 2:
this.Canvas1 = ((System.Windows.Controls.Canvas)(target));
return;
}
this._contentLoaded = true;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment