Wrote Breakout, and only with minimal bugs this time!

This commit is contained in:
Richie Moch 2018-12-23 23:41:07 -06:00
parent 8f34b3a0c7
commit 87546f325f
10 changed files with 179 additions and 173 deletions

View file

@ -31,9 +31,9 @@
this.components = new System.ComponentModel.Container();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.changeSize = new System.Windows.Forms.Timer(this.components);
this.label1 = new System.Windows.Forms.TextBox();
this.btnOpt1 = new ShiftOS.Engine.UI.ShiftButton();
this.btnOpt2 = new ShiftOS.Engine.UI.ShiftButton();
this.label1 = new System.Windows.Forms.Label();
this.btnOpt1 = new System.Windows.Forms.Button();
this.btnOpt2 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
@ -42,7 +42,7 @@
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.pictureBox1.Image = global::ShiftOS.Engine.Properties.Resources.Symbolinfo;
this.pictureBox1.Location = new System.Drawing.Point(3, 35);
this.pictureBox1.Location = new System.Drawing.Point(3, 38);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(80, 70);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
@ -55,57 +55,47 @@
//
// label1
//
this.label1.BackColor = System.Drawing.Color.White;
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.label1.Font = new System.Drawing.Font("Lucida Console", 8.25F);
this.label1.Location = new System.Drawing.Point(90, 35);
this.label1.Multiline = true;
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Courier New", 8.25F);
this.label1.Location = new System.Drawing.Point(105, 63);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(256, 125);
this.label1.TabIndex = 6;
this.label1.Size = new System.Drawing.Size(49, 14);
this.label1.TabIndex = 3;
this.label1.Text = "label1";
//
// btnOpt1
//
this.btnOpt1.BackColor = System.Drawing.Color.White;
this.btnOpt1.FlatAppearance.BorderColor = System.Drawing.Color.Black;
this.btnOpt1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnOpt1.Font = new System.Drawing.Font("Lucida Console", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnOpt1.ForeColor = System.Drawing.Color.Black;
this.btnOpt1.Location = new System.Drawing.Point(105, 163);
this.btnOpt1.Margin = new System.Windows.Forms.Padding(0);
this.btnOpt1.MinimumSize = new System.Drawing.Size(75, 23);
this.btnOpt1.Location = new System.Drawing.Point(108, 171);
this.btnOpt1.Name = "btnOpt1";
this.btnOpt1.Padding = new System.Windows.Forms.Padding(3);
this.btnOpt1.Size = new System.Drawing.Size(105, 26);
this.btnOpt1.TabIndex = 7;
this.btnOpt1.Text = "shiftButton1";
this.btnOpt1.Size = new System.Drawing.Size(75, 23);
this.btnOpt1.TabIndex = 4;
this.btnOpt1.Text = "button1";
this.btnOpt1.UseVisualStyleBackColor = false;
this.btnOpt1.Click += new System.EventHandler(this.btnOpt1_Click);
//
// btnOpt2
//
this.btnOpt2.BackColor = System.Drawing.Color.White;
this.btnOpt2.FlatAppearance.BorderColor = System.Drawing.Color.Black;
this.btnOpt2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnOpt2.Font = new System.Drawing.Font("Lucida Console", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnOpt2.ForeColor = System.Drawing.Color.Black;
this.btnOpt2.Location = new System.Drawing.Point(229, 163);
this.btnOpt2.Margin = new System.Windows.Forms.Padding(0);
this.btnOpt2.MinimumSize = new System.Drawing.Size(75, 23);
this.btnOpt2.Location = new System.Drawing.Point(247, 171);
this.btnOpt2.Name = "btnOpt2";
this.btnOpt2.Padding = new System.Windows.Forms.Padding(3);
this.btnOpt2.Size = new System.Drawing.Size(105, 26);
this.btnOpt2.TabIndex = 8;
this.btnOpt2.Text = "shiftButton2";
this.btnOpt2.Size = new System.Drawing.Size(75, 23);
this.btnOpt2.TabIndex = 5;
this.btnOpt2.Text = "button2";
this.btnOpt2.UseVisualStyleBackColor = false;
this.btnOpt1.Click += new System.EventHandler(this.btnOpt1_Click);
//
// InfoboxTemplate
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.btnOpt2);
this.Controls.Add(this.btnOpt1);
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox1);
this.Font = new System.Drawing.Font("Courier New", 8.25F);
this.Name = "InfoboxTemplate";
this.Size = new System.Drawing.Size(438, 210);
this.Load += new System.EventHandler(this.InfoboxTemplate_Load);
@ -118,8 +108,8 @@
#endregion
public System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Timer changeSize;
public System.Windows.Forms.TextBox label1;
private UI.ShiftButton btnOpt1;
private UI.ShiftButton btnOpt2;
private System.Windows.Forms.Button btnOpt1;
private System.Windows.Forms.Button btnOpt2;
public System.Windows.Forms.Label label1;
}
}

