Skip to content

Commit

Permalink
0.2.3-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
IamPurpleRed committed Jun 3, 2021
1 parent e84006a commit 3719eee
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 25 deletions.
73 changes: 50 additions & 23 deletions FinalProject/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public partial class Form1 : Form

bool enable1 = false; // 決定1P能不能按按鍵
bool enable2 = false; // 決定2P能不能按按鍵
bool key_w, key_s, key_a, key_d, key_space, key_caps, key_b, key_tab; // 1P按鍵

public Form1()
{
Expand Down Expand Up @@ -137,6 +138,13 @@ void initPage()
result_pictureBox1.Visible = false;
result_pictureBox2.Visible = false;

/* 使玩家按鍵失效 */
enable1 = false;
enable2 = false;

/* 按鍵按下偵測 */
key_w = key_s = key_a = key_d = key_space = key_caps = key_b = key_tab = false; // 1P按鍵

/* Player類別成員變數初始 */
p1.init();
p2.init();
Expand Down Expand Up @@ -194,8 +202,6 @@ private void countdown_timer_Tick(object sender, EventArgs e)
{
if (coundown_tick == 0)
{
enable1 = true;
enable2 = true;
system_player.SoundLocation = "src/countdown.wav";
system_player.Play();
countdown_pictureBox1.Visible = true;
Expand All @@ -208,6 +214,8 @@ private void countdown_timer_Tick(object sender, EventArgs e)
}
else
{
enable1 = true;
enable2 = true;
countdown_timer.Stop();
coundown_tick = 0;
countdown_pictureBox1.Visible = false;
Expand Down Expand Up @@ -397,6 +405,7 @@ void p1KO()
ko_player.URL = "src/ko.wav";
ko_player.controls.play();
enable1 = false;
key_w = key_s = key_a = key_d = key_space = key_caps = key_b = key_tab = false;
p1_timer.Interval = p1.drop_timer;
p2.KO++;
KO_pictureBox2.Image = KO_img.Images[p2.KO - 1];
Expand Down Expand Up @@ -437,8 +446,32 @@ private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (enable1)
{
/* 1P按鍵 */
if (e.KeyCode == Keys.Left)
if (e.KeyCode == Keys.Up) key_w = true;
if (e.KeyCode == Keys.Down) key_s = true;
if (e.KeyCode == Keys.Left) key_a = true;
if (e.KeyCode == Keys.Right) key_d = true;
if (e.KeyCode == Keys.Space) key_space = true;
if (e.KeyCode == Keys.CapsLock) key_caps = true;
if (e.KeyCode == Keys.B) key_b = true;
if (e.KeyCode == Keys.Tab) key_tab = true;

/* 1P按鍵 */
if (key_w)
{
int tmp_row = p1.block_row, tmp_col = p1.block_col, tmp_type = p1.block_type; // 先記錄原本block_row & block_col & block_type位置
p1.block_type = p1.rotateBlock(p1.block_row, p1.block_col, p1.block_type);
p1.eraseBlock(tmp_row, tmp_col, tmp_type);
p1.updateBlock(p1.block_row, p1.block_col, p1.block_type);
p1.predict_block_row = p1.block_row;
p1.predict_block_col = p1.block_col;
p1.predictBlock(p1.block_row, p1.block_col, p1.block_type);
p1.showGrids();
}
if (key_s)
{
p1_timer.Interval = 150;
}
if (key_a)
{
if (p1.directionX(p1.block_row, p1.block_col, p1.block_type, -1))
{
Expand All @@ -451,7 +484,7 @@ private void Form1_KeyDown(object sender, KeyEventArgs e)
p1.showGrids();
}
}
if (e.KeyCode == Keys.Right)
if (key_d)
{
if (p1.directionX(p1.block_row, p1.block_col, p1.block_type, 1))
{
Expand All @@ -464,22 +497,7 @@ private void Form1_KeyDown(object sender, KeyEventArgs e)
p1.showGrids();
}
}
if (e.KeyCode == Keys.Up)
{
int tmp_row = p1.block_row, tmp_col = p1.block_col, tmp_type = p1.block_type; // 先記錄原本block_row & block_col & block_type位置
p1.block_type = p1.rotateBlock(p1.block_row, p1.block_col, p1.block_type);
p1.eraseBlock(tmp_row, tmp_col, tmp_type);
p1.updateBlock(p1.block_row, p1.block_col, p1.block_type);
p1.predict_block_row = p1.block_row;
p1.predict_block_col = p1.block_col;
p1.predictBlock(p1.block_row, p1.block_col, p1.block_type);
p1.showGrids();
}
if (e.KeyCode == Keys.Down)
{
p1_timer.Interval = 100;
}
if (e.KeyCode == Keys.Space || e.KeyCode == Keys.CapsLock)
if (key_space || key_caps)
{
p1_timer.Stop();
while (p1.directionY(p1.block_row, p1.block_col, p1.block_type))
Expand All @@ -492,7 +510,7 @@ private void Form1_KeyDown(object sender, KeyEventArgs e)
p1BlockSet();
p1_timer.Start();
}
if ((e.KeyCode == Keys.B || e.KeyCode == Keys.Tab) && !p1.has_hold)
if ((key_b || key_tab) && !p1.has_hold)
{
p1.has_hold = true;

Expand Down Expand Up @@ -540,7 +558,16 @@ private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (enable1)
{
if (e.KeyCode == Keys.Down) p1_timer.Interval = p1.drop_timer; // TODO: 之後改回S
if (e.KeyCode == Keys.Up) key_w = false;
if (e.KeyCode == Keys.Down) key_s = false;
if (e.KeyCode == Keys.Left) key_a = false;
if (e.KeyCode == Keys.Right) key_d = false;
if (e.KeyCode == Keys.Space) key_space = false;
if (e.KeyCode == Keys.CapsLock) key_caps = false;
if (e.KeyCode == Keys.B) key_b = false;
if (e.KeyCode == Keys.Tab) key_tab = false;

if (!key_s) p1_timer.Interval = p1.drop_timer;
}
if (enable2)
{
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,8 @@ This repository is my personal final project of **"109-2 視窗程式設計"**.
* 地雷機制想要還原原作,不過實施難度偏高,考慮開一個新分支試著寫寫看,但是暫不納入正規進度
* **version 0.2.2-beta (2021/06/01):**
* 為了測試方便,在2P實作之前,**1P的WSAD鍵位暫時分別以上下左右鍵代替**
* 修正1P在按下**方塊快速下降鍵(S,目前為下鍵)**的同時被KO之後,1P方塊下降速率沒有回到正常速度的問題
* 修正receiveMine函式中,新增的地雷數計算結果可能會產生負整數的情況,此漏洞導致在重新繪製grids時會跳出例外狀況(index out of range)
* 修正1P在按下 **方塊快速下降鍵(S,目前為下鍵)** 的同時被KO之後,1P方塊下降速率沒有回到正常速度的問題
* 修正receiveMine函式中,新增的地雷數計算結果可能會產生負整數的情況,此漏洞導致在重新繪製grids時會跳出例外狀況(index out of range)
* **version 0.2.3-beta (2021/06/03):**
* 有一位優質的測試玩家在遊戲還在倒數的時候,手指很健康的一直按**方塊直接下降鍵(空白鍵)**,意外發現了在倒數畫面時,方塊就可以讓玩家直接下降的漏洞,此漏洞會使偵測KO的邏輯錯誤,導致誤判玩家KO的情況發生
* 重新撰寫偵測鍵盤按鍵的程式邏輯,此改進將會使玩家的操作更加順暢

0 comments on commit 3719eee

Please sign in to comment.