102 lines
2.4 KiB
C++
102 lines
2.4 KiB
C++
|
/*
|
||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/cppFiles/main.cc to edit this template
|
||
|
*/
|
||
|
|
||
|
/*
|
||
|
* File: main.cpp
|
||
|
* Author: caleb
|
||
|
*
|
||
|
* Created on March 4, 2024, 7:18 PM
|
||
|
*/
|
||
|
|
||
|
#include <iostream>
|
||
|
#include <ncurses.h>
|
||
|
|
||
|
using namespace std;
|
||
|
#include "rockPaperScissors.h"
|
||
|
#include "main.h"
|
||
|
|
||
|
int main(){
|
||
|
int ch;
|
||
|
static int selection = 0;
|
||
|
static int * selectionPointer = &selection;
|
||
|
initscr();
|
||
|
raw();
|
||
|
keypad(stdscr, TRUE);
|
||
|
noecho();
|
||
|
//clear();
|
||
|
|
||
|
do {
|
||
|
switch(ch) {
|
||
|
case KEY_UP:
|
||
|
--selection;
|
||
|
break;
|
||
|
|
||
|
case KEY_DOWN:
|
||
|
++selection;
|
||
|
break;
|
||
|
case '\n':
|
||
|
getch();
|
||
|
endwin();
|
||
|
|
||
|
switch (selection) {
|
||
|
case 0:
|
||
|
gameLoop();
|
||
|
break;
|
||
|
case 1:
|
||
|
break;
|
||
|
case 2:
|
||
|
break;
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
// Ensure selection stays within bounds
|
||
|
selection = (selection < 0) ? 0 : selection;
|
||
|
selection = (selection > 2) ? 2 : selection;
|
||
|
//std::system("clear");
|
||
|
move(0, 0);
|
||
|
printw("%s", printMenu(selectionPointer).c_str());
|
||
|
refresh();
|
||
|
} while ((ch = getch()) != '#');
|
||
|
|
||
|
|
||
|
|
||
|
getch();
|
||
|
endwin();
|
||
|
}
|
||
|
|
||
|
|
||
|
std::string printMenu(int* selection) {
|
||
|
const int ARRAY_SIZE = 3;
|
||
|
std::string outputString = "";
|
||
|
std::string cursor[ARRAY_SIZE] = {"> ", " ", " "};
|
||
|
std::string menu[ARRAY_SIZE] = {"Rock Paper Scissors", "2D Arrays", "Binary Search"};
|
||
|
//printf("%i", *selection);
|
||
|
/*
|
||
|
if (*selection >= ARRAY_SIZE - 1) {
|
||
|
*selection = 0;
|
||
|
}
|
||
|
if (*selection < 0) {
|
||
|
*selection = ARRAY_SIZE - 1;
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
std::string temp;
|
||
|
for (int j = 0; j < *selection; ++j) {
|
||
|
temp = cursor[j];
|
||
|
cursor[j] = cursor[j + 1];
|
||
|
cursor[j + 1] = temp;
|
||
|
}
|
||
|
//cursor[0] = temp;
|
||
|
outputString.append("Use the arrow keys to navigate the menu. Press # to exit.\n");
|
||
|
for (int i = 0; i < ARRAY_SIZE; ++i) {
|
||
|
outputString.append(cursor[i]);
|
||
|
outputString.append(menu[i]);
|
||
|
outputString.append("\n");
|
||
|
}
|
||
|
return outputString;
|
||
|
}
|