View file

@ -51,7 +51,6 @@ namespace ShiftOS.Engine.WindowManager
void btnOpt1_Click(object sender, EventArgs e)
{
isOK = true;
MessageBox.Show("button was clicked");
ParentForm?.Close();
}
@ -62,9 +61,6 @@ namespace ShiftOS.Engine.WindowManager
case "No":
isNo = true;
ParentForm?.Close();
break;
case "Cancel":
isNo = true;
break;
}
}

View file

@ -40,6 +40,12 @@ namespace ShiftOS.Engine.WindowManager
Title = { Text = title }
};
if (showAsInfobox)
{
app.btnMin.Visible = false;
app.btnMax.Visible = false;
}
app.Width = content.Width + app.leftSide.Width + app.rightSide.Width;
app.Height = content.Height + app.bottomSide.Height + app.titleBar.Height;

View file

@ -1,6 +1,6 @@
namespace ShiftOS.Main.Apps
{
partial class Pong
partial class Breakout
{
/// <summary>
/// Required designer variable.
@ -29,37 +29,17 @@
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.playerPaddle = new System.Windows.Forms.PictureBox();
this.cpuPaddle = new System.Windows.Forms.PictureBox();
this.ball = new System.Windows.Forms.PictureBox();
this.gameTimer = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.playerPaddle)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.cpuPaddle)).BeginInit();
this.playerPaddle = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.ball)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.playerPaddle)).BeginInit();
this.SuspendLayout();
//
// playerPaddle
//
this.playerPaddle.BackColor = System.Drawing.Color.White;
this.playerPaddle.Location = new System.Drawing.Point(27, 153);
this.playerPaddle.Name = "playerPaddle";
this.playerPaddle.Size = new System.Drawing.Size(22, 103);
this.playerPaddle.TabIndex = 0;
this.playerPaddle.TabStop = false;
//
// cpuPaddle
//
this.cpuPaddle.BackColor = System.Drawing.Color.White;
this.cpuPaddle.Location = new System.Drawing.Point(751, 153);
this.cpuPaddle.Name = "cpuPaddle";
this.cpuPaddle.Size = new System.Drawing.Size(22, 103);
this.cpuPaddle.TabIndex = 1;
this.cpuPaddle.TabStop = false;
//
// ball
//
this.ball.BackColor = System.Drawing.Color.White;
this.ball.Location = new System.Drawing.Point(390, 201);
this.ball.Location = new System.Drawing.Point(393, 229);
this.ball.Name = "ball";
this.ball.Size = new System.Drawing.Size(18, 18);
this.ball.TabIndex = 2;
@ -70,31 +50,36 @@
this.gameTimer.Interval = 20;
this.gameTimer.Tick += new System.EventHandler(this.gameTimer_Tick);
//
// playerPaddle
//
this.playerPaddle.BackColor = System.Drawing.Color.White;
this.playerPaddle.Location = new System.Drawing.Point(337, 421);
this.playerPaddle.Name = "playerPaddle";
this.playerPaddle.Size = new System.Drawing.Size(142, 15);
this.playerPaddle.TabIndex = 3;
this.playerPaddle.TabStop = false;
//
// Pong
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Black;
this.Controls.Add(this.ball);
this.Controls.Add(this.cpuPaddle);
this.Controls.Add(this.playerPaddle);
this.Controls.Add(this.ball);
this.ForeColor = System.Drawing.Color.White;
this.Name = "Pong";
this.Size = new System.Drawing.Size(801, 470);
this.Size = new System.Drawing.Size(664, 470);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Pong_KeyDown);
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Pong_KeyUp);
((System.ComponentModel.ISupportInitialize)(this.playerPaddle)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.cpuPaddle)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.ball)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.playerPaddle)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox playerPaddle;
private System.Windows.Forms.PictureBox cpuPaddle;
private System.Windows.Forms.PictureBox ball;
private System.Windows.Forms.Timer gameTimer;
private System.Windows.Forms.PictureBox playerPaddle;
}
}

View file

@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ShiftOS.Engine.WindowManager;
namespace ShiftOS.Main.Apps
{
public partial class Breakout : UserControl
{
bool goLeft = false;
bool goRight = false;
int speed = 5;
float ballX = 5;
float ballY = 5;
int rows = 5;
int col = 8;
public PictureBox[,] blocks;
public Breakout()
{
InitializeComponent();
DrawBlocks();
gameTimer.Start();
ResetToRest();
}
void ResetToRest()
{
ball.Location = new Point((int)Math.Round(this.Width / 2d, 0), (int)Math.Round(this.Height / 2d, 0));
playerPaddle.Location = new Point((int)Math.Round(ClientSize.Width / 2d, 0), playerPaddle.Location.Y);
}
private void Pong_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.A && playerPaddle.Left > 0) goLeft = true;
if (e.KeyCode == Keys.D && playerPaddle.Left + playerPaddle.Width < this.Width) goRight = true;
}
private void Pong_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.A) goLeft = false;
if (e.KeyCode == Keys.D) goRight = false;
}
private void gameTimer_Tick(object sender, EventArgs e)
{
ball.Top += (int)ballY;
ball.Left += (int)ballX;
if (ball.Bottom > ClientSize.Height || ball.Top < 0) ballY = -ballY;
if (ball.Right > ClientSize.Width || ball.Left < 0) ballX = -ballX;
if (ball.Bounds.IntersectsWith(playerPaddle.Bounds)) ballY = -ballY;
if (goRight) playerPaddle.Left += 8;
if (goLeft) playerPaddle.Left -= 8;
if (playerPaddle.Left < 1) goLeft = false;
if (playerPaddle.Left + playerPaddle.Width > this.Width) goRight = false;
for (int j = 0; j < rows; j++)
{
for (int i = 0; i < col; i++)
{
if (ball.Bounds.IntersectsWith(blocks[j,i].Bounds) && blocks[j,i].Visible)
{
ballY = -ballY;
blocks[j,i].Visible = false;
}
}
}
if (ball.Top + ball.Height > ClientSize.Height)
{
gameTimer.Stop();
var infoBox = ShiftWM.StartInfoboxSession("Breakout - You Lose! ", "It appears that you have lost the game, meaning\nall codepoints won were lost. Would you\nlike to try again?", InfoboxTemplate.ButtonType.YesNo);
ShiftWM.StartInfoboxSession(null, infoBox.isOK.ToString(), InfoboxTemplate.ButtonType.Ok);
if (infoBox.isOK)
{
DrawBlocks();
ResetToRest();
gameTimer.Start();
}
}
}
private void DrawBlocks()
{
int h = 20;
int w = 75;
blocks = new PictureBox[rows, col];
for (int j = 0; j < rows; j++)
{
for (int i = 0; i < col; i++)
{
blocks[j, i] = new PictureBox();
blocks[j, i].Height = h;
blocks[j, i].Width = w;
blocks[j, i].Top = h * j;
blocks[j, i].Left = w * i;
blocks[j, i].Paint += (o, a) =>
{
Rectangle rect = new Rectangle(blocks[j,i].Location.X, blocks[j,i].Location.Y, blocks[j,i].ClientSize.Width, blocks[j,i].ClientSize.Height);
rect.Inflate(1,1); // border thickness
ControlPaint.DrawBorder(a.Graphics, rect, Color.Black, ButtonBorderStyle.Solid);
};
this.Controls.Add(blocks[j, i]);
}
}
}
}
}

View file

@ -1,83 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ShiftOS.Main.Apps
{
public partial class Pong : UserControl
{
bool goUp = false;
bool goDown = false;
int speed = 5;
float ballX = 5;
float ballY = 5;
public Pong()
{
InitializeComponent();
gameTimer.Start();
ResetToRest();
}
void ResetToRest()
{
ball.Location = new Point((int)Math.Round(this.Width / 2d, 0), (int)Math.Round(this.Height / 2d, 0));
playerPaddle.Location = new Point(playerPaddle.Location.X, (int)Math.Round(this.Height / 2d, 0));
cpuPaddle.Location = new Point(cpuPaddle.Location.X, (int)Math.Round(this.Height / 2d, 0));
}
private void Pong_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.W) goUp = true;
if (e.KeyCode == Keys.S) goDown = true;
}
private void Pong_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.W) goUp = false;
if (e.KeyCode == Keys.S) goDown = false;
}
private void gameTimer_Tick(object sender, EventArgs e)
{
ball.Top -= (int)ballY;
ball.Left -= (int)ballX;
//CPU
if (ballX < 0)
{
if (ball.Top < cpuPaddle.Top + 51)
{
cpuPaddle.Top -= 5;
}
if(ball.Top > cpuPaddle.Top + 51)
{
cpuPaddle.Top += 5;
}
}
if (ball.Left < 0)
{
ResetToRest();
ballX = -ballX;
}
if (ball.Left + ball.Width > this.Width)
{
ResetToRest();
ballX = -ballX;
}
if (ball.Top < 0 || ball.Top + ball.Height > this.Height) ballY = -ballY;
if (ball.Bounds.IntersectsWith(playerPaddle.Bounds) || ball.Bounds.IntersectsWith(cpuPaddle.Bounds)) ballX = -ballX;
if (goUp && playerPaddle.Top > 0) playerPaddle.Top -= 8;
if (goDown && playerPaddle.Top < this.Height) playerPaddle.Top += 8;
}
}
}

View file

@ -35,7 +35,7 @@
this.terminalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.fileSkimmerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.textPadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.pongToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.breakOutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.shifterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@ -62,7 +62,7 @@
this.terminalToolStripMenuItem,
this.fileSkimmerToolStripMenuItem,
this.textPadToolStripMenuItem,
this.pongToolStripMenuItem,
this.breakOutToolStripMenuItem,
this.shifterToolStripMenuItem});
this.applicationsToolStripMenuItem.Font = new System.Drawing.Font("Courier New", 9F);
this.applicationsToolStripMenuItem.ForeColor = System.Drawing.Color.White;
@ -91,12 +91,12 @@
this.textPadToolStripMenuItem.Text = "TextPad";
this.textPadToolStripMenuItem.Click += new System.EventHandler(this.textPadToolStripMenuItem_Click);
//
// pongToolStripMenuItem
// breakOutToolStripMenuItem
//
this.pongToolStripMenuItem.Name = "pongToolStripMenuItem";
this.pongToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.pongToolStripMenuItem.Text = "Pong";
this.pongToolStripMenuItem.Click += new System.EventHandler(this.pongToolStripMenuItem_Click);
this.breakOutToolStripMenuItem.Name = "breakOutToolStripMenuItem";
this.breakOutToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.breakOutToolStripMenuItem.Text = "Breakout";
this.breakOutToolStripMenuItem.Click += new System.EventHandler(this.breakOutToolStripMenuItem_Click);
//
// shifterToolStripMenuItem
//
@ -132,7 +132,7 @@
private System.Windows.Forms.ToolStripMenuItem terminalToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem fileSkimmerToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem textPadToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem pongToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem breakOutToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem shifterToolStripMenuItem;
}
}

View file

@ -42,9 +42,9 @@ namespace ShiftOS.Main
ShiftWM.Init(new Apps.TextPad(), "TextPad", Properties.Resources.iconTextPad);
}
private void pongToolStripMenuItem_Click(object sender, EventArgs e)
private void breakOutToolStripMenuItem_Click(object sender, EventArgs e)
{
ShiftWM.Init(new Apps.Pong(), "Pong", null);
ShiftWM.Init(new Apps.Breakout(), "Breakout", null);
}
}

View file

@ -52,11 +52,11 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Apps\Pong.cs">
<Compile Include="Apps\Breakout.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Apps\Pong.Designer.cs">
<DependentUpon>Pong.cs</DependentUpon>
<Compile Include="Apps\Breakout.Designer.cs">
<DependentUpon>Breakout.cs</DependentUpon>
</Compile>
<Compile Include="Desktop.cs">
<SubType>Form</SubType>
@ -107,8 +107,8 @@
<Compile Include="Terminal\Commands\upgrade.cs" />
<Compile Include="Terminal\TerminalBackend.cs" />
<Compile Include="Terminal\TerminalCommand.cs" />
<EmbeddedResource Include="Apps\Pong.resx">
<DependentUpon>Pong.cs</DependentUpon>
<EmbeddedResource Include="Apps\Breakout.resx">
<DependentUpon>Breakout.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Desktop.resx">
<DependentUpon>Desktop.cs</DependentUpon>