Explorar o código

menu selection logic

Abderrahmane Faiz hai 4 semanas
pai
achega
b75263307d
Modificáronse 1 ficheiros con 54 adicións e 6 borrados
  1. 54 6
      cmd/game/main.go

+ 54 - 6
cmd/game/main.go

@@ -103,17 +103,53 @@ func main() {
 	// the queue, or else a single-party deadlock might occur.
 	// s.EventQ() <- tcell.NewEventKey(tcell.KeyRune, rune('a'), 0)
 
+
+	curr_menu_item := 0
+	menu := true
+	gap_title_menu := 3
+	credits := false
 	// Event loop
 	for {
+		s.Clear()
+		
+		// Draw Title
+		xmax, ymax := s.Size()
+		for l:= range lines{
+			drawText(s,10, l, xmax, ymax, defStyle, lines[l])
+		}
+
+		// Draw Menu
+		if menu {
+			drawText(s, 10, len(lines)+gap_title_menu, xmax, ymax, defStyle,   "Arrows to navigate. Press ENTER to select")
+			switch curr_menu_item {
+			case 0:
+				drawText(s, 10, len(lines)+gap_title_menu+2, xmax, ymax, defStyle,   "▶ Start New Game")
+				drawText(s, 10, len(lines)+gap_title_menu+3, xmax, ymax, defStyle, "  Level Selector")
+				drawText(s, 10, len(lines)+gap_title_menu+4, xmax, ymax, defStyle, "  Credits")
+			case 1:
+				drawText(s, 10, len(lines)+gap_title_menu+2, xmax, ymax, defStyle,   "  Start New Game")
+				drawText(s, 10, len(lines)+gap_title_menu+3, xmax, ymax, defStyle, "▶ Level Selector")
+				drawText(s, 10, len(lines)+gap_title_menu+4, xmax, ymax, defStyle, "  Credits")
+			case 2:
+				drawText(s, 10, len(lines)+gap_title_menu+2, xmax, ymax, defStyle,   "  Start New Game")
+				drawText(s, 10, len(lines)+gap_title_menu+3, xmax, ymax, defStyle, "  Level Selector")
+				drawText(s, 10, len(lines)+gap_title_menu+4, xmax, ymax, defStyle, "▶ Credits")
+			}
+		}
+		
+		if credits {
+			drawText(s, 10, len(lines)+gap_title_menu, xmax,ymax, defStyle, "Abderrahmane Faiz")
+			drawText(s, 10, len(lines)+gap_title_menu+1, xmax,ymax, defStyle, "\u001B]8;;https://afaiz.dev\u001B\\https://afaiz.dev\u001B]8;;\u001B\\")
+			drawText(s, 10, len(lines)+gap_title_menu+2, xmax,ymax, defStyle, "\u001B]8;;mailto:learn_in_public@afaiz.dev\u001B\\learn_in_public@afaiz.dev\u001B]8;;\u001B\\")
+			drawText(s, 10, len(lines)+gap_title_menu+3, xmax,ymax, defStyle, "2026")
+			drawText(s, 10, len(lines)+gap_title_menu+5, xmax,ymax, defStyle, "Press ENTER to go back to the menu")
+		}
+		
 		// Update screen
 		s.Show()
 
 		// Poll event (this can be in a select statement as well)
 		ev := <-s.EventQ()
-		xmax, ymax := s.Size()
-		for l:= range lines{
-			drawText(s,10, l, xmax, ymax, defStyle, lines[l])
-		}
 		// Process event
 		switch ev := ev.(type) {
 		case *tcell.EventResize:
@@ -121,8 +157,20 @@ func main() {
 		case *tcell.EventKey:
 			if ev.Key() == tcell.KeyEscape || ev.Key() == tcell.KeyCtrlC {
 				return
-			} else if ev.Key() == tcell.KeyCtrlL {
-				s.Sync()
+			} else if ev.Key() == tcell.KeyUp && menu {
+				if curr_menu_item == 0 {
+					curr_menu_item = 2
+				} else {
+					curr_menu_item = curr_menu_item - 1
+				}
+			} else if ev.Key() == tcell.KeyDown && menu {
+				curr_menu_item = (curr_menu_item + 1) % 3
+			} else if ev.Key() == tcell.KeyEnter && credits {
+				credits = false
+				menu = true
+			}  else if ev.Key() == tcell.KeyEnter && curr_menu_item == 2 {
+				menu = false
+				credits = true
 			}
 		}
 	